abdullah alamoudi has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/1759

Change subject: Fix upsert deadlock and upsert with filtered primary only bug
......................................................................

Fix upsert deadlock and upsert with filtered primary only bug

Change-Id: Ic702d6e1984ea33408c360b6f522f493848cbd87
---
M 
asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/LSMInsertDeleteOperatorNodePushable.java
M 
asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/NoOpFrameOperationCallbackFactory.java
M 
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/operators/LSMPrimaryUpsertOperatorNodePushable.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/ExternalBTreeOpContext.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/ExternalBTreeWithBuddyOpContext.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/LSMBTree.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/LSMBTreeOpContext.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/IFrameOperationCallback.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMComponentFilterFactory.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMHarness.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMIndex.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMIndexAccessor.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMIndexOperationContext.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndex.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndexOperationContext.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMComponentFilterFactory.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMHarness.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMTreeIndexAccessor.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndex.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndexAccessor.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndexOpContext.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/AbstractLSMRTree.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/ExternalRTreeOpContext.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/LSMRTree.java
M 
hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/LSMRTreeOpContext.java
25 files changed, 228 insertions(+), 145 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/59/1759/1

diff --git 
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/LSMInsertDeleteOperatorNodePushable.java
 
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/LSMInsertDeleteOperatorNodePushable.java
index 3f9fba9..14d6e10 100644
--- 
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/LSMInsertDeleteOperatorNodePushable.java
+++ 
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/LSMInsertDeleteOperatorNodePushable.java
@@ -106,7 +106,6 @@
         currentTupleIdx = 0;
         lastFlushedTupleIdx = 0;
         flushedPartialTuples = false;
-
         accessor.reset(buffer);
         ILSMIndexAccessor lsmAccessor = (ILSMIndexAccessor) indexAccessor;
         int tupleCount = accessor.getTupleCount();
diff --git 
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/NoOpFrameOperationCallbackFactory.java
 
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/NoOpFrameOperationCallbackFactory.java
index 3952b11..5e3879f 100644
--- 
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/NoOpFrameOperationCallbackFactory.java
+++ 
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/NoOpFrameOperationCallbackFactory.java
@@ -40,7 +40,7 @@
 
     private static class NoOpFrameOperationCallback implements 
IFrameOperationCallback {
         @Override
-        public void frameCompleted(boolean modified) throws 
HyracksDataException {
+        public void frameCompleted() throws HyracksDataException {
             // No Op
         }
     }
diff --git 
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/operators/LSMPrimaryUpsertOperatorNodePushable.java
 
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/operators/LSMPrimaryUpsertOperatorNodePushable.java
index bff3ca6..2ffc690 100644
--- 
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/operators/LSMPrimaryUpsertOperatorNodePushable.java
+++ 
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/operators/LSMPrimaryUpsertOperatorNodePushable.java
@@ -214,8 +214,8 @@
         accessor.reset(buffer);
         LSMTreeIndexAccessor lsmAccessor = (LSMTreeIndexAccessor) 
indexAccessor;
         int tupleCount = accessor.getTupleCount();
-        boolean firstModification = true;
         int i = 0;
+        lsmAccessor.enter();
         try {
             while (i < tupleCount) {
                 tb.reset();
@@ -223,7 +223,7 @@
                 boolean recordWasDeleted = false;
                 tuple.reset(accessor, i);
                 resetSearchPredicate(i);
-                if (hasSecondaries) {
+                if (isFiltered || hasSecondaries) {
                     lsmAccessor.search(cursor, searchPred);
                     if (cursor.hasNext()) {
                         cursor.next();
@@ -239,35 +239,32 @@
                 } else {
                     searchCallback.before(key); // lock
                     appendPreviousTupleAsMissing();
+                    prevTuple = tuple;
                 }
                 if (isDeleteOperation(tuple, numOfPrimaryKeys)) {
                     // Only delete if it is a delete and not upsert
                     abstractModCallback.setOp(Operation.DELETE);
-                    if (firstModification) {
-                        lsmAccessor.delete(tuple);
-                        firstModification = false;
-                    } else {
-                        lsmAccessor.forceDelete(tuple);
-                    }
+                    lsmAccessor.forceDelete(prevTuple);
                     recordWasDeleted = true;
                 } else {
                     abstractModCallback.setOp(Operation.UPSERT);
-                    if (firstModification) {
-                        lsmAccessor.upsert(tuple);
-                        firstModification = false;
-                    } else {
-                        lsmAccessor.forceUpsert(tuple);
-                    }
+                    lsmAccessor.forceUpsert(tuple);
                     recordWasInserted = true;
+                }
+                if (isFiltered || hasSecondaries) {
+                    // need to update the filter of the new component with the 
previous value
+                    lsmAccessor.updateFilter(prevTuple);
                 }
                 writeOutput(i, recordWasInserted, recordWasDeleted);
                 i++;
             }
             // callback here before calling nextFrame on the next operator
-            frameOpCallback.frameCompleted(!firstModification);
+            frameOpCallback.frameCompleted();
             appender.write(writer, true);
         } catch (Exception e) {
             throw HyracksDataException.create(e);
+        } finally {
+            lsmAccessor.exit();
         }
     }
 
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/ExternalBTreeOpContext.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/ExternalBTreeOpContext.java
index 69c633c..9fe63bd 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/ExternalBTreeOpContext.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/ExternalBTreeOpContext.java
@@ -52,6 +52,7 @@
             ITreeIndexFrameFactory deleteLeafFrameFactory, 
ISearchOperationCallback searchCallback,
             int numBloomFilterKeyFields, IBinaryComparatorFactory[] 
cmpFactories, int targetIndexVersion,
             ILSMHarness lsmHarness) {
+        super(null, null, null);
         if (cmpFactories != null) {
             this.cmp = MultiComparator.create(cmpFactories);
         } else {
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/ExternalBTreeWithBuddyOpContext.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/ExternalBTreeWithBuddyOpContext.java
index ce18b20..3dc106b 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/ExternalBTreeWithBuddyOpContext.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/ExternalBTreeWithBuddyOpContext.java
@@ -50,6 +50,7 @@
             IBinaryComparatorFactory[] buddyBtreeCmpFactories, 
ISearchOperationCallback searchCallback,
             int targetIndexVersion, ILSMHarness lsmHarness, 
ITreeIndexFrameFactory btreeInteriorFrameFactory,
             ITreeIndexFrameFactory btreeLeafFrameFactory, 
ITreeIndexFrameFactory buddyBtreeLeafFrameFactory) {
+        super(null, null, null);
         this.componentHolder = new LinkedList<>();
         this.componentsToBeMerged = new LinkedList<>();
         this.componentsToBeReplicated = new LinkedList<>();
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/LSMBTree.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/LSMBTree.java
index 1c99d5a..af16268 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/LSMBTree.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/LSMBTree.java
@@ -111,7 +111,7 @@
             int[] btreeFields, int[] filterFields, boolean durable) throws 
HyracksDataException {
         super(ioManager, virtualBufferCaches, 
diskBTreeFactory.getBufferCache(), fileManager, diskFileMapProvider,
                 bloomFilterFalsePositiveRate, mergePolicy, opTracker, 
ioScheduler, ioOpCallback, filterFrameFactory,
-                filterManager, filterFields, durable);
+                filterManager, filterFields, durable, filterFactory);
         this.insertLeafFrameFactory = insertLeafFrameFactory;
         this.deleteLeafFrameFactory = deleteLeafFrameFactory;
         this.cmpFactories = cmpFactories;
@@ -316,7 +316,6 @@
     @Override
     public void modify(IIndexOperationContext ictx, ITupleReference tuple) 
throws HyracksDataException {
         LSMBTreeOpContext ctx = (LSMBTreeOpContext) ictx;
-
         ITupleReference indexTuple;
         if (ctx.getIndexTuple() != null) {
             ctx.getIndexTuple().reset(tuple);
@@ -336,11 +335,7 @@
                 ctx.getCurrentMutableBTreeAccessor().upsert(indexTuple);
                 break;
         }
-        if (ctx.getFilterTuple() != null) {
-            ctx.getFilterTuple().reset(tuple);
-            
memoryComponents.get(currentMutableComponentId.get()).getLSMComponentFilter().update(ctx.getFilterTuple(),
-                    ctx.getFilterCmp());
-        }
+        updateFilter(ctx, tuple);
     }
 
     private boolean insert(ITupleReference tuple, LSMBTreeOpContext ctx) 
throws HyracksDataException {
@@ -747,7 +742,8 @@
             ISearchOperationCallback searchCallback) {
         int numBloomFilterKeyFields = hasBloomFilter ? 
componentFactory.getBloomFilterKeyFields().length : 0;
         return new LSMBTreeOpContext(memoryComponents, insertLeafFrameFactory, 
deleteLeafFrameFactory,
-                modificationCallback, searchCallback, numBloomFilterKeyFields, 
btreeFields, filterFields, lsmHarness);
+                modificationCallback, searchCallback, numBloomFilterKeyFields, 
btreeFields, filterFields, lsmHarness,
+                getFilterCmpFactories());
     }
 
     @Override
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/LSMBTreeOpContext.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/LSMBTreeOpContext.java
index 8b7a8a8..cf56246 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/LSMBTreeOpContext.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/impls/LSMBTreeOpContext.java
@@ -31,7 +31,6 @@
 import org.apache.hyracks.storage.am.common.api.ITreeIndexFrameFactory;
 import org.apache.hyracks.storage.am.common.impls.NoOpOperationCallback;
 import org.apache.hyracks.storage.am.common.ophelpers.IndexOperation;
-import org.apache.hyracks.storage.am.common.tuples.PermutingTupleReference;
 import org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent;
 import org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent;
 import org.apache.hyracks.storage.am.lsm.common.api.ILSMHarness;
@@ -61,9 +60,6 @@
     private final List<ILSMComponent> componentHolder;
     private final List<ILSMDiskComponent> componentsToBeMerged;
     private final List<ILSMDiskComponent> componentsToBeReplicated;
-    private final PermutingTupleReference indexTuple;
-    private final MultiComparator filterCmp;
-    private final PermutingTupleReference filterTuple;
     private final BTreeRangeSearchCursor memCursor;
     private final LSMBTreeCursorInitialState searchInitialState;
     private final LSMBTreePointSearchCursor insertSearchCursor;
@@ -78,7 +74,8 @@
     public LSMBTreeOpContext(List<ILSMMemoryComponent> mutableComponents, 
ITreeIndexFrameFactory insertLeafFrameFactory,
             ITreeIndexFrameFactory deleteLeafFrameFactory, 
IModificationOperationCallback modificationCallback,
             ISearchOperationCallback searchCallback, int 
numBloomFilterKeyFields, int[] btreeFields, int[] filterFields,
-            ILSMHarness lsmHarness) {
+            ILSMHarness lsmHarness, IBinaryComparatorFactory[] 
filterCmpFactories) {
+        super(btreeFields, filterFields, filterCmpFactories);
         LSMBTreeMemoryComponent c = (LSMBTreeMemoryComponent) 
mutableComponents.get(0);
         IBinaryComparatorFactory cmpFactories[] = 
c.getBTree().getComparatorFactories();
         if (cmpFactories[0] != null) {
@@ -116,16 +113,6 @@
         this.componentsToBeReplicated = new LinkedList<>();
         this.modificationCallback = modificationCallback;
         this.searchCallback = searchCallback;
-
-        if (filterFields != null) {
-            indexTuple = new PermutingTupleReference(btreeFields);
-            filterCmp = 
MultiComparator.create(c.getLSMComponentFilter().getFilterCmpFactories());
-            filterTuple = new PermutingTupleReference(filterFields);
-        } else {
-            indexTuple = null;
-            filterCmp = null;
-            filterTuple = null;
-        }
         searchPredicate = new RangePredicate(null, null, true, true, getCmp(), 
getCmp());
         memCursor = (insertLeafFrame != null) ? new 
BTreeRangeSearchCursor(insertLeafFrame, false) : null;
         searchInitialState = new 
LSMBTreeCursorInitialState(insertLeafFrameFactory, getCmp(), bloomFilterCmp,
@@ -220,24 +207,12 @@
         return componentsToBeReplicated;
     }
 
-    public MultiComparator getFilterCmp() {
-        return filterCmp;
-    }
-
-    public PermutingTupleReference getIndexTuple() {
-        return indexTuple;
-    }
-
     public BTree.BTreeAccessor getCurrentMutableBTreeAccessor() {
         return currentMutableBTreeAccessor;
     }
 
     public void setCurrentMutableBTreeAccessor(BTree.BTreeAccessor 
currentMutableBTreeAccessor) {
         this.currentMutableBTreeAccessor = currentMutableBTreeAccessor;
-    }
-
-    public PermutingTupleReference getFilterTuple() {
-        return filterTuple;
     }
 
     public LSMBTreePointSearchCursor getInsertSearchCursor() {
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/IFrameOperationCallback.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/IFrameOperationCallback.java
index de72690..96eb559 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/IFrameOperationCallback.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/IFrameOperationCallback.java
@@ -29,9 +29,7 @@
      * Called once processing the frame is done before calling nextFrame on 
the next IFrameWriter in
      * the pipeline
      *
-     * @param modified
-     *            true if the index was modified during the processing of the 
frame, false otherwise
      * @throws HyracksDataException
      */
-    void frameCompleted(boolean modified) throws HyracksDataException;
+    void frameCompleted() throws HyracksDataException;
 }
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMComponentFilterFactory.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMComponentFilterFactory.java
index 64562bd..6284d4e 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMComponentFilterFactory.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMComponentFilterFactory.java
@@ -18,8 +18,17 @@
  */
 package org.apache.hyracks.storage.am.lsm.common.api;
 
-@FunctionalInterface
+import org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory;
+
 public interface ILSMComponentFilterFactory {
+    /**
+     * @return an instance of ILSMComponentFilter
+     */
     ILSMComponentFilter createFilter();
 
+    /**
+     * @return the array of binary comparator factories for the filter
+     */
+    IBinaryComparatorFactory[] getFilterCmpFactories();
+
 }
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMHarness.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMHarness.java
index e57acab..f9a4e80 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMHarness.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMHarness.java
@@ -68,8 +68,7 @@
      * @throws HyracksDataException
      * @throws IndexException
      */
-    void search(ILSMIndexOperationContext ctx, IIndexCursor cursor, 
ISearchPredicate pred)
-            throws HyracksDataException;
+    void search(ILSMIndexOperationContext ctx, IIndexCursor cursor, 
ISearchPredicate pred) throws HyracksDataException;
 
     /**
      * End the search
@@ -87,8 +86,7 @@
      * @throws HyracksDataException
      * @throws IndexException
      */
-    void scheduleMerge(ILSMIndexOperationContext ctx, ILSMIOOperationCallback 
callback)
-            throws HyracksDataException;
+    void scheduleMerge(ILSMIndexOperationContext ctx, ILSMIOOperationCallback 
callback) throws HyracksDataException;
 
     /**
      * Schedule full merge
@@ -98,8 +96,7 @@
      * @throws HyracksDataException
      * @throws IndexException
      */
-    void scheduleFullMerge(ILSMIndexOperationContext ctx, 
ILSMIOOperationCallback callback)
-            throws HyracksDataException;
+    void scheduleFullMerge(ILSMIndexOperationContext ctx, 
ILSMIOOperationCallback callback) throws HyracksDataException;
 
     /**
      * Perform a merge operation
@@ -198,4 +195,28 @@
      */
     void forceUpdateMeta(ILSMIndexOperationContext ctx, IValueReference key, 
IValueReference value)
             throws HyracksDataException;
+
+    /**
+     * Enter components for the operation
+     *
+     * @param ctx
+     * @throws HyracksDataException
+     */
+    void enter(ILSMIndexOperationContext ctx) throws HyracksDataException;
+
+    /**
+     * Exits components for the operation
+     *
+     * @param ctx
+     * @throws HyracksDataException
+     */
+    void exit(ILSMIndexOperationContext ctx) throws HyracksDataException;
+
+    /**
+     * Update the filter with the value in the passed tuple
+     *
+     * @param ctx
+     * @throws HyracksDataException
+     */
+    void updateFilter(ILSMIndexOperationContext ctx, ITupleReference tuple) 
throws HyracksDataException;
 }
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMIndex.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMIndex.java
index 9fb48c4..e702ee5 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMIndex.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMIndex.java
@@ -130,4 +130,13 @@
      * @return true if the index is durable. Otherwise false.
      */
     boolean isDurable();
+
+    /**
+     * Update the filter with the passed tuple
+     *
+     * @param ictx
+     * @param tuple
+     * @throws HyracksDataException
+     */
+    void updateFilter(ILSMIndexOperationContext ictx, ITupleReference tuple) 
throws HyracksDataException;
 }
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMIndexAccessor.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMIndexAccessor.java
index 5473670..f846c80 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMIndexAccessor.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMIndexAccessor.java
@@ -33,6 +33,17 @@
  * concurrent operations).
  */
 public interface ILSMIndexAccessor extends IIndexAccessor {
+
+    /**
+     * Enter the memory component for modification
+     */
+    void enter() throws HyracksDataException;
+
+    /**
+     * Exit the memory component
+     */
+    void exit() throws HyracksDataException;
+
     /**
      * Schedule a flush operation
      *
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMIndexOperationContext.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMIndexOperationContext.java
index 8bdf5fa..5b0378a 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMIndexOperationContext.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/api/ILSMIndexOperationContext.java
@@ -21,9 +21,11 @@
 import java.util.List;
 
 import org.apache.hyracks.storage.am.common.api.IIndexOperationContext;
+import org.apache.hyracks.storage.am.common.tuples.PermutingTupleReference;
 import org.apache.hyracks.storage.common.IModificationOperationCallback;
 import org.apache.hyracks.storage.common.ISearchOperationCallback;
 import org.apache.hyracks.storage.common.ISearchPredicate;
+import org.apache.hyracks.storage.common.MultiComparator;
 
 public interface ILSMIndexOperationContext extends IIndexOperationContext {
     List<ILSMComponent> getComponentHolder();
@@ -48,4 +50,10 @@
     boolean isAccessingComponents();
 
     void setAccessingComponents(boolean accessingComponents);
+
+    PermutingTupleReference getIndexTuple();
+
+    PermutingTupleReference getFilterTuple();
+
+    MultiComparator getFilterCmp();
 }
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 df42972..2112491 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
@@ -28,14 +28,17 @@
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.api.io.IIOManager;
 import 
org.apache.hyracks.api.replication.IReplicationJob.ReplicationExecutionType;
 import org.apache.hyracks.api.replication.IReplicationJob.ReplicationOperation;
+import org.apache.hyracks.dataflow.common.data.accessors.ITupleReference;
 import org.apache.hyracks.storage.am.bloomfilter.impls.BloomFilter;
 import org.apache.hyracks.storage.am.common.api.ITreeIndex;
 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.ILSMComponentFilterFactory;
 import 
org.apache.hyracks.storage.am.lsm.common.api.ILSMComponentFilterFrameFactory;
 import org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent;
 import org.apache.hyracks.storage.am.lsm.common.api.ILSMHarness;
@@ -73,6 +76,7 @@
     protected final double bloomFilterFalsePositiveRate;
     protected final ILSMComponentFilterFrameFactory filterFrameFactory;
     protected final LSMComponentFilterManager filterManager;
+    protected final ILSMComponentFilterFactory filterFactory;
     protected final int[] filterFields;
     protected final boolean durable;
     protected boolean isActivated;
@@ -84,7 +88,7 @@
             double bloomFilterFalsePositiveRate, ILSMMergePolicy mergePolicy, 
ILSMOperationTracker opTracker,
             ILSMIOOperationScheduler ioScheduler, ILSMIOOperationCallback 
ioOpCallback,
             ILSMComponentFilterFrameFactory filterFrameFactory, 
LSMComponentFilterManager filterManager,
-            int[] filterFields, boolean durable) {
+            int[] filterFields, boolean durable, ILSMComponentFilterFactory 
filterFactory) {
         this.ioManager = ioManager;
         this.virtualBufferCaches = virtualBufferCaches;
         this.diskBufferCache = diskBufferCache;
@@ -94,6 +98,7 @@
         this.ioScheduler = ioScheduler;
         this.ioOpCallback = ioOpCallback;
         
this.ioOpCallback.setNumOfMutableComponents(virtualBufferCaches.size());
+        this.filterFactory = filterFactory;
         this.filterFrameFactory = filterFrameFactory;
         this.filterManager = filterManager;
         this.filterFields = filterFields;
@@ -108,6 +113,10 @@
         for (int i = 0; i < virtualBufferCaches.size(); i++) {
             flushRequests[i] = new AtomicBoolean();
         }
+    }
+
+    protected IBinaryComparatorFactory[] getFilterCmpFactories() {
+        return filterFactory == null ? null : 
filterFactory.getFilterCmpFactories();
     }
 
     // The constructor used by external indexes
@@ -132,6 +141,7 @@
         memoryComponents = null;
         currentMutableComponentId = null;
         flushRequests = null;
+        filterFactory = null;
         filterFrameFactory = null;
         filterManager = null;
         filterFields = null;
@@ -322,4 +332,13 @@
     public int getNumOfFilterFields() {
         return filterFields == null ? 0 : filterFields.length;
     }
+
+    @Override
+    public void updateFilter(ILSMIndexOperationContext ctx, ITupleReference 
tuple) throws HyracksDataException {
+        if (ctx.getFilterTuple() != null) {
+            ctx.getFilterTuple().reset(tuple);
+            
memoryComponents.get(currentMutableComponentId.get()).getLSMComponentFilter().update(ctx.getFilterTuple(),
+                    ctx.getFilterCmp());
+        }
+    }
 }
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndexOperationContext.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndexOperationContext.java
index 3b907c3..c328ade 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndexOperationContext.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/AbstractLSMIndexOperationContext.java
@@ -18,11 +18,30 @@
  */
 package org.apache.hyracks.storage.am.lsm.common.impls;
 
+import org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory;
+import org.apache.hyracks.storage.am.common.tuples.PermutingTupleReference;
 import org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexOperationContext;
+import org.apache.hyracks.storage.common.MultiComparator;
 
 public abstract class AbstractLSMIndexOperationContext implements 
ILSMIndexOperationContext {
 
-    private boolean accessingComponents = false;
+    protected final PermutingTupleReference indexTuple;
+    protected final MultiComparator filterCmp;
+    protected final PermutingTupleReference filterTuple;
+    protected boolean accessingComponents = false;
+
+    public AbstractLSMIndexOperationContext(int[] treeFields, int[] 
filterFields,
+            IBinaryComparatorFactory[] filterCmpFactories) {
+        if (filterFields != null) {
+            indexTuple = new PermutingTupleReference(treeFields);
+            filterCmp = MultiComparator.create(filterCmpFactories);
+            filterTuple = new PermutingTupleReference(filterFields);
+        } else {
+            indexTuple = null;
+            filterCmp = null;
+            filterTuple = null;
+        }
+    }
 
     @Override
     public boolean isAccessingComponents() {
@@ -38,4 +57,19 @@
     public void reset() {
         accessingComponents = false;
     }
+
+    @Override
+    public final PermutingTupleReference getIndexTuple() {
+        return indexTuple;
+    }
+
+    @Override
+    public final PermutingTupleReference getFilterTuple() {
+        return filterTuple;
+    }
+
+    @Override
+    public final MultiComparator getFilterCmp() {
+        return filterCmp;
+    }
 }
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMComponentFilterFactory.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMComponentFilterFactory.java
index 46a629a..390321f 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMComponentFilterFactory.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMComponentFilterFactory.java
@@ -38,4 +38,9 @@
     public ILSMComponentFilter createFilter() {
         return new LSMComponentFilter(tupleWriterFactory.createTupleWriter(), 
filterCmpFactories);
     }
+
+    @Override
+    public IBinaryComparatorFactory[] getFilterCmpFactories() {
+        return filterCmpFactories;
+    }
 }
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMHarness.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMHarness.java
index 94fd2bb..4ba36e5 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMHarness.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMHarness.java
@@ -376,6 +376,37 @@
         }
     }
 
+    @Override
+    public void updateFilter(ILSMIndexOperationContext ctx, ITupleReference 
tuple) throws HyracksDataException {
+        if (!lsmIndex.isMemoryComponentsAllocated()) {
+            lsmIndex.allocateMemoryComponents();
+        }
+        lsmIndex.updateFilter(ctx, tuple);
+    }
+
+    @Override
+    public void enter(ILSMIndexOperationContext ctx) throws 
HyracksDataException {
+        if (!lsmIndex.isMemoryComponentsAllocated()) {
+            lsmIndex.allocateMemoryComponents();
+        }
+        getAndEnterComponents(ctx, LSMOperationType.MODIFICATION, false);
+    }
+
+    @Override
+    public void exit(ILSMIndexOperationContext ctx) throws 
HyracksDataException {
+        getAndExitComponentsAndComplete(ctx, LSMOperationType.MODIFICATION);
+    }
+
+    private void getAndExitComponentsAndComplete(ILSMIndexOperationContext 
ctx, LSMOperationType op)
+            throws HyracksDataException {
+        validateOperationEnterComponentsState(ctx);
+        synchronized (opTracker) {
+            lsmIndex.getOperationalComponents(ctx);
+            ctx.setAccessingComponents(true);
+            exitAndComplete(ctx, op);
+        }
+    }
+
     private void exitAndComplete(ILSMIndexOperationContext ctx, 
LSMOperationType op) throws HyracksDataException {
         try {
             exitComponents(ctx, op, null, false);
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMTreeIndexAccessor.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMTreeIndexAccessor.java
index f117e63..5c56f73 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMTreeIndexAccessor.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMTreeIndexAccessor.java
@@ -174,14 +174,31 @@
     @Override
     public void updateMeta(IValueReference key, IValueReference value) throws 
HyracksDataException {
         // a hack because delete only gets the memory component
-        ctx.setOperation(IndexOperation.DELETE);
+        ctx.setOperation(IndexOperation.UPSERT);
         lsmHarness.updateMeta(ctx, key, value);
     }
 
     @Override
     public void forceUpdateMeta(IValueReference key, IValueReference value) 
throws HyracksDataException {
         // a hack because delete only gets the memory component
-        ctx.setOperation(IndexOperation.DELETE);
+        ctx.setOperation(IndexOperation.UPSERT);
         lsmHarness.forceUpdateMeta(ctx, key, value);
     }
+
+    @Override
+    public void enter() throws HyracksDataException {
+        ctx.setOperation(IndexOperation.UPSERT);
+        lsmHarness.enter(ctx);
+    }
+
+    @Override
+    public void exit() throws HyracksDataException {
+        ctx.setOperation(IndexOperation.UPSERT);
+        lsmHarness.exit(ctx);
+    }
+
+    public void updateFilter(ITupleReference tuple) throws 
HyracksDataException {
+        ctx.setOperation(IndexOperation.UPSERT);
+        lsmHarness.updateFilter(ctx, tuple);
+    }
 }
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndex.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndex.java
index 3d7b716..e31ef90 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndex.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndex.java
@@ -120,8 +120,7 @@
             boolean durable) throws HyracksDataException {
         super(ioManager, virtualBufferCaches, 
diskInvIndexFactory.getBufferCache(), fileManager, diskFileMapProvider,
                 bloomFilterFalsePositiveRate, mergePolicy, opTracker, 
ioScheduler, ioOpCallback, filterFrameFactory,
-                filterManager, filterFields, durable);
-
+                filterManager, filterFields, durable, filterFactory);
         this.tokenizerFactory = tokenizerFactory;
         this.invListTypeTraits = invListTypeTraits;
         this.invListCmpFactories = invListCmpFactories;
@@ -358,11 +357,7 @@
                 throw new UnsupportedOperationException("Operation " + 
ctx.getOperation() + " not supported.");
             }
         }
-        if (ctx.getFilterTuple() != null) {
-            ctx.getFilterTuple().reset(tuple);
-            
memoryComponents.get(currentMutableComponentId.get()).getLSMComponentFilter().update(ctx.getFilterTuple(),
-                    ctx.getFilterCmp());
-        }
+        updateFilter(ctx, tuple);
     }
 
     @Override
@@ -817,7 +812,7 @@
     private LSMInvertedIndexOpContext 
createOpContext(IModificationOperationCallback modificationCallback,
             ISearchOperationCallback searchCallback) throws 
HyracksDataException {
         return new LSMInvertedIndexOpContext(memoryComponents, 
modificationCallback, searchCallback,
-                invertedIndexFieldsForNonBulkLoadOps, 
filterFieldsForNonBulkLoadOps);
+                invertedIndexFieldsForNonBulkLoadOps, 
filterFieldsForNonBulkLoadOps, getFilterCmpFactories());
     }
 
     @Override
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndexAccessor.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndexAccessor.java
index edae439..80607f7 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndexAccessor.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndexAccessor.java
@@ -203,4 +203,21 @@
         throw new UnsupportedOperationException("Upsert not supported by lsm 
inverted index.");
     }
 
+    /**
+     * enter the memory component for modification
+     */
+    @Override
+    public void enter() throws HyracksDataException {
+        ctx.setOperation(IndexOperation.UPSERT);
+        lsmHarness.enter(ctx);
+    }
+
+    /**
+     * exit the memory component
+     */
+    @Override
+    public void exit() throws HyracksDataException {
+        ctx.setOperation(IndexOperation.UPSERT);
+        lsmHarness.exit(ctx);
+    }
 }
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndexOpContext.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndexOpContext.java
index 44c1c13..fec303b 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndexOpContext.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/impls/LSMInvertedIndexOpContext.java
@@ -22,6 +22,7 @@
 import java.util.LinkedList;
 import java.util.List;
 
+import org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.storage.am.common.impls.NoOpOperationCallback;
 import org.apache.hyracks.storage.am.common.ophelpers.IndexOperation;
@@ -35,7 +36,6 @@
 import org.apache.hyracks.storage.common.IModificationOperationCallback;
 import org.apache.hyracks.storage.common.ISearchOperationCallback;
 import org.apache.hyracks.storage.common.ISearchPredicate;
-import org.apache.hyracks.storage.common.MultiComparator;
 
 public class LSMInvertedIndexOpContext extends 
AbstractLSMIndexOperationContext {
 
@@ -60,15 +60,13 @@
     private IInvertedIndexAccessor currentMutableInvIndexAccessors;
     private IIndexAccessor currentDeletedKeysBTreeAccessors;
 
-    private final PermutingTupleReference indexTuple;
-    private final MultiComparator filterCmp;
-    private final PermutingTupleReference filterTuple;
-
     private ISearchPredicate searchPredicate;
 
     public LSMInvertedIndexOpContext(List<ILSMMemoryComponent> 
mutableComponents,
             IModificationOperationCallback modificationCallback, 
ISearchOperationCallback searchCallback,
-            int[] invertedIndexFields, int[] filterFields) throws 
HyracksDataException {
+            int[] invertedIndexFields, int[] filterFields, 
IBinaryComparatorFactory[] filterComparatorFactories)
+            throws HyracksDataException {
+        super(invertedIndexFields, filterFields, filterComparatorFactories);
         this.componentHolder = new LinkedList<>();
         this.componentsToBeMerged = new LinkedList<>();
         this.componentsToBeReplicated = new LinkedList<>();
@@ -87,8 +85,6 @@
                     .createAccessor(NoOpOperationCallback.INSTANCE, 
NoOpOperationCallback.INSTANCE);
         }
 
-        assert mutableComponents.size() > 0;
-
         // Project away the document fields, leaving only the key fields.
         LSMInvertedIndexMemoryComponent c = (LSMInvertedIndexMemoryComponent) 
mutableComponents.get(0);
         int numKeyFields = c.getInvIndex().getInvListTypeTraits().length;
@@ -97,16 +93,6 @@
             keyFieldPermutation[i] = NUM_DOCUMENT_FIELDS + i;
         }
         keysOnlyTuple = new PermutingTupleReference(keyFieldPermutation);
-
-        if (filterFields != null) {
-            indexTuple = new PermutingTupleReference(invertedIndexFields);
-            filterCmp = 
MultiComparator.create(c.getLSMComponentFilter().getFilterCmpFactories());
-            filterTuple = new PermutingTupleReference(filterFields);
-        } else {
-            indexTuple = null;
-            filterCmp = null;
-            filterTuple = null;
-        }
     }
 
     @Override
@@ -170,14 +156,6 @@
         return componentsToBeReplicated;
     }
 
-    public MultiComparator getFilterCmp() {
-        return filterCmp;
-    }
-
-    public PermutingTupleReference getIndexTuple() {
-        return indexTuple;
-    }
-
     public IInvertedIndexAccessor getCurrentMutableInvIndexAccessors() {
         return currentMutableInvIndexAccessors;
     }
@@ -188,9 +166,5 @@
 
     public IIndexAccessor getCurrentDeletedKeysBTreeAccessors() {
         return currentDeletedKeysBTreeAccessors;
-    }
-
-    public PermutingTupleReference getFilterTuple() {
-        return filterTuple;
     }
 }
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/AbstractLSMRTree.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/AbstractLSMRTree.java
index 9c56dec..d89f64a 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/AbstractLSMRTree.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/AbstractLSMRTree.java
@@ -97,7 +97,7 @@
             throws HyracksDataException {
         super(ioManager, virtualBufferCaches, diskBufferCache, fileManager, 
diskFileMapProvider,
                 bloomFilterFalsePositiveRate, mergePolicy, opTracker, 
ioScheduler, ioOpCallback, filterFrameFactory,
-                filterManager, filterFields, durable);
+                filterManager, filterFields, durable, filterFactory);
         int i = 0;
         for (IVirtualBufferCache virtualBufferCache : virtualBufferCaches) {
             RTree memRTree = new RTree(virtualBufferCache, 
virtualBufferCache.getFileMapProvider(),
@@ -373,18 +373,14 @@
                 }
             }
         }
-        if (ctx.getFilterTuple() != null) {
-            ctx.getFilterTuple().reset(tuple);
-            
memoryComponents.get(currentMutableComponentId.get()).getLSMComponentFilter().update(ctx.getFilterTuple(),
-                    ctx.getFilterCmp());
-        }
+        updateFilter(ctx, tuple);
     }
 
     protected LSMRTreeOpContext createOpContext(IModificationOperationCallback 
modCallback,
             ISearchOperationCallback searchCallback) {
         return new LSMRTreeOpContext(memoryComponents, rtreeLeafFrameFactory, 
rtreeInteriorFrameFactory,
                 btreeLeafFrameFactory, modCallback, searchCallback, 
rtreeFields, filterFields, lsmHarness,
-                comparatorFields, linearizerArray);
+                comparatorFields, linearizerArray, getFilterCmpFactories());
     }
 
     @Override
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/ExternalRTreeOpContext.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/ExternalRTreeOpContext.java
index 76cf339..d0fac63 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/ExternalRTreeOpContext.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/ExternalRTreeOpContext.java
@@ -50,6 +50,7 @@
             int targetIndexVersion, ILSMHarness lsmHarness, int[] 
comparatorFields,
             IBinaryComparatorFactory[] linearizerArray, ITreeIndexFrameFactory 
rtreeLeafFrameFactory,
             ITreeIndexFrameFactory rtreeInteriorFrameFactory, 
ITreeIndexFrameFactory btreeLeafFrameFactory) {
+        super(null, null, null);
         this.componentHolder = new LinkedList<>();
         this.componentsToBeMerged = new LinkedList<>();
         this.componentsToBeReplicated = new LinkedList<>();
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/LSMRTree.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/LSMRTree.java
index 8882639..7ad115d 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/LSMRTree.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/LSMRTree.java
@@ -503,11 +503,7 @@
                 }
             }
         }
-        if (ctx.getFilterTuple() != null) {
-            ctx.getFilterTuple().reset(tuple);
-            
memoryComponents.get(currentMutableComponentId.get()).getLSMComponentFilter().update(ctx.getFilterTuple(),
-                    ctx.getFilterCmp());
-        }
+        updateFilter(ctx, tuple);
     }
 
     public class LSMRTreeBulkLoader implements IIndexBulkLoader {
diff --git 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/LSMRTreeOpContext.java
 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/LSMRTreeOpContext.java
index 83ca78c..0061ffe 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/LSMRTreeOpContext.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/LSMRTreeOpContext.java
@@ -28,7 +28,6 @@
 import org.apache.hyracks.storage.am.common.api.ITreeIndexFrameFactory;
 import org.apache.hyracks.storage.am.common.impls.NoOpOperationCallback;
 import org.apache.hyracks.storage.am.common.ophelpers.IndexOperation;
-import org.apache.hyracks.storage.am.common.tuples.PermutingTupleReference;
 import org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent;
 import org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent;
 import org.apache.hyracks.storage.am.lsm.common.api.ILSMHarness;
@@ -59,9 +58,6 @@
     private final List<ILSMDiskComponent> componentsToBeReplicated;
     private IModificationOperationCallback modificationCallback;
     private ISearchOperationCallback searchCallback;
-    private final PermutingTupleReference indexTuple;
-    private final MultiComparator filterCmp;
-    private final PermutingTupleReference filterTuple;
     private ISearchPredicate searchPredicate;
     private LSMRTreeCursorInitialState searchInitialState;
 
@@ -69,7 +65,8 @@
             ITreeIndexFrameFactory rtreeInteriorFrameFactory, 
ITreeIndexFrameFactory btreeLeafFrameFactory,
             IModificationOperationCallback modificationCallback, 
ISearchOperationCallback searchCallback,
             int[] rtreeFields, int[] filterFields, ILSMHarness lsmHarness, 
int[] comparatorFields,
-            IBinaryComparatorFactory[] linearizerArray) {
+            IBinaryComparatorFactory[] linearizerArray, 
IBinaryComparatorFactory[] filterComparatorFactories) {
+        super(rtreeFields, filterFields, filterComparatorFactories);
         mutableRTreeAccessors = new 
RTree.RTreeAccessor[mutableComponents.size()];
         mutableBTreeAccessors = new 
BTree.BTreeAccessor[mutableComponents.size()];
         rtreeOpContexts = new RTreeOpContext[mutableComponents.size()];
@@ -87,8 +84,6 @@
             rtreeOpContexts[i] = mutableRTreeAccessors[i].getOpContext();
             btreeOpContexts[i] = mutableBTreeAccessors[i].getOpContext();
         }
-
-        assert mutableComponents.size() > 0;
         currentRTreeOpContext = rtreeOpContexts[0];
         currentBTreeOpContext = btreeOpContexts[0];
         this.componentHolder = new LinkedList<>();
@@ -96,16 +91,6 @@
         this.componentsToBeReplicated = new LinkedList<>();
         this.modificationCallback = modificationCallback;
         this.searchCallback = searchCallback;
-
-        if (filterFields != null) {
-            indexTuple = new PermutingTupleReference(rtreeFields);
-            filterCmp = 
MultiComparator.create(c.getLSMComponentFilter().getFilterCmpFactories());
-            filterTuple = new PermutingTupleReference(filterFields);
-        } else {
-            indexTuple = null;
-            filterCmp = null;
-            filterTuple = null;
-        }
         searchInitialState = new 
LSMRTreeCursorInitialState(rtreeLeafFrameFactory, rtreeInteriorFrameFactory,
                 btreeLeafFrameFactory, getBTreeMultiComparator(), lsmHarness, 
comparatorFields, linearizerArray,
                 searchCallback, componentHolder);
@@ -181,16 +166,8 @@
         return componentsToBeReplicated;
     }
 
-    public MultiComparator getFilterCmp() {
-        return filterCmp;
-    }
-
     public LSMRTreeCursorInitialState getSearchInitialState() {
         return searchInitialState;
-    }
-
-    public PermutingTupleReference getIndexTuple() {
-        return indexTuple;
     }
 
     public RTree.RTreeAccessor getCurrentMutableRTreeAccessor() {
@@ -199,10 +176,6 @@
 
     public BTree.BTreeAccessor getCurrentMutableBTreeAccessor() {
         return currentMutableBTreeAccessor;
-    }
-
-    public PermutingTupleReference getFilterTuple() {
-        return filterTuple;
     }
 
     public RTreeOpContext getCurrentRTreeOpContext() {

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/1759
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic702d6e1984ea33408c360b6f522f493848cbd87
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: abdullah alamoudi <bamou...@gmail.com>

Reply via email to