[ASTERIXDB-2308][STO] Prevent Race To Allocate Memory Components
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- Ensure concurrent threads will not attempt
to allocate memory components twice.
- Synchronize index lifecycle operations.
- Remove unused methods.
Change-Id: Ibd424ba6a2a68939f6ab8a4338c2f6c0c8057ed1
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2489
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ian Maxon <imaxon@apache.org>
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndex.java b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndex.java
index af8c702..2db2f79 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndex.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndex.java
@@ -41,7 +41,6 @@
import org.apache.hyracks.storage.am.common.ophelpers.IndexOperation;
import org.apache.hyracks.storage.am.lsm.common.api.IComponentFilterHelper;
import org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent;
-import org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent.ComponentState;
import org.apache.hyracks.storage.am.lsm.common.api.ILSMComponentFilterFrameFactory;
import org.apache.hyracks.storage.am.lsm.common.api.ILSMComponentId;
import org.apache.hyracks.storage.am.lsm.common.api.ILSMComponentId.IdCompareResult;
@@ -97,7 +96,7 @@
protected final boolean durable;
protected boolean isActive;
protected final AtomicBoolean[] flushRequests;
- protected boolean memoryComponentsAllocated = false;
+ protected volatile boolean memoryComponentsAllocated = false;
protected ITracer tracer;
// Factory for creating on-disk index components during flush and merge.
protected final ILSMDiskComponentFactory componentFactory;
@@ -219,7 +218,7 @@
isActive = false;
}
- protected void flushMemoryComponent() throws HyracksDataException {
+ private void flushMemoryComponent() throws HyracksDataException {
BlockingIOOperationCallbackWrapper cb = new BlockingIOOperationCallbackWrapper(ioOpCallback);
ILSMIndexAccessor accessor = createAccessor(NoOpIndexAccessParameters.INSTANCE);
accessor.scheduleFlush(cb);
@@ -247,7 +246,7 @@
}
@Override
- public void destroy() throws HyracksDataException {
+ public synchronized void destroy() throws HyracksDataException {
if (isActive) {
throw HyracksDataException.create(ErrorCode.CANNOT_DESTROY_ACTIVE_INDEX);
}
@@ -262,7 +261,7 @@
}
@Override
- public void clear() throws HyracksDataException {
+ public synchronized void clear() throws HyracksDataException {
if (!isActive) {
throw HyracksDataException.create(ErrorCode.CANNOT_CLEAR_INACTIVE_INDEX);
}
@@ -572,18 +571,6 @@
return !memoryComponents.get(currentMutableComponentId.get()).isModified();
}
- public void setCurrentMutableComponentState(ComponentState componentState) {
- memoryComponents.get(currentMutableComponentId.get()).setState(componentState);
- }
-
- public ComponentState getCurrentMutableComponentState() {
- return memoryComponents.get(currentMutableComponentId.get()).getState();
- }
-
- public int getCurrentMutableComponentWriterCount() {
- return memoryComponents.get(currentMutableComponentId.get()).getWriterCount();
- }
-
@Override
public List<ILSMDiskComponent> getInactiveDiskComponents() {
return inactiveDiskComponents;