Skip to content

Commit

Permalink
Avoid to open an online-db store if it is already open
Browse files Browse the repository at this point in the history
  • Loading branch information
massimo-ferraro committed Aug 7, 2017
1 parent ab53ca8 commit d19641b
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,20 @@ private synchronized MVStore getStore(String workflowId) {
wfMVStore = storedWFMetrics.get(workflowId);
else {
LOGGER.debug("Opening file for workflow {}", workflowId);
wfMVStore = MVStore.open(config.getOnlineDbDir().toString() + File.separator + STORED_WORKFLOW_PREFIX + workflowId);
wfMVStore = openStore(workflowId);
storedWFMetrics.put(workflowId, wfMVStore);
}
return wfMVStore;
}

private MVStore openStore(String workflowId) {
return MVStore.open(config.getOnlineDbDir().toString() + File.separator + STORED_WORKFLOW_PREFIX + workflowId);
}

private boolean storeOpen(String workflowId) {
return storedWFMetrics.containsKey(workflowId);
}

@Override
public void storeMetrics(String workflowId, OnlineStep step, Map<String, String> metrics) {
LOGGER.info("Storing metrics for wf {} and step {}", workflowId, step.name());
Expand Down Expand Up @@ -847,7 +855,7 @@ public OnlineWorkflowParameters getWorkflowParameters(String workflowId) {
if (isWorkflowStored(workflowId)) {
MVStore wfMVStore = null;
try {
wfMVStore = MVStore.open(config.getOnlineDbDir().toString() + File.separator + STORED_WORKFLOW_PREFIX + workflowId);
wfMVStore = storeOpen(workflowId) ? getStore(workflowId) : openStore(workflowId);
if (wfMVStore.hasMap(STORED_PARAMETERS_MAP_NAME)) {
MVMap<String, String> storedParametersMap = wfMVStore.openMap(STORED_PARAMETERS_MAP_NAME, mapBuilder);
DateTime baseCaseDate = DateTime.parse(storedParametersMap.get(STORED_PARAMETERS_BASECASE_KEY));
Expand Down Expand Up @@ -903,7 +911,7 @@ public OnlineWorkflowParameters getWorkflowParameters(String workflowId) {
return null;
}
} finally {
if (wfMVStore != null) {
if (wfMVStore != null && !storeOpen(workflowId)) {
wfMVStore.close();
}
}
Expand Down

0 comments on commit d19641b

Please sign in to comment.