Issue #1795 speed up publish by optimizing publish time updates in grid histories
Change-Id: I43c3f63d60832c49c6d02dab97c47d2b1f12f1c8 Former-commit-id: 788242460621edfffaf2a2c62c0c5b01da6c0e09
This commit is contained in:
parent
93e99b64a6
commit
235952a115
5 changed files with 136 additions and 7 deletions
|
@ -28,6 +28,7 @@ import java.util.Collections;
|
|||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -111,6 +112,7 @@ import com.raytheon.uf.edex.database.query.DatabaseQuery;
|
|||
* 01/21/12 #1504 randerso Back ported change to use ParameterMapper into 13.1.2
|
||||
* 02/10/13 #1603 randerso Eliminated unnecessary conversion from lists to arrays
|
||||
* 02/12/13 #1608 randerso Changed to use explicit deletes for groups and datasets
|
||||
* 03/15/13 #1795 njensen Added updatePublishTime()
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -478,6 +480,7 @@ public class GFEDao extends DefaultPluginDao {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Deprecated
|
||||
public void updateGridHistories(ParmID parmId,
|
||||
Map<TimeRange, List<GridDataHistory>> history)
|
||||
throws DataAccessLayerException {
|
||||
|
@ -1138,4 +1141,59 @@ public class GFEDao extends DefaultPluginDao {
|
|||
&& (id.getParmName().startsWith("mxt") || id.getParmName()
|
||||
.startsWith("mnt"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the publish times in the database of all provided
|
||||
* GridDataHistories. Does not alter the publish times in memory.
|
||||
*
|
||||
* @param history
|
||||
* the histories to alter in the database
|
||||
* @param publishTime
|
||||
* the publish time to update to
|
||||
* @throws DataAccessLayerException
|
||||
*/
|
||||
public void updatePublishTime(List<GridDataHistory> history,
|
||||
Date publishTime) throws DataAccessLayerException {
|
||||
StringBuilder query = new StringBuilder();
|
||||
query.append("update gfe_gridhistory set publishtime=:publishtime where key in (");
|
||||
Iterator<GridDataHistory> itr = history.iterator();
|
||||
while (itr.hasNext()) {
|
||||
query.append(itr.next().getKey());
|
||||
if (itr.hasNext()) {
|
||||
query.append(",");
|
||||
}
|
||||
}
|
||||
query.append(");");
|
||||
|
||||
Session sess = null;
|
||||
Transaction tx = null;
|
||||
|
||||
try {
|
||||
sess = getHibernateTemplate().getSessionFactory().openSession();
|
||||
tx = sess.beginTransaction();
|
||||
Query q = sess.createSQLQuery(query.toString());
|
||||
q.setTimestamp("publishtime", publishTime);
|
||||
q.executeUpdate();
|
||||
tx.commit();
|
||||
} catch (Exception e) {
|
||||
if (tx != null) {
|
||||
try {
|
||||
tx.rollback();
|
||||
tx = null;
|
||||
} catch (Exception e1) {
|
||||
logger.error("Error occurred rolling back transaction", e1);
|
||||
}
|
||||
}
|
||||
throw new DataAccessLayerException("Error updating history", e);
|
||||
} finally {
|
||||
if (sess != null) {
|
||||
try {
|
||||
sess.close();
|
||||
} catch (Exception e) {
|
||||
statusHandler.error(
|
||||
"Error occurred closing database session", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
package com.raytheon.edex.plugin.gfe.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -64,6 +65,7 @@ import com.raytheon.uf.edex.database.plugin.PluginFactory;
|
|||
* 04/08/08 #875 bphillip Initial Creation
|
||||
* 06/17/08 #940 bphillip Implemented GFE Locking
|
||||
* 02/10/13 #1603 randerso Returned number of records purged from timePurge
|
||||
* 03/15/13 #1795 njensen Added updatePublishTime()
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -131,10 +133,34 @@ public class GridParm {
|
|||
return db.getGridHistory(id, trs);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ServerResponse<?> updateGridHistory(
|
||||
Map<TimeRange, List<GridDataHistory>> history) {
|
||||
ServerResponse<?> sr = new ServerResponse<String>();
|
||||
db.updateGridHistory(id, history);
|
||||
return db.updateGridHistory(id, history);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the publish times in the database of all provided
|
||||
* GridDataHistories. Does not alter the publish times in memory.
|
||||
*
|
||||
* @param history
|
||||
* the histories to alter in the database
|
||||
* @param publishTime
|
||||
* the publish time to update to
|
||||
* @return
|
||||
*/
|
||||
public ServerResponse<?> updatePublishTime(
|
||||
Collection<List<GridDataHistory>> history, Date publishTime) {
|
||||
ServerResponse<?> sr = null;
|
||||
List<GridDataHistory> oneList = new ArrayList<GridDataHistory>();
|
||||
for (List<GridDataHistory> innerList : history) {
|
||||
oneList.addAll(innerList);
|
||||
}
|
||||
if (!oneList.isEmpty()) {
|
||||
sr = db.updatePublishTime(oneList, publishTime);
|
||||
} else {
|
||||
sr = new ServerResponse<String>();
|
||||
}
|
||||
return sr;
|
||||
}
|
||||
|
||||
|
|
|
@ -90,6 +90,7 @@ import com.raytheon.uf.edex.database.purge.PurgeLogger;
|
|||
* fixed error which caused D2D purging to remove
|
||||
* smartInit hdf5 data
|
||||
* 03/07/13 #1773 njensen Logged commitGrid() times
|
||||
* 03/15/13 #1795 njensen Sped up commitGrid()
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -711,10 +712,11 @@ public class GridParmManager {
|
|||
histories.put(tr, histList);
|
||||
}
|
||||
|
||||
// update the histories into the source database, update the
|
||||
// update the publish times in the source database, update the
|
||||
// notifications
|
||||
historyUpdateTimer.start();
|
||||
sr.addMessages(sourceGP.updateGridHistory(histories));
|
||||
sr.addMessages(sourceGP.updatePublishTime(histories.values(),
|
||||
(Date) nowTime.clone()));
|
||||
// System.out.println("Updated " + histories.size() + " histories");
|
||||
historyUpdateTimer.stop();
|
||||
|
||||
|
@ -737,8 +739,14 @@ public class GridParmManager {
|
|||
destHistList.get(i).replaceValues(srcHistList.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
// only need to update the publish time on the destination histories
|
||||
// of grids that are not being saved (due to no changes), because
|
||||
// the saveGridSlices() call below will update the publish time
|
||||
// of the ones with changes
|
||||
historyUpdateTimer.start();
|
||||
destGP.updateGridHistory(destHistory);
|
||||
destGP.updatePublishTime(destHistory.values(),
|
||||
(Date) nowTime.clone());
|
||||
historyUpdateTimer.stop();
|
||||
|
||||
// save data directly to the official database (bypassing
|
||||
|
|
|
@ -22,6 +22,7 @@ package com.raytheon.edex.plugin.gfe.server.database;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -71,6 +72,7 @@ import com.raytheon.uf.common.time.TimeRange;
|
|||
* in the gfeBaseDataDir.
|
||||
* 02/10/13 #1603 randerso Moved removeFromDb, removeFromHDF5 and deleteModelHDF5
|
||||
* methods down to IFPGridDatabase
|
||||
* 03/15/13 #1795 njensen Added updatePublishTime()
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -442,6 +444,22 @@ public abstract class GridDatabase {
|
|||
+ this.getClass().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the publish times in the database of all provided
|
||||
* GridDataHistories. Does not alter the publish times in memory.
|
||||
*
|
||||
* @param history
|
||||
* the histories to alter in the database
|
||||
* @param publishTime
|
||||
* the publish time to update to
|
||||
* @return
|
||||
*/
|
||||
public ServerResponse<?> updatePublishTime(List<GridDataHistory> history,
|
||||
Date publishTime) {
|
||||
throw new UnsupportedOperationException("Not implemented for class "
|
||||
+ this.getClass().getName());
|
||||
}
|
||||
|
||||
public ServerResponse<?> saveGridSlices(ParmID parmId, TimeRange tr,
|
||||
List<IGridSlice> sliceData, WsId requestor,
|
||||
List<TimeRange> skipDelete) {
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.io.File;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -113,6 +114,7 @@ import com.vividsolutions.jts.io.WKTReader;
|
|||
* Added performance logging
|
||||
* 02/12/13 #1608 randerso Changed to explicitly call deleteGroups
|
||||
* 03/07/13 #1737 njensen Logged getGridData times
|
||||
* 03/15/13 #1795 njensen Added updatePublishTime()
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -1174,6 +1176,7 @@ public class IFPGridDatabase extends GridDatabase {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public ServerResponse<?> updateGridHistory(ParmID parmId,
|
||||
Map<TimeRange, List<GridDataHistory>> history) {
|
||||
ServerResponse<?> sr = new ServerResponse<String>();
|
||||
|
@ -1188,7 +1191,6 @@ public class IFPGridDatabase extends GridDatabase {
|
|||
"Unable to update grid history!!", e);
|
||||
}
|
||||
return sr;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2481,8 +2483,25 @@ public class IFPGridDatabase extends GridDatabase {
|
|||
Priority.PROBLEM,
|
||||
"Error deleting GFE model data from hdf5 for "
|
||||
+ dbId.toString(), e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerResponse<?> updatePublishTime(List<GridDataHistory> history,
|
||||
Date publishTime) {
|
||||
ServerResponse<?> sr = new ServerResponse<String>();
|
||||
GFEDao dao = null;
|
||||
try {
|
||||
dao = (GFEDao) PluginFactory.getInstance().getPluginDao("gfe");
|
||||
dao.updatePublishTime(history, publishTime);
|
||||
} catch (PluginException e1) {
|
||||
statusHandler.handle(Priority.PROBLEM, "Unable to get gfe dao", e1);
|
||||
} catch (DataAccessLayerException e) {
|
||||
statusHandler.handle(Priority.PROBLEM,
|
||||
"Unable to update grid history!", e);
|
||||
sr.addMessage("Error updating history");
|
||||
}
|
||||
return sr;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue