ASTERIXDB-1498: Validate DatasetLifeCycleManager State
This change adds appropriate error message when trying
to access a dataset/index after the DatasetLifeCycleManager
has been stopped.
Change-Id: Ie2c4a506103e0c04ec6b203253144603704e7e5c
Reviewed-on: https://asterix-gerrit.ics.uci.edu/964
Reviewed-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <michael.blow@couchbase.com>
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/context/DatasetLifecycleManager.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/context/DatasetLifecycleManager.java
index 84317ea..f4eec05 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/context/DatasetLifecycleManager.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/context/DatasetLifecycleManager.java
@@ -63,6 +63,7 @@
private final ILogManager logManager;
private final LogRecord logRecord;
private final int numPartitions;
+ private boolean stopped = false;
public DatasetLifecycleManager(AsterixStorageProperties storageProperties,
ILocalResourceRepository resourceRepository, int firstAvilableUserDatasetID, ILogManager logManager,
@@ -82,6 +83,7 @@
@Override
public synchronized IIndex getIndex(String resourcePath) throws HyracksDataException {
+ validateDatasetLifecycleManagerState();
int datasetID = getDIDfromResourcePath(resourcePath);
long resourceID = getResourceIDfromResourcePath(resourcePath);
return getIndex(datasetID, resourceID);
@@ -89,6 +91,7 @@
@Override
public synchronized IIndex getIndex(int datasetID, long resourceID) throws HyracksDataException {
+ validateDatasetLifecycleManagerState();
DatasetInfo dsInfo = datasetInfos.get(datasetID);
if (dsInfo == null) {
return null;
@@ -102,6 +105,7 @@
@Override
public synchronized void register(String resourcePath, IIndex index) throws HyracksDataException {
+ validateDatasetLifecycleManagerState();
int did = getDIDfromResourcePath(resourcePath);
long resourceID = getResourceIDfromResourcePath(resourcePath);
DatasetInfo dsInfo = datasetInfos.get(did);
@@ -138,6 +142,7 @@
@Override
public synchronized void unregister(String resourcePath) throws HyracksDataException {
+ validateDatasetLifecycleManagerState();
int did = getDIDfromResourcePath(resourcePath);
long resourceID = getResourceIDfromResourcePath(resourcePath);
@@ -183,6 +188,7 @@
@Override
public synchronized void open(String resourcePath) throws HyracksDataException {
+ validateDatasetLifecycleManagerState();
int did = getDIDfromResourcePath(resourcePath);
long resourceID = getResourceIDfromResourcePath(resourcePath);
@@ -267,6 +273,7 @@
@Override
public synchronized void close(String resourcePath) throws HyracksDataException {
+ validateDatasetLifecycleManagerState();
int did = getDIDfromResourcePath(resourcePath);
long resourceID = getResourceIDfromResourcePath(resourcePath);
@@ -348,6 +355,12 @@
}
}
+ private void validateDatasetLifecycleManagerState() throws HyracksDataException {
+ if (stopped) {
+ throw new HyracksDataException(DatasetLifecycleManager.class.getSimpleName() + " was stopped.");
+ }
+ }
+
private static abstract class Info {
protected int referenceCount;
protected boolean isOpen;
@@ -630,6 +643,9 @@
@Override
public synchronized void stop(boolean dumpState, OutputStream outputStream) throws IOException {
+ if (stopped) {
+ return;
+ }
if (dumpState) {
dumpState(outputStream);
}
@@ -639,6 +655,7 @@
datasetVirtualBufferCachesMap.clear();
datasetOpTrackers.clear();
datasetInfos.clear();
+ stopped = true;
}
@Override