From a50f42d93e78720fa041a520f7cf73027daa7b7f Mon Sep 17 00:00:00 2001 From: Sasha Sherstnev Date: Mon, 11 Nov 2013 17:25:16 +0000 Subject: [PATCH] Fix problem with filling new tables --- conf/Proteocache.properties | 2 +- .../cassandra/CassandraNativeConnector.java | 2 +- .../compbio/cassandra/CassandraNewTableWriter.java | 28 ++++++++------------ server/compbio/listeners/ContextListener.java | 1 + 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/conf/Proteocache.properties b/conf/Proteocache.properties index ffd1a6c..a5e72ab 100644 --- a/conf/Proteocache.properties +++ b/conf/Proteocache.properties @@ -3,7 +3,7 @@ # test server is 10.0.115.190 cassandra.host=localhost -cassandra.newtables.update=false; +cassandra.newtables.update=true ################################################################################# # Jpred sources diff --git a/datadb/compbio/cassandra/CassandraNativeConnector.java b/datadb/compbio/cassandra/CassandraNativeConnector.java index acb50de..59a2988 100644 --- a/datadb/compbio/cassandra/CassandraNativeConnector.java +++ b/datadb/compbio/cassandra/CassandraNativeConnector.java @@ -70,7 +70,7 @@ public class CassandraNativeConnector { + "predictions map, archive blob, LOG varchar, PRIMARY KEY(JobID));"); session.execute("CREATE TABLE IF NOT EXISTS JobDateInfo " - + "(jobday bigint, Total bigint, PRIMARY KEY(jobday));"); + + "(jobday bigint, Total bigint, Program varchar, Version varchar, PRIMARY KEY(jobday));"); session.execute("CREATE INDEX IF NOT EXISTS ProteinSeq ON ProteinRow (protein);"); session.execute("CREATE INDEX IF NOT EXISTS JobDateStamp ON ProteinData (jobtime);"); diff --git a/datadb/compbio/cassandra/CassandraNewTableWriter.java b/datadb/compbio/cassandra/CassandraNewTableWriter.java index 88a4ca2..0d68b1a 100644 --- a/datadb/compbio/cassandra/CassandraNewTableWriter.java +++ b/datadb/compbio/cassandra/CassandraNewTableWriter.java @@ -49,34 +49,28 @@ public class CassandraNewTableWriter { * fill new table */ public void FillNewTable() { - long date1 = CassandraNativeConnector.getEarliestDateInDB(); - Calendar start = Calendar.getInstance(); - start.setTime(new Date(date1)); + final long StartTime = System.currentTimeMillis(); + long erldate = CassandraNativeConnector.getEarliestDateInDB(); + Calendar runnicCal = Calendar.getInstance(); + runnicCal.setTime(new Date(erldate)); Calendar endcal = Calendar.getInstance(); - Date end = endcal.getTime(); - for (Date date = start.getTime(); !start.after(end); start.add(Calendar.DATE, 1), date = start.getTime()) { - final long startTime = System.currentTimeMillis(); - String query1 = "SELECT * FROM ProteinData WHERE jobtime = " + date.getTime() + ";"; - System.out.println("Query db: " + query1); + long endTime = endcal.getTime().getTime(); + for (Date date = runnicCal.getTime(); date.getTime() < endTime; runnicCal.add(Calendar.DATE, 1), date = runnicCal.getTime()) { try { - ResultSet results = session.execute(query1); - final long queryTime = System.currentTimeMillis(); - System.out.println("Query time for " + date.toString() + " is " + (queryTime - startTime) + " msec"); - String query2 = "INSERT INTO JobDateInfo " + "(jobday, Total)" + " VALUES (" + date.getTime() + "," + results.all().size() - + ");"; - System.out.println("Insert DB: " + query2); - session.execute(query2); + ResultSet results = session.execute("SELECT * FROM ProteinData WHERE jobtime = " + date.getTime() + ";"); + session.execute("INSERT INTO JobDateInfo " + "(jobday, Total)" + " VALUES (" + date.getTime() + "," + results.all().size() + + ");"); } catch (QueryExecutionException e) { e.printStackTrace(); } } - System.out.println("Table JobDateInfo filled"); + System.out.println("Table JobDateInfo filled: total time is " + (System.currentTimeMillis() - StartTime) + " msec"); } /* * fill a table with the database global parameters */ - public void FillParameters() { + public void FillMainDBParameters() { Date bubu = new Date(CassandraNativeConnector.getEarliestDateInDB()); System.out.println("Old EarliestJobDate is " + bubu.toString()); diff --git a/server/compbio/listeners/ContextListener.java b/server/compbio/listeners/ContextListener.java index a1ff9cb..ed15609 100644 --- a/server/compbio/listeners/ContextListener.java +++ b/server/compbio/listeners/ContextListener.java @@ -61,6 +61,7 @@ public class ContextListener implements ServletContextListener { FILL_NEWTABLE = initBooleanValue("cassandra.newtables.update"); if (FILL_NEWTABLE) { + System.out.println("Initializating new table update scheduler"); update_scheduler = Executors.newSingleThreadScheduledExecutor(); update_scheduler.schedule(new Runnable() { @Override -- 1.7.10.2