Using consistent file naming for LSMBTree. More code cleanup.

git-svn-id: https://hyracks.googlecode.com/svn/branches/hyracks_lsm_tree@1078 123451ca-8445-de46-9d55-352943316053
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/tests/OrderedIndexExamplesTest.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/tests/OrderedIndexExamplesTest.java
index ff4ce07..bdbd9e9 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/tests/OrderedIndexExamplesTest.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/tests/OrderedIndexExamplesTest.java
@@ -60,7 +60,7 @@
      * field. Fill index with random values using insertions (not bulk load).
      * Perform scans and range search.
      */
-    //@Test
+    @Test
     public void fixedLengthKeyValueExample() throws Exception {
         if (LOGGER.isLoggable(Level.INFO)) {
             LOGGER.info("Fixed-Length Key,Value Example.");
@@ -137,7 +137,7 @@
      * value field. Fill index with random values using insertions (not bulk
      * load) Perform scans and range search.
      */
-    //@Test
+    @Test
     public void twoFixedLengthKeysOneFixedLengthValueExample() throws Exception {
         if (LOGGER.isLoggable(Level.INFO)) {
             LOGGER.info("Composite Key Test");
@@ -216,7 +216,7 @@
      * field and one variable-length value field. Fill BTree with random values
      * using insertions (not bulk load) Perform ordered scans and range search.
      */
-    //@Test
+    @Test
     public void varLenKeyValueExample() throws Exception {
         if (LOGGER.isLoggable(Level.INFO)) {
             LOGGER.info("Variable-Length Key,Value Example");
@@ -295,7 +295,7 @@
      * value field. Fill B-tree with random values using insertions, then delete
      * entries one-by-one. Repeat procedure a few times on same BTree.
      */
-    //@Test
+    @Test
     public void deleteExample() throws Exception {
         if (LOGGER.isLoggable(Level.INFO)) {
             LOGGER.info("Deletion Example");
@@ -396,7 +396,7 @@
      * value field. Fill B-tree with random values using insertions, then update
      * entries one-by-one. Repeat procedure a few times on same BTree.
      */
-    //@Test
+    @Test
     public void updateExample() throws Exception {
         if (LOGGER.isLoggable(Level.INFO)) {
             LOGGER.info("Update example");
diff --git a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMTree.java b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMBTree.java
similarity index 82%
rename from hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMTree.java
rename to hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMBTree.java
index d12d7f6..2563cda 100644
--- a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMTree.java
+++ b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMBTree.java
@@ -21,6 +21,8 @@
 import java.util.Comparator;
 import java.util.LinkedList;
 import java.util.ListIterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.api.io.FileReference;
@@ -46,7 +48,9 @@
 import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
 import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
 
-public class LSMTree implements ILSMTree {
+public class LSMBTree implements ILSMTree {
+    protected final Logger LOGGER = Logger.getLogger(LSMBTree.class.getName());
+    
     // In-memory components.
     private final BTree memBTree;
     private final InMemoryFreePageManager memFreePageManager;    
@@ -60,12 +64,9 @@
     private final BTreeFactory bulkLoadBTreeFactory;
     private final IBufferCache diskBufferCache;
     private final IFileMapProvider diskFileMapProvider;
-    private LinkedList<BTree> onDiskBTrees = new LinkedList<BTree>();
-    private LinkedList<BTree> mergedBTrees = new LinkedList<BTree>();
-    private int onDiskBTreeCount;
+    private LinkedList<BTree> diskBTrees = new LinkedList<BTree>();
     
     // Common for in-memory and on-disk components.
-    private final ITreeIndexFrameFactory interiorFrameFactory;
     private final ITreeIndexFrameFactory insertLeafFrameFactory;
     private final ITreeIndexFrameFactory deleteLeafFrameFactory;
     private final MultiComparator cmp;
@@ -74,14 +75,13 @@
     private int threadRefCount;
     private boolean flushFlag;
 
-    public LSMTree(IBufferCache memBufferCache, InMemoryFreePageManager memFreePageManager,
+    public LSMBTree(IBufferCache memBufferCache, InMemoryFreePageManager memFreePageManager,
             ITreeIndexFrameFactory interiorFrameFactory, ITreeIndexFrameFactory insertLeafFrameFactory,
             ITreeIndexFrameFactory deleteLeafFrameFactory, ILSMFileNameManager fileNameManager, BTreeFactory diskBTreeFactory,
             BTreeFactory bulkLoadBTreeFactory, IFileMapProvider diskFileMapProvider, int fieldCount, MultiComparator cmp) {
         memBTree = new BTree(memBufferCache, fieldCount, cmp, memFreePageManager, interiorFrameFactory,
                 insertLeafFrameFactory);
         this.memFreePageManager = memFreePageManager;
-        this.interiorFrameFactory = interiorFrameFactory;
         this.insertLeafFrameFactory = insertLeafFrameFactory;
         this.deleteLeafFrameFactory = deleteLeafFrameFactory;
         this.diskBufferCache = diskBTreeFactory.getBufferCache();
@@ -89,8 +89,7 @@
         this.diskBTreeFactory = diskBTreeFactory;
         this.bulkLoadBTreeFactory = bulkLoadBTreeFactory;
         this.cmp = cmp;
-        this.onDiskBTrees = new LinkedList<BTree>();
-        this.onDiskBTreeCount = 0;
+        this.diskBTrees = new LinkedList<BTree>();
         this.threadRefCount = 0;
         this.flushFlag = false;
         this.fileNameManager = fileNameManager;
@@ -134,22 +133,21 @@
         Arrays.sort(files, fileNameCmp);
         for (String fileName : files) {
             BTree btree = createDiskBTree(diskBTreeFactory, fileName, false);
-            onDiskBTrees.add(btree);
+            diskBTrees.add(btree);
         }
     }
 
     @Override
     public void close() throws HyracksDataException {
-        for (BTree btree : onDiskBTrees) {
+        for (BTree btree : diskBTrees) {
             diskBufferCache.closeFile(btree.getFileId());
             btree.close();
         }
-        onDiskBTrees.clear();
-        onDiskBTreeCount = 0;
+        diskBTrees.clear();
         memBTree.close();
     }
 
-	private void lsmPerformOp(ITupleReference tuple, LSMTreeOpContext ctx) throws HyracksDataException, TreeIndexException {
+	private void lsmPerformOp(ITupleReference tuple, LSMBTreeOpContext ctx) throws HyracksDataException, TreeIndexException {
 		boolean waitForFlush = true;
 		do {
 		    // Wait for ongoing flush to complete.
@@ -180,7 +178,7 @@
 		threadExit();
 	}
 
-	private void deleteExistingKey(ITupleReference tuple, LSMTreeOpContext ctx) throws HyracksDataException, TreeIndexException {
+	private void deleteExistingKey(ITupleReference tuple, LSMBTreeOpContext ctx) throws HyracksDataException, TreeIndexException {
         // We assume that tuple given by the user for deletion only contains the
         // key fields, but not any non-key fields.
         // Therefore, to set the delete bit in the tuple that already exist in
@@ -215,7 +213,7 @@
         }            
 	}
 	
-    private void insertOrUpdateExistingKey(ITupleReference tuple, LSMTreeOpContext ctx) throws HyracksDataException,
+    private void insertOrUpdateExistingKey(ITupleReference tuple, LSMBTreeOpContext ctx) throws HyracksDataException,
             TreeIndexException {        
         // If all fields are keys, and the key we are trying to insert/update
         // already exists, then we are already done.
@@ -228,7 +226,7 @@
         }
     }
     
-    private void memBTreeDeleteAndReinsert(ITupleReference tuple, LSMTreeOpContext ctx) throws HyracksDataException,
+    private void memBTreeDeleteAndReinsert(ITupleReference tuple, LSMBTreeOpContext ctx) throws HyracksDataException,
             TreeIndexException {
         // All fields are key fields, therefore a true BTree update is not
         // allowed.
@@ -249,7 +247,7 @@
         lsmPerformOp(tuple, ctx);
     }
     
-    private void memBTreeUpdate(ITupleReference tuple, LSMTreeOpContext ctx) throws HyracksDataException,
+    private void memBTreeUpdate(ITupleReference tuple, LSMBTreeOpContext ctx) throws HyracksDataException,
             TreeIndexException {
         IndexOp originalOp = ctx.getIndexOp();
         try {
@@ -285,7 +283,9 @@
 
     @Override
     public void flush() throws HyracksDataException, TreeIndexException {
-        System.out.println("FLUSHING!");
+        if (LOGGER.isLoggable(Level.INFO)) {
+            LOGGER.info("Flushing LSM-BTree.");
+        }
         // Bulk load a new on-disk BTree from the in-memory BTree.        
         RangePredicate nullPred = new RangePredicate(true, null, null, true, true, null, null);
         ITreeIndexAccessor memBTreeAccessor = memBTree.createAccessor();
@@ -304,7 +304,7 @@
         }
         diskBTree.endBulkLoad(bulkLoadCtx);
         resetMemBTree();
-        onDiskBTrees.addFirst(diskBTree);
+        diskBTrees.addFirst(diskBTree);
     }
 
     private void resetMemBTree() throws HyracksDataException {
@@ -347,7 +347,7 @@
         return diskBTree;
     }
     
-    private void search(ITreeIndexCursor cursor, RangePredicate pred, LSMTreeOpContext ctx, boolean includeMemBTree) throws HyracksDataException, TreeIndexException {                
+    private void search(ITreeIndexCursor cursor, RangePredicate pred, LSMBTreeOpContext ctx, boolean includeMemBTree) throws HyracksDataException, TreeIndexException {                
         boolean waitForFlush = true;
         do {
             synchronized (this) {
@@ -360,13 +360,13 @@
         } while (waitForFlush);
         
         // TODO: Think about what happens with possibly concurrent merges.
-        LSMTreeRangeSearchCursor lsmTreeCursor = (LSMTreeRangeSearchCursor) cursor;
-        int numDiskBTrees = onDiskBTrees.size();
+        LSMBTreeRangeSearchCursor lsmTreeCursor = (LSMBTreeRangeSearchCursor) cursor;
+        int numDiskBTrees = diskBTrees.size();
         int numBTrees = (includeMemBTree) ? numDiskBTrees + 1 : numDiskBTrees;        
-        ListIterator<BTree> diskBTreesIter = onDiskBTrees.listIterator();
-        LSMTreeCursorInitialState initialState = new LSMTreeCursorInitialState(numBTrees,
+        ListIterator<BTree> diskBTreesIter = diskBTrees.listIterator();
+        LSMBTreeCursorInitialState initialState = new LSMBTreeCursorInitialState(numBTrees,
                 insertLeafFrameFactory, cmp, this);
-        lsmTreeCursor.open(initialState, pred);                  
+        lsmTreeCursor.open(initialState, pred);
         
         int cursorIx;
         if (includeMemBTree) {
@@ -388,44 +388,29 @@
             cursorIx++;
             diskBTreeIx++;
         }
-        LSMPriorityQueueComparator LSMPriorityQueueCmp = new LSMPriorityQueueComparator(cmp);
-        lsmTreeCursor.initPriorityQueue(LSMPriorityQueueCmp);
+        lsmTreeCursor.initPriorityQueue();
     }
     
-    private void insert(ITupleReference tuple, LSMTreeOpContext ctx) throws HyracksDataException, TreeIndexException {
+    private void insert(ITupleReference tuple, LSMBTreeOpContext ctx) throws HyracksDataException, TreeIndexException {
         lsmPerformOp(tuple, ctx);
     }
 
-    private void delete(ITupleReference tuple, LSMTreeOpContext ctx) throws HyracksDataException, TreeIndexException {
+    private void delete(ITupleReference tuple, LSMBTreeOpContext ctx) throws HyracksDataException, TreeIndexException {
         lsmPerformOp(tuple, ctx);
     }
 
     public void merge() throws Exception {
-        LSMTreeOpContext ctx = createOpContext();
-        ITreeIndexCursor cursor = new LSMTreeRangeSearchCursor();
+        if (LOGGER.isLoggable(Level.INFO)) {
+            LOGGER.info("Merging LSM-BTree.");
+        }
+        LSMBTreeOpContext ctx = createOpContext();
+        ITreeIndexCursor cursor = new LSMBTreeRangeSearchCursor();
         RangePredicate rangePred = new RangePredicate(true, null, null, true, true, null, null);
         // Ordered scan, ignoring the in-memory BTree.
         search(cursor, (RangePredicate) rangePred, ctx, false);
 
-        // Create a new Merged BTree, which have full fillfactor.
-        // Register the BTree information into system.
-        // TODO: change the naming schema for the new tree
-        // TODO: Alex. fix this.
-        String dummy = "abc";
-        FileReference file = new FileReference(new File(dummy));
-        // TODO: Delete the file during cleanup.
-        diskBufferCache.createFile(file);
-        int mergedBTreeId = diskFileMapProvider.lookupFileId(file);
-        // TODO: Close the file during cleanup.
-        diskBufferCache.openFile(mergedBTreeId);
-
-        // Create new in-Disk BTree.
-        BTree mergedBTree = this.diskBTreeFactory.createBTreeInstance(mergedBTreeId);
-        mergedBTree.create(mergedBTreeId);
-        // TODO: Close the BTree during cleanup.
-        mergedBTree.open(mergedBTreeId);
-
-        // BulkLoad the tuples from the in-memory tree into the new disk BTree.
+        // Bulk load the tuples from all on-disk BTrees into the new BTree.
+        BTree mergedBTree = createMergeTargetBTree();
         IIndexBulkLoadContext bulkLoadCtx = mergedBTree.beginBulkLoad(1.0f);
         try {
             while (cursor.hasNext()) {
@@ -437,34 +422,6 @@
             cursor.close();
         }
         mergedBTree.endBulkLoad(bulkLoadCtx);
-
-        /*
-        synchronized (onDiskBTrees) {
-            mergedBTrees = (LinkedList<BTree>) onDiskBTrees.clone();
-            // Remove the redundant trees, and add the new merged tree in the
-            // last off the list
-            for (int i = 0; i < numberOfInDiskTrees; i++) {
-                mergedBTrees.removeLast();
-            }
-            mergedBTrees.addLast(mergedBTree);
-
-            // TODO: to swap the linkedlists
-            //
-            // tempInDiskTreeInfo = inDiskTreeInfoList; inDiskTreeInfoList =
-            // mergedInDiskTreeInfoList; mergedInDiskTreeInfoList =
-            // tempInDiskTreeInfo;
-            //
-            // TODO: to swap the searchThreadCounters
-
-            // 1. should add the searcherReferenceCounter
-            // 2. Wrap the searcherReferenceCounter as Integer object,
-            // otherwise, the reference cannot be swapped
-            // 3. modify the "decrease counter part" in search(), and let the
-            // searcher remember the localReferences
-
-        }
-        // TODO: to wake up the cleaning thread
-         */
     }
     
     public class LSMTreeBulkLoadContext implements IIndexBulkLoadContext {
@@ -506,7 +463,7 @@
     public void endBulkLoad(IIndexBulkLoadContext ictx) throws HyracksDataException {
         LSMTreeBulkLoadContext bulkLoadCtx = (LSMTreeBulkLoadContext) ictx;
         bulkLoadCtx.getBTree().endBulkLoad(bulkLoadCtx.getBulkLoadCtx());
-        onDiskBTrees.addFirst(bulkLoadCtx.getBTree());
+        diskBTrees.addFirst(bulkLoadCtx.getBTree());
     }
 
     @Override
@@ -543,8 +500,8 @@
         return cmp;
     }
     
-    public LSMTreeOpContext createOpContext() {
-        return new LSMTreeOpContext(memBTree, insertLeafFrameFactory, deleteLeafFrameFactory);
+    public LSMBTreeOpContext createOpContext() {
+        return new LSMBTreeOpContext(memBTree, insertLeafFrameFactory, deleteLeafFrameFactory);
     }
 
     @Override
@@ -553,10 +510,10 @@
     }
 
     private class LSMTreeIndexAccessor implements ITreeIndexAccessor {
-        private LSMTree lsmTree;
-        private LSMTreeOpContext ctx;
+        private LSMBTree lsmTree;
+        private LSMBTreeOpContext ctx;
 
-        public LSMTreeIndexAccessor(LSMTree lsmTree) {
+        public LSMTreeIndexAccessor(LSMBTree lsmTree) {
             this.lsmTree = lsmTree;
             this.ctx = lsmTree.createOpContext();
         }
@@ -582,7 +539,7 @@
 
         @Override
         public ITreeIndexCursor createSearchCursor() {
-            return new LSMTreeRangeSearchCursor();
+            return new LSMBTreeRangeSearchCursor();
         }
         
         @Override
diff --git a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMBTreeCursorInitialState.java b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMBTreeCursorInitialState.java
new file mode 100644
index 0000000..672ff4a
--- /dev/null
+++ b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMBTreeCursorInitialState.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2009-2010 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.impls;
+
+import edu.uci.ics.hyracks.storage.am.common.api.ICursorInitialState;
+import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexFrameFactory;
+import edu.uci.ics.hyracks.storage.am.common.ophelpers.MultiComparator;
+import edu.uci.ics.hyracks.storage.common.buffercache.ICachedPage;
+
+public class LSMBTreeCursorInitialState implements ICursorInitialState {
+
+	private int numBTrees;
+	private ITreeIndexFrameFactory leafFrameFactory;
+	private MultiComparator cmp;
+	private LSMBTree lsm;
+	
+	public LSMBTreeCursorInitialState(int numBTrees, ITreeIndexFrameFactory leafFrameFactory, MultiComparator cmp, LSMBTree lsm) {
+		this.numBTrees = numBTrees;
+		this.leafFrameFactory = leafFrameFactory;
+		this.cmp = cmp;
+		this.lsm = lsm;
+	}
+	
+	public int getNumBTrees() {
+		return numBTrees;
+	}
+
+	public ITreeIndexFrameFactory getLeafFrameFactory() {
+		return leafFrameFactory;
+	}
+
+	public MultiComparator getCmp() {
+		return cmp;
+	}
+
+	@Override
+	public ICachedPage getPage() {
+		return null;
+	}
+
+	@Override
+	public void setPage(ICachedPage page) {
+	}
+
+	public LSMBTree getLsm() {
+		return lsm;
+	}
+
+}
diff --git a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMTreeOpContext.java b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMBTreeOpContext.java
similarity index 95%
rename from hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMTreeOpContext.java
rename to hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMBTreeOpContext.java
index 92a9988..daf27ad 100644
--- a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMTreeOpContext.java
+++ b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMBTreeOpContext.java
@@ -22,7 +22,7 @@
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexFrameFactory;
 import edu.uci.ics.hyracks.storage.am.common.ophelpers.IndexOp;
 
-public final class LSMTreeOpContext implements IIndexOpContext {
+public final class LSMBTreeOpContext implements IIndexOpContext {
     
 	public ITreeIndexFrameFactory insertLeafFrameFactory;
 	public ITreeIndexFrameFactory deleteLeafFrameFactory;
@@ -33,7 +33,7 @@
 	public BTreeOpContext memBTreeOpCtx;
 	public IndexOp op;
 	
-    public LSMTreeOpContext(BTree memBTree, ITreeIndexFrameFactory insertLeafFrameFactory,
+    public LSMBTreeOpContext(BTree memBTree, ITreeIndexFrameFactory insertLeafFrameFactory,
             ITreeIndexFrameFactory deleteLeafFrameFactory) {
 		this.memBTree = memBTree;
 		this.insertLeafFrameFactory = insertLeafFrameFactory;
diff --git a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMTreeRangeSearchCursor.java b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMBTreeRangeSearchCursor.java
similarity index 65%
rename from hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMTreeRangeSearchCursor.java
rename to hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMBTreeRangeSearchCursor.java
index 9e59c11..cf2a9e3 100644
--- a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMTreeRangeSearchCursor.java
+++ b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMBTreeRangeSearchCursor.java
@@ -1,5 +1,21 @@
+/*
+ * Copyright 2009-2010 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.impls;
 
+import java.util.Comparator;
 import java.util.PriorityQueue;
 
 import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
@@ -11,33 +27,33 @@
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexCursor;
 import edu.uci.ics.hyracks.storage.am.common.api.TreeIndexException;
 import edu.uci.ics.hyracks.storage.am.common.ophelpers.MultiComparator;
-import edu.uci.ics.hyracks.storage.am.lsm.tuples.LSMTypeAwareTupleReference;
+import edu.uci.ics.hyracks.storage.am.lsm.tuples.LSMBTreeTupleReference;
 import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
 import edu.uci.ics.hyracks.storage.common.buffercache.ICachedPage;
 
-public class LSMTreeRangeSearchCursor implements ITreeIndexCursor {
-
+public class LSMBTreeRangeSearchCursor implements ITreeIndexCursor {
     private BTreeRangeSearchCursor[] rangeCursors;
-    private PriorityQueue<LSMPriorityQueueElement> outputPriorityQueue;
+    private PriorityQueue<PriorityQueueElement> outputPriorityQueue;
     private MultiComparator cmp;
-    private LSMPriorityQueueElement outputElement;
-    private LSMPriorityQueueElement reusedElement;
+    private PriorityQueueComparator pqCmp;
+    private PriorityQueueElement outputElement;
+    private PriorityQueueElement reusedElement;
     private boolean needPush;
-    private LSMTree lsmTree;
+    private LSMBTree lsmTree;
 
-    public LSMTreeRangeSearchCursor() {
+    public LSMBTreeRangeSearchCursor() {
         outputElement = null;
         needPush = false;
     }
 
-    public void initPriorityQueue(LSMPriorityQueueComparator LSMPriorityQueueCmp)
-            throws HyracksDataException {
-        outputPriorityQueue = new PriorityQueue<LSMPriorityQueueElement>(rangeCursors.length, LSMPriorityQueueCmp);
+    public void initPriorityQueue()
+            throws HyracksDataException {                
+        outputPriorityQueue = new PriorityQueue<PriorityQueueElement>(rangeCursors.length, pqCmp);
         for (int i = 0; i < rangeCursors.length; i++) {
-            LSMPriorityQueueElement element;
+            PriorityQueueElement element;
             if (rangeCursors[i].hasNext()) {
                 rangeCursors[i].next();
-                element = new LSMPriorityQueueElement(rangeCursors[i].getTuple(), i);
+                element = new PriorityQueueElement(rangeCursors[i].getTuple(), i);
                 outputPriorityQueue.offer(element);
             }
         }
@@ -71,7 +87,7 @@
 
     @Override
     public void open(ICursorInitialState initialState, ISearchPredicate searchPred) throws HyracksDataException {
-        LSMTreeCursorInitialState lsmInitialState = (LSMTreeCursorInitialState) initialState;
+        LSMBTreeCursorInitialState lsmInitialState = (LSMBTreeCursorInitialState) initialState;
         lsmTree = lsmInitialState.getLsm();
         cmp = lsmInitialState.getCmp();
         int numBTrees = lsmInitialState.getNumBTrees();
@@ -80,6 +96,13 @@
             IBTreeLeafFrame leafFrame = (IBTreeLeafFrame) lsmInitialState.getLeafFrameFactory().createFrame();
             rangeCursors[i] = new BTreeRangeSearchCursor(leafFrame, false);
         }
+        setPriorityQueueComparator();
+    }
+    
+    private void setPriorityQueueComparator() {
+        if (pqCmp == null || cmp != pqCmp.getMultiComparator()) {
+            pqCmp = new PriorityQueueComparator(cmp);
+        }
     }
 
     @Override
@@ -128,12 +151,12 @@
     private void checkPriorityQueue() throws HyracksDataException {
         while (!outputPriorityQueue.isEmpty() || needPush == true) {
             if (!outputPriorityQueue.isEmpty()) {
-                LSMPriorityQueueElement checkElement = outputPriorityQueue.peek();
+                PriorityQueueElement checkElement = outputPriorityQueue.peek();
                 // If there is no previous tuple or the previous tuple can be
                 // ignored
                 if (outputElement == null) {
                     // Test the tuple is a delete tuple or not
-                    if (((LSMTypeAwareTupleReference) checkElement.getTuple()).isAntimatter() == true) {
+                    if (((LSMBTreeTupleReference) checkElement.getTuple()).isAntimatter() == true) {
                         // If the tuple is a delete tuple then pop it and mark
                         // it "needPush"
                         // Cannot push at this time because the tuple may be
@@ -181,4 +204,52 @@
     public boolean exclusiveLatchNodes() {
         return false;
     }
+    
+    public class PriorityQueueComparator implements Comparator<PriorityQueueElement> {
+
+        private final MultiComparator cmp;
+
+        public PriorityQueueComparator(MultiComparator cmp) {
+            this.cmp = cmp;
+        }
+
+        @Override
+        public int compare(PriorityQueueElement elementA, PriorityQueueElement elementB) {
+            int result = cmp.compare(elementA.getTuple(), elementB.getTuple());
+            if (result != 0) {
+                return result;
+            }
+            if (elementA.getCursorIndex() > elementB.getCursorIndex()) {
+                return 1;
+            } else {
+                return -1;
+            }
+        }
+
+        public MultiComparator getMultiComparator() {
+            return cmp;
+        }
+    }
+    
+    public class PriorityQueueElement {
+        private ITupleReference tuple;
+        private int cursorIndex;
+        
+        public PriorityQueueElement(ITupleReference tuple, int cursorIndex) {
+            reset(tuple, cursorIndex);
+        }
+
+        public ITupleReference getTuple() {
+            return tuple;
+        }
+
+        public int getCursorIndex() {
+            return cursorIndex;
+        }
+        
+        public void reset(ITupleReference tuple, int cursorIndex) {
+            this.tuple = tuple;
+            this.cursorIndex = cursorIndex;
+        }
+    }
 }
diff --git a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMPriorityQueueComparator.java b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMPriorityQueueComparator.java
deleted file mode 100644
index 674b94d..0000000
--- a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMPriorityQueueComparator.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2009-2010 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.impls;
-
-import java.util.Comparator;
-
-import edu.uci.ics.hyracks.storage.am.common.ophelpers.MultiComparator;
-
-public class LSMPriorityQueueComparator implements Comparator<LSMPriorityQueueElement> {
-
-	private final MultiComparator cmp;
-	
-	public LSMPriorityQueueComparator(MultiComparator cmp) {
-		this.cmp = cmp;
-	}
-	
-	@Override
-	public int compare(LSMPriorityQueueElement elementA, LSMPriorityQueueElement elementB) {
-		
-		int result = cmp.compare(elementA.getTuple(), elementB.getTuple());
-		
-		if(result == 1) {
-			return 1;
-		}
-		else if(result == -1) {
-			return -1;
-		}
-		else {
-			if(elementA.getCursorIndex() > elementB.getCursorIndex()) {
-				return 1;
-			}
-			else {
-				return -1;
-			}
-		}
-	}
-
-}
diff --git a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMPriorityQueueElement.java b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMPriorityQueueElement.java
deleted file mode 100644
index 4ed9818..0000000
--- a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMPriorityQueueElement.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package edu.uci.ics.hyracks.storage.am.lsm.impls;
-
-import edu.uci.ics.hyracks.dataflow.common.data.accessors.ITupleReference;
-
-public class LSMPriorityQueueElement {
-	private ITupleReference tuple;
-	private int cursorIndex;
-	
-	public LSMPriorityQueueElement(ITupleReference tuple, int cursorIndex) {
-		reset(tuple, cursorIndex);
-	}
-
-	public ITupleReference getTuple() {
-		return tuple;
-	}
-
-	public int getCursorIndex() {
-		return cursorIndex;
-	}
-	
-	public void reset(ITupleReference tuple, int cursorIndex) {
-		this.tuple = tuple;
-		this.cursorIndex = cursorIndex;
-	}
-}
diff --git a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMTreeCursorInitialState.java b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMTreeCursorInitialState.java
deleted file mode 100644
index 10bbac6..0000000
--- a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/impls/LSMTreeCursorInitialState.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package edu.uci.ics.hyracks.storage.am.lsm.impls;
-
-import edu.uci.ics.hyracks.storage.am.common.api.ICursorInitialState;
-import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexFrameFactory;
-import edu.uci.ics.hyracks.storage.am.common.ophelpers.MultiComparator;
-import edu.uci.ics.hyracks.storage.common.buffercache.ICachedPage;
-
-public class LSMTreeCursorInitialState implements ICursorInitialState {
-
-	private int numBTrees;
-	private ITreeIndexFrameFactory leafFrameFactory;
-	private MultiComparator cmp;
-	private LSMTree lsm;
-	
-	public LSMTreeCursorInitialState(int numBTrees, ITreeIndexFrameFactory leafFrameFactory, MultiComparator cmp, LSMTree lsm) {
-		this.numBTrees = numBTrees;
-		this.leafFrameFactory = leafFrameFactory;
-		this.cmp = cmp;
-		this.lsm = lsm;
-	}
-	
-	public int getNumBTrees() {
-		return numBTrees;
-	}
-
-	public ITreeIndexFrameFactory getLeafFrameFactory() {
-		return leafFrameFactory;
-	}
-
-	public MultiComparator getCmp() {
-		return cmp;
-	}
-
-	@Override
-	public ICachedPage getPage() {
-		return null;
-	}
-
-	@Override
-	public void setPage(ICachedPage page) {
-	}
-
-	public LSMTree getLsm() {
-		return lsm;
-	}
-
-}
diff --git a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/ILSMTreeTupleReference.java b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/ILSMBTreeTupleReference.java
similarity index 91%
rename from hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/ILSMTreeTupleReference.java
rename to hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/ILSMBTreeTupleReference.java
index 5f6a79c..a4d2f92 100644
--- a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/ILSMTreeTupleReference.java
+++ b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/ILSMBTreeTupleReference.java
@@ -17,6 +17,6 @@
 
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexTupleReference;
 
-public interface ILSMTreeTupleReference extends ITreeIndexTupleReference {
+public interface ILSMBTreeTupleReference extends ITreeIndexTupleReference {
 	public boolean isAntimatter();
 }
diff --git a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMBTreeCopyTupleWriter.java b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMBTreeCopyTupleWriter.java
new file mode 100644
index 0000000..db75995
--- /dev/null
+++ b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMBTreeCopyTupleWriter.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2009-2010 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.tuples;
+
+import edu.uci.ics.hyracks.api.dataflow.value.ITypeTraits;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ITupleReference;
+
+public class LSMBTreeCopyTupleWriter extends LSMBTreeTupleWriter {
+	public LSMBTreeCopyTupleWriter(ITypeTraits[] typeTraits, int numKeyFields){
+		// Third parameter is never used locally, just give false.
+	    super(typeTraits, numKeyFields, false);
+	}
+	
+	@Override
+    public int writeTuple(ITupleReference tuple, byte[] targetBuf, int targetOff) {
+		int tupleSize = bytesRequired(tuple);
+		byte[] buf = tuple.getFieldData(0);
+		int tupleStartOff = ((LSMBTreeTupleReference)tuple).getTupleStart();
+		System.arraycopy(buf, tupleStartOff, targetBuf, targetOff, tupleSize);
+        return tupleSize;
+    }
+}
diff --git a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMTypeAwareTupleWriterFactory.java b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMBTreeCopyTupleWriterFactory.java
similarity index 79%
copy from hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMTypeAwareTupleWriterFactory.java
copy to hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMBTreeCopyTupleWriterFactory.java
index 35eff4f..78de794 100644
--- a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMTypeAwareTupleWriterFactory.java
+++ b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMBTreeCopyTupleWriterFactory.java
@@ -19,22 +19,19 @@
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexTupleWriter;
 import edu.uci.ics.hyracks.storage.am.common.tuples.TypeAwareTupleWriterFactory;
 
-public class LSMTypeAwareTupleWriterFactory extends TypeAwareTupleWriterFactory {
-
+public class LSMBTreeCopyTupleWriterFactory extends TypeAwareTupleWriterFactory {
 	private static final long serialVersionUID = 1L;
 	private final ITypeTraits[] typeTraits;
 	private final int numKeyFields;
-	private final boolean isDelete;
 	
-	public LSMTypeAwareTupleWriterFactory(ITypeTraits[] typeTraits, int numKeyFields, boolean isDelete) {
+	public LSMBTreeCopyTupleWriterFactory(ITypeTraits[] typeTraits, int numKeyFields) {
 		super(typeTraits);
 		this.typeTraits = typeTraits;
 		this.numKeyFields = numKeyFields;
-		this.isDelete = isDelete;
 	}
 
 	@Override
 	public ITreeIndexTupleWriter createTupleWriter() {
-		return new LSMTypeAwareTupleWriter(typeTraits, numKeyFields, isDelete);
+		return new LSMBTreeCopyTupleWriter(typeTraits, numKeyFields);
 	}
 }
diff --git a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMTypeAwareTupleReference.java b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMBTreeTupleReference.java
similarity index 93%
rename from hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMTypeAwareTupleReference.java
rename to hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMBTreeTupleReference.java
index 2d3d31a..d5d44bd 100644
--- a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMTypeAwareTupleReference.java
+++ b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMBTreeTupleReference.java
@@ -21,7 +21,7 @@
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexFrame;
 import edu.uci.ics.hyracks.storage.am.common.tuples.TypeAwareTupleReference;
 
-public class LSMTypeAwareTupleReference extends TypeAwareTupleReference implements ILSMTreeTupleReference {
+public class LSMBTreeTupleReference extends TypeAwareTupleReference implements ILSMBTreeTupleReference {
 
     // Indicates whether the last call to setFieldCount() was initiated by
     // by the outside or whether it was called internally to set up an
@@ -29,7 +29,7 @@
     private boolean resetFieldCount = false;
     private final int numKeyFields;
     
-    public LSMTypeAwareTupleReference(ITypeTraits[] typeTraits, int numKeyFields) {
+    public LSMBTreeTupleReference(ITypeTraits[] typeTraits, int numKeyFields) {
 		super(typeTraits);
 		this.numKeyFields = numKeyFields;
 	}
diff --git a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMTypeAwareTupleWriter.java b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMBTreeTupleWriter.java
similarity index 90%
rename from hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMTypeAwareTupleWriter.java
rename to hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMBTreeTupleWriter.java
index b7a0a9c..ea58282 100644
--- a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMTypeAwareTupleWriter.java
+++ b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMBTreeTupleWriter.java
@@ -20,11 +20,11 @@
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexTupleReference;
 import edu.uci.ics.hyracks.storage.am.common.tuples.TypeAwareTupleWriter;
 
-public class LSMTypeAwareTupleWriter extends TypeAwareTupleWriter {
+public class LSMBTreeTupleWriter extends TypeAwareTupleWriter {
 	private final boolean isDelete;
 	private final int numKeyFields;
 	
-	public LSMTypeAwareTupleWriter(ITypeTraits[] typeTraits, int numKeyFields, boolean isDelete) {
+	public LSMBTreeTupleWriter(ITypeTraits[] typeTraits, int numKeyFields, boolean isDelete) {
 		super(typeTraits);
 		this.numKeyFields = numKeyFields;
 		this.isDelete = isDelete;
@@ -32,7 +32,7 @@
 
 	@Override
     public ITreeIndexTupleReference createTupleReference() {
-        return new LSMTypeAwareTupleReference(typeTraits, numKeyFields);
+        return new LSMBTreeTupleReference(typeTraits, numKeyFields);
     }
 	
 	@Override
diff --git a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMTypeAwareTupleWriterFactory.java b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMBTreeTupleWriterFactory.java
similarity index 82%
rename from hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMTypeAwareTupleWriterFactory.java
rename to hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMBTreeTupleWriterFactory.java
index 35eff4f..cd016ea 100644
--- a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMTypeAwareTupleWriterFactory.java
+++ b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMBTreeTupleWriterFactory.java
@@ -19,14 +19,14 @@
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexTupleWriter;
 import edu.uci.ics.hyracks.storage.am.common.tuples.TypeAwareTupleWriterFactory;
 
-public class LSMTypeAwareTupleWriterFactory extends TypeAwareTupleWriterFactory {
+public class LSMBTreeTupleWriterFactory extends TypeAwareTupleWriterFactory {
 
 	private static final long serialVersionUID = 1L;
 	private final ITypeTraits[] typeTraits;
 	private final int numKeyFields;
 	private final boolean isDelete;
 	
-	public LSMTypeAwareTupleWriterFactory(ITypeTraits[] typeTraits, int numKeyFields, boolean isDelete) {
+	public LSMBTreeTupleWriterFactory(ITypeTraits[] typeTraits, int numKeyFields, boolean isDelete) {
 		super(typeTraits);
 		this.typeTraits = typeTraits;
 		this.numKeyFields = numKeyFields;
@@ -35,6 +35,6 @@
 
 	@Override
 	public ITreeIndexTupleWriter createTupleWriter() {
-		return new LSMTypeAwareTupleWriter(typeTraits, numKeyFields, isDelete);
+		return new LSMBTreeTupleWriter(typeTraits, numKeyFields, isDelete);
 	}
 }
diff --git a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMEntireTupleWriter.java b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMEntireTupleWriter.java
deleted file mode 100644
index 3632939..0000000
--- a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMEntireTupleWriter.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package edu.uci.ics.hyracks.storage.am.lsm.tuples;
-
-import edu.uci.ics.hyracks.api.dataflow.value.ITypeTraits;
-import edu.uci.ics.hyracks.dataflow.common.data.accessors.ITupleReference;
-
-public class LSMEntireTupleWriter extends LSMTypeAwareTupleWriter {
-	public LSMEntireTupleWriter(ITypeTraits[] typeTraits, int numKeyFields){
-		// Third parameter is never used locally, just give false.
-	    super(typeTraits, numKeyFields, false);
-	}
-	
-	@Override
-    public int writeTuple(ITupleReference tuple, byte[] targetBuf, int targetOff) {
-		int tupleSize = bytesRequired(tuple);
-		byte[] buf = tuple.getFieldData(0);
-		int tupleStartOff = ((LSMTypeAwareTupleReference)tuple).getTupleStart();
-		System.arraycopy(buf, tupleStartOff, targetBuf, targetOff, tupleSize);
-        return tupleSize;
-    }
-}
diff --git a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMEntireTupleWriterFactory.java b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMEntireTupleWriterFactory.java
deleted file mode 100644
index b214a6a..0000000
--- a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/tuples/LSMEntireTupleWriterFactory.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package edu.uci.ics.hyracks.storage.am.lsm.tuples;
-
-import edu.uci.ics.hyracks.api.dataflow.value.ITypeTraits;
-import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexTupleWriter;
-import edu.uci.ics.hyracks.storage.am.common.tuples.TypeAwareTupleWriterFactory;
-
-public class LSMEntireTupleWriterFactory extends TypeAwareTupleWriterFactory {
-	private static final long serialVersionUID = 1L;
-	private final ITypeTraits[] typeTraits;
-	private final int numKeyFields;
-	
-	public LSMEntireTupleWriterFactory(ITypeTraits[] typeTraits, int numKeyFields) {
-		super(typeTraits);
-		this.typeTraits = typeTraits;
-		this.numKeyFields = numKeyFields;
-	}
-
-	@Override
-	public ITreeIndexTupleWriter createTupleWriter() {
-		return new LSMEntireTupleWriter(typeTraits, numKeyFields);
-	}
-}
diff --git a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/util/LSMBTreeUtils.java b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/util/LSMBTreeUtils.java
index d8794aa..1262a14 100644
--- a/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/util/LSMBTreeUtils.java
+++ b/hyracks-storage-am-lsm-btree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/util/LSMBTreeUtils.java
@@ -29,22 +29,22 @@
 import edu.uci.ics.hyracks.storage.am.lsm.common.freepage.InMemoryFreePageManager;
 import edu.uci.ics.hyracks.storage.am.lsm.impls.BTreeFactory;
 import edu.uci.ics.hyracks.storage.am.lsm.impls.LSMBTreeFileNameManager;
-import edu.uci.ics.hyracks.storage.am.lsm.impls.LSMTree;
-import edu.uci.ics.hyracks.storage.am.lsm.tuples.LSMEntireTupleWriterFactory;
-import edu.uci.ics.hyracks.storage.am.lsm.tuples.LSMTypeAwareTupleWriterFactory;
+import edu.uci.ics.hyracks.storage.am.lsm.impls.LSMBTree;
+import edu.uci.ics.hyracks.storage.am.lsm.tuples.LSMBTreeCopyTupleWriterFactory;
+import edu.uci.ics.hyracks.storage.am.lsm.tuples.LSMBTreeTupleWriterFactory;
 import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
 import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
 
 public class LSMBTreeUtils {
-    public static LSMTree createLSMTree(InMemoryBufferCache memBufferCache, InMemoryFreePageManager memFreePageManager,
+    public static LSMBTree createLSMTree(InMemoryBufferCache memBufferCache, InMemoryFreePageManager memFreePageManager,
             String onDiskDir, IBufferCache diskBufferCache, IFileMapProvider diskFileMapProvider,
             ITypeTraits[] typeTraits, IBinaryComparator[] cmps) {
         MultiComparator cmp = new MultiComparator(cmps);
-        LSMTypeAwareTupleWriterFactory insertTupleWriterFactory = new LSMTypeAwareTupleWriterFactory(typeTraits,
+        LSMBTreeTupleWriterFactory insertTupleWriterFactory = new LSMBTreeTupleWriterFactory(typeTraits,
                 cmps.length, false);
-        LSMTypeAwareTupleWriterFactory deleteTupleWriterFactory = new LSMTypeAwareTupleWriterFactory(typeTraits,
+        LSMBTreeTupleWriterFactory deleteTupleWriterFactory = new LSMBTreeTupleWriterFactory(typeTraits,
                 cmps.length, true);
-        LSMEntireTupleWriterFactory copyTupleWriterFactory = new LSMEntireTupleWriterFactory(typeTraits, cmps.length);
+        LSMBTreeCopyTupleWriterFactory copyTupleWriterFactory = new LSMBTreeCopyTupleWriterFactory(typeTraits, cmps.length);
         ITreeIndexFrameFactory insertLeafFrameFactory = new BTreeNSMLeafFrameFactory(insertTupleWriterFactory);
         ITreeIndexFrameFactory copyTupleLeafFrameFactory = new BTreeNSMLeafFrameFactory(copyTupleWriterFactory);
         ITreeIndexFrameFactory deleteLeafFrameFactory = new BTreeNSMLeafFrameFactory(deleteTupleWriterFactory);
@@ -57,7 +57,7 @@
         BTreeFactory bulkLoadBTreeFactory = new BTreeFactory(diskBufferCache, freePageManagerFactory, cmp,
                 typeTraits.length, interiorFrameFactory, insertLeafFrameFactory);
         ILSMFileNameManager fileNameManager = new LSMBTreeFileNameManager(onDiskDir);
-        LSMTree lsmTree = new LSMTree(memBufferCache, memFreePageManager, interiorFrameFactory, insertLeafFrameFactory,
+        LSMBTree lsmTree = new LSMBTree(memBufferCache, memFreePageManager, interiorFrameFactory, insertLeafFrameFactory,
                 deleteLeafFrameFactory, fileNameManager, diskBTreeFactory, bulkLoadBTreeFactory, diskFileMapProvider,
                 typeTraits.length, cmp);
         return lsmTree;
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BulkLoadTest.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeBulkLoadTest.java
similarity index 95%
rename from hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BulkLoadTest.java
rename to hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeBulkLoadTest.java
index b29c239..f509284 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BulkLoadTest.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeBulkLoadTest.java
@@ -29,9 +29,9 @@
 import edu.uci.ics.hyracks.storage.am.btree.util.BTreeTestHarness;
 
 @SuppressWarnings("rawtypes")
-public class BulkLoadTest extends OrderedIndexBulkLoadTest {
+public class BTreeBulkLoadTest extends OrderedIndexBulkLoadTest {
     
-    public BulkLoadTest() {
+    public BTreeBulkLoadTest() {
         super(BTreeTestHarness.LEAF_FRAMES_TO_TEST);
     }
 
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/DeleteTest.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeDeleteTest.java
similarity index 95%
rename from hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/DeleteTest.java
rename to hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeDeleteTest.java
index a0def7d..e4475fe 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/DeleteTest.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeDeleteTest.java
@@ -29,9 +29,9 @@
 import edu.uci.ics.hyracks.storage.am.btree.util.BTreeTestHarness;
 
 @SuppressWarnings("rawtypes")
-public class DeleteTest extends OrderedIndexDeleteTest {
+public class BTreeDeleteTest extends OrderedIndexDeleteTest {
     
-    public DeleteTest() {
+    public BTreeDeleteTest() {
         super(BTreeTestHarness.LEAF_FRAMES_TO_TEST);
     }
 
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/InsertTest.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeInsertTest.java
similarity index 96%
rename from hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/InsertTest.java
rename to hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeInsertTest.java
index 4625353..a4d9570 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/InsertTest.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeInsertTest.java
@@ -39,9 +39,9 @@
  * 
  */
 @SuppressWarnings("rawtypes")
-public class InsertTest extends OrderedIndexInsertTest {
+public class BTreeInsertTest extends OrderedIndexInsertTest {
 
-    public InsertTest() {
+    public BTreeInsertTest() {
         super(BTreeTestHarness.LEAF_FRAMES_TO_TEST);
     }
 
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/RangeSearchCursorTest.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeSearchCursorTest.java
similarity index 99%
rename from hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/RangeSearchCursorTest.java
rename to hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeSearchCursorTest.java
index 052caaf..764cbb6 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/RangeSearchCursorTest.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeSearchCursorTest.java
@@ -60,7 +60,7 @@
 import edu.uci.ics.hyracks.storage.am.common.util.IndexUtils;
 import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
 
-public class RangeSearchCursorTest extends AbstractBTreeTest {
+public class BTreeSearchCursorTest extends AbstractBTreeTest {
     // Declare fields
     int fieldCount = 2;
     ITypeTraits[] typeTraits = new ITypeTraits[fieldCount];
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/UpdateSearchTest.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeUpdateSearchTest.java
similarity index 99%
rename from hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/UpdateSearchTest.java
rename to hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeUpdateSearchTest.java
index 36c29e1..f1059dd 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/UpdateSearchTest.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeUpdateSearchTest.java
@@ -36,7 +36,7 @@
 import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
 
 @SuppressWarnings("rawtypes")
-public class UpdateSearchTest extends AbstractBTreeTest {
+public class BTreeUpdateSearchTest extends AbstractBTreeTest {
 
     // Update scan test on fixed-length tuples.
     @Test
diff --git a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/UpdateTest.java b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeUpdateTest.java
similarity index 95%
rename from hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/UpdateTest.java
rename to hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeUpdateTest.java
index c8dd1e0..14f8d18 100644
--- a/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/UpdateTest.java
+++ b/hyracks-tests/hyracks-storage-am-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeUpdateTest.java
@@ -29,9 +29,9 @@
 import edu.uci.ics.hyracks.storage.am.btree.util.BTreeTestHarness;
 
 @SuppressWarnings("rawtypes")
-public class UpdateTest extends OrderedIndexUpdateTest {
+public class BTreeUpdateTest extends OrderedIndexUpdateTest {
     
-    public UpdateTest() {
+    public BTreeUpdateTest() {
         super(BTreeTestHarness.LEAF_FRAMES_TO_TEST);
     }
 
diff --git a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/BulkLoadTest.java b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/LSMBTreeBulkLoadTest.java
similarity index 95%
rename from hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/BulkLoadTest.java
rename to hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/LSMBTreeBulkLoadTest.java
index 49e16ce..8103191 100644
--- a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/BulkLoadTest.java
+++ b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/LSMBTreeBulkLoadTest.java
@@ -29,9 +29,9 @@
 import edu.uci.ics.hyracks.storage.am.lsm.btree.util.LSMBTreeTestHarness;
 
 @SuppressWarnings("rawtypes")
-public class BulkLoadTest extends OrderedIndexBulkLoadTest {
+public class LSMBTreeBulkLoadTest extends OrderedIndexBulkLoadTest {
     
-    public BulkLoadTest() {
+    public LSMBTreeBulkLoadTest() {
         super(LSMBTreeTestHarness.LEAF_FRAMES_TO_TEST);
     }
     
diff --git a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/DeleteTest.java b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/LSMBTreeDeleteTest.java
similarity index 95%
rename from hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/DeleteTest.java
rename to hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/LSMBTreeDeleteTest.java
index bfc8bc8..27ef60f 100644
--- a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/DeleteTest.java
+++ b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/LSMBTreeDeleteTest.java
@@ -29,9 +29,9 @@
 import edu.uci.ics.hyracks.storage.am.lsm.btree.util.LSMBTreeTestHarness;
 
 @SuppressWarnings("rawtypes")
-public class DeleteTest extends OrderedIndexDeleteTest {
+public class LSMBTreeDeleteTest extends OrderedIndexDeleteTest {
     
-    public DeleteTest() {
+    public LSMBTreeDeleteTest() {
         super(LSMBTreeTestHarness.LEAF_FRAMES_TO_TEST);
     }
     
diff --git a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/InsertTest.java b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/LSMBTreeInsertTest.java
similarity index 95%
rename from hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/InsertTest.java
rename to hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/LSMBTreeInsertTest.java
index f6809ac..4ab58a7 100644
--- a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/InsertTest.java
+++ b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/LSMBTreeInsertTest.java
@@ -29,9 +29,9 @@
 import edu.uci.ics.hyracks.storage.am.lsm.btree.util.LSMBTreeTestHarness;
 
 @SuppressWarnings("rawtypes")
-public class InsertTest extends OrderedIndexInsertTest {
+public class LSMBTreeInsertTest extends OrderedIndexInsertTest {
     
-    public InsertTest() {
+    public LSMBTreeInsertTest() {
         super(LSMBTreeTestHarness.LEAF_FRAMES_TO_TEST);
     }
 
diff --git a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/UpdateTest.java b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/LSMBTreeUpdateTest.java
similarity index 95%
rename from hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/UpdateTest.java
rename to hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/LSMBTreeUpdateTest.java
index 2abc826..8fbe9da 100644
--- a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/UpdateTest.java
+++ b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/LSMBTreeUpdateTest.java
@@ -29,9 +29,9 @@
 import edu.uci.ics.hyracks.storage.am.lsm.btree.util.LSMBTreeTestHarness;
 
 @SuppressWarnings("rawtypes")
-public class UpdateTest extends OrderedIndexUpdateTest {
+public class LSMBTreeUpdateTest extends OrderedIndexUpdateTest {
     
-    public UpdateTest() {
+    public LSMBTreeUpdateTest() {
         super(LSMBTreeTestHarness.LEAF_FRAMES_TO_TEST);
     }
 
diff --git a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/BTreeBulkLoadRunner.java b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/BTreeBulkLoadRunner.java
index 6991308..1590b17 100644
--- a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/BTreeBulkLoadRunner.java
+++ b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/BTreeBulkLoadRunner.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2009-2010 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.btree.perf;
 
 import edu.uci.ics.hyracks.api.dataflow.value.ITypeTraits;
diff --git a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/BTreePageSizePerf.java b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/BTreePageSizePerf.java
index 41f00f1..31a4c92 100644
--- a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/BTreePageSizePerf.java
+++ b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/BTreePageSizePerf.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2009-2010 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.btree.perf;
 
 import java.util.Enumeration;
diff --git a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/BTreeRunner.java b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/BTreeRunner.java
index ac61fb4..f110941 100644
--- a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/BTreeRunner.java
+++ b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/BTreeRunner.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2009-2010 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.btree.perf;
 
 import java.io.File;
diff --git a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/ConcurrentSkipListRunner.java b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/ConcurrentSkipListRunner.java
index fd55622..8f44966 100644
--- a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/ConcurrentSkipListRunner.java
+++ b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/ConcurrentSkipListRunner.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2009-2010 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.btree.perf;
 
 import java.nio.ByteBuffer;
diff --git a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/IExperimentRunner.java b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/IExperimentRunner.java
index 734baa1..0ea3a71 100644
--- a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/IExperimentRunner.java
+++ b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/IExperimentRunner.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2009-2010 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.btree.perf;
 
 import edu.uci.ics.hyracks.storage.am.common.datagen.DataGenThread;
diff --git a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/InMemoryBTreeRunner.java b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/InMemoryBTreeRunner.java
index 65efda5..1afd3d8 100644
--- a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/InMemoryBTreeRunner.java
+++ b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/InMemoryBTreeRunner.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2009-2010 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.btree.perf;
 
 import java.text.SimpleDateFormat;
diff --git a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/InMemorySortRunner.java b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/InMemorySortRunner.java
index e38c38f..53fbd88 100644
--- a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/InMemorySortRunner.java
+++ b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/InMemorySortRunner.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2009-2010 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.btree.perf;
 
 import java.nio.ByteBuffer;
diff --git a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/LSMTreeRunner.java b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/LSMTreeRunner.java
index b5f1324..28e58c7 100644
--- a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/LSMTreeRunner.java
+++ b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/LSMTreeRunner.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2009-2010 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.btree.perf;
 
 import java.text.SimpleDateFormat;
@@ -15,7 +30,7 @@
 import edu.uci.ics.hyracks.storage.am.common.ophelpers.MultiComparator;
 import edu.uci.ics.hyracks.storage.am.lsm.common.freepage.InMemoryBufferCache;
 import edu.uci.ics.hyracks.storage.am.lsm.common.freepage.InMemoryFreePageManager;
-import edu.uci.ics.hyracks.storage.am.lsm.impls.LSMTree;
+import edu.uci.ics.hyracks.storage.am.lsm.impls.LSMBTree;
 import edu.uci.ics.hyracks.storage.am.lsm.util.LSMBTreeUtils;
 import edu.uci.ics.hyracks.storage.common.buffercache.HeapBufferAllocator;
 import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
@@ -39,7 +54,7 @@
     protected String onDiskDir;
     
     protected final int numBatches;
-    protected final LSMTree lsmtree;
+    protected final LSMBTree lsmtree;
     protected IBufferCache memBufferCache;
     private final int onDiskPageSize;
     private final int onDiskNumPages;
@@ -105,10 +120,10 @@
 
 	public class LSMTreeThread extends Thread {
         private final DataGenThread dataGen;
-        private final LSMTree lsmTree;
+        private final LSMBTree lsmTree;
         private final int numBatches;
         private final ITreeIndexAccessor lsmTreeAccessor;
-        public LSMTreeThread(DataGenThread dataGen, LSMTree lsmTree, int numBatches) {
+        public LSMTreeThread(DataGenThread dataGen, LSMBTree lsmTree, int numBatches) {
             this.dataGen = dataGen;
             this.lsmTree = lsmTree;
             this.numBatches = numBatches;
diff --git a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/PerfExperiment.java b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/PerfExperiment.java
index d1cc426..f7cf57b 100644
--- a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/PerfExperiment.java
+++ b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/perf/PerfExperiment.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2009-2010 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.btree.perf;
 
 import java.io.FileOutputStream;
diff --git a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/util/LSMBTreeTestContext.java b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/util/LSMBTreeTestContext.java
index 02a84df..ff462b5 100644
--- a/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/util/LSMBTreeTestContext.java
+++ b/hyracks-tests/hyracks-storage-am-lsm-btree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/btree/util/LSMBTreeTestContext.java
@@ -24,7 +24,7 @@
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndex;
 import edu.uci.ics.hyracks.storage.am.lsm.common.freepage.InMemoryBufferCache;
 import edu.uci.ics.hyracks.storage.am.lsm.common.freepage.InMemoryFreePageManager;
-import edu.uci.ics.hyracks.storage.am.lsm.impls.LSMTree;
+import edu.uci.ics.hyracks.storage.am.lsm.impls.LSMBTree;
 import edu.uci.ics.hyracks.storage.am.lsm.util.LSMBTreeUtils;
 import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
 import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
@@ -38,13 +38,13 @@
 
     @Override
     public int getKeyFieldCount() {
-        LSMTree lsmTree = (LSMTree) treeIndex;
+        LSMBTree lsmTree = (LSMBTree) treeIndex;
         return lsmTree.getMultiComparator().getKeyFieldCount();
     }
 
     @Override
     public IBinaryComparator[] getComparators() {
-        LSMTree lsmTree = (LSMTree) treeIndex;
+        LSMBTree lsmTree = (LSMBTree) treeIndex;
         return lsmTree.getMultiComparator().getComparators();
     }
 
@@ -84,7 +84,7 @@
             throws Exception {
         ITypeTraits[] typeTraits = SerdeUtils.serdesToTypeTraits(fieldSerdes);
         IBinaryComparator[] cmps = SerdeUtils.serdesToComparators(fieldSerdes, numKeyFields);
-        LSMTree lsmTree = LSMBTreeUtils.createLSMTree(memBufferCache, memFreePageManager, onDiskDir, diskBufferCache,
+        LSMBTree lsmTree = LSMBTreeUtils.createLSMTree(memBufferCache, memFreePageManager, onDiskDir, diskBufferCache,
                 diskFileMapProvider, typeTraits, cmps);
         lsmTree.create(fileId);
         lsmTree.open(fileId);