Merge "Issue #2348 Fix leak of D2DGridDatabase objects." into omaha_13.5.1.1

Former-commit-id: e6c5b29c9d [formerly 83574f2fff] [formerly e6c5b29c9d [formerly 83574f2fff] [formerly 9f222b38df [formerly b0261b95da14e9d783e57fd4270c9fff646b3b82]]]
Former-commit-id: 9f222b38df
Former-commit-id: 579c8323e5 [formerly 2f8a4e0078]
Former-commit-id: c7558575a6
This commit is contained in:
Ron Anderson 2013-09-17 08:36:12 -05:00 committed by Gerrit Code Review
commit 730729219d
3 changed files with 80 additions and 38 deletions

View file

@ -21,7 +21,6 @@
package com.raytheon.edex.plugin.gfe.cache.d2dparms;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@ -72,6 +71,8 @@ import com.raytheon.uf.edex.site.SiteAwareRegistry;
* Mar 20, 2013 #1774 randerso Changed to use GFDD2DDao
* Apr 01, 2013 #1774 randerso Moved wind component checking to GfeIngestNotificaionFilter
* May 14, 2013 #2004 randerso Added DBInvChangeNotifications when D2D data is purged
* Sep 12, 2013 #2348 randerso Changed to send DBInvChangeNotifications in a batch instead
* of one at a time.
*
* </pre>
*
@ -346,13 +347,8 @@ public class D2DParmIdCache {
putParmIDList(parmIds);
List<DatabaseID> currentDbInventory = this.getDatabaseIDs();
dbsToRemove.removeAll(currentDbInventory);
List<DBInvChangeNotification> invChgList = new ArrayList<DBInvChangeNotification>(
dbsToRemove.size());
for (DatabaseID dbId : dbsToRemove) {
invChgList.add(new DBInvChangeNotification(null, Arrays
.asList(dbId), siteID));
}
SendNotifications.send(invChgList);
SendNotifications.send(new DBInvChangeNotification(null,
dbsToRemove, siteID));
// inform GfeIngestNotificationFilter of removed dbs
GfeIngestNotificationFilter.purgeDbs(dbsToRemove);

View file

@ -100,6 +100,12 @@ import com.raytheon.uf.edex.database.purge.PurgeLogger;
* Removed inventory from DBInvChangedNotification
* 05/03/13 #1974 randerso Fixed error logging to include stack trace
* 05/14/13 #2004 randerso Added methods to synch GridParmManager across JVMs
* 09/12/13 #2348 randerso Added logging when database are added/removed from dbMap
* Fixed the synchronization of dbMap with the database inventory
* Changed to call D2DGridDatabase.getDatabase instead of calling
* the constructor directly to ensure the data exists before creating
* the D2DGridDatabase object
*
* </pre>
*
* @author bphillip
@ -1016,10 +1022,10 @@ public class GridParmManager {
sr.addMessage("VersionPurge failed - couldn't get inventory");
return sr;
}
List<DatabaseID> databases = sr.getPayload();
List<DatabaseID> currentInv = sr.getPayload();
// sort the inventory by site, type, model, time (most recent first)
Collections.sort(databases);
Collections.sort(currentInv);
// process the inventory looking for "old" unwanted databases
String model = null;
@ -1027,7 +1033,7 @@ public class GridParmManager {
String type = null;
int count = 0;
int desiredVersions = 0;
for (DatabaseID dbId : databases) {
for (DatabaseID dbId : currentInv) {
// new series?
if (!dbId.getSiteId().equals(site)
|| !dbId.getDbType().equals(type)
@ -1055,11 +1061,31 @@ public class GridParmManager {
}
}
List<DatabaseID> newInv = getDbInventory(siteID).getPayload();
List<DatabaseID> additions = new ArrayList<DatabaseID>(newInv);
additions.removeAll(currentInv);
List<DatabaseID> deletions = new ArrayList<DatabaseID>(currentInv);
deletions.removeAll(newInv);
// kludge to keep dbMap in synch until GridParmManager/D2DParmICache
// merge/refactor
dbMap.keySet().retainAll(databases);
List<DatabaseID> toRemove = new ArrayList<DatabaseID>(dbMap.keySet());
toRemove.removeAll(newInv);
for (DatabaseID dbId : toRemove) {
statusHandler
.info("Synching GridParmManager with database inventory, removing "
+ dbId);
dbMap.remove(dbId);
createDbNotification(siteID, databases);
// add any removals to the deletions list
// so notifications go to the other JVMs
if (!deletions.contains(dbId)) {
deletions.add(dbId);
}
}
createDbNotification(siteID, additions, deletions);
return sr;
}
@ -1220,8 +1246,8 @@ public class GridParmManager {
// ingested
String d2dModelName = serverConfig
.d2dModelNameMapping(modelName);
db = new D2DGridDatabase(serverConfig, d2dModelName,
dbId.getModelTimeAsDate());
db = D2DGridDatabase.getDatabase(serverConfig,
d2dModelName, dbId.getModelTimeAsDate());
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM,
e.getLocalizedMessage(), e);
@ -1244,6 +1270,7 @@ public class GridParmManager {
}
if ((db != null) && db.databaseIsValid()) {
statusHandler.info("getDb called, adding " + dbId);
dbMap.put(dbId, db);
}
}
@ -1255,6 +1282,8 @@ public class GridParmManager {
while (iter.hasNext()) {
DatabaseID dbId = iter.next();
if (dbId.getSiteId().equals(siteID)) {
statusHandler.info("purgeDbCache(" + siteID + "), removing "
+ dbId);
iter.remove();
}
}
@ -1370,18 +1399,6 @@ public class GridParmManager {
return sr;
}
private static void createDbNotification(String siteID,
List<DatabaseID> prevInventory) {
List<DatabaseID> newInventory = getDbInventory(siteID).getPayload();
List<DatabaseID> additions = new ArrayList<DatabaseID>(newInventory);
additions.removeAll(prevInventory);
List<DatabaseID> deletions = new ArrayList<DatabaseID>(prevInventory);
deletions.removeAll(newInventory);
createDbNotification(siteID, additions, deletions);
}
private static void createDbNotification(String siteID,
List<DatabaseID> additions, List<DatabaseID> deletions) {
if (!additions.isEmpty() || !deletions.isEmpty()) {
@ -1400,6 +1417,7 @@ public class GridParmManager {
"Unable to purge model database: " + id, e);
}
}
statusHandler.info("deallocateDb called, removing " + id);
dbMap.remove(id);
}
@ -1429,6 +1447,9 @@ public class GridParmManager {
}
for (DatabaseID dbId : invChanged.getDeletions()) {
statusHandler
.info("DBInvChangeNotification deletion received, removing "
+ dbId);
dbMap.remove(dbId);
}
}

View file

@ -43,7 +43,6 @@ import com.raytheon.edex.plugin.gfe.db.dao.GFED2DDao;
import com.raytheon.edex.plugin.gfe.paraminfo.GridParamInfo;
import com.raytheon.edex.plugin.gfe.paraminfo.GridParamInfoLookup;
import com.raytheon.edex.plugin.gfe.paraminfo.ParameterInfo;
import com.raytheon.edex.plugin.gfe.server.GridParmManager;
import com.raytheon.uf.common.comm.CommunicationException;
import com.raytheon.uf.common.dataplugin.PluginException;
import com.raytheon.uf.common.dataplugin.gfe.GridDataHistory;
@ -107,6 +106,9 @@ import com.raytheon.uf.edex.database.DataAccessLayerException;
* 04/17/2013 #1913 randerso Added GFE level mapping to replace GridTranslator
* 05/02/2013 #1969 randerso Removed unnecessary updateDbs method
* 05/03/2013 #1974 randerso Fixed error handling when no D2D level mapping found
* 09/12/2013 #2348 randerso Removed code that called getDb from getD2DDatabaseIdsFromDb
* Added function to create a D2DGridDatabase object only if there is
* data in postgres for the desired model/reftime
*
* </pre>
*
@ -135,6 +137,33 @@ public class D2DGridDatabase extends VGridDatabase {
gfeModelName, modelTime);
}
/**
* Get a D2DGridDatabase if it is available
*
* @param config
* configuration for site
* @param dbId
* DatabaseID of desired database
* @return D2DGridDatabase or null if not available
*/
public static D2DGridDatabase getDatabase(IFPServerConfig config,
String d2dModelName, Date refTime) {
try {
GFED2DDao dao = new GFED2DDao();
List<Date> result = dao.getModelRunTimes(d2dModelName, -1);
if (result.contains(refTime)) {
D2DGridDatabase db = new D2DGridDatabase(config, d2dModelName,
refTime);
return db;
}
return null;
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
return null;
}
}
/**
* Retrieves DatabaseIDs for all model runs of a given d2dModelName
*
@ -178,15 +207,7 @@ public class D2DGridDatabase extends VGridDatabase {
for (Date date : result) {
DatabaseID dbId = null;
dbId = getDbId(d2dModelName, date, config);
try {
GridDatabase db = GridParmManager.getDb(dbId);
if ((db != null) && !dbInventory.contains(dbId)) {
dbInventory.add(dbId);
}
} catch (GfeException e) {
statusHandler.handle(Priority.PROBLEM,
e.getLocalizedMessage(), e);
}
dbInventory.add(dbId);
}
return dbInventory;
} catch (PluginException e) {
@ -285,10 +306,14 @@ public class D2DGridDatabase extends VGridDatabase {
/**
* Constructs a new D2DGridDatabase
*
* For internal use only. External code should call
* D2DGridDatabase.getDatabase(IFPServerConfig, String, Date) to ensure
* objects are only created if data is present
*
* @param dbId
* The database ID of this database
*/
public D2DGridDatabase(IFPServerConfig config, String d2dModelName,
private D2DGridDatabase(IFPServerConfig config, String d2dModelName,
Date refTime) throws GfeException {
super(config);