Fix for issue 575.
diff --git a/hyracks/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/btree/impls/LSMBTree.java b/hyracks/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/btree/impls/LSMBTree.java
index 59af99e..342faac 100644
--- a/hyracks/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/btree/impls/LSMBTree.java
+++ b/hyracks/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/btree/impls/LSMBTree.java
@@ -223,6 +223,11 @@
     }
 
     @Override
+    public ILSMComponent getMutableComponent() {
+        return mutableComponent;
+    }
+
+    @Override
     public void getOperationalComponents(ILSMIndexOperationContext ctx) {
         List<ILSMComponent> immutableComponents = componentsRef.get();
         List<ILSMComponent> operationalComponents = ctx.getComponentHolder();
diff --git a/hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/api/ILSMIndexInternal.java b/hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/api/ILSMIndexInternal.java
index c65c7cb..8fb7bdd 100644
--- a/hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/api/ILSMIndexInternal.java
+++ b/hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/api/ILSMIndexInternal.java
@@ -59,6 +59,8 @@
     public void getOperationalComponents(ILSMIndexOperationContext ctx);
 
     public List<ILSMComponent> getImmutableComponents();
+    
+    public ILSMComponent getMutableComponent();
 
     public void markAsValid(ILSMComponent lsmComponent) throws HyracksDataException;
 
diff --git a/hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/AbstractMutableLSMComponent.java b/hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/AbstractMutableLSMComponent.java
index 6ca6581..7180492 100644
--- a/hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/AbstractMutableLSMComponent.java
+++ b/hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/AbstractMutableLSMComponent.java
@@ -22,6 +22,7 @@
     private int readerCount;
     private int writerCount;
     private ComponentState state;
+    private IMutableResetCallback resetCallback;
 
     private boolean isModified;
 
@@ -92,6 +93,7 @@
                 readerCount--;
                 if (state == ComponentState.UNREADABLE_UNWRITABLE && readerCount == 0) {
                     reset();
+                    resetCallback.reset();
                     state = ComponentState.READABLE_WRITABLE;
                 } else if (state == ComponentState.READABLE_WRITABLE && isFull()) {
                     state = ComponentState.READABLE_UNWRITABLE;
@@ -104,6 +106,7 @@
                 readerCount--;
                 if (readerCount == 0) {
                     reset();
+                    resetCallback.reset();
                     state = ComponentState.READABLE_WRITABLE;
                 } else if (state == ComponentState.READABLE_UNWRITABLE_FLUSHING) {
                     state = ComponentState.UNREADABLE_UNWRITABLE;
@@ -115,6 +118,10 @@
         notifyAll();
     }
 
+    public void registerOnResetCallback(IMutableResetCallback resetCallback) {
+        this.resetCallback = resetCallback;
+    }
+
     public void setIsModified() {
         isModified = true;
     }
diff --git a/hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/IMutableResetCallback.java b/hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/IMutableResetCallback.java
new file mode 100644
index 0000000..ff4a5d0
--- /dev/null
+++ b/hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/IMutableResetCallback.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.hyracks.storage.am.lsm.common.impls;
+
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+
+public interface IMutableResetCallback {
+
+    public void reset() throws HyracksDataException;
+
+}
diff --git a/hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/LSMHarness.java b/hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/LSMHarness.java
index df6d3d5..b004f56 100644
--- a/hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/LSMHarness.java
+++ b/hyracks/hyracks-storage-am-lsm-common/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/common/impls/LSMHarness.java
@@ -178,6 +178,12 @@
         if (!lsmIndex.scheduleFlush(ctx, callback)) {
             callback.beforeOperation();
             callback.afterOperation(null, null);
+            AbstractMutableLSMComponent mutableComponent = (AbstractMutableLSMComponent) lsmIndex.getMutableComponent();
+            mutableComponent.registerOnResetCallback(new IMutableResetCallback() {
+                public void reset() throws HyracksDataException {
+                    // do nothing
+                }
+            });
             exitComponents(ctx, LSMOperationType.FLUSH, false);
             callback.afterFinalize(null);
         }
@@ -190,15 +196,25 @@
         if (LOGGER.isLoggable(Level.INFO)) {
             LOGGER.info(lsmIndex + ": flushing");
         }
-        ILSMComponent newComponent = lsmIndex.flush(operation);
+        final ILSMComponent newComponent = lsmIndex.flush(operation);
 
         operation.getCallback().afterOperation(null, newComponent);
         lsmIndex.markAsValid(newComponent);
 
-        lsmIndex.addComponent(newComponent);
-        int numComponents = lsmIndex.getImmutableComponents().size();
+        AbstractMutableLSMComponent mutableComponent = (AbstractMutableLSMComponent) lsmIndex.getMutableComponent();
+        mutableComponent.registerOnResetCallback(new IMutableResetCallback() {
+            public void reset() throws HyracksDataException {
+                lsmIndex.addComponent(newComponent);
+                int numComponents = lsmIndex.getImmutableComponents().size();
+                try {
+                    mergePolicy.diskComponentAdded(lsmIndex, numComponents);
+                } catch (IndexException e) {
+                    throw new HyracksDataException(e);
+                }
 
-        mergePolicy.diskComponentAdded(lsmIndex, numComponents);
+            }
+        });
+
         exitComponents(ctx, LSMOperationType.FLUSH, false);
         operation.getCallback().afterFinalize(newComponent);
     }
diff --git a/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndex.java b/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndex.java
index 244dfa0..98df518 100644
--- a/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndex.java
+++ b/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndex.java
@@ -245,6 +245,11 @@
     }
 
     @Override
+    public ILSMComponent getMutableComponent() {
+        return mutableComponent;
+    }
+    
+    @Override
     public void getOperationalComponents(ILSMIndexOperationContext ctx) {
         List<ILSMComponent> immutableComponents = componentsRef.get();
         List<ILSMComponent> operationalComponents = ctx.getComponentHolder();
diff --git a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/impls/AbstractLSMRTree.java b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/impls/AbstractLSMRTree.java
index 285010c..31a2773 100644
--- a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/impls/AbstractLSMRTree.java
+++ b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/impls/AbstractLSMRTree.java
@@ -189,6 +189,11 @@
     }
 
     @Override
+    public ILSMComponent getMutableComponent() {
+        return mutableComponent;
+    }
+
+    @Override
     public void getOperationalComponents(ILSMIndexOperationContext ctx) {
         List<ILSMComponent> operationalComponents = ctx.getComponentHolder();
         operationalComponents.clear();