1. Changed BTree code to use the new IBufferCache and IStorageManagerInterface to cleanly deal with the lifecycle of files.
2. Identified possible bug in BufferCache related to flushing pages when file reference count reaches zero. Code will compile but some tests fail. To be fixed next.

git-svn-id: https://hyracks.googlecode.com/svn/branches/hyracks_storage_cleanup@254 123451ca-8445-de46-9d55-352943316053
diff --git a/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/InsertPipelineExample.java b/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/InsertPipelineExample.java
index 80cc608..62915ba 100644
--- a/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/InsertPipelineExample.java
+++ b/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/InsertPipelineExample.java
@@ -30,19 +30,17 @@
 import edu.uci.ics.hyracks.dataflow.std.file.IFileSplitProvider;
 import edu.uci.ics.hyracks.dataflow.std.misc.NullSinkOperatorDescriptor;
 import edu.uci.ics.hyracks.examples.btree.helper.BTreeRegistryProvider;
-import edu.uci.ics.hyracks.examples.btree.helper.BufferCacheProvider;
 import edu.uci.ics.hyracks.examples.btree.helper.DataGenOperatorDescriptor;
-import edu.uci.ics.hyracks.examples.btree.helper.FileMappingProviderProvider;
+import edu.uci.ics.hyracks.examples.btree.helper.SimpleStorageManager;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeInteriorFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeLeafFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.BTreeInsertUpdateDeleteOperatorDescriptor;
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.IBTreeRegistryProvider;
-import edu.uci.ics.hyracks.storage.am.btree.dataflow.IBufferCacheProvider;
-import edu.uci.ics.hyracks.storage.am.btree.dataflow.IFileMappingProviderProvider;
 import edu.uci.ics.hyracks.storage.am.btree.frames.NSMInteriorFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.frames.NSMLeafFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.impls.BTreeOp;
 import edu.uci.ics.hyracks.storage.am.btree.tuples.TypeAwareTupleWriterFactory;
+import edu.uci.ics.hyracks.storage.common.IStorageManagerInterface;
 
 // This example will insert tuples into the primary and secondary index using an insert pipeline
 
@@ -108,10 +106,9 @@
         // run data generator on first nodecontroller given
         PartitionConstraint dataGenConstraint = new ExplicitPartitionConstraint(new LocationConstraint[] { new AbsoluteLocationConstraint(splitNCs[0]) });
         dataGen.setPartitionConstraint(dataGenConstraint);
-                
-        IBufferCacheProvider bufferCacheProvider = BufferCacheProvider.INSTANCE;
-        IBTreeRegistryProvider btreeRegistryProvider = BTreeRegistryProvider.INSTANCE;
-        IFileMappingProviderProvider fileMappingProviderProvider = FileMappingProviderProvider.INSTANCE;
+        
+        IBTreeRegistryProvider btreeRegistryProvider = BTreeRegistryProvider.INSTANCE;        
+        IStorageManagerInterface storageManager = SimpleStorageManager.INSTANCE;
         
         // prepare insertion into primary index
         // tuples to be put into B-Tree shall have 4 fields
@@ -132,9 +129,10 @@
         // comparator factories for primary index
         IBinaryComparatorFactory[] primaryComparatorFactories = new IBinaryComparatorFactory[1];
 		primaryComparatorFactories[0] = IntegerBinaryComparatorFactory.INSTANCE;
-		IFileSplitProvider primarySplitProvider = JobHelper.createFileSplitProvider(splitNCs, options.primaryBTreeName);
+		IFileSplitProvider primarySplitProvider = JobHelper.createFileSplitProvider(splitNCs, options.primaryBTreeName);		
+		
 		// create operator descriptor
-        BTreeInsertUpdateDeleteOperatorDescriptor primaryInsert = new BTreeInsertUpdateDeleteOperatorDescriptor(spec, recDesc, bufferCacheProvider, btreeRegistryProvider, primarySplitProvider, fileMappingProviderProvider, primaryInteriorFrameFactory, primaryLeafFrameFactory, primaryTypeTraits, primaryComparatorFactories, primaryFieldPermutation, BTreeOp.BTO_INSERT);
+        BTreeInsertUpdateDeleteOperatorDescriptor primaryInsert = new BTreeInsertUpdateDeleteOperatorDescriptor(spec, recDesc, storageManager, btreeRegistryProvider, primarySplitProvider, primaryInteriorFrameFactory, primaryLeafFrameFactory, primaryTypeTraits, primaryComparatorFactories, primaryFieldPermutation, BTreeOp.BTO_INSERT);
         PartitionConstraint primaryInsertConstraint = JobHelper.createPartitionConstraint(splitNCs);
         primaryInsert.setPartitionConstraint(primaryInsertConstraint);
         
@@ -158,7 +156,7 @@
 		secondaryComparatorFactories[1] = IntegerBinaryComparatorFactory.INSTANCE;
 		IFileSplitProvider secondarySplitProvider = JobHelper.createFileSplitProvider(splitNCs, options.secondaryBTreeName);
 		// create operator descriptor
-        BTreeInsertUpdateDeleteOperatorDescriptor secondaryInsert = new BTreeInsertUpdateDeleteOperatorDescriptor(spec, recDesc, bufferCacheProvider, btreeRegistryProvider, secondarySplitProvider, fileMappingProviderProvider, secondaryInteriorFrameFactory, secondaryLeafFrameFactory, secondaryTypeTraits, secondaryComparatorFactories, secondaryFieldPermutation, BTreeOp.BTO_INSERT);
+        BTreeInsertUpdateDeleteOperatorDescriptor secondaryInsert = new BTreeInsertUpdateDeleteOperatorDescriptor(spec, recDesc, storageManager, btreeRegistryProvider, secondarySplitProvider, secondaryInteriorFrameFactory, secondaryLeafFrameFactory, secondaryTypeTraits, secondaryComparatorFactories, secondaryFieldPermutation, BTreeOp.BTO_INSERT);
         PartitionConstraint secondaryInsertConstraint = JobHelper.createPartitionConstraint(splitNCs);
         secondaryInsert.setPartitionConstraint(secondaryInsertConstraint);
         
diff --git a/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/PrimaryIndexBulkLoadExample.java b/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/PrimaryIndexBulkLoadExample.java
index 8a8f60e..fc0fecf 100644
--- a/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/PrimaryIndexBulkLoadExample.java
+++ b/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/PrimaryIndexBulkLoadExample.java
@@ -43,18 +43,16 @@
 import edu.uci.ics.hyracks.dataflow.std.file.IFileSplitProvider;
 import edu.uci.ics.hyracks.dataflow.std.sort.ExternalSortOperatorDescriptor;
 import edu.uci.ics.hyracks.examples.btree.helper.BTreeRegistryProvider;
-import edu.uci.ics.hyracks.examples.btree.helper.BufferCacheProvider;
 import edu.uci.ics.hyracks.examples.btree.helper.DataGenOperatorDescriptor;
-import edu.uci.ics.hyracks.examples.btree.helper.FileMappingProviderProvider;
+import edu.uci.ics.hyracks.examples.btree.helper.SimpleStorageManager;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeInteriorFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeLeafFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.BTreeBulkLoadOperatorDescriptor;
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.IBTreeRegistryProvider;
-import edu.uci.ics.hyracks.storage.am.btree.dataflow.IBufferCacheProvider;
-import edu.uci.ics.hyracks.storage.am.btree.dataflow.IFileMappingProviderProvider;
 import edu.uci.ics.hyracks.storage.am.btree.frames.NSMInteriorFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.frames.NSMLeafFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.tuples.TypeAwareTupleWriterFactory;
+import edu.uci.ics.hyracks.storage.common.IStorageManagerInterface;
 
 // This example will load a primary index from randomly generated data
 
@@ -143,15 +141,14 @@
         TypeAwareTupleWriterFactory tupleWriterFactory = new TypeAwareTupleWriterFactory(typeTraits);
         IBTreeInteriorFrameFactory interiorFrameFactory = new NSMInteriorFrameFactory(tupleWriterFactory);
         IBTreeLeafFrameFactory leafFrameFactory = new NSMLeafFrameFactory(tupleWriterFactory);        
-        IBufferCacheProvider bufferCacheProvider = BufferCacheProvider.INSTANCE;
         IBTreeRegistryProvider btreeRegistryProvider = BTreeRegistryProvider.INSTANCE;
-        IFileMappingProviderProvider fileMappingProviderProvider = FileMappingProviderProvider.INSTANCE;        
+        IStorageManagerInterface storageManager = SimpleStorageManager.INSTANCE;               
         
         // the B-Tree expects its keyfields to be at the front of its input tuple 
         int[] fieldPermutation = { 2, 1, 3, 4 }; // map field 2 of input tuple to field 0 of B-Tree tuple, etc.
         IFileSplitProvider btreeSplitProvider = JobHelper.createFileSplitProvider(splitNCs, options.btreeName);
         BTreeBulkLoadOperatorDescriptor btreeBulkLoad = new BTreeBulkLoadOperatorDescriptor(spec, 
-        		bufferCacheProvider, btreeRegistryProvider, btreeSplitProvider, fileMappingProviderProvider, interiorFrameFactory,
+        		storageManager, btreeRegistryProvider, btreeSplitProvider, interiorFrameFactory,
                 leafFrameFactory, typeTraits, comparatorFactories, fieldPermutation, 0.7f);
         PartitionConstraint bulkLoadConstraint = JobHelper.createPartitionConstraint(splitNCs);
         btreeBulkLoad.setPartitionConstraint(bulkLoadConstraint);
diff --git a/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/PrimaryIndexEnlistFilesExample.java b/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/PrimaryIndexEnlistFilesExample.java
index 1bed3bf..c3d7cc1 100644
--- a/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/PrimaryIndexEnlistFilesExample.java
+++ b/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/PrimaryIndexEnlistFilesExample.java
@@ -33,17 +33,15 @@
 import edu.uci.ics.hyracks.dataflow.common.data.marshalling.UTF8StringSerializerDeserializer;
 import edu.uci.ics.hyracks.dataflow.std.file.IFileSplitProvider;
 import edu.uci.ics.hyracks.examples.btree.helper.BTreeRegistryProvider;
-import edu.uci.ics.hyracks.examples.btree.helper.BufferCacheProvider;
-import edu.uci.ics.hyracks.examples.btree.helper.FileMappingProviderProvider;
+import edu.uci.ics.hyracks.examples.btree.helper.SimpleStorageManager;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeInteriorFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeLeafFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.BTreeFileEnlistmentOperatorDescriptor;
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.IBTreeRegistryProvider;
-import edu.uci.ics.hyracks.storage.am.btree.dataflow.IBufferCacheProvider;
-import edu.uci.ics.hyracks.storage.am.btree.dataflow.IFileMappingProviderProvider;
 import edu.uci.ics.hyracks.storage.am.btree.frames.NSMInteriorFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.frames.NSMLeafFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.tuples.TypeAwareTupleWriterFactory;
+import edu.uci.ics.hyracks.storage.common.IStorageManagerInterface;
 
 // This example will enlist existing files as primary index
 
@@ -106,16 +104,15 @@
         // create factories and providers for B-Tree
         TypeAwareTupleWriterFactory tupleWriterFactory = new TypeAwareTupleWriterFactory(typeTraits);
         IBTreeInteriorFrameFactory interiorFrameFactory = new NSMInteriorFrameFactory(tupleWriterFactory);
-        IBTreeLeafFrameFactory leafFrameFactory = new NSMLeafFrameFactory(tupleWriterFactory);        
-        IBufferCacheProvider bufferCacheProvider = BufferCacheProvider.INSTANCE;
+        IBTreeLeafFrameFactory leafFrameFactory = new NSMLeafFrameFactory(tupleWriterFactory);       
         IBTreeRegistryProvider btreeRegistryProvider = BTreeRegistryProvider.INSTANCE;
-        IFileMappingProviderProvider fileMappingProviderProvider = FileMappingProviderProvider.INSTANCE;
+        IStorageManagerInterface storageManager = SimpleStorageManager.INSTANCE;
         
         IBinaryComparatorFactory[] comparatorFactories = new IBinaryComparatorFactory[1];
         comparatorFactories[0] = IntegerBinaryComparatorFactory.INSTANCE;
         
         IFileSplitProvider btreeSplitProvider = JobHelper.createFileSplitProvider(splitNCs, options.btreeName);
-        BTreeFileEnlistmentOperatorDescriptor fileEnlistmentOp = new BTreeFileEnlistmentOperatorDescriptor(spec, recDesc, bufferCacheProvider, btreeRegistryProvider, btreeSplitProvider, fileMappingProviderProvider, interiorFrameFactory, leafFrameFactory, typeTraits, comparatorFactories);
+        BTreeFileEnlistmentOperatorDescriptor fileEnlistmentOp = new BTreeFileEnlistmentOperatorDescriptor(spec, recDesc, storageManager, btreeRegistryProvider, btreeSplitProvider, interiorFrameFactory, leafFrameFactory, typeTraits, comparatorFactories);
         PartitionConstraint fileEnlistmentConstraint = JobHelper.createPartitionConstraint(splitNCs);
         fileEnlistmentOp.setPartitionConstraint(fileEnlistmentConstraint);                                            
         
diff --git a/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/PrimaryIndexSearchExample.java b/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/PrimaryIndexSearchExample.java
index 8e444a4..6ae162a 100644
--- a/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/PrimaryIndexSearchExample.java
+++ b/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/PrimaryIndexSearchExample.java
@@ -38,18 +38,16 @@
 import edu.uci.ics.hyracks.dataflow.std.file.IFileSplitProvider;
 import edu.uci.ics.hyracks.dataflow.std.misc.PrinterOperatorDescriptor;
 import edu.uci.ics.hyracks.examples.btree.helper.BTreeRegistryProvider;
-import edu.uci.ics.hyracks.examples.btree.helper.BufferCacheProvider;
-import edu.uci.ics.hyracks.examples.btree.helper.FileMappingProviderProvider;
+import edu.uci.ics.hyracks.examples.btree.helper.SimpleStorageManager;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeInteriorFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeLeafFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.BTreeSearchOperatorDescriptor;
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.ConstantTupleSourceOperatorDescriptor;
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.IBTreeRegistryProvider;
-import edu.uci.ics.hyracks.storage.am.btree.dataflow.IBufferCacheProvider;
-import edu.uci.ics.hyracks.storage.am.btree.dataflow.IFileMappingProviderProvider;
 import edu.uci.ics.hyracks.storage.am.btree.frames.NSMInteriorFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.frames.NSMLeafFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.tuples.TypeAwareTupleWriterFactory;
+import edu.uci.ics.hyracks.storage.common.IStorageManagerInterface;
 
 // This example will perform an ordered scan on the primary index
 // i.e. a range-search for [-infinity, +infinity]
@@ -106,9 +104,8 @@
         TypeAwareTupleWriterFactory tupleWriterFactory = new TypeAwareTupleWriterFactory(typeTraits);
         IBTreeInteriorFrameFactory interiorFrameFactory = new NSMInteriorFrameFactory(tupleWriterFactory);
         IBTreeLeafFrameFactory leafFrameFactory = new NSMLeafFrameFactory(tupleWriterFactory);        
-        IBufferCacheProvider bufferCacheProvider = BufferCacheProvider.INSTANCE;
         IBTreeRegistryProvider btreeRegistryProvider = BTreeRegistryProvider.INSTANCE;
-        IFileMappingProviderProvider fileMappingProviderProvider = FileMappingProviderProvider.INSTANCE;
+        IStorageManagerInterface storageManager = SimpleStorageManager.INSTANCE;     
     	
     	// schema of tuples coming out of primary index
         RecordDescriptor recDesc = new RecordDescriptor(new ISerializerDeserializer[] {                
@@ -143,7 +140,7 @@
         int[] highKeyFields = { 1 }; // low key is in field 1 of tuples going into search op
         		
         IFileSplitProvider btreeSplitProvider = JobHelper.createFileSplitProvider(splitNCs, options.btreeName);
-        BTreeSearchOperatorDescriptor btreeSearchOp = new BTreeSearchOperatorDescriptor(spec, recDesc, bufferCacheProvider, btreeRegistryProvider, btreeSplitProvider, fileMappingProviderProvider, interiorFrameFactory, leafFrameFactory, typeTraits, comparatorFactories, true, lowKeyFields, highKeyFields, true, true);
+        BTreeSearchOperatorDescriptor btreeSearchOp = new BTreeSearchOperatorDescriptor(spec, recDesc, storageManager, btreeRegistryProvider, btreeSplitProvider, interiorFrameFactory, leafFrameFactory, typeTraits, comparatorFactories, true, lowKeyFields, highKeyFields, true, true);
         PartitionConstraint btreeSearchConstraint = JobHelper.createPartitionConstraint(splitNCs);
         btreeSearchOp.setPartitionConstraint(btreeSearchConstraint);
         
diff --git a/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/SecondaryIndexBulkLoadExample.java b/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/SecondaryIndexBulkLoadExample.java
index 7702090..8b1a12c 100644
--- a/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/SecondaryIndexBulkLoadExample.java
+++ b/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/SecondaryIndexBulkLoadExample.java
@@ -36,18 +36,16 @@
 import edu.uci.ics.hyracks.dataflow.std.file.IFileSplitProvider;
 import edu.uci.ics.hyracks.dataflow.std.sort.ExternalSortOperatorDescriptor;
 import edu.uci.ics.hyracks.examples.btree.helper.BTreeRegistryProvider;
-import edu.uci.ics.hyracks.examples.btree.helper.BufferCacheProvider;
-import edu.uci.ics.hyracks.examples.btree.helper.FileMappingProviderProvider;
+import edu.uci.ics.hyracks.examples.btree.helper.SimpleStorageManager;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeInteriorFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeLeafFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.BTreeBulkLoadOperatorDescriptor;
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.BTreeDiskOrderScanOperatorDescriptor;
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.IBTreeRegistryProvider;
-import edu.uci.ics.hyracks.storage.am.btree.dataflow.IBufferCacheProvider;
-import edu.uci.ics.hyracks.storage.am.btree.dataflow.IFileMappingProviderProvider;
 import edu.uci.ics.hyracks.storage.am.btree.frames.NSMInteriorFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.frames.NSMLeafFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.tuples.TypeAwareTupleWriterFactory;
+import edu.uci.ics.hyracks.storage.common.IStorageManagerInterface;
 
 // This example will load a secondary index with <key, primary-index key> pairs
 // We require an existing primary index built with PrimaryIndexBulkLoadExample
@@ -98,10 +96,9 @@
     	JobSpecification spec = new JobSpecification();
 
     	String[] splitNCs = options.ncs.split(",");
-    	
-    	IBufferCacheProvider bufferCacheProvider = BufferCacheProvider.INSTANCE;
+    	    	
         IBTreeRegistryProvider btreeRegistryProvider = BTreeRegistryProvider.INSTANCE;
-        IFileMappingProviderProvider fileMappingProviderProvider = FileMappingProviderProvider.INSTANCE;
+        IStorageManagerInterface storageManager = SimpleStorageManager.INSTANCE;
     	
     	// schema of tuples that we are retrieving from the primary index
         RecordDescriptor recDesc = new RecordDescriptor(new ISerializerDeserializer[] {                                    
@@ -125,7 +122,7 @@
         
         // use a disk-order scan to read primary index    	
         IFileSplitProvider primarySplitProvider = JobHelper.createFileSplitProvider(splitNCs, options.primaryBTreeName);
-        BTreeDiskOrderScanOperatorDescriptor btreeScanOp = new BTreeDiskOrderScanOperatorDescriptor(spec, recDesc, bufferCacheProvider, btreeRegistryProvider, primarySplitProvider, fileMappingProviderProvider, primaryInteriorFrameFactory, primaryLeafFrameFactory, primaryTypeTraits);		
+        BTreeDiskOrderScanOperatorDescriptor btreeScanOp = new BTreeDiskOrderScanOperatorDescriptor(spec, recDesc, storageManager, btreeRegistryProvider, primarySplitProvider, primaryInteriorFrameFactory, primaryLeafFrameFactory, primaryTypeTraits);		
 		PartitionConstraint scanPartitionConstraint = JobHelper.createPartitionConstraint(splitNCs);
 		btreeScanOp.setPartitionConstraint(scanPartitionConstraint);
 		        
@@ -155,7 +152,7 @@
         int[] fieldPermutation = { 1, 0 };
         IFileSplitProvider btreeSplitProvider = JobHelper.createFileSplitProvider(splitNCs, options.secondaryBTreeName);
         BTreeBulkLoadOperatorDescriptor btreeBulkLoad = new BTreeBulkLoadOperatorDescriptor(spec, 
-        		bufferCacheProvider, btreeRegistryProvider, btreeSplitProvider, fileMappingProviderProvider, secondaryInteriorFrameFactory,
+        		storageManager, btreeRegistryProvider, btreeSplitProvider, secondaryInteriorFrameFactory,
                 secondaryLeafFrameFactory, secondaryTypeTraits, comparatorFactories, fieldPermutation, 0.7f);
         PartitionConstraint bulkLoadConstraint = JobHelper.createPartitionConstraint(splitNCs);
         btreeBulkLoad.setPartitionConstraint(bulkLoadConstraint);        
@@ -163,8 +160,7 @@
         // connect the ops
                
         spec.connect(new OneToOneConnectorDescriptor(spec), btreeScanOp, 0, sorter, 0);
-                      
-        //spec.connect(new OneToOneConnectorDescriptor(spec), sorter, 0, btreeBulkLoad, 0);
+        
         spec.connect(new OneToOneConnectorDescriptor(spec), sorter, 0, btreeBulkLoad, 0);
         
         spec.addRoot(btreeBulkLoad);
diff --git a/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/SecondaryIndexSearchExample.java b/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/SecondaryIndexSearchExample.java
index 490169c..a8f63f1 100644
--- a/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/SecondaryIndexSearchExample.java
+++ b/hyracks-examples/btree-example/btreeclient/src/main/java/edu/uci/ics/hyracks/examples/btree/client/SecondaryIndexSearchExample.java
@@ -38,18 +38,16 @@
 import edu.uci.ics.hyracks.dataflow.std.file.IFileSplitProvider;
 import edu.uci.ics.hyracks.dataflow.std.misc.PrinterOperatorDescriptor;
 import edu.uci.ics.hyracks.examples.btree.helper.BTreeRegistryProvider;
-import edu.uci.ics.hyracks.examples.btree.helper.BufferCacheProvider;
-import edu.uci.ics.hyracks.examples.btree.helper.FileMappingProviderProvider;
+import edu.uci.ics.hyracks.examples.btree.helper.SimpleStorageManager;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeInteriorFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeLeafFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.BTreeSearchOperatorDescriptor;
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.ConstantTupleSourceOperatorDescriptor;
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.IBTreeRegistryProvider;
-import edu.uci.ics.hyracks.storage.am.btree.dataflow.IBufferCacheProvider;
-import edu.uci.ics.hyracks.storage.am.btree.dataflow.IFileMappingProviderProvider;
 import edu.uci.ics.hyracks.storage.am.btree.frames.NSMInteriorFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.frames.NSMLeafFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.tuples.TypeAwareTupleWriterFactory;
+import edu.uci.ics.hyracks.storage.common.IStorageManagerInterface;
 
 // This example will perform range search on the secondary index
 // and then retrieve the corresponding source records from the primary index
@@ -97,10 +95,9 @@
     	JobSpecification spec = new JobSpecification();
 
     	String[] splitNCs = options.ncs.split(",");
-    	
-    	IBufferCacheProvider bufferCacheProvider = BufferCacheProvider.INSTANCE;
+    	    	
         IBTreeRegistryProvider btreeRegistryProvider = BTreeRegistryProvider.INSTANCE;
-        IFileMappingProviderProvider fileMappingProviderProvider = FileMappingProviderProvider.INSTANCE;    	              
+        IStorageManagerInterface storageManager = SimpleStorageManager.INSTANCE;    	              
     	
     	// schema of tuples coming out of secondary index
         RecordDescriptor secondaryRecDesc = new RecordDescriptor(new ISerializerDeserializer[] {                
@@ -164,7 +161,7 @@
         int[] secondaryHighKeyFields = { 1 }; // high key is in field 1 of tuples going into secondary index search op
 		
         IFileSplitProvider secondarySplitProvider = JobHelper.createFileSplitProvider(splitNCs, options.secondaryBTreeName);
-        BTreeSearchOperatorDescriptor secondarySearchOp = new BTreeSearchOperatorDescriptor(spec, secondaryRecDesc, bufferCacheProvider, btreeRegistryProvider, secondarySplitProvider, fileMappingProviderProvider, secondaryInteriorFrameFactory, secondaryLeafFrameFactory, secondaryTypeTraits, comparatorFactories, true, secondaryLowKeyFields, secondaryHighKeyFields, true, true);
+        BTreeSearchOperatorDescriptor secondarySearchOp = new BTreeSearchOperatorDescriptor(spec, secondaryRecDesc, storageManager, btreeRegistryProvider, secondarySplitProvider, secondaryInteriorFrameFactory, secondaryLeafFrameFactory, secondaryTypeTraits, comparatorFactories, true, secondaryLowKeyFields, secondaryHighKeyFields, true, true);
         PartitionConstraint secondarySearchConstraint = JobHelper.createPartitionConstraint(splitNCs);
         secondarySearchOp.setPartitionConstraint(secondarySearchConstraint);
         
@@ -174,7 +171,7 @@
         int[] primaryHighKeyFields = { 1 }; // high key is in field 1 of tuples going into primary index search op
 		
         IFileSplitProvider primarySplitProvider = JobHelper.createFileSplitProvider(splitNCs, options.primaryBTreeName);
-        BTreeSearchOperatorDescriptor primarySearchOp = new BTreeSearchOperatorDescriptor(spec, primaryRecDesc, bufferCacheProvider, btreeRegistryProvider, primarySplitProvider, fileMappingProviderProvider, primaryInteriorFrameFactory, primaryLeafFrameFactory, primaryTypeTraits, comparatorFactories, true, primaryLowKeyFields, primaryHighKeyFields, true, true);
+        BTreeSearchOperatorDescriptor primarySearchOp = new BTreeSearchOperatorDescriptor(spec, primaryRecDesc, storageManager, btreeRegistryProvider, primarySplitProvider, primaryInteriorFrameFactory, primaryLeafFrameFactory, primaryTypeTraits, comparatorFactories, true, primaryLowKeyFields, primaryHighKeyFields, true, true);
         PartitionConstraint primarySearchConstraint = JobHelper.createPartitionConstraint(splitNCs);
         primarySearchOp.setPartitionConstraint(primarySearchConstraint);
         
diff --git a/hyracks-examples/btree-example/btreehelper/src/main/java/edu/uci/ics/hyracks/examples/btree/helper/BufferCacheProvider.java b/hyracks-examples/btree-example/btreehelper/src/main/java/edu/uci/ics/hyracks/examples/btree/helper/BufferCacheProvider.java
deleted file mode 100644
index db1368d..0000000
--- a/hyracks-examples/btree-example/btreehelper/src/main/java/edu/uci/ics/hyracks/examples/btree/helper/BufferCacheProvider.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package edu.uci.ics.hyracks.examples.btree.helper;
-
-import edu.uci.ics.hyracks.storage.am.btree.dataflow.IBufferCacheProvider;
-import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
-import edu.uci.ics.hyracks.storage.common.file.FileManager;
-
-public class BufferCacheProvider implements IBufferCacheProvider {
-    private static final long serialVersionUID = 1L;
-
-    public static final BufferCacheProvider INSTANCE = new BufferCacheProvider();
-
-    private BufferCacheProvider() {
-    }
-
-    @Override
-    public IBufferCache getBufferCache() {
-        return RuntimeContext.getInstance().getBufferCache();
-    }
-
-    @Override
-    public FileManager getFileManager() {
-        return RuntimeContext.getInstance().getFileManager();
-    }
-}
\ No newline at end of file
diff --git a/hyracks-examples/btree-example/btreehelper/src/main/java/edu/uci/ics/hyracks/examples/btree/helper/FileMappingProvider.java b/hyracks-examples/btree-example/btreehelper/src/main/java/edu/uci/ics/hyracks/examples/btree/helper/FileMappingProvider.java
deleted file mode 100644
index 76350e4..0000000
--- a/hyracks-examples/btree-example/btreehelper/src/main/java/edu/uci/ics/hyracks/examples/btree/helper/FileMappingProvider.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package edu.uci.ics.hyracks.examples.btree.helper;
-
-import java.util.Hashtable;
-import java.util.Map;
-
-import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
-
-public class FileMappingProvider implements IFileMapProvider {				
-	
-	private static final long serialVersionUID = 1L;
-	private int nextFileId = 0;
-	private Map<String, Integer> map = new Hashtable<String, Integer>();
-		
-	@Override
-	public Integer mapNameToFileId(String name, boolean create) {
-		Integer val = map.get(name);						
-		if(create) {
-			if(val == null) {
-				int ret = nextFileId;
-				map.put(name, nextFileId++);
-				return ret;
-			}
-			else {
-				return null; // create requested but value already exists				
-			}
-		}
-		else {
-			return val; // just return value
-		}			
-	}
-	
-	@Override
-	public void unmapName(String name) {
-		map.remove(name);
-	}
-	
-	@Override
-	public Integer getFileId(String name) {
-		return map.get(name);
-	}
-}
diff --git a/hyracks-examples/btree-example/btreehelper/src/main/java/edu/uci/ics/hyracks/examples/btree/helper/FileMappingProviderProvider.java b/hyracks-examples/btree-example/btreehelper/src/main/java/edu/uci/ics/hyracks/examples/btree/helper/FileMappingProviderProvider.java
deleted file mode 100644
index 1738d81..0000000
--- a/hyracks-examples/btree-example/btreehelper/src/main/java/edu/uci/ics/hyracks/examples/btree/helper/FileMappingProviderProvider.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package edu.uci.ics.hyracks.examples.btree.helper;
-
-import edu.uci.ics.hyracks.storage.am.btree.dataflow.IFileMappingProviderProvider;
-import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
-
-public class FileMappingProviderProvider implements IFileMappingProviderProvider {
-	private static final long serialVersionUID = 1L;
-	
-	public static final IFileMappingProviderProvider INSTANCE = new FileMappingProviderProvider();
-	
-	@Override
-	public IFileMapProvider getFileMappingProvider() {
-		return RuntimeContext.getInstance().getFileMappingProvider();
-	}
-}
diff --git a/hyracks-examples/btree-example/btreehelper/src/main/java/edu/uci/ics/hyracks/examples/btree/helper/RuntimeContext.java b/hyracks-examples/btree-example/btreehelper/src/main/java/edu/uci/ics/hyracks/examples/btree/helper/RuntimeContext.java
index fd8e58d..b615cab 100644
--- a/hyracks-examples/btree-example/btreehelper/src/main/java/edu/uci/ics/hyracks/examples/btree/helper/RuntimeContext.java
+++ b/hyracks-examples/btree-example/btreehelper/src/main/java/edu/uci/ics/hyracks/examples/btree/helper/RuntimeContext.java
@@ -1,22 +1,22 @@
 package edu.uci.ics.hyracks.examples.btree.helper;
 
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.BTreeRegistry;
-import edu.uci.ics.hyracks.storage.am.btree.dataflow.FileMappingProvider;
 import edu.uci.ics.hyracks.storage.common.buffercache.BufferCache;
 import edu.uci.ics.hyracks.storage.common.buffercache.ClockPageReplacementStrategy;
 import edu.uci.ics.hyracks.storage.common.buffercache.HeapBufferAllocator;
 import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
-import edu.uci.ics.hyracks.storage.common.file.FileManager;
+import edu.uci.ics.hyracks.storage.common.buffercache.ICacheMemoryAllocator;
+import edu.uci.ics.hyracks.storage.common.buffercache.IPageReplacementStrategy;
+import edu.uci.ics.hyracks.storage.common.file.IFileMapManager;
 import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
 
 public class RuntimeContext {
     private static RuntimeContext INSTANCE;
-
-    private FileManager fileManager;
-    private IBufferCache bufferCache;
-    private BTreeRegistry btreeRegistry;
-    private IFileMapProvider fileMappingProvider;
     
+    private BTreeRegistry btreeRegistry;
+    private IBufferCache bufferCache;
+    private IFileMapManager fileMapManager;
+        
     private RuntimeContext() {
     }
     
@@ -37,15 +37,14 @@
 
     private void stop() {
         bufferCache.close();
-        fileManager.close();
     }
 
     private void start() {
-        fileManager = new FileManager();
-        bufferCache = new BufferCache(new HeapBufferAllocator(), new ClockPageReplacementStrategy(), fileManager,
-                32768, 1024);
+    	fileMapManager = new SimpleFileMapManager();
+    	ICacheMemoryAllocator allocator = new HeapBufferAllocator();
+        IPageReplacementStrategy prs = new ClockPageReplacementStrategy();
+        bufferCache = new BufferCache(allocator, prs, fileMapManager, 32768, 50);
         btreeRegistry = new BTreeRegistry();
-        fileMappingProvider = new FileMappingProvider();
     }
 
     public static RuntimeContext getInstance() {
@@ -56,15 +55,11 @@
         return bufferCache;
     }
 
-    public FileManager getFileManager() {
-        return fileManager;
-    }
-
-    public BTreeRegistry getBTreeRegistry() {
-        return btreeRegistry;
+    public IFileMapProvider getFileMapManager() {
+        return fileMapManager;
     }
     
-    public IFileMapProvider getFileMappingProvider() {
-    	return fileMappingProvider;
+    public BTreeRegistry getBTreeRegistry() {
+        return btreeRegistry;
     }
 }
\ No newline at end of file
diff --git a/hyracks-examples/btree-example/btreehelper/src/main/java/edu/uci/ics/hyracks/examples/btree/helper/SimpleFileMapManager.java b/hyracks-examples/btree-example/btreehelper/src/main/java/edu/uci/ics/hyracks/examples/btree/helper/SimpleFileMapManager.java
new file mode 100644
index 0000000..aa100a8
--- /dev/null
+++ b/hyracks-examples/btree-example/btreehelper/src/main/java/edu/uci/ics/hyracks/examples/btree/helper/SimpleFileMapManager.java
@@ -0,0 +1,56 @@
+package edu.uci.ics.hyracks.examples.btree.helper;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.storage.common.file.IFileMapManager;
+
+public class SimpleFileMapManager implements IFileMapManager {
+	
+	private static final long serialVersionUID = 1L;
+	private Map<Integer, String> id2nameMap = new HashMap<Integer, String>();
+    private Map<String, Integer> name2IdMap = new HashMap<String, Integer>();
+    private int idCounter = 0;
+
+    @Override
+    public String lookupFileName(int fileId) throws HyracksDataException {
+        String fName = id2nameMap.get(fileId);
+        if (fName == null) {
+            throw new HyracksDataException("No mapping found for id: " + fileId);
+        }
+        return fName;
+    }
+
+    @Override
+    public int lookupFileId(String fileName) throws HyracksDataException {
+        Integer fileId = name2IdMap.get(fileName);
+        if (fileId == null) {
+            throw new HyracksDataException("No mapping found for name: " + fileName);
+        }
+        return fileId;
+    }
+
+    @Override
+    public boolean isMapped(String fileName) {
+        return name2IdMap.containsKey(fileName);
+    }
+
+    @Override
+    public boolean isMapped(int fileId) {
+        return id2nameMap.containsKey(fileId);
+    }
+
+    @Override
+    public void unregisterFile(int fileId) throws HyracksDataException {
+        String fileName = id2nameMap.remove(fileId);
+        name2IdMap.remove(fileName);
+    }
+
+    @Override
+    public void registerFile(String fileName) throws HyracksDataException {
+        Integer fileId = idCounter++;
+        id2nameMap.put(fileId, fileName);
+        name2IdMap.put(fileName, fileId);
+    }
+}
diff --git a/hyracks-examples/btree-example/btreehelper/src/main/java/edu/uci/ics/hyracks/examples/btree/helper/SimpleStorageManager.java b/hyracks-examples/btree-example/btreehelper/src/main/java/edu/uci/ics/hyracks/examples/btree/helper/SimpleStorageManager.java
new file mode 100644
index 0000000..7cc3847
--- /dev/null
+++ b/hyracks-examples/btree-example/btreehelper/src/main/java/edu/uci/ics/hyracks/examples/btree/helper/SimpleStorageManager.java
@@ -0,0 +1,23 @@
+package edu.uci.ics.hyracks.examples.btree.helper;
+
+import edu.uci.ics.hyracks.storage.common.IStorageManagerInterface;
+import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
+import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
+
+public class SimpleStorageManager implements IStorageManagerInterface {
+
+	private static final long serialVersionUID = 1L;
+	
+	public static SimpleStorageManager INSTANCE = new SimpleStorageManager();	
+
+	@Override
+	public IBufferCache getBufferCache() {
+		return RuntimeContext.getInstance().getBufferCache();
+	}
+
+	@Override
+	public IFileMapProvider getFileMapProvider() {
+		return RuntimeContext.getInstance().getFileMapManager();
+	}
+
+}
diff --git a/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/btree/BTreeOperatorsTest.java b/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/btree/BTreeOperatorsTest.java
index 7a67c19..6d33c71 100644
--- a/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/btree/BTreeOperatorsTest.java
+++ b/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/btree/BTreeOperatorsTest.java
@@ -17,7 +17,6 @@
 
 import java.io.DataOutput;
 import java.io.File;
-import java.io.RandomAccessFile;
 
 import org.junit.Test;
 
@@ -55,12 +54,9 @@
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.BTreeRegistry;
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.BTreeRegistryProvider;
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.BTreeSearchOperatorDescriptor;
-import edu.uci.ics.hyracks.storage.am.btree.dataflow.BufferCacheProvider;
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.ConstantTupleSourceOperatorDescriptor;
-import edu.uci.ics.hyracks.storage.am.btree.dataflow.FileMappingProviderProvider;
+import edu.uci.ics.hyracks.storage.am.btree.dataflow.HyracksSimpleStorageManagerInterface;
 import edu.uci.ics.hyracks.storage.am.btree.dataflow.IBTreeRegistryProvider;
-import edu.uci.ics.hyracks.storage.am.btree.dataflow.IBufferCacheProvider;
-import edu.uci.ics.hyracks.storage.am.btree.dataflow.IFileMappingProviderProvider;
 import edu.uci.ics.hyracks.storage.am.btree.frames.MetaDataFrame;
 import edu.uci.ics.hyracks.storage.am.btree.frames.NSMInteriorFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.frames.NSMLeafFrameFactory;
@@ -72,16 +68,16 @@
 import edu.uci.ics.hyracks.storage.am.btree.impls.RangeSearchCursor;
 import edu.uci.ics.hyracks.storage.am.btree.tuples.TypeAwareTupleWriterFactory;
 import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
-import edu.uci.ics.hyracks.storage.common.file.FileHandle;
-import edu.uci.ics.hyracks.storage.common.file.FileManager;
+import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
 import edu.uci.ics.hyracks.tests.integration.AbstractIntegrationTest;
 
 public class BTreeOperatorsTest extends AbstractIntegrationTest {
 	
+	// TODO: fix bug when given fewer pages in buffer cache, talk to Vinayak
+	private static HyracksSimpleStorageManagerInterface storageManager = new HyracksSimpleStorageManagerInterface(8192, 100);
+	
 	@Test
 	public void bulkLoadTest() throws Exception {		
-		// relies on the fact that NCs are run from same process
-		//System.setProperty("NodeControllerDataPath", System.getProperty("java.io.tmpdir") + "/");
 		
 		JobSpecification spec = new JobSpecification();
 		
@@ -126,18 +122,16 @@
 		TypeAwareTupleWriterFactory tupleWriterFactory = new TypeAwareTupleWriterFactory(typeTraits);
 		//SimpleTupleWriterFactory tupleWriterFactory = new SimpleTupleWriterFactory();
 		IBTreeInteriorFrameFactory interiorFrameFactory = new NSMInteriorFrameFactory(tupleWriterFactory);
-		IBTreeLeafFrameFactory leafFrameFactory = new NSMLeafFrameFactory(tupleWriterFactory);		
-		IBufferCacheProvider bufferCacheProvider = new BufferCacheProvider();		
+		IBTreeLeafFrameFactory leafFrameFactory = new NSMLeafFrameFactory(tupleWriterFactory);	
 		IBTreeRegistryProvider btreeRegistryProvider = new BTreeRegistryProvider();
-		IFileMappingProviderProvider fileMappingProviderProvider = new FileMappingProviderProvider();
-		
-		int[] fieldPermutation = { 0, 4, 5};
+				
+		int[] fieldPermutation = {0, 4, 5};
 		String btreeName = "btree.bin";
 		String nc1FileName = System.getProperty("java.io.tmpdir") + "/nc1/" + btreeName;
 		IFileSplitProvider btreeSplitProvider = new ConstantFileSplitProvider(
 				new FileSplit[] { new FileSplit(NC1_ID, new File(nc1FileName)) } );
 		
-		BTreeBulkLoadOperatorDescriptor btreeBulkLoad = new BTreeBulkLoadOperatorDescriptor(spec, bufferCacheProvider, btreeRegistryProvider, btreeSplitProvider, fileMappingProviderProvider, interiorFrameFactory, leafFrameFactory, typeTraits, comparatorFactories, fieldPermutation, 0.7f);		
+		BTreeBulkLoadOperatorDescriptor btreeBulkLoad = new BTreeBulkLoadOperatorDescriptor(spec, storageManager, btreeRegistryProvider, btreeSplitProvider, interiorFrameFactory, leafFrameFactory, typeTraits, comparatorFactories, fieldPermutation, 0.7f);		
 		PartitionConstraint btreePartitionConstraintA = new ExplicitPartitionConstraint(new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
 		btreeBulkLoad.setPartitionConstraint(btreePartitionConstraintA);
 				
@@ -157,7 +151,8 @@
         MultiComparator cmp = new MultiComparator(typeTraits, comparators);
         
         // try an ordered scan on the bulk-loaded btree
-        int btreeFileId = 0; // TODO: this relies on the way FileMappingProvider assigns ids (in sequence starting from 0)
+        int btreeFileId = storageManager.getFileMapProvider().lookupFileId(nc1FileName);
+        storageManager.getBufferCache().openFile(btreeFileId);        
         BTree btree = btreeRegistryProvider.getBTreeRegistry().get(btreeFileId);
         IBTreeCursor scanCursor = new RangeSearchCursor(leafFrameFactory.getFrame());
         RangePredicate nullPred = new RangePredicate(true, null, null, true, true, null, null);
@@ -174,14 +169,12 @@
         	e.printStackTrace();
         } finally {
         	scanCursor.close();
-        }             
+        }        
+        storageManager.getBufferCache().closeFile(btreeFileId);
 	}	
-		
+	
 	@Test
-	public void btreeSearchTest() throws Exception {
-		// relies on the fact that NCs are run from same process
-		System.setProperty("NodeControllerDataPath", System.getProperty("java.io.tmpdir") + "/");
-		
+	public void btreeSearchTest() throws Exception {		
 		JobSpecification spec = new JobSpecification();
 						
 		// declare fields
@@ -216,18 +209,15 @@
 		UTF8StringSerializerDeserializer.INSTANCE.serialize("100", dos); // low key
 		tb.addFieldEndOffset();		
 		UTF8StringSerializerDeserializer.INSTANCE.serialize("200", dos); // high key
-		tb.addFieldEndOffset();		
+		tb.addFieldEndOffset();
     	
 		ISerializerDeserializer[] keyRecDescSers = { UTF8StringSerializerDeserializer.INSTANCE, UTF8StringSerializerDeserializer.INSTANCE };
 		RecordDescriptor keyRecDesc = new RecordDescriptor(keyRecDescSers);
 		
     	ConstantTupleSourceOperatorDescriptor keyProviderOp = new ConstantTupleSourceOperatorDescriptor(spec, keyRecDesc, tb.getFieldEndOffsets(), tb.getByteArray(), tb.getSize());
 		PartitionConstraint keyProviderPartitionConstraint = new ExplicitPartitionConstraint(new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
-		keyProviderOp.setPartitionConstraint(keyProviderPartitionConstraint);
-    	    	    	
-		IBufferCacheProvider bufferCacheProvider = new BufferCacheProvider();
-		IBTreeRegistryProvider btreeRegistryProvider = new BTreeRegistryProvider();		
-		IFileMappingProviderProvider fileMappingProviderProvider = new FileMappingProviderProvider();
+		keyProviderOp.setPartitionConstraint(keyProviderPartitionConstraint);    	    	    			
+		IBTreeRegistryProvider btreeRegistryProvider = new BTreeRegistryProvider();				
 		
 		RecordDescriptor recDesc = new RecordDescriptor(
                 new ISerializerDeserializer[] { UTF8StringSerializerDeserializer.INSTANCE, UTF8StringSerializerDeserializer.INSTANCE, UTF8StringSerializerDeserializer.INSTANCE });		
@@ -237,7 +227,7 @@
 		IFileSplitProvider btreeSplitProvider = new ConstantFileSplitProvider(
 				new FileSplit[] { new FileSplit(NC1_ID, new File(nc1FileName)) } );
 		
-		BTreeSearchOperatorDescriptor btreeSearchOp = new BTreeSearchOperatorDescriptor(spec, recDesc, bufferCacheProvider, btreeRegistryProvider, btreeSplitProvider, fileMappingProviderProvider, interiorFrameFactory, leafFrameFactory, typeTraits, comparatorFactories, true, new int[]{0}, new int[]{1}, true, true);
+		BTreeSearchOperatorDescriptor btreeSearchOp = new BTreeSearchOperatorDescriptor(spec, recDesc, storageManager, btreeRegistryProvider, btreeSplitProvider, interiorFrameFactory, leafFrameFactory, typeTraits, comparatorFactories, true, new int[]{0}, new int[]{1}, true, true);
 		//BTreeDiskOrderScanOperatorDescriptor btreeSearchOp = new BTreeDiskOrderScanOperatorDescriptor(spec, splitProvider, recDesc, bufferCacheProvider, btreeRegistryProvider, 0, "btreetest.bin", interiorFrameFactory, leafFrameFactory, cmp);
 		
 		PartitionConstraint btreePartitionConstraint = new ExplicitPartitionConstraint(new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
@@ -252,8 +242,8 @@
         
         spec.addRoot(printer);
         runTest(spec);
-    }
-		
+    }	
+	
 	@Test
 	public void insertTest() throws Exception {
 		// relies on the fact that NCs are run from same process
@@ -299,15 +289,9 @@
 		TypeAwareTupleWriterFactory primaryTupleWriterFactory = new TypeAwareTupleWriterFactory(primaryTypeTraits);
 		//SimpleTupleWriterFactory primaryTupleWriterFactory = new SimpleTupleWriterFactory();
 		IBTreeInteriorFrameFactory primaryInteriorFrameFactory = new NSMInteriorFrameFactory(primaryTupleWriterFactory);
-		IBTreeLeafFrameFactory primaryLeafFrameFactory = new NSMLeafFrameFactory(primaryTupleWriterFactory);		
-				
-		IBufferCacheProvider bufferCacheProvider = new BufferCacheProvider();		
+		IBTreeLeafFrameFactory primaryLeafFrameFactory = new NSMLeafFrameFactory(primaryTupleWriterFactory);						
 		IBTreeRegistryProvider btreeRegistryProvider = new BTreeRegistryProvider();		
 		
-		// trick to clear pages of old fileids
-		BufferCacheProvider tmp = (BufferCacheProvider)bufferCacheProvider;
-		tmp.reset();
-				
 		// construct a multicomparator for the primary index       
     	IBinaryComparator[] primaryComparators = new IBinaryComparator[primaryComparatorFactories.length];
     	for(int i = 0; i < primaryComparatorFactories.length; i++) {
@@ -340,52 +324,52 @@
     	
         MultiComparator secondaryCmp = new MultiComparator(secondaryTypeTraits, secondaryComparators);
         
-        // we create and register 3 btrees for in an insert pipeline being fed from a filescan op        
-        IBufferCache bufferCache = bufferCacheProvider.getBufferCache();
+        // we create and register 3 btrees for in an insert pipeline being fed from a filescan op         
         BTreeRegistry btreeRegistry = btreeRegistryProvider.getBTreeRegistry();        
-        FileManager fileManager = bufferCacheProvider.getFileManager();
-        IFileMappingProviderProvider fileMappingProviderProvider = new FileMappingProviderProvider();
+        IBufferCache bufferCache = storageManager.getBufferCache();
+        IFileMapProvider fileMapProvider = storageManager.getFileMapProvider();        
         
         // primary index
-        int fileIdA = fileMappingProviderProvider.getFileMappingProvider().mapNameToFileId("/tmp/btreetestA.ix", true);
-        File fA = new File("/tmp/btreetestA.ix");
-        RandomAccessFile rafA = new RandomAccessFile(fA, "rw");                
-        FileHandle fiA = new FileHandle(fileIdA, rafA);
-        fileManager.registerFile(fiA);
-        BTree btreeA = new BTree(bufferCache, primaryInteriorFrameFactory, primaryLeafFrameFactory, primaryCmp);		
-		btreeA.create(fileIdA, primaryLeafFrameFactory.getFrame(), new MetaDataFrame());
+        String fileNameA = "/tmp/btreetestA.ix";
+        bufferCache.createFile(fileNameA);       
+        int fileIdA = fileMapProvider.lookupFileId(fileNameA);        
+        bufferCache.openFile(fileIdA);
+        BTree btreeA = new BTree(bufferCache, primaryInteriorFrameFactory, primaryLeafFrameFactory, primaryCmp);		        
+        btreeA.create(fileIdA, primaryLeafFrameFactory.getFrame(), new MetaDataFrame());
         btreeA.open(fileIdA);
         btreeRegistry.register(fileIdA, btreeA);
+        bufferCache.closeFile(fileIdA);
         
         // first secondary index
-        int fileIdB = fileMappingProviderProvider.getFileMappingProvider().mapNameToFileId("/tmp/btreetestB.ix", true);
-        File fB = new File("/tmp/btreetestB.ix");
-        RandomAccessFile rafB = new RandomAccessFile(fB, "rw");   
-        FileHandle fiB = new FileHandle(fileIdB, rafB);
-        fileManager.registerFile(fiB);
+        String fileNameB = "/tmp/btreetestB.ix";
+        bufferCache.createFile(fileNameB);                
+        int fileIdB = fileMapProvider.lookupFileId(fileNameB);
+        bufferCache.openFile(fileIdB);
         BTree btreeB = new BTree(bufferCache, secondaryInteriorFrameFactory, secondaryLeafFrameFactory, secondaryCmp);		
 		btreeB.create(fileIdB, secondaryLeafFrameFactory.getFrame(), new MetaDataFrame());
         btreeB.open(fileIdB);
         btreeRegistry.register(fileIdB, btreeB);
+        bufferCache.closeFile(fileIdB);
         
         // second secondary index
-        int fileIdC = fileMappingProviderProvider.getFileMappingProvider().mapNameToFileId("/tmp/btreetestC.ix", true);
-        File fC = new File("/tmp/btreetestC.ix");
-        RandomAccessFile rafC = new RandomAccessFile(fC, "rw");                
-        FileHandle fiC = new FileHandle(fileIdC, rafC);
-        fileManager.registerFile(fiC);
+        String fileNameC = "/tmp/btreetestC.ix";
+        bufferCache.createFile(fileNameC);
+        int fileIdC = fileMapProvider.lookupFileId(fileNameC);
+        bufferCache.openFile(fileIdC);
         BTree btreeC = new BTree(bufferCache, secondaryInteriorFrameFactory, secondaryLeafFrameFactory, secondaryCmp);	
 		btreeC.create(fileIdC, secondaryLeafFrameFactory.getFrame(), new MetaDataFrame());
         btreeC.open(fileIdC);
-        btreeRegistry.register(fileIdC, btreeC);
-                        
+        btreeRegistry.register(fileIdC, btreeC);  
+        bufferCache.closeFile(fileIdC);
+        
+        
         // create insert operators
         
         // primary index               
 		IFileSplitProvider btreeSplitProviderA = new ConstantFileSplitProvider(
 				new FileSplit[] { new FileSplit(NC1_ID, new File("/tmp/btreetestA.ix")) } );        
         int[] fieldPermutationA = { 0,1,2,3,4,5 };                       
-        BTreeInsertUpdateDeleteOperatorDescriptor insertOpA = new BTreeInsertUpdateDeleteOperatorDescriptor(spec, ordersDesc, bufferCacheProvider, btreeRegistryProvider, btreeSplitProviderA, fileMappingProviderProvider, primaryInteriorFrameFactory, primaryLeafFrameFactory, primaryTypeTraits, primaryComparatorFactories, fieldPermutationA, BTreeOp.BTO_INSERT);
+        BTreeInsertUpdateDeleteOperatorDescriptor insertOpA = new BTreeInsertUpdateDeleteOperatorDescriptor(spec, ordersDesc, storageManager, btreeRegistryProvider, btreeSplitProviderA, primaryInteriorFrameFactory, primaryLeafFrameFactory, primaryTypeTraits, primaryComparatorFactories, fieldPermutationA, BTreeOp.BTO_INSERT);
         PartitionConstraint insertPartitionConstraintA = new ExplicitPartitionConstraint(new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
         insertOpA.setPartitionConstraint(insertPartitionConstraintA);
         
@@ -393,7 +377,7 @@
         IFileSplitProvider btreeSplitProviderB = new ConstantFileSplitProvider(
 				new FileSplit[] { new FileSplit(NC1_ID, new File("/tmp/btreetestB.ix")) } );   
         int[] fieldPermutationB = { 3, 0 };                    
-        BTreeInsertUpdateDeleteOperatorDescriptor insertOpB = new BTreeInsertUpdateDeleteOperatorDescriptor(spec, ordersDesc, bufferCacheProvider, btreeRegistryProvider, btreeSplitProviderB, fileMappingProviderProvider, secondaryInteriorFrameFactory, secondaryLeafFrameFactory, secondaryTypeTraits, secondaryComparatorFactories, fieldPermutationB, BTreeOp.BTO_INSERT);
+        BTreeInsertUpdateDeleteOperatorDescriptor insertOpB = new BTreeInsertUpdateDeleteOperatorDescriptor(spec, ordersDesc, storageManager, btreeRegistryProvider, btreeSplitProviderB, secondaryInteriorFrameFactory, secondaryLeafFrameFactory, secondaryTypeTraits, secondaryComparatorFactories, fieldPermutationB, BTreeOp.BTO_INSERT);
         PartitionConstraint insertPartitionConstraintB = new ExplicitPartitionConstraint(new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
         insertOpB.setPartitionConstraint(insertPartitionConstraintB);
 		
@@ -401,7 +385,7 @@
         IFileSplitProvider btreeSplitProviderC = new ConstantFileSplitProvider(
 				new FileSplit[] { new FileSplit(NC1_ID, new File("/tmp/btreetestC.ix")) } );   
         int[] fieldPermutationC = { 4, 0 };                       
-        BTreeInsertUpdateDeleteOperatorDescriptor insertOpC = new BTreeInsertUpdateDeleteOperatorDescriptor(spec, ordersDesc, bufferCacheProvider, btreeRegistryProvider, btreeSplitProviderC, fileMappingProviderProvider, secondaryInteriorFrameFactory, secondaryLeafFrameFactory, secondaryTypeTraits, secondaryComparatorFactories, fieldPermutationC, BTreeOp.BTO_INSERT);
+        BTreeInsertUpdateDeleteOperatorDescriptor insertOpC = new BTreeInsertUpdateDeleteOperatorDescriptor(spec, ordersDesc, storageManager, btreeRegistryProvider, btreeSplitProviderC, secondaryInteriorFrameFactory, secondaryLeafFrameFactory, secondaryTypeTraits, secondaryComparatorFactories, fieldPermutationC, BTreeOp.BTO_INSERT);
         PartitionConstraint insertPartitionConstraintC = new ExplicitPartitionConstraint(new LocationConstraint[] { new AbsoluteLocationConstraint(NC1_ID) });
         insertOpC.setPartitionConstraint(insertPartitionConstraintC);
                 
@@ -422,9 +406,10 @@
         
         // scan primary index         
         System.out.println("PRINTING PRIMARY INDEX");
+        bufferCache.openFile(fileIdA);
         IBTreeCursor scanCursorA = new RangeSearchCursor(primaryLeafFrameFactory.getFrame());
         RangePredicate nullPredA = new RangePredicate(true, null, null, true, true, null, null);
-        BTreeOpContext opCtxA = btreeA.createOpContext(BTreeOp.BTO_SEARCH, primaryLeafFrameFactory.getFrame(), primaryInteriorFrameFactory.getFrame(), null);
+        BTreeOpContext opCtxA = btreeA.createOpContext(BTreeOp.BTO_SEARCH, primaryLeafFrameFactory.getFrame(), primaryInteriorFrameFactory.getFrame(), null);        
         btreeA.search(scanCursorA, nullPredA, opCtxA);
         try {
         	while (scanCursorA.hasNext()) {
@@ -438,10 +423,12 @@
         } finally {
         	scanCursorA.close();
         }            
+        bufferCache.closeFile(fileIdA);
         System.out.println();
         
         // scan first secondary index
         System.out.println("PRINTING FIRST SECONDARY INDEX");
+        bufferCache.openFile(fileIdB);
         IBTreeCursor scanCursorB = new RangeSearchCursor(secondaryLeafFrameFactory.getFrame());
         RangePredicate nullPredB = new RangePredicate(true, null, null, true, true, null, null);
         BTreeOpContext opCtxB = btreeB.createOpContext(BTreeOp.BTO_SEARCH, secondaryLeafFrameFactory.getFrame(), secondaryInteriorFrameFactory.getFrame(), null);
@@ -458,10 +445,12 @@
         } finally {
         	scanCursorB.close();
         }           
+        bufferCache.closeFile(fileIdB);
         System.out.println();
         
         // scan second secondary index
         System.out.println("PRINTING SECOND SECONDARY INDEX");
+        bufferCache.openFile(fileIdC);
         IBTreeCursor scanCursorC = new RangeSearchCursor(secondaryLeafFrameFactory.getFrame());
         RangePredicate nullPredC = new RangePredicate(true, null, null, true, true, null, null);
         BTreeOpContext opCtxC = btreeC.createOpContext(BTreeOp.BTO_SEARCH, secondaryLeafFrameFactory.getFrame(), secondaryInteriorFrameFactory.getFrame(), null);
@@ -478,6 +467,7 @@
         } finally {
         	scanCursorC.close();
         }        
+        bufferCache.closeFile(fileIdC);
         System.out.println();
 	}
 }
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/DummySMI.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/DummySMI.java
index cf36a70..6766f51 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/DummySMI.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/DummySMI.java
@@ -35,12 +35,17 @@
 
     private transient IBufferCache bufferCache = null;
     private transient IFileMapManager fmManager;
-    private static final int PAGE_SIZE = 8192;
-    private static final int NUM_PAGES = 40;
-
-    public DummySMI() {
+    private int PAGE_SIZE = 8192;
+    private int NUM_PAGES = 40;
+    
+    public DummySMI() {    
     }
-
+    
+    public DummySMI(int pageSize, int numPages) {
+    	PAGE_SIZE = pageSize;
+    	NUM_PAGES = numPages;
+    }
+    
     @Override
     public synchronized IBufferCache getBufferCache() {
         if (bufferCache == null) {
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IBTreeFrame.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IBTreeFrame.java
index 0ba6e1d..72e5970 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IBTreeFrame.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/api/IBTreeFrame.java
@@ -35,7 +35,7 @@
 	public void delete(ITupleReference tuple, MultiComparator cmp, boolean exactDelete) throws Exception;
 	
 	public void compact(MultiComparator cmp);
-	public boolean compress(MultiComparator cmp) throws Exception;
+	public boolean compress(MultiComparator cmp) throws HyracksDataException;
 	
 	public void initBuffer(byte level);
 	
@@ -71,7 +71,7 @@
 	public boolean getSmFlag(); // structure modification flag
 	public void setSmFlag(boolean smFlag);	
 	
-	public void insertSorted(ITupleReference tuple, MultiComparator cmp) throws Exception;
+	public void insertSorted(ITupleReference tuple, MultiComparator cmp) throws HyracksDataException;
 	
 	public int getSlotSize();
 		
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/AbstractBTreeOperatorDescriptor.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/AbstractBTreeOperatorDescriptor.java
index 3f42e8e..f26a5dc 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/AbstractBTreeOperatorDescriptor.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/AbstractBTreeOperatorDescriptor.java
@@ -36,18 +36,18 @@
     protected final IBTreeInteriorFrameFactory interiorFrameFactory;
     protected final IBTreeLeafFrameFactory leafFrameFactory;
 
-    protected final IStorageManagerInterface smi;
+    protected final IStorageManagerInterface storageManager;
     protected final IBTreeRegistryProvider btreeRegistryProvider;
 
     protected final ITypeTrait[] typeTraits;
 
     public AbstractBTreeOperatorDescriptor(JobSpecification spec, int inputArity, int outputArity,
-            RecordDescriptor recDesc, IStorageManagerInterface smi, IBTreeRegistryProvider btreeRegistryProvider,
+            RecordDescriptor recDesc, IStorageManagerInterface storageManager, IBTreeRegistryProvider btreeRegistryProvider,
             IFileSplitProvider fileSplitProvider, IBTreeInteriorFrameFactory interiorFactory,
             IBTreeLeafFrameFactory leafFactory, ITypeTrait[] typeTraits, IBinaryComparatorFactory[] comparatorFactories) {
         super(spec, inputArity, outputArity);
         this.fileSplitProvider = fileSplitProvider;
-        this.smi = smi;
+        this.storageManager = storageManager;
         this.btreeRegistryProvider = btreeRegistryProvider;
         this.interiorFrameFactory = interiorFactory;
         this.leafFrameFactory = leafFactory;
@@ -77,8 +77,8 @@
         return leafFrameFactory;
     }
 
-    public IStorageManagerInterface getSMI() {
-        return smi;
+    public IStorageManagerInterface getStorageManager() {
+        return storageManager;
     }
 
     public IBTreeRegistryProvider getBtreeRegistryProvider() {
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeBulkLoadOperatorDescriptor.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeBulkLoadOperatorDescriptor.java
index 29a35d6..d5bfd4d 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeBulkLoadOperatorDescriptor.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeBulkLoadOperatorDescriptor.java
@@ -25,6 +25,7 @@
 import edu.uci.ics.hyracks.dataflow.std.file.IFileSplitProvider;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeInteriorFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeLeafFrameFactory;
+import edu.uci.ics.hyracks.storage.common.IStorageManagerInterface;
 
 public class BTreeBulkLoadOperatorDescriptor extends AbstractBTreeOperatorDescriptor {
 	
@@ -34,14 +35,14 @@
     private final float fillFactor;
         
 	public BTreeBulkLoadOperatorDescriptor(JobSpecification spec,			
-			IBufferCacheProvider bufferCacheProvider,
+			IStorageManagerInterface storageManager,
 			IBTreeRegistryProvider btreeRegistryProvider,
-			IFileSplitProvider fileSplitProvider, IFileMappingProviderProvider fileMappingProviderProvider, IBTreeInteriorFrameFactory interiorFactory,
+			IFileSplitProvider fileSplitProvider, IBTreeInteriorFrameFactory interiorFactory,
 			IBTreeLeafFrameFactory leafFactory, ITypeTrait[] typeTraits, 
 			IBinaryComparatorFactory[] comparatorFactories,			
 			int[] fieldPermutation, float fillFactor) {
-		super(spec, 1, 0, null, bufferCacheProvider,
-				btreeRegistryProvider, fileSplitProvider, fileMappingProviderProvider, interiorFactory,
+		super(spec, 1, 0, null, storageManager,
+				btreeRegistryProvider, fileSplitProvider, interiorFactory,
 				leafFactory, typeTraits, comparatorFactories);
 		this.fieldPermutation = fieldPermutation;
 		this.fillFactor = fillFactor;
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeBulkLoadOperatorNodePushable.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeBulkLoadOperatorNodePushable.java
index 92bbce1..a45c118 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeBulkLoadOperatorNodePushable.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeBulkLoadOperatorNodePushable.java
@@ -52,35 +52,27 @@
         IBTreeMetaDataFrame metaFrame = new MetaDataFrame();        
         btreeOpHelper.init();
         btreeOpHelper.getBTree().open(btreeOpHelper.getBTreeFileId());        
-        try {
-			bulkLoadCtx = btreeOpHelper.getBTree().beginBulkLoad(fillFactor, btreeOpHelper.getLeafFrame(), btreeOpHelper.getInteriorFrame(), metaFrame);
-		} catch (Exception e) {
-			throw new HyracksDataException(e);
-		}
+        bulkLoadCtx = btreeOpHelper.getBTree().beginBulkLoad(fillFactor, btreeOpHelper.getLeafFrame(), btreeOpHelper.getInteriorFrame(), metaFrame);		
     }
     
     @Override
     public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
         accessor.reset(buffer);
-
         int tupleCount = accessor.getTupleCount();
         for (int i = 0; i < tupleCount; i++) {
             tuple.reset(accessor, i);
-            try {
-                btreeOpHelper.getBTree().bulkLoadAddTuple(bulkLoadCtx, tuple);
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
+            btreeOpHelper.getBTree().bulkLoadAddTuple(bulkLoadCtx, tuple);            
         }
     }
     
     @Override
     public void close() throws HyracksDataException {
-        try {
-            btreeOpHelper.getBTree().endBulkLoad(bulkLoadCtx);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+    	try {
+    		btreeOpHelper.getBTree().endBulkLoad(bulkLoadCtx);
+    	}
+    	finally {
+    		btreeOpHelper.deinit();
+    	}    	
     }
     
     @Override
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeDiskOrderScanOperatorDescriptor.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeDiskOrderScanOperatorDescriptor.java
index 730b5f3..8d1c0dd 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeDiskOrderScanOperatorDescriptor.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeDiskOrderScanOperatorDescriptor.java
@@ -25,6 +25,7 @@
 import edu.uci.ics.hyracks.dataflow.std.file.IFileSplitProvider;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeInteriorFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeLeafFrameFactory;
+import edu.uci.ics.hyracks.storage.common.IStorageManagerInterface;
 
 public class BTreeDiskOrderScanOperatorDescriptor extends AbstractBTreeOperatorDescriptor {
 	
@@ -32,13 +33,13 @@
 	
 	public BTreeDiskOrderScanOperatorDescriptor(JobSpecification spec,
 			RecordDescriptor recDesc,
-			IBufferCacheProvider bufferCacheProvider,
+			IStorageManagerInterface storageManager,
 			IBTreeRegistryProvider btreeRegistryProvider,
-			IFileSplitProvider fileSplitProvider, IFileMappingProviderProvider fileMappingProviderProvider, IBTreeInteriorFrameFactory interiorFactory,
+			IFileSplitProvider fileSplitProvider, IBTreeInteriorFrameFactory interiorFactory,
 			IBTreeLeafFrameFactory leafFactory, 
 			ITypeTrait[] typeTraits) {
-		super(spec, 0, 1, recDesc, bufferCacheProvider,
-				btreeRegistryProvider, fileSplitProvider, fileMappingProviderProvider, interiorFactory,
+		super(spec, 0, 1, recDesc, storageManager,
+				btreeRegistryProvider, fileSplitProvider, interiorFactory,
 				leafFactory, typeTraits, null);
 	}
 	
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeDiskOrderScanOperatorNodePushable.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeDiskOrderScanOperatorNodePushable.java
index ebe1a9b..38b15bb 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeDiskOrderScanOperatorNodePushable.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeDiskOrderScanOperatorNodePushable.java
@@ -15,7 +15,6 @@
 package edu.uci.ics.hyracks.storage.am.btree.dataflow;
 
 import java.io.DataOutput;
-import java.io.FileNotFoundException;
 import java.nio.ByteBuffer;
 
 import edu.uci.ics.hyracks.api.context.IHyracksContext;
@@ -44,17 +43,10 @@
         IBTreeLeafFrame cursorFrame = btreeOpHelper.getOperatorDescriptor().getLeafFactory().getFrame();
         DiskOrderScanCursor cursor = new DiskOrderScanCursor(cursorFrame);
         IBTreeMetaDataFrame metaFrame = new MetaDataFrame();
+                
+        btreeOpHelper.init();
+        btreeOpHelper.getBTree().diskOrderScan(cursor, cursorFrame, metaFrame);
         
-        try {
-            btreeOpHelper.init();
-            //btreeOpHelper.fill();
-            btreeOpHelper.getBTree().diskOrderScan(cursor, cursorFrame, metaFrame);
-        } catch (FileNotFoundException e1) {
-            e1.printStackTrace();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
         MultiComparator cmp = btreeOpHelper.getBTree().getMultiComparator();
         ByteBuffer frame = btreeOpHelper.getHyracksContext().getResourceManager().allocateFrame();
         FrameTupleAppender appender = new FrameTupleAppender(btreeOpHelper.getHyracksContext());
@@ -91,6 +83,11 @@
 
         } catch (Exception e) {
             e.printStackTrace();
-        }
+        }                              
+    }
+    
+    @Override
+    public void deinitialize() throws HyracksDataException {
+    	btreeOpHelper.deinit();
     }
 }
\ No newline at end of file
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeDropOperatorDescriptor.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeDropOperatorDescriptor.java
index 295fd50..20c8a22 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeDropOperatorDescriptor.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeDropOperatorDescriptor.java
@@ -22,23 +22,22 @@
 import edu.uci.ics.hyracks.api.job.JobSpecification;
 import edu.uci.ics.hyracks.dataflow.std.base.AbstractSingleActivityOperatorDescriptor;
 import edu.uci.ics.hyracks.dataflow.std.file.IFileSplitProvider;
+import edu.uci.ics.hyracks.storage.common.IStorageManagerInterface;
 
 public class BTreeDropOperatorDescriptor extends AbstractSingleActivityOperatorDescriptor {
 	
 	private static final long serialVersionUID = 1L;
 	
-	private IBufferCacheProvider bufferCacheProvider;
-	private IBTreeRegistryProvider btreeRegistryProvider;	
-	private IFileMappingProviderProvider fileMappingProviderProvider;
+	private IStorageManagerInterface storageManager;	
+	private IBTreeRegistryProvider btreeRegistryProvider;
 	private IFileSplitProvider fileSplitProvider;
 	
 	public BTreeDropOperatorDescriptor(JobSpecification spec,			
-			IBufferCacheProvider bufferCacheProvider,
+			IStorageManagerInterface storageManager,
 			IBTreeRegistryProvider btreeRegistryProvider,
-			IFileSplitProvider fileSplitProvider, IFileMappingProviderProvider fileMappingProviderProvider) {
-		super(spec, 0, 0);
-		this.fileMappingProviderProvider = fileMappingProviderProvider;
-		this.bufferCacheProvider = bufferCacheProvider;
+			IFileSplitProvider fileSplitProvider) {
+		super(spec, 0, 0);		
+		this.storageManager = storageManager;
 		this.btreeRegistryProvider = btreeRegistryProvider;
 		this.fileSplitProvider = fileSplitProvider;
 	}
@@ -48,6 +47,6 @@
 			IOperatorEnvironment env,
 			IRecordDescriptorProvider recordDescProvider, int partition,
 			int nPartitions) {
-		return new BTreeDropOperatorNodePushable(bufferCacheProvider, btreeRegistryProvider, fileSplitProvider, partition, fileMappingProviderProvider);
+		return new BTreeDropOperatorNodePushable(storageManager, btreeRegistryProvider, fileSplitProvider, partition);
 	}	
 }
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeDropOperatorNodePushable.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeDropOperatorNodePushable.java
index 3bdf4a2..c365b86 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeDropOperatorNodePushable.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeDropOperatorNodePushable.java
@@ -7,28 +7,27 @@
 import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.dataflow.std.base.AbstractOperatorNodePushable;
 import edu.uci.ics.hyracks.dataflow.std.file.IFileSplitProvider;
-import edu.uci.ics.hyracks.storage.common.file.FileManager;
+import edu.uci.ics.hyracks.storage.common.IStorageManagerInterface;
+import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
+import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
 
 public class BTreeDropOperatorNodePushable extends AbstractOperatorNodePushable {
 	
     private IBTreeRegistryProvider btreeRegistryProvider;
-    private IBufferCacheProvider bufferCacheProvider;
-    private IFileMappingProviderProvider fileMappingProviderProvider;
+    private IStorageManagerInterface storageManager;    
     private IFileSplitProvider fileSplitProvider;
     private int partition;
     
-    public BTreeDropOperatorNodePushable(IBufferCacheProvider bufferCacheProvider,
-            IBTreeRegistryProvider btreeRegistryProvider, IFileSplitProvider fileSplitProvider, int partition,
-            IFileMappingProviderProvider fileMappingProviderProvider) {
-        this.fileMappingProviderProvider = fileMappingProviderProvider;
-        this.bufferCacheProvider = bufferCacheProvider;
+    public BTreeDropOperatorNodePushable(IStorageManagerInterface storageManager,
+            IBTreeRegistryProvider btreeRegistryProvider, IFileSplitProvider fileSplitProvider, int partition) {
+        this.storageManager = storageManager;
         this.btreeRegistryProvider = btreeRegistryProvider;
         this.fileSplitProvider = fileSplitProvider;
         this.partition = partition;
     }
 
     @Override
-    public void deinitialize() throws HyracksDataException {
+    public void deinitialize() throws HyracksDataException {    	
     }
 
     @Override
@@ -45,17 +44,19 @@
     public void initialize() throws HyracksDataException {
 
         BTreeRegistry btreeRegistry = btreeRegistryProvider.getBTreeRegistry();
-        FileManager fileManager = bufferCacheProvider.getFileManager();
-        
+        IBufferCache bufferCache = storageManager.getBufferCache();
+        IFileMapProvider fileMapProvider = storageManager.getFileMapProvider(); 
+                        
         File f = fileSplitProvider.getFileSplits()[partition].getLocalFile();        
         String fileName = f.getAbsolutePath();            
                 
-        Integer fileId = fileMappingProviderProvider.getFileMappingProvider().getFileId(fileName);
-        if(fileId == null) {
+        boolean fileIsMapped = fileMapProvider.isMapped(fileName);
+        if(!fileIsMapped) {
         	throw new HyracksDataException("Cannot drop B-Tree with name " + fileName + ". No file mapping exists.");
         }
-        int btreeFileId = fileId; 
         
+        int btreeFileId = fileMapProvider.lookupFileId(fileName);
+                
         // unregister btree instance            
         btreeRegistry.lock();
         try {
@@ -65,11 +66,9 @@
         }
         
         // remove name to id mapping
-        fileMappingProviderProvider.getFileMappingProvider().unmapName(fileName);
-                
-        // unregister file
-        fileManager.unregisterFile(btreeFileId);
+        bufferCache.deleteFile(btreeFileId);
         
+        // TODO: should this be handled through the BufferCache or FileMapProvider?
         if (f.exists()) {
             f.delete();
         }
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeFileEnlistmentOperatorDescriptor.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeFileEnlistmentOperatorDescriptor.java
index fd7c5a6..c68258a 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeFileEnlistmentOperatorDescriptor.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeFileEnlistmentOperatorDescriptor.java
@@ -12,6 +12,7 @@
 import edu.uci.ics.hyracks.dataflow.std.file.IFileSplitProvider;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeInteriorFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeLeafFrameFactory;
+import edu.uci.ics.hyracks.storage.common.IStorageManagerInterface;
 
 // re-create in-memory state for a btree that has already been built (i.e., the file exists):
 // 1. register files in file manager (FileManager)
@@ -24,15 +25,14 @@
 	
 	public BTreeFileEnlistmentOperatorDescriptor(JobSpecification spec,
 			RecordDescriptor recDesc,
-			IBufferCacheProvider bufferCacheProvider,
+			IStorageManagerInterface storageManager,
 			IBTreeRegistryProvider btreeRegistryProvider,
 			IFileSplitProvider fileSplitProvider,
-			IFileMappingProviderProvider fileMappingProviderProvider,
 			IBTreeInteriorFrameFactory interiorFactory,
 			IBTreeLeafFrameFactory leafFactory, ITypeTrait[] typeTraits,
 			IBinaryComparatorFactory[] comparatorFactories) {
-		super(spec, 0, 0, recDesc, bufferCacheProvider,
-				btreeRegistryProvider, fileSplitProvider, fileMappingProviderProvider,
+		super(spec, 0, 0, recDesc, storageManager,
+				btreeRegistryProvider, fileSplitProvider,
 				interiorFactory, leafFactory, typeTraits, comparatorFactories);		
 	}
 	
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeFileEnlistmentOperatorNodePushable.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeFileEnlistmentOperatorNodePushable.java
index cd0b4b3..6cad109 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeFileEnlistmentOperatorNodePushable.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeFileEnlistmentOperatorNodePushable.java
@@ -30,7 +30,8 @@
 
 	@Override
 	public void initialize() throws HyracksDataException {
-		btreeOpHelper.init();		
+		btreeOpHelper.init();
+		btreeOpHelper.deinit();
 	}
 
 	@Override
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeInsertUpdateDeleteOperatorDescriptor.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeInsertUpdateDeleteOperatorDescriptor.java
index 7fb4398..acb09fe 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeInsertUpdateDeleteOperatorDescriptor.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeInsertUpdateDeleteOperatorDescriptor.java
@@ -27,6 +27,7 @@
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeInteriorFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeLeafFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.impls.BTreeOp;
+import edu.uci.ics.hyracks.storage.common.IStorageManagerInterface;
 
 public class BTreeInsertUpdateDeleteOperatorDescriptor extends AbstractBTreeOperatorDescriptor {
 	
@@ -38,15 +39,15 @@
 	
 	public BTreeInsertUpdateDeleteOperatorDescriptor(JobSpecification spec,
 			RecordDescriptor recDesc,
-			IBufferCacheProvider bufferCacheProvider,
+			IStorageManagerInterface storageManager,
 			IBTreeRegistryProvider btreeRegistryProvider,
-			IFileSplitProvider fileSplitProvider, IFileMappingProviderProvider fileMappingProviderProvider, 
+			IFileSplitProvider fileSplitProvider, 
 			IBTreeInteriorFrameFactory interiorFactory,
 			IBTreeLeafFrameFactory leafFactory, ITypeTrait[] typeTraits, 
 			IBinaryComparatorFactory[] comparatorFactories,			
 			int[] fieldPermutation, BTreeOp op) {
-		super(spec, 1, 1, recDesc, bufferCacheProvider,
-				btreeRegistryProvider, fileSplitProvider, fileMappingProviderProvider, interiorFactory,
+		super(spec, 1, 1, recDesc, storageManager,
+				btreeRegistryProvider, fileSplitProvider, interiorFactory,
 				leafFactory, typeTraits, comparatorFactories);
 		this.fieldPermutation = fieldPermutation;		
 		this.op = op;
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeInsertUpdateDeleteOperatorNodePushable.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeInsertUpdateDeleteOperatorNodePushable.java
index 44d26da..d5846b0 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeInsertUpdateDeleteOperatorNodePushable.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeInsertUpdateDeleteOperatorNodePushable.java
@@ -44,12 +44,18 @@
         this.op = op;
         tuple.setFieldPermutation(fieldPermutation);
     }
-
+    
     @Override
-    public void close() throws HyracksDataException {
-        writer.close();
+    public void open() throws HyracksDataException {
+    	AbstractBTreeOperatorDescriptor opDesc = btreeOpHelper.getOperatorDescriptor();
+    	RecordDescriptor inputRecDesc = recordDescProvider.getInputRecordDescriptor(opDesc.getOperatorId(), 0);
+    	accessor = new FrameTupleAccessor(btreeOpHelper.getHyracksContext(), inputRecDesc);
+    	writeBuffer = btreeOpHelper.getHyracksContext().getResourceManager().allocateFrame();        
+    	btreeOpHelper.init();
+    	btreeOpHelper.getBTree().open(btreeOpHelper.getBTreeFileId());
+    	opCtx = btreeOpHelper.getBTree().createOpContext(op, btreeOpHelper.getLeafFrame(), btreeOpHelper.getInteriorFrame(), new MetaDataFrame());
     }
-
+    
     @Override
     public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
         final BTree btree = btreeOpHelper.getBTree();       
@@ -57,52 +63,46 @@
         
         int tupleCount = accessor.getTupleCount();
         for (int i = 0; i < tupleCount; i++) {
-            tuple.reset(accessor, i);
-            try {
+        	tuple.reset(accessor, i);
+        	try {
+        		switch (op) {
 
-                switch (op) {
+        		case BTO_INSERT: {
+        			btree.insert(tuple, opCtx);
+        		}
+        		break;
 
-                    case BTO_INSERT: {
-                        btree.insert(tuple, opCtx);
-                    }
-                        break;
+        		case BTO_DELETE: {
+        			btree.delete(tuple, opCtx);
+        		}
+        		break;
 
-                    case BTO_DELETE: {
-                        btree.delete(tuple, opCtx);
-                    }
-                        break;
+        		default: {
+        			throw new HyracksDataException("Unsupported operation " + op + " in BTree InsertUpdateDelete operator");
+        		}
 
-                    default: {
-                        throw new HyracksDataException("Unsupported operation " + op + " in BTree InsertUpdateDelete operator");
-                    }
+        		}
 
-                }
-
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
+        	} catch (Exception e) {
+        		e.printStackTrace();
+        	}
         }
 
         // pass a copy of the frame to next op
         System.arraycopy(buffer.array(), 0, writeBuffer.array(), 0, buffer.capacity());
         FrameUtils.flushFrame(writeBuffer, writer);
     }
-
+    
     @Override
-    public void open() throws HyracksDataException {
-        AbstractBTreeOperatorDescriptor opDesc = btreeOpHelper.getOperatorDescriptor();
-        RecordDescriptor inputRecDesc = recordDescProvider.getInputRecordDescriptor(opDesc.getOperatorId(), 0);
-        accessor = new FrameTupleAccessor(btreeOpHelper.getHyracksContext(), inputRecDesc);
-        writeBuffer = btreeOpHelper.getHyracksContext().getResourceManager().allocateFrame();        
-        try {
-            btreeOpHelper.init();
-            btreeOpHelper.getBTree().open(btreeOpHelper.getBTreeFileId());
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        opCtx = btreeOpHelper.getBTree().createOpContext(op, btreeOpHelper.getLeafFrame(), btreeOpHelper.getInteriorFrame(), new MetaDataFrame());
+    public void close() throws HyracksDataException {
+    	try {
+    		writer.close();
+    	}
+    	finally {
+    		btreeOpHelper.deinit();
+    	}    	    	
     }
-
+    
     @Override
     public void flush() throws HyracksDataException {
     }
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeOpHelper.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeOpHelper.java
index 4ca44e8..67d3ef8 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeOpHelper.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeOpHelper.java
@@ -15,8 +15,6 @@
 package edu.uci.ics.hyracks.storage.am.btree.dataflow;
 
 import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.RandomAccessFile;
 
 import edu.uci.ics.hyracks.api.context.IHyracksContext;
 import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparator;
@@ -28,7 +26,6 @@
 import edu.uci.ics.hyracks.storage.am.btree.impls.BTree;
 import edu.uci.ics.hyracks.storage.am.btree.impls.MultiComparator;
 import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
-import edu.uci.ics.hyracks.storage.common.file.FileHandle;
 import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
 
 final class BTreeOpHelper {
@@ -60,67 +57,38 @@
     
     void init() throws HyracksDataException {
     	
-    	IBufferCache bufferCache = opDesc.getSMI().getBufferCache();
-        IFileSplitProvider fileSplitProvider = opDesc.getFileSplitProvider();
+    	IBufferCache bufferCache = opDesc.getStorageManager().getBufferCache();
+        IFileMapProvider fileMapProvider = opDesc.getStorageManager().getFileMapProvider();
+    	IFileSplitProvider fileSplitProvider = opDesc.getFileSplitProvider();
         
-        File f = fileSplitProvider.getFileSplits()[partition].getLocalFile();
-        if(!f.exists()) {
-        	File dir = new File(f.getParent());        	
-        	dir.mkdirs();
-        }
-        RandomAccessFile raf;
-		try {
-			raf = new RandomAccessFile(f, "rw");
-		} catch (FileNotFoundException e) {
-			throw new HyracksDataException(e);
-		}
-        
-        String fileName = f.getAbsolutePath();
-        Integer fileId = opDesc.getSMI().getFileMapProvider().lookupFileId(fileName);        
+        File f = fileSplitProvider.getFileSplits()[partition].getLocalFile();                
+        String fileName = f.getAbsolutePath();        
+        boolean fileIsMapped = fileMapProvider.isMapped(fileName); 
         
         switch(mode) {
     	
-    	case OPEN_BTREE: {
-    		if(fileId == null) {
-    			throw new HyracksDataException("Cannot get id for file " + fileName + ". File name has not been mapped.");
-    		}
-    		if(!f.exists()) {
-    			throw new HyracksDataException("Trying to open btree from file " + fileName + " but file doesn't exist.");
-    		}
-    	} break;
-        
-    	case CREATE_BTREE: {
-    		if(fileId == null) {
-    			fileId = fileMappingProviderProvider.getFileMappingProvider().mapNameToFileId(fileName, true);
-    		}
-    		else {
-    			throw new HyracksDataException("Cannot map file " + fileName + " to an id. File name has already been mapped.");
+    	case OPEN_BTREE: {    		
+    		if(!fileIsMapped) {
+    			bufferCache.createFile(fileName);
+    			//throw new HyracksDataException("Trying to open btree from unmapped file " + fileName);
     		}    		
     	} break;
         
-    	case ENLIST_BTREE: {
-    		if(fileId == null) {
-    			fileId = fileMappingProviderProvider.getFileMappingProvider().mapNameToFileId(fileName, true);
-    		}
-    		else {
-    			throw new HyracksDataException("Cannot map file " + fileName + " to an id. File name has already been mapped.");
-    		}    		
-    		if(!f.exists()) {
-    			throw new HyracksDataException("Trying to enlist btree from file " + fileName + " but file doesn't exist.");
-    		}
+    	case CREATE_BTREE: 
+    	case ENLIST_BTREE: {    		
+    		if(!fileIsMapped) {
+    			bufferCache.createFile(fileName);
+    		}    		    	
     	} break;
+            	
         }
     	
-    	btreeFileId = fileId;
+        btreeFileId = fileMapProvider.lookupFileId(fileName);
+    	bufferCache.openFile(btreeFileId);
     	
-        if(mode == BTreeMode.CREATE_BTREE || mode == BTreeMode.ENLIST_BTREE) {
-        	FileHandle fi = new FileHandle(btreeFileId, raf);
-        	fileManager.registerFile(fi);
-        }
-        
         interiorFrame = opDesc.getInteriorFactory().getFrame();
         leafFrame = opDesc.getLeafFactory().getFrame();
-
+        
         BTreeRegistry btreeRegistry = opDesc.getBtreeRegistryProvider().getBTreeRegistry();
         btree = btreeRegistry.get(btreeFileId);
         if (btree == null) {
@@ -145,17 +113,24 @@
                         MetaDataFrame metaFrame = new MetaDataFrame();
                         try {
 							btree.create(btreeFileId, leafFrame, metaFrame);
+							btree.open(btreeFileId);
 						} catch (Exception e) {
 							throw new HyracksDataException(e);
 						}
-                    }
-                    btree.open(btreeFileId);
+                    }                    
                     btreeRegistry.register(btreeFileId, btree);
                 }
             } finally {
                 btreeRegistry.unlock();
             }
-        }
+        }        
+    }
+    
+    public void deinit() throws HyracksDataException {
+    	if(btreeFileId != -1) {
+    		IBufferCache bufferCache = opDesc.getStorageManager().getBufferCache();
+    		bufferCache.closeFile(btreeFileId);
+    	}
     }
     
     public BTree getBTree() {
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorDescriptor.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorDescriptor.java
index 6b0e4de..de41eb8 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorDescriptor.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorDescriptor.java
@@ -26,26 +26,38 @@
 import edu.uci.ics.hyracks.dataflow.std.file.IFileSplitProvider;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeInteriorFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeLeafFrameFactory;
+import edu.uci.ics.hyracks.storage.common.IStorageManagerInterface;
 
 public class BTreeSearchOperatorDescriptor extends AbstractBTreeOperatorDescriptor {
-	
+
 	private static final long serialVersionUID = 1L;
 
 	private boolean isForward;	
 	private int[] lowKeyFields; // fields in input tuple to be used as low keys
 	private int[] highKeyFields; // fields in input tuple to be used as high keys
 	private boolean lowKeyInclusive;
-    private boolean highKeyInclusive;
-	
-	public BTreeSearchOperatorDescriptor(JobSpecification spec, RecordDescriptor recDesc, IBufferCacheProvider bufferCacheProvider, IBTreeRegistryProvider btreeRegistryProvider, IFileSplitProvider fileSplitProvider, IFileMappingProviderProvider fileMappingProviderProvider, IBTreeInteriorFrameFactory interiorFactory, IBTreeLeafFrameFactory leafFactory, ITypeTrait[] typeTraits, IBinaryComparatorFactory[] comparatorFactories, boolean isForward, int[] lowKeyFields, int[] highKeyFields, boolean lowKeyInclusive, boolean highKeyInclusive) {		
-		super(spec, 1, 1, recDesc, bufferCacheProvider, btreeRegistryProvider, fileSplitProvider, fileMappingProviderProvider, interiorFactory, leafFactory, typeTraits, comparatorFactories);
+	private boolean highKeyInclusive;
+
+	public BTreeSearchOperatorDescriptor(JobSpecification spec, 
+			RecordDescriptor recDesc, 
+			IStorageManagerInterface storageManager, 
+			IBTreeRegistryProvider btreeRegistryProvider, 
+			IFileSplitProvider fileSplitProvider, 
+			IBTreeInteriorFrameFactory interiorFactory, 
+			IBTreeLeafFrameFactory leafFactory, 
+			ITypeTrait[] typeTraits, 
+			IBinaryComparatorFactory[] comparatorFactories, 
+			boolean isForward, 
+			int[] lowKeyFields, int[] highKeyFields, 
+			boolean lowKeyInclusive, boolean highKeyInclusive) {		
+		super(spec, 1, 1, recDesc, storageManager, btreeRegistryProvider, fileSplitProvider, interiorFactory, leafFactory, typeTraits, comparatorFactories);
 		this.isForward = isForward;
 		this.lowKeyFields = lowKeyFields;
 		this.highKeyFields = highKeyFields;
 		this.lowKeyInclusive = lowKeyInclusive;
 		this.highKeyInclusive = highKeyInclusive;
 	}
-	
+
 	@Override
 	public IOperatorNodePushable createPushRuntime(final IHyracksContext ctx, final IOperatorEnvironment env,
 			IRecordDescriptorProvider recordDescProvider, int partition, int nPartitions) {
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorNodePushable.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorNodePushable.java
index 052d7e1..286bfad 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorNodePushable.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorNodePushable.java
@@ -85,11 +85,7 @@
         cursorFrame = opDesc.getLeafFactory().getFrame();
         cursor = new RangeSearchCursor(cursorFrame);
         
-        try {
-			btreeOpHelper.init();
-		} catch (Exception e) {
-			throw new HyracksDataException(e);
-		}
+        btreeOpHelper.init();		
         btree = btreeOpHelper.getBTree();
         
         // construct range predicate
@@ -174,15 +170,20 @@
 	
 	@Override
 	public void close() throws HyracksDataException {
-		if (appender.getTupleCount() > 0) {
-			FrameUtils.flushFrame(writeBuffer, writer);
-		}		
-		writer.close();
 		try {
-			cursor.close();
-		} catch (Exception e) {
-			throw new HyracksDataException(e);
-		}    	
+			if (appender.getTupleCount() > 0) {
+				FrameUtils.flushFrame(writeBuffer, writer);
+			}		
+			writer.close();
+			try {
+				cursor.close();
+			} catch (Exception e) {
+				throw new HyracksDataException(e);
+			}		
+		}
+		finally {
+			btreeOpHelper.deinit();
+		}
 	}
 
 	@Override
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/HyracksSimpleStorageManagerInterface.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/HyracksSimpleStorageManagerInterface.java
new file mode 100644
index 0000000..4b74fd4
--- /dev/null
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/HyracksSimpleStorageManagerInterface.java
@@ -0,0 +1,95 @@
+package edu.uci.ics.hyracks.storage.am.btree.dataflow;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.storage.common.IStorageManagerInterface;
+import edu.uci.ics.hyracks.storage.common.buffercache.BufferCache;
+import edu.uci.ics.hyracks.storage.common.buffercache.ClockPageReplacementStrategy;
+import edu.uci.ics.hyracks.storage.common.buffercache.HeapBufferAllocator;
+import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
+import edu.uci.ics.hyracks.storage.common.buffercache.ICacheMemoryAllocator;
+import edu.uci.ics.hyracks.storage.common.buffercache.IPageReplacementStrategy;
+import edu.uci.ics.hyracks.storage.common.file.IFileMapManager;
+import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
+
+public class HyracksSimpleStorageManagerInterface implements IStorageManagerInterface {
+	private static final long serialVersionUID = 1L;
+
+	private static transient IBufferCache bufferCache = null;
+    private static transient IFileMapManager fmManager;
+	private int PAGE_SIZE = 8192;
+    private int NUM_PAGES = 40;    
+        
+    public HyracksSimpleStorageManagerInterface() {
+    	init();
+    }
+    
+    public HyracksSimpleStorageManagerInterface(int pageSize, int numPages) {
+    	PAGE_SIZE = pageSize;
+    	NUM_PAGES = numPages;
+    	init();
+    }
+    
+    private void init() {
+    	ICacheMemoryAllocator allocator = new HeapBufferAllocator();
+        IPageReplacementStrategy prs = new ClockPageReplacementStrategy();
+        fmManager = new IFileMapManager() {
+            private Map<Integer, String> id2nameMap = new HashMap<Integer, String>();
+            private Map<String, Integer> name2IdMap = new HashMap<String, Integer>();
+            private int idCounter = 0;
+
+            @Override
+            public String lookupFileName(int fileId) throws HyracksDataException {
+                String fName = id2nameMap.get(fileId);
+                if (fName == null) {
+                    throw new HyracksDataException("No mapping found for id: " + fileId);
+                }
+                return fName;
+            }
+
+            @Override
+            public int lookupFileId(String fileName) throws HyracksDataException {
+                Integer fileId = name2IdMap.get(fileName);
+                if (fileId == null) {
+                    throw new HyracksDataException("No mapping found for name: " + fileName);
+                }
+                return fileId;
+            }
+
+            @Override
+            public boolean isMapped(String fileName) {
+                return name2IdMap.containsKey(fileName);
+            }
+
+            @Override
+            public boolean isMapped(int fileId) {
+                return id2nameMap.containsKey(fileId);
+            }
+
+            @Override
+            public void unregisterFile(int fileId) throws HyracksDataException {
+                String fileName = id2nameMap.remove(fileId);
+                name2IdMap.remove(fileName);
+            }
+
+            @Override
+            public void registerFile(String fileName) throws HyracksDataException {
+                Integer fileId = idCounter++;
+                id2nameMap.put(fileId, fileName);
+                name2IdMap.put(fileName, fileId);
+            }
+        };
+        bufferCache = new BufferCache(allocator, prs, fmManager, PAGE_SIZE, NUM_PAGES);
+    }
+    
+    public IFileMapProvider getFileMapProvider() {
+        return fmManager;
+    }
+
+	@Override
+	public IBufferCache getBufferCache() {
+		return bufferCache;
+	}
+}
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/IBTreeOperatorDescriptor.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/IBTreeOperatorDescriptor.java
deleted file mode 100644
index 707d20e..0000000
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/IBTreeOperatorDescriptor.java
+++ /dev/null
@@ -1,35 +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.btree.dataflow;
-
-import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeInteriorFrameFactory;
-import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeLeafFrameFactory;
-import edu.uci.ics.hyracks.storage.am.btree.impls.MultiComparator;
-import edu.uci.ics.hyracks.storage.am.btree.impls.RangePredicate;
-
-public interface IBTreeOperatorDescriptor {
-	public String getBTreeFileName();
-	public int getBTreeFileId();
-	
-	public MultiComparator getMultiComparator();	
-	public RangePredicate getRangePred();
-	
-	public IBTreeInteriorFrameFactory getInteriorFactory();
-	public IBTreeLeafFrameFactory getLeafFactory();
-	
-	public IBufferCacheProvider getBufferCacheProvider();
-	public IBTreeRegistryProvider getBTreeRegistryProvider();
-}
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/FieldPrefixNSMLeafFrame.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/FieldPrefixNSMLeafFrame.java
index 65327ae..7437111 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/FieldPrefixNSMLeafFrame.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/FieldPrefixNSMLeafFrame.java
@@ -100,8 +100,12 @@
     }
         
     @Override
-    public boolean compress(MultiComparator cmp) throws Exception {
-        return compressor.compress(this, cmp);
+    public boolean compress(MultiComparator cmp) throws HyracksDataException {
+        try {
+			return compressor.compress(this, cmp);
+		} catch (Exception e) {
+			throw new HyracksDataException(e);
+		}
     }
     
     // assumptions: 
@@ -392,7 +396,7 @@
 	}
 	
     @Override
-    public void insertSorted(ITupleReference tuple, MultiComparator cmp) throws Exception {    	
+    public void insertSorted(ITupleReference tuple, MultiComparator cmp) throws HyracksDataException {    	
     	int freeSpace = buf.getInt(freeSpaceOff);				
 		int fieldsToTruncate = 0;
 		
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/NSMInteriorFrame.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/NSMInteriorFrame.java
index b34a3df..f388fd8 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/NSMInteriorFrame.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/NSMInteriorFrame.java
@@ -117,7 +117,7 @@
 	}
 	
 	@Override
-	public void insertSorted(ITupleReference tuple, MultiComparator cmp) throws Exception {
+	public void insertSorted(ITupleReference tuple, MultiComparator cmp) throws HyracksDataException {
 		int freeSpace = buf.getInt(freeSpaceOff);
 		slotManager.insertSlot(-1, freeSpace);
 		int bytesWritten = tupleWriter.writeTupleFields(tuple, 0, cmp.getKeyFieldCount(), buf, freeSpace);
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/NSMLeafFrame.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/NSMLeafFrame.java
index 2dd6bc0..b1cdcf3 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/NSMLeafFrame.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/frames/NSMLeafFrame.java
@@ -17,6 +17,7 @@
 
 import java.nio.ByteBuffer;
 
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.ITupleReference;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeFrame;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeLeafFrame;
@@ -92,7 +93,7 @@
 	}
 	
 	@Override
-	public void insertSorted(ITupleReference tuple, MultiComparator cmp) throws Exception {		
+	public void insertSorted(ITupleReference tuple, MultiComparator cmp) throws HyracksDataException {		
 		int freeSpace = buf.getInt(freeSpaceOff);
 		slotManager.insertSlot(-1, freeSpace);		
 		int bytesWritten = tupleWriter.writeTuple(tuple, buf, freeSpace);	
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTree.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTree.java
index a305dc1..3e77b86 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTree.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/BTree.java
@@ -22,8 +22,6 @@
 import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
 import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.ITupleReference;
-import edu.uci.ics.hyracks.dataflow.common.data.marshalling.IntegerSerializerDeserializer;
-import edu.uci.ics.hyracks.dataflow.common.data.marshalling.UTF8StringSerializerDeserializer;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeCursor;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeFrame;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeInteriorFrame;
@@ -161,7 +159,7 @@
         fileId = -1;
     }
 
-    private int getFreePage(IBTreeMetaDataFrame metaFrame) throws Exception {
+    private int getFreePage(IBTreeMetaDataFrame metaFrame) throws HyracksDataException {
         ICachedPage metaNode = bufferCache.pin(FileHandle.getDiskPageId(fileId, metaDataPage), false);
         pins++;
         
@@ -374,7 +372,7 @@
         }
     }
 
-    public void diskOrderScan(DiskOrderScanCursor cursor, IBTreeLeafFrame leafFrame, IBTreeMetaDataFrame metaFrame) throws Exception {
+    public void diskOrderScan(DiskOrderScanCursor cursor, IBTreeLeafFrame leafFrame, IBTreeMetaDataFrame metaFrame) throws HyracksDataException {
         int currentPageId = rootPage + 1;
         int maxPageId = -1;
         
@@ -434,7 +432,7 @@
         cursor.setFileId(fileId);
     }
 
-    private void unsetSmPages(BTreeOpContext ctx) throws Exception {
+    private void unsetSmPages(BTreeOpContext ctx) throws HyracksDataException {
         ICachedPage originalPage = ctx.interiorFrame.getPage();
         for(int i = 0; i < ctx.smPages.size(); i++) {
             int pageId = ctx.smPages.get(i);
@@ -980,7 +978,7 @@
     }
 
     private void performOp(int pageId, ICachedPage parent, BTreeOpContext ctx) throws Exception {
-        ICachedPage node = bufferCache.pin(FileHandle.getDiskPageId(fileId, pageId), false);
+    	ICachedPage node = bufferCache.pin(FileHandle.getDiskPageId(fileId, pageId), false);        
         pins++;
 
         ctx.interiorFrame.setPage(node);
@@ -1167,7 +1165,7 @@
         private final IBTreeTupleWriter tupleWriter;
         
         public BulkLoadContext(float fillFactor, IBTreeLeafFrame leafFrame, IBTreeInteriorFrame interiorFrame,
-                IBTreeMetaDataFrame metaFrame) throws Exception {
+                IBTreeMetaDataFrame metaFrame) throws HyracksDataException {
 
         	splitKey = new SplitKey(leafFrame.getTupleWriter().createTupleReference());
         	tupleWriter = leafFrame.getTupleWriter();
@@ -1194,7 +1192,7 @@
             nodeFrontiers.add(leafFrontier);
         }
 
-        private void addLevel() throws Exception {
+        private void addLevel() throws HyracksDataException {
             NodeFrontier frontier = new NodeFrontier(tupleWriter.createTupleReference());
             frontier.pageId = getFreePage(metaFrame);
             frontier.page = bufferCache.pin(FileHandle.getDiskPageId(fileId, frontier.pageId), bulkNewPage);
@@ -1206,7 +1204,7 @@
         }
     }
 
-    private void propagateBulk(BulkLoadContext ctx, int level) throws Exception {
+    private void propagateBulk(BulkLoadContext ctx, int level) throws HyracksDataException {
 
         if (ctx.splitKey.getBuffer() == null)
             return;
@@ -1255,9 +1253,9 @@
     }
     
     // assumes btree has been created and opened
-    public BulkLoadContext beginBulkLoad(float fillFactor, IBTreeLeafFrame leafFrame, IBTreeInteriorFrame interiorFrame, IBTreeMetaDataFrame metaFrame) throws Exception {
+    public BulkLoadContext beginBulkLoad(float fillFactor, IBTreeLeafFrame leafFrame, IBTreeInteriorFrame interiorFrame, IBTreeMetaDataFrame metaFrame) throws HyracksDataException {
         
-    	if(loaded) throw new BTreeException("Trying to bulk-load BTree but has BTree already been loaded.");
+    	if(loaded) throw new HyracksDataException("Trying to bulk-load BTree but has BTree already been loaded.");
     	
     	BulkLoadContext ctx = new BulkLoadContext(fillFactor, leafFrame, interiorFrame, metaFrame);
         ctx.nodeFrontiers.get(0).lastTuple.setFieldCount(cmp.getFieldCount());
@@ -1265,7 +1263,7 @@
         return ctx;
     }
     
-    public void bulkLoadAddTuple(BulkLoadContext ctx, ITupleReference tuple) throws Exception {                        
+    public void bulkLoadAddTuple(BulkLoadContext ctx, ITupleReference tuple) throws HyracksDataException {                        
         NodeFrontier leafFrontier = ctx.nodeFrontiers.get(0);
         IBTreeLeafFrame leafFrame = ctx.leafFrame;
         
@@ -1311,7 +1309,7 @@
         //System.out.println(s);        
     }
     
-    public void endBulkLoad(BulkLoadContext ctx) throws Exception {                
+    public void endBulkLoad(BulkLoadContext ctx) throws HyracksDataException {                
         // copy root
         ICachedPage rootNode = bufferCache.pin(FileHandle.getDiskPageId(fileId, rootPage), bulkNewPage);
         rootNode.acquireWriteLatch();
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/DiskOrderScanCursor.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/DiskOrderScanCursor.java
index a0b9d6b..f49e2f9 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/DiskOrderScanCursor.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/DiskOrderScanCursor.java
@@ -15,6 +15,7 @@
 
 package edu.uci.ics.hyracks.storage.am.btree.impls;
 
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeCursor;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeLeafFrame;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeTupleReference;
@@ -59,7 +60,7 @@
         return page;
     }
     
-    private boolean positionToNextLeaf(boolean skipCurrent) throws Exception {
+    private boolean positionToNextLeaf(boolean skipCurrent) throws HyracksDataException {
         while( (frame.getLevel() != 0 || skipCurrent) && (currentPageId <= maxPageId) || (frame.getTupleCount() == 0) ) {            
             currentPageId++;
             
@@ -101,7 +102,7 @@
     }
     
     @Override
-    public void open(ICachedPage page, ISearchPredicate searchPred) throws Exception {       
+    public void open(ICachedPage page, ISearchPredicate searchPred) throws HyracksDataException {       
         // in case open is called multiple times without closing
         if(this.page != null) {
             this.page.releaseReadLatch();
@@ -116,7 +117,7 @@
 		frameTuple.setFieldCount(lowKeyCmp.getFieldCount());
         boolean leafExists = positionToNextLeaf(false);
         if(!leafExists) {
-            throw new Exception("Failed to open disk-order scan cursor for B-tree. Traget B-tree has no leaves.");
+            throw new HyracksDataException("Failed to open disk-order scan cursor for B-tree. Traget B-tree has no leaves.");
         }
     }
     
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/RangeSearchCursor.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/RangeSearchCursor.java
index 1299f04..6272c21 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/RangeSearchCursor.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/impls/RangeSearchCursor.java
@@ -23,7 +23,7 @@
 import edu.uci.ics.hyracks.storage.am.btree.api.ISearchPredicate;
 import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
 import edu.uci.ics.hyracks.storage.common.buffercache.ICachedPage;
-import edu.uci.ics.hyracks.storage.common.file.FileInfo;
+import edu.uci.ics.hyracks.storage.common.file.FileHandle;
 
 public class RangeSearchCursor implements IBTreeCursor {
 	
@@ -74,7 +74,7 @@
 	}	
 	
 	private void fetchNextLeafPage(int nextLeafPage) throws HyracksDataException {
-		ICachedPage nextLeaf = bufferCache.pin(FileInfo.getDiskPageId(fileId, nextLeafPage), false);
+		ICachedPage nextLeaf = bufferCache.pin(FileHandle.getDiskPageId(fileId, nextLeafPage), false);
 		nextLeaf.acquireReadLatch();
 
 		page.releaseReadLatch();
diff --git a/hyracks-storage-am-btree/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeFieldPrefixNSMTest.java b/hyracks-storage-am-btree/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeFieldPrefixNSMTest.java
index 3cfdf46..532ec50 100644
--- a/hyracks-storage-am-btree/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeFieldPrefixNSMTest.java
+++ b/hyracks-storage-am-btree/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeFieldPrefixNSMTest.java
@@ -16,8 +16,6 @@
 package edu.uci.ics.hyracks.storage.am.btree;
 
 import java.io.DataOutput;
-import java.io.File;
-import java.io.RandomAccessFile;
 import java.nio.ByteBuffer;
 import java.util.Random;
 
@@ -40,6 +38,7 @@
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.ITupleReference;
 import edu.uci.ics.hyracks.dataflow.common.data.comparators.IntegerBinaryComparatorFactory;
 import edu.uci.ics.hyracks.dataflow.common.data.marshalling.IntegerSerializerDeserializer;
+import edu.uci.ics.hyracks.storage.am.btree.api.DummySMI;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeTupleWriter;
 import edu.uci.ics.hyracks.storage.am.btree.api.IPrefixSlotManager;
 import edu.uci.ics.hyracks.storage.am.btree.frames.FieldPrefixNSMLeafFrame;
@@ -47,22 +46,15 @@
 import edu.uci.ics.hyracks.storage.am.btree.impls.FieldPrefixSlotManager;
 import edu.uci.ics.hyracks.storage.am.btree.impls.MultiComparator;
 import edu.uci.ics.hyracks.storage.am.btree.tuples.TypeAwareTupleWriter;
-import edu.uci.ics.hyracks.storage.common.buffercache.BufferCache;
-import edu.uci.ics.hyracks.storage.common.buffercache.ClockPageReplacementStrategy;
 import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
 import edu.uci.ics.hyracks.storage.common.buffercache.ICacheMemoryAllocator;
 import edu.uci.ics.hyracks.storage.common.buffercache.ICachedPage;
-import edu.uci.ics.hyracks.storage.common.buffercache.IPageReplacementStrategy;
 import edu.uci.ics.hyracks.storage.common.file.FileHandle;
-import edu.uci.ics.hyracks.storage.common.file.FileManager;
+import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
 
 public class BTreeFieldPrefixNSMTest {
 	
-    //private static final int PAGE_SIZE = 8192;
-    //private static final int PAGE_SIZE = 8192;
 	private static final int PAGE_SIZE = 32768; // 32K
-	//private static final int PAGE_SIZE = 65536; // 64K
-	//private static final int PAGE_SIZE = 131072; // 128K
     private static final int NUM_PAGES = 40;
     private static final int HYRACKS_FRAME_SIZE = 128;
     
@@ -122,16 +114,13 @@
     @Test
     public void test01() throws Exception {
     	
-        FileManager fileManager = new FileManager();
-        ICacheMemoryAllocator allocator = new BufferAllocator();
-        IPageReplacementStrategy prs = new ClockPageReplacementStrategy();
-        IBufferCache bufferCache = new BufferCache(allocator, prs, fileManager, PAGE_SIZE, NUM_PAGES);
-        
-        File f = new File(tmpDir + "/" + "btreetest.bin");
-        RandomAccessFile raf = new RandomAccessFile(f, "rw");
-        int fileId = 0;
-        FileHandle fi = new FileHandle(fileId, raf);
-        fileManager.registerFile(fi);
+    	DummySMI smi = new DummySMI(PAGE_SIZE, NUM_PAGES);    	
+    	IBufferCache bufferCache = smi.getBufferCache();
+    	IFileMapProvider fmp = smi.getFileMapProvider();
+    	String fileName = tmpDir + "/" + "btreetest.bin";
+    	bufferCache.createFile(fileName);    	
+    	int fileId = fmp.lookupFileId(fileName);
+    	bufferCache.openFile(fileId);
         
         // declare fields
         int fieldCount = 3;
@@ -245,8 +234,8 @@
         } finally {            
             bufferCache.unpin(page);
         }              
-        
+                
+        bufferCache.closeFile(fileId);
         bufferCache.close();
-        fileManager.close();
     }
 }
diff --git a/hyracks-storage-am-btree/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeTest.java b/hyracks-storage-am-btree/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeTest.java
index 6094bd6..4ab3e80 100644
--- a/hyracks-storage-am-btree/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeTest.java
+++ b/hyracks-storage-am-btree/src/test/java/edu/uci/ics/hyracks/storage/am/btree/BTreeTest.java
@@ -16,8 +16,6 @@
 package edu.uci.ics.hyracks.storage.am.btree;
 
 import java.io.DataOutput;
-import java.io.File;
-import java.io.RandomAccessFile;
 import java.nio.ByteBuffer;
 import java.util.Random;
 
@@ -40,6 +38,7 @@
 import edu.uci.ics.hyracks.dataflow.common.data.comparators.UTF8StringBinaryComparatorFactory;
 import edu.uci.ics.hyracks.dataflow.common.data.marshalling.IntegerSerializerDeserializer;
 import edu.uci.ics.hyracks.dataflow.common.data.marshalling.UTF8StringSerializerDeserializer;
+import edu.uci.ics.hyracks.storage.am.btree.api.DummySMI;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeCursor;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeInteriorFrame;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeInteriorFrameFactory;
@@ -60,20 +59,14 @@
 import edu.uci.ics.hyracks.storage.am.btree.impls.RangeSearchCursor;
 import edu.uci.ics.hyracks.storage.am.btree.tuples.SimpleTupleWriterFactory;
 import edu.uci.ics.hyracks.storage.am.btree.tuples.TypeAwareTupleWriterFactory;
-import edu.uci.ics.hyracks.storage.common.buffercache.BufferCache;
-import edu.uci.ics.hyracks.storage.common.buffercache.ClockPageReplacementStrategy;
 import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
 import edu.uci.ics.hyracks.storage.common.buffercache.ICacheMemoryAllocator;
-import edu.uci.ics.hyracks.storage.common.buffercache.IPageReplacementStrategy;
-import edu.uci.ics.hyracks.storage.common.file.FileHandle;
-import edu.uci.ics.hyracks.storage.common.file.FileManager;
+import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
 
 @SuppressWarnings("unchecked")
 
 public class BTreeTest {    
 	
-    //private static final int PAGE_SIZE = 128;
-    //private static final int PAGE_SIZE = 8192;
 	private static final int PAGE_SIZE = 256;
     private static final int NUM_PAGES = 10;
     private static final int HYRACKS_FRAME_SIZE = 128;
@@ -108,18 +101,15 @@
     public void test01() throws Exception {
     	
     	print("FIXED-LENGTH KEY TEST\n");
+
+    	DummySMI smi = new DummySMI(PAGE_SIZE, NUM_PAGES);    	
+    	IBufferCache bufferCache = smi.getBufferCache();
+    	IFileMapProvider fmp = smi.getFileMapProvider();
+    	String fileName = tmpDir + "/" + "btreetest.bin";
+    	bufferCache.createFile(fileName);    	
+    	int fileId = fmp.lookupFileId(fileName);
+    	bufferCache.openFile(fileId);
     	
-        FileManager fileManager = new FileManager();
-        ICacheMemoryAllocator allocator = new BufferAllocator();
-        IPageReplacementStrategy prs = new ClockPageReplacementStrategy();
-        IBufferCache bufferCache = new BufferCache(allocator, prs, fileManager, PAGE_SIZE, NUM_PAGES);
-        
-        File f = new File(tmpDir + "/" + "btreetest.bin");
-        RandomAccessFile raf = new RandomAccessFile(f, "rw");
-        int fileId = 0;
-        FileHandle fi = new FileHandle(fileId, raf);
-        fileManager.registerFile(fi);
-        
         // declare fields
         int fieldCount = 2;
         ITypeTrait[] typeTraits = new ITypeTrait[fieldCount];
@@ -311,13 +301,12 @@
         }  
                 
         btree.close();
-
+        bufferCache.closeFile(fileId);
         bufferCache.close();
-        fileManager.close();
+        
         print("\n");
     }
-    
-    
+            
     // COMPOSITE KEY TEST (NON-UNIQUE B-TREE)
     // create a B-tree with one two fixed-length "key" fields and one fixed-length "value" field
     // fill B-tree with random values using insertions (not bulk load)
@@ -327,16 +316,13 @@
 
     	print("COMPOSITE KEY TEST\n");
     	
-        FileManager fileManager = new FileManager();
-        ICacheMemoryAllocator allocator = new BufferAllocator();
-        IPageReplacementStrategy prs = new ClockPageReplacementStrategy();
-        IBufferCache bufferCache = new BufferCache(allocator, prs, fileManager, PAGE_SIZE, NUM_PAGES);
-
-        File f = new File(tmpDir + "/" + "btreetest.bin");
-        RandomAccessFile raf = new RandomAccessFile(f, "rw");
-        int fileId = 0;
-        FileHandle fi = new FileHandle(fileId, raf);
-        fileManager.registerFile(fi);
+    	DummySMI smi = new DummySMI(PAGE_SIZE, NUM_PAGES);    	
+    	IBufferCache bufferCache = smi.getBufferCache();
+    	IFileMapProvider fmp = smi.getFileMapProvider();
+    	String fileName = tmpDir + "/" + "btreetest.bin";
+    	bufferCache.createFile(fileName);    	
+    	int fileId = fmp.lookupFileId(fileName);
+    	bufferCache.openFile(fileId);    	        
                 
         // declare fields
         int fieldCount = 3;
@@ -499,9 +485,8 @@
         }
 
         btree.close();
-        
+        bufferCache.closeFile(fileId);
         bufferCache.close();
-        fileManager.close();
         
         print("\n");
     }
@@ -515,16 +500,13 @@
 
     	print("VARIABLE-LENGTH KEY TEST\n");
     	
-    	FileManager fileManager = new FileManager();
-    	ICacheMemoryAllocator allocator = new BufferAllocator();
-    	IPageReplacementStrategy prs = new ClockPageReplacementStrategy();
-    	IBufferCache bufferCache = new BufferCache(allocator, prs, fileManager, PAGE_SIZE, NUM_PAGES);
-
-    	File f = new File(tmpDir + "/" + "btreetest.bin");
-    	RandomAccessFile raf = new RandomAccessFile(f, "rw");
-    	int fileId = 0;
-    	FileHandle fi = new FileHandle(fileId, raf);
-    	fileManager.registerFile(fi);
+    	DummySMI smi = new DummySMI(PAGE_SIZE, NUM_PAGES);    	
+    	IBufferCache bufferCache = smi.getBufferCache();
+    	IFileMapProvider fmp = smi.getFileMapProvider();
+    	String fileName = tmpDir + "/" + "btreetest.bin";
+    	bufferCache.createFile(fileName);    	
+    	int fileId = fmp.lookupFileId(fileName);
+    	bufferCache.openFile(fileId);
     	
     	// declare fields
     	int fieldCount = 2;
@@ -678,9 +660,8 @@
         }
     	
         btree.close();
-
+        bufferCache.closeFile(fileId);
         bufferCache.close();
-        fileManager.close();
         
         print("\n");
     }
@@ -695,16 +676,13 @@
 
     	print("DELETION TEST\n");
     	
-        FileManager fileManager = new FileManager();
-        ICacheMemoryAllocator allocator = new BufferAllocator();
-        IPageReplacementStrategy prs = new ClockPageReplacementStrategy();
-        IBufferCache bufferCache = new BufferCache(allocator, prs, fileManager, PAGE_SIZE, NUM_PAGES);
-
-        File f = new File(tmpDir + "/" + "btreetest.bin");
-        RandomAccessFile raf = new RandomAccessFile(f, "rw");
-        int fileId = 0;
-        FileHandle fi = new FileHandle(fileId, raf);
-        fileManager.registerFile(fi);
+    	DummySMI smi = new DummySMI(PAGE_SIZE, NUM_PAGES);    	
+    	IBufferCache bufferCache = smi.getBufferCache();
+    	IFileMapProvider fmp = smi.getFileMapProvider();
+    	String fileName = tmpDir + "/" + "btreetest.bin";
+    	bufferCache.createFile(fileName);    	
+    	int fileId = fmp.lookupFileId(fileName);
+    	bufferCache.openFile(fileId);
                 
         // declare fields
         int fieldCount = 2;
@@ -845,9 +823,8 @@
         }
         
         btree.close();
-
+        bufferCache.closeFile(fileId);
         bufferCache.close();
-        fileManager.close();
         
         print("\n");
     }
@@ -861,16 +838,13 @@
 
     	print("BULK LOAD TEST\n");
     	
-        FileManager fileManager = new FileManager();
-        ICacheMemoryAllocator allocator = new BufferAllocator();
-        IPageReplacementStrategy prs = new ClockPageReplacementStrategy();
-        IBufferCache bufferCache = new BufferCache(allocator, prs, fileManager, PAGE_SIZE, NUM_PAGES);
-
-        File f = new File(tmpDir + "/" + "btreetest.bin");
-        RandomAccessFile raf = new RandomAccessFile(f, "rw");
-        int fileId = 0;
-        FileHandle fi = new FileHandle(fileId, raf);
-        fileManager.registerFile(fi);
+    	DummySMI smi = new DummySMI(PAGE_SIZE, NUM_PAGES);    	
+    	IBufferCache bufferCache = smi.getBufferCache();
+    	IFileMapProvider fmp = smi.getFileMapProvider();
+    	String fileName = tmpDir + "/" + "btreetest.bin";
+    	bufferCache.createFile(fileName);    	
+    	int fileId = fmp.lookupFileId(fileName);
+    	bufferCache.openFile(fileId);
         
         // declare fields
         int fieldCount = 3;
@@ -1006,9 +980,8 @@
         }
 
         btree.close();
-
+        bufferCache.closeFile(fileId);
         bufferCache.close();
-        fileManager.close();
         
         print("\n");
     }    
@@ -1020,16 +993,13 @@
 
     	print("TIME-INTERVAL INTERSECTION DEMO\n");
     	
-        FileManager fileManager = new FileManager();
-        ICacheMemoryAllocator allocator = new BufferAllocator();
-        IPageReplacementStrategy prs = new ClockPageReplacementStrategy();
-        IBufferCache bufferCache = new BufferCache(allocator, prs, fileManager, PAGE_SIZE, NUM_PAGES);
-
-        File f = new File(tmpDir + "/" + "btreetest.bin");
-        RandomAccessFile raf = new RandomAccessFile(f, "rw");
-        int fileId = 0;
-        FileHandle fi = new FileHandle(fileId, raf);
-        fileManager.registerFile(fi);       
+    	DummySMI smi = new DummySMI(PAGE_SIZE, NUM_PAGES);    	
+    	IBufferCache bufferCache = smi.getBufferCache();
+    	IFileMapProvider fmp = smi.getFileMapProvider();
+    	String fileName = tmpDir + "/" + "btreetest.bin";
+    	bufferCache.createFile(fileName);    	
+    	int fileId = fmp.lookupFileId(fileName);
+    	bufferCache.openFile(fileId); 
         
         // declare fields
         int fieldCount = 3;
@@ -1230,13 +1200,12 @@
         }
 
         btree.close();
-
+        bufferCache.closeFile(fileId);
         bufferCache.close();
-        fileManager.close();
         
         print("\n");
     }
-        
+    
     public static String randomString(int length, Random random) {
         String s = Long.toHexString(Double.doubleToLongBits(random.nextDouble()));
         StringBuilder strBuilder = new StringBuilder();
diff --git a/hyracks-storage-am-btree/src/test/java/edu/uci/ics/hyracks/storage/am/btree/RangeSearchCursorTest.java b/hyracks-storage-am-btree/src/test/java/edu/uci/ics/hyracks/storage/am/btree/RangeSearchCursorTest.java
index 9bfaa6b..5c9c4b5 100644
--- a/hyracks-storage-am-btree/src/test/java/edu/uci/ics/hyracks/storage/am/btree/RangeSearchCursorTest.java
+++ b/hyracks-storage-am-btree/src/test/java/edu/uci/ics/hyracks/storage/am/btree/RangeSearchCursorTest.java
@@ -4,8 +4,6 @@
 import java.io.DataInput;
 import java.io.DataInputStream;
 import java.io.DataOutput;
-import java.io.File;
-import java.io.RandomAccessFile;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -32,6 +30,7 @@
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.ITupleReference;
 import edu.uci.ics.hyracks.dataflow.common.data.comparators.IntegerBinaryComparatorFactory;
 import edu.uci.ics.hyracks.dataflow.common.data.marshalling.IntegerSerializerDeserializer;
+import edu.uci.ics.hyracks.storage.am.btree.api.DummySMI;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeCursor;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeInteriorFrame;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeInteriorFrameFactory;
@@ -51,13 +50,9 @@
 import edu.uci.ics.hyracks.storage.am.btree.impls.RangePredicate;
 import edu.uci.ics.hyracks.storage.am.btree.impls.RangeSearchCursor;
 import edu.uci.ics.hyracks.storage.am.btree.tuples.TypeAwareTupleWriterFactory;
-import edu.uci.ics.hyracks.storage.common.buffercache.BufferCache;
-import edu.uci.ics.hyracks.storage.common.buffercache.ClockPageReplacementStrategy;
 import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
 import edu.uci.ics.hyracks.storage.common.buffercache.ICacheMemoryAllocator;
-import edu.uci.ics.hyracks.storage.common.buffercache.IPageReplacementStrategy;
-import edu.uci.ics.hyracks.storage.common.file.FileInfo;
-import edu.uci.ics.hyracks.storage.common.file.FileManager;
+import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
 
 public class RangeSearchCursorTest {
 	private static final int PAGE_SIZE = 256;
@@ -66,10 +61,6 @@
     
     private String tmpDir = System.getProperty("java.io.tmpdir");
     
-    private void print(String str) {
-    	System.out.print(str);
-    }       
-    
     public class BufferAllocator implements ICacheMemoryAllocator {
         @Override
         public ByteBuffer[] allocate(int pageSize, int numPages) {
@@ -117,16 +108,13 @@
     	    	
     	System.out.println("TESTING RANGE SEARCH CURSOR ON UNIQUE INDEX");
     	
-        FileManager fileManager = new FileManager();
-        ICacheMemoryAllocator allocator = new BufferAllocator();
-        IPageReplacementStrategy prs = new ClockPageReplacementStrategy();
-        IBufferCache bufferCache = new BufferCache(allocator, prs, fileManager, PAGE_SIZE, NUM_PAGES);
-        
-        File f = new File(tmpDir + "/" + "btreetest.bin");
-        RandomAccessFile raf = new RandomAccessFile(f, "rw");
-        int fileId = 0;
-        FileInfo fi = new FileInfo(fileId, raf);
-        fileManager.registerFile(fi);
+    	DummySMI smi = new DummySMI(PAGE_SIZE, NUM_PAGES);    	
+    	IBufferCache bufferCache = smi.getBufferCache();
+    	IFileMapProvider fmp = smi.getFileMapProvider();
+    	String fileName = tmpDir + "/" + "btreetest.bin";
+    	bufferCache.createFile(fileName);    	
+    	int fileId = fmp.lookupFileId(fileName);
+    	bufferCache.openFile(fileId);
                 
         // declare keys
         int keyFieldCount = 1;
@@ -199,9 +187,8 @@
         performSearches(keys, btree, leafFrame, interiorFrame, minSearchKey, maxSearchKey, false, true, true, false);
         
         btree.close();
-
+        bufferCache.closeFile(fileId);
         bufferCache.close();
-        fileManager.close();
     }    
     
     @Test
@@ -209,16 +196,13 @@
     	    	
     	System.out.println("TESTING RANGE SEARCH CURSOR ON NONUNIQUE INDEX");
     	
-        FileManager fileManager = new FileManager();
-        ICacheMemoryAllocator allocator = new BufferAllocator();
-        IPageReplacementStrategy prs = new ClockPageReplacementStrategy();
-        IBufferCache bufferCache = new BufferCache(allocator, prs, fileManager, PAGE_SIZE, NUM_PAGES);
-        
-        File f = new File(tmpDir + "/" + "btreetest.bin");
-        RandomAccessFile raf = new RandomAccessFile(f, "rw");
-        int fileId = 0;
-        FileInfo fi = new FileInfo(fileId, raf);
-        fileManager.registerFile(fi);
+    	DummySMI smi = new DummySMI(PAGE_SIZE, NUM_PAGES);    	
+    	IBufferCache bufferCache = smi.getBufferCache();
+    	IFileMapProvider fmp = smi.getFileMapProvider();
+    	String fileName = tmpDir + "/" + "btreetest.bin";
+    	bufferCache.createFile(fileName);    	
+    	int fileId = fmp.lookupFileId(fileName);
+    	bufferCache.openFile(fileId);
                 
         // declare keys
         int keyFieldCount = 2;
@@ -289,9 +273,8 @@
         performSearches(keys, btree, leafFrame, interiorFrame, minSearchKey, maxSearchKey, false, true, true, false);
         
         btree.close();
-
+        bufferCache.closeFile(fileId);
         bufferCache.close();
-        fileManager.close();
     }    
     
     @Test
@@ -302,16 +285,13 @@
     	IBTreeLeafFrameFactory leafFrameFactory = new FieldPrefixNSMLeafFrameFactory(tupleWriterFactory);
     	IBTreeLeafFrame leafFrame = leafFrameFactory.getFrame();
     	
-        FileManager fileManager = new FileManager();
-        ICacheMemoryAllocator allocator = new BufferAllocator();
-        IPageReplacementStrategy prs = new ClockPageReplacementStrategy();
-        IBufferCache bufferCache = new BufferCache(allocator, prs, fileManager, PAGE_SIZE, NUM_PAGES);
-        
-        File f = new File(tmpDir + "/" + "btreetest.bin");
-        RandomAccessFile raf = new RandomAccessFile(f, "rw");
-        int fileId = 0;
-        FileInfo fi = new FileInfo(fileId, raf);
-        fileManager.registerFile(fi);
+    	DummySMI smi = new DummySMI(PAGE_SIZE, NUM_PAGES);    	
+    	IBufferCache bufferCache = smi.getBufferCache();
+    	IFileMapProvider fmp = smi.getFileMapProvider();
+    	String fileName = tmpDir + "/" + "btreetest.bin";
+    	bufferCache.createFile(fileName);    	
+    	int fileId = fmp.lookupFileId(fileName);
+    	bufferCache.openFile(fileId);
                 
         // declare keys
         int keyFieldCount = 2;
@@ -382,9 +362,8 @@
         performSearches(keys, btree, leafFrame, interiorFrame, minSearchKey, maxSearchKey, false, true, true, false);
         
         btree.close();
-
+        bufferCache.closeFile(fileId);
         bufferCache.close();
-        fileManager.close();
     }    
     
     public RangePredicate createRangePredicate(int lk, int hk, boolean isForward, boolean lowKeyInclusive, boolean highKeyInclusive, MultiComparator cmp, ITypeTrait[] typeTraits) throws HyracksDataException {        
diff --git a/hyracks-storage-am-invertedindex/src/main/java/edu/uci/ics/hyracks/storage/am/invertedindex/api/IInvertedIndexSearcher.java b/hyracks-storage-am-invertedindex/src/main/java/edu/uci/ics/hyracks/storage/am/invertedindex/api/IInvertedIndexSearcher.java
index fc2dfd1..72cc6fe 100644
--- a/hyracks-storage-am-invertedindex/src/main/java/edu/uci/ics/hyracks/storage/am/invertedindex/api/IInvertedIndexSearcher.java
+++ b/hyracks-storage-am-invertedindex/src/main/java/edu/uci/ics/hyracks/storage/am/invertedindex/api/IInvertedIndexSearcher.java
@@ -1,9 +1,8 @@
 package edu.uci.ics.hyracks.storage.am.invertedindex.api;
 
-import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.ITupleReference;
 
 public interface IInvertedIndexSearcher {			
-	public void search(ITupleReference queryTuple, int queryFieldIndex) throws HyracksDataException;
+	public void search(ITupleReference queryTuple, int queryFieldIndex) throws Exception;
 	public IInvertedIndexResultCursor getResultCursor();
 }
diff --git a/hyracks-storage-am-invertedindex/src/main/java/edu/uci/ics/hyracks/storage/am/invertedindex/impls/SimpleConjunctiveSearcher.java b/hyracks-storage-am-invertedindex/src/main/java/edu/uci/ics/hyracks/storage/am/invertedindex/impls/SimpleConjunctiveSearcher.java
index b6e3547..f81ccdb 100644
--- a/hyracks-storage-am-invertedindex/src/main/java/edu/uci/ics/hyracks/storage/am/invertedindex/impls/SimpleConjunctiveSearcher.java
+++ b/hyracks-storage-am-invertedindex/src/main/java/edu/uci/ics/hyracks/storage/am/invertedindex/impls/SimpleConjunctiveSearcher.java
@@ -100,7 +100,7 @@
 		resultFrameAccessor = new FrameTupleAccessor(ctx, valueRecDesc);
 	}
 	
-	public void search(ITupleReference queryTuple, int queryFieldIndex) throws HyracksDataException {
+	public void search(ITupleReference queryTuple, int queryFieldIndex) throws Exception {
 		
 		// parse query, TODO: this parsing is too simple
 		RecordDescriptor queryTokenRecDesc = new RecordDescriptor(new ISerializerDeserializer[] { UTF8StringSerializerDeserializer.INSTANCE } );
@@ -144,6 +144,7 @@
 				btreeCursor.next();
 				maxResultBufIdx = appendTupleToNewResults(btreeCursor, maxResultBufIdx);				
 			}
+			btreeCursor.close();
 			btreeCursor.reset();
 		} catch (Exception e) {
 			throw new HyracksDataException(e);
@@ -163,6 +164,7 @@
 			} catch (Exception e) {
 				throw new HyracksDataException(e);
 			}		
+			btreeCursor.close();
 			btreeCursor.reset();			
 		}				
 	}	
diff --git a/hyracks-storage-am-invertedindex/src/test/java/edu/uci/ics/hyracks/storage/am/invertedindex/searchers/SimpleConjunctiveSearcherTest.java b/hyracks-storage-am-invertedindex/src/test/java/edu/uci/ics/hyracks/storage/am/invertedindex/searchers/SimpleConjunctiveSearcherTest.java
index ae68bf3..80201f0 100644
--- a/hyracks-storage-am-invertedindex/src/test/java/edu/uci/ics/hyracks/storage/am/invertedindex/searchers/SimpleConjunctiveSearcherTest.java
+++ b/hyracks-storage-am-invertedindex/src/test/java/edu/uci/ics/hyracks/storage/am/invertedindex/searchers/SimpleConjunctiveSearcherTest.java
@@ -4,8 +4,6 @@
 import java.io.DataInput;
 import java.io.DataInputStream;
 import java.io.DataOutput;
-import java.io.File;
-import java.io.RandomAccessFile;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
@@ -29,6 +27,7 @@
 import edu.uci.ics.hyracks.dataflow.common.data.comparators.UTF8StringBinaryComparatorFactory;
 import edu.uci.ics.hyracks.dataflow.common.data.marshalling.IntegerSerializerDeserializer;
 import edu.uci.ics.hyracks.dataflow.common.data.marshalling.UTF8StringSerializerDeserializer;
+import edu.uci.ics.hyracks.storage.am.btree.api.DummySMI;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeInteriorFrame;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeInteriorFrameFactory;
 import edu.uci.ics.hyracks.storage.am.btree.api.IBTreeLeafFrame;
@@ -47,13 +46,9 @@
 import edu.uci.ics.hyracks.storage.am.invertedindex.api.IInvertedIndexResultCursor;
 import edu.uci.ics.hyracks.storage.am.invertedindex.impls.SimpleConjunctiveSearcher;
 import edu.uci.ics.hyracks.storage.am.invertedindex.tokenizers.DelimitedUTF8StringBinaryTokenizer;
-import edu.uci.ics.hyracks.storage.common.buffercache.BufferCache;
-import edu.uci.ics.hyracks.storage.common.buffercache.ClockPageReplacementStrategy;
 import edu.uci.ics.hyracks.storage.common.buffercache.IBufferCache;
 import edu.uci.ics.hyracks.storage.common.buffercache.ICacheMemoryAllocator;
-import edu.uci.ics.hyracks.storage.common.buffercache.IPageReplacementStrategy;
-import edu.uci.ics.hyracks.storage.common.file.FileHandle;
-import edu.uci.ics.hyracks.storage.common.file.FileManager;
+import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
 
 public class SimpleConjunctiveSearcherTest {
 	
@@ -84,16 +79,13 @@
 	@Test	
 	public void test01() throws Exception { 
 		
-    	FileManager fileManager = new FileManager();
-    	ICacheMemoryAllocator allocator = new BufferAllocator();
-    	IPageReplacementStrategy prs = new ClockPageReplacementStrategy();
-    	IBufferCache bufferCache = new BufferCache(allocator, prs, fileManager, PAGE_SIZE, NUM_PAGES);
-
-    	File f = new File(tmpDir + "/" + "btreetest.bin");
-    	RandomAccessFile raf = new RandomAccessFile(f, "rw");
-    	int fileId = 0;
-    	FileHandle fi = new FileHandle(fileId, raf);
-    	fileManager.registerFile(fi);
+		DummySMI smi = new DummySMI(PAGE_SIZE, NUM_PAGES);    	
+    	IBufferCache bufferCache = smi.getBufferCache();
+    	IFileMapProvider fmp = smi.getFileMapProvider();
+    	String fileName = tmpDir + "/" + "btreetest.bin";
+    	bufferCache.createFile(fileName);    	
+    	int fileId = fmp.lookupFileId(fileName);
+    	bufferCache.openFile(fileId);
     	
     	// declare fields
     	int fieldCount = 2;
@@ -147,7 +139,7 @@
 		tokens.add("science");		
 		tokens.add("major");				
 		
-		int maxId = 1000000;
+		int maxId = 10000;
 		int addProb = 0;
 		int addProbStep = 2;
 		
@@ -233,9 +225,9 @@
 					ByteArrayInputStream inStream = new ByteArrayInputStream(resultTuple.getFieldData(j), resultTuple.getFieldStart(j), resultTuple.getFieldLength(j));
 					DataInput dataIn = new DataInputStream(inStream);
 					Object o = resultSerde[j].deserialize(dataIn);		
-					//System.out.print(o + " ");
+					System.out.print(o + " ");
 				}
-				//System.out.println();
+				System.out.println();
 			}
     	}
     	    	    	
@@ -263,11 +255,9 @@
             scanCursor.close();
         }
         */
-        
-                
-        btree.close();
-
+                        
+    	btree.close();
+        bufferCache.closeFile(fileId);
         bufferCache.close();
-        fileManager.close();
 	}		
 }