Merged asterix_stabilization r235:r248.

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix-fix-issue-9@249 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java
index 7fa281f..4ef030b 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java
@@ -65,20 +65,21 @@
         FunctionIdentifier fid = null;
         AbstractLogicalOperator op2 = op1;
         List<LogicalVariable> recordVar = new ArrayList<LogicalVariable>();
+        // Find assign op that creates record to be inserted/deleted.
         while (fid != AsterixBuiltinFunctions.OPEN_RECORD_CONSTRUCTOR) {
-            if (op2.getInputs().size() == 0)
+            if (op2.getInputs().size() == 0) {
                 return false;
+            }
             op2 = (AbstractLogicalOperator) op2.getInputs().get(0).getValue();
             if (op2.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
                 continue;
-            } else {
-                AssignOperator assignOp = (AssignOperator) op2;
-                ILogicalExpression assignExpr = assignOp.getExpressions().get(0).getValue();
-                if (assignExpr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
-                    ScalarFunctionCallExpression funcExpr = (ScalarFunctionCallExpression) assignOp.getExpressions()
-                            .get(0).getValue();
-                    fid = funcExpr.getFunctionIdentifier();
-                }
+            }
+            AssignOperator assignOp = (AssignOperator) op2;
+            ILogicalExpression assignExpr = assignOp.getExpressions().get(0).getValue();
+            if (assignExpr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
+                ScalarFunctionCallExpression funcExpr = (ScalarFunctionCallExpression) assignOp.getExpressions()
+                        .get(0).getValue();
+                fid = funcExpr.getFunctionIdentifier();
             }
         }
         AssignOperator assignOp2 = (AssignOperator) op2;
@@ -92,12 +93,13 @@
         if (adecl == null) {
             throw new AlgebricksException("Unknown dataset " + datasetName);
         }
-        if (adecl.getDatasetType() == DatasetType.EXTERNAL)
+        if (adecl.getDatasetType() == DatasetType.EXTERNAL) {
             return false;
+        }
 
         List<LogicalVariable> projectVars = new ArrayList<LogicalVariable>();
         VariableUtilities.getUsedVariables(op1, projectVars);
-        // create operators for secondary index insert
+        // Create operators for secondary index insert/delete.
         String itemTypeName = adecl.getItemTypeName();
         IAType itemType = metadata.findType(itemTypeName);
         if (itemType.getTypeTag() != ATypeTag.RECORD) {
@@ -105,8 +107,9 @@
         }
         ARecordType recType = (ARecordType) itemType;
         List<AqlCompiledIndexDecl> secondaryIndexes = DatasetUtils.getSecondaryIndexes(adecl);
-        if (secondaryIndexes.size() <= 0)
+        if (secondaryIndexes.isEmpty()) {
             return false;
+        }
         ILogicalOperator currentTop = op1;
         for (AqlCompiledIndexDecl index : secondaryIndexes) {
             List<String> secondaryKeyFields = index.getFieldExprs();
@@ -118,9 +121,13 @@
                         new VariableReferenceExpression(recordVar.get(0)));
                 String[] fieldNames = recType.getFieldNames();
                 int pos = -1;
-                for (int j = 0; j < fieldNames.length; j++)
-                    if (fieldNames[j].equals(secondaryKey))
+                for (int j = 0; j < fieldNames.length; j++) {
+                    if (fieldNames[j].equals(secondaryKey)) {
                         pos = j;
+                        break;
+                    }
+                }
+                // Assumes the indexed field is in the closed portion of the type.
                 Mutable<ILogicalExpression> indexRef = new MutableObject<ILogicalExpression>(new ConstantExpression(
                         new AsterixConstantValue(new AInt32(pos))));
                 AbstractFunctionCallExpression func = new ScalarFunctionCallExpression(
@@ -133,9 +140,10 @@
             AssignOperator assign = new AssignOperator(secondaryKeyVars, expressions);
             ProjectOperator project = new ProjectOperator(projectVars);
             if (index.getKind() == IndexKind.BTREE) {
-                for (LogicalVariable secondaryKeyVar : secondaryKeyVars)
+                for (LogicalVariable secondaryKeyVar : secondaryKeyVars) {
                     secondaryExpressions.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(
                             secondaryKeyVar)));
+                }
                 AqlIndex dataSourceIndex = new AqlIndex(index, metadata, datasetName);
                 IndexInsertDeleteOperator indexUpdate = new IndexInsertDeleteOperator(dataSourceIndex,
                         insertOp.getPrimaryKeyExpressions(), secondaryExpressions, insertOp.getOperation());
@@ -171,9 +179,10 @@
                                     new AInt32(i)))));
                     keyExprList.add(new MutableObject<ILogicalExpression>(createMBR));
                 }
-                for (LogicalVariable secondaryKeyVar : keyVarList)
+                for (LogicalVariable secondaryKeyVar : keyVarList) {
                     secondaryExpressions.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(
                             secondaryKeyVar)));
+                }
                 AqlIndex dataSourceIndex = new AqlIndex(index, metadata, datasetName);
                 IndexInsertDeleteOperator indexUpdate = new IndexInsertDeleteOperator(dataSourceIndex,
                         insertOp.getPrimaryKeyExpressions(), secondaryExpressions, insertOp.getOperation());
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/file/DatasetOperations.java b/asterix-app/src/main/java/edu/uci/ics/asterix/file/DatasetOperations.java
index 554ce3c..fcc0158 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/file/DatasetOperations.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/file/DatasetOperations.java
@@ -23,8 +23,8 @@
 import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
 import edu.uci.ics.asterix.common.config.GlobalConfig;
 import edu.uci.ics.asterix.common.config.OptimizationConfUtil;
+import edu.uci.ics.asterix.common.context.AsterixIndexRegistryProvider;
 import edu.uci.ics.asterix.common.context.AsterixStorageManagerInterface;
-import edu.uci.ics.asterix.common.context.AsterixTreeRegistryProvider;
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.formats.base.IDataFormat;
 import edu.uci.ics.asterix.metadata.declared.AqlCompiledDatasetDecl;
@@ -89,7 +89,7 @@
 
         LOGGER.info("DROP DATASETPATH: " + datasetPath);
 
-        IIndexRegistryProvider<IIndex> btreeRegistryProvider = AsterixTreeRegistryProvider.INSTANCE;
+        IIndexRegistryProvider<IIndex> indexRegistryProvider = AsterixIndexRegistryProvider.INSTANCE;
         IStorageManagerInterface storageManager = AsterixStorageManagerInterface.INSTANCE;
 
         AqlCompiledDatasetDecl adecl = metadata.findDataset(datasetName);
@@ -114,7 +114,7 @@
                 Pair<IFileSplitProvider, AlgebricksPartitionConstraint> idxSplitsAndConstraint = metadata
                         .splitProviderAndPartitionConstraintsForInternalOrFeedDataset(datasetName, acid.getIndexName());
                 TreeIndexDropOperatorDescriptor secondaryBtreeDrop = new TreeIndexDropOperatorDescriptor(specs[i],
-                        storageManager, btreeRegistryProvider, idxSplitsAndConstraint.first);
+                        storageManager, indexRegistryProvider, idxSplitsAndConstraint.first);
                 AlgebricksPartitionConstraintHelper.setPartitionConstraintInJobSpec(specs[i], secondaryBtreeDrop,
                         idxSplitsAndConstraint.second);
                 i++;
@@ -128,7 +128,7 @@
         Pair<IFileSplitProvider, AlgebricksPartitionConstraint> splitsAndConstraint = metadata
                 .splitProviderAndPartitionConstraintsForInternalOrFeedDataset(datasetName, datasetName);
         TreeIndexDropOperatorDescriptor primaryBtreeDrop = new TreeIndexDropOperatorDescriptor(specPrimary,
-                storageManager, btreeRegistryProvider, splitsAndConstraint.first);
+                storageManager, indexRegistryProvider, splitsAndConstraint.first);
         AlgebricksPartitionConstraintHelper.setPartitionConstraintInJobSpec(specPrimary, primaryBtreeDrop,
                 splitsAndConstraint.second);
 
@@ -161,8 +161,8 @@
                 compiledDatasetDecl, metadata.getFormat().getBinaryComparatorFactoryProvider());
         ITypeTraits[] typeTraits = DatasetUtils.computeTupleTypeTraits(compiledDatasetDecl, metadata);
 
-        AqlCompiledExternalDatasetDetails externalDatasetDetails = new AqlCompiledExternalDatasetDetails(loadStmt.getAdapter(),
-                loadStmt.getProperties());
+        AqlCompiledExternalDatasetDetails externalDatasetDetails = new AqlCompiledExternalDatasetDetails(
+                loadStmt.getAdapter(), loadStmt.getProperties());
         Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> p = AqlMetadataProvider
                 .buildExternalDataScannerRuntime(spec, itemType, externalDatasetDetails, format);
         IOperatorDescriptor scanner = p.first;
@@ -201,10 +201,10 @@
         }
         LOGGER.info("LOAD into File Splits: " + sb.toString());
 
-        IIndexRegistryProvider<IIndex> btreeRegistryProvider = AsterixTreeRegistryProvider.INSTANCE;
+        IIndexRegistryProvider<IIndex> indexRegistryProvider = AsterixIndexRegistryProvider.INSTANCE;
         IStorageManagerInterface storageManager = AsterixStorageManagerInterface.INSTANCE;
         TreeIndexBulkLoadOperatorDescriptor btreeBulkLoad = new TreeIndexBulkLoadOperatorDescriptor(spec,
-                storageManager, btreeRegistryProvider, splitsAndConstraint.first, typeTraits, comparatorFactories,
+                storageManager, indexRegistryProvider, splitsAndConstraint.first, typeTraits, comparatorFactories,
                 fieldPermutation, GlobalConfig.DEFAULT_BTREE_FILL_FACTOR, new BTreeDataflowHelperFactory(),
                 NoOpOperationCallbackProvider.INSTANCE);
         AlgebricksPartitionConstraintHelper.setPartitionConstraintInJobSpec(spec, btreeBulkLoad,
@@ -232,7 +232,7 @@
 
         return new Job(spec);
     }
-    
+
     private static String stringOf(FileSplit fs) {
         return fs.getNodeName() + ":" + fs.getLocalFile().toString();
     }
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/file/IndexOperations.java b/asterix-app/src/main/java/edu/uci/ics/asterix/file/IndexOperations.java
index 0ce064b..e788e0f 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/file/IndexOperations.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/file/IndexOperations.java
@@ -1,11 +1,10 @@
 package edu.uci.ics.asterix.file;
 
-import java.util.logging.Logger;
 
 import edu.uci.ics.asterix.aql.translator.DdlTranslator.CompiledIndexDropStatement;
 import edu.uci.ics.asterix.common.config.OptimizationConfUtil;
+import edu.uci.ics.asterix.common.context.AsterixIndexRegistryProvider;
 import edu.uci.ics.asterix.common.context.AsterixStorageManagerInterface;
-import edu.uci.ics.asterix.common.context.AsterixTreeRegistryProvider;
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.metadata.MetadataException;
 import edu.uci.ics.asterix.metadata.declared.AqlCompiledMetadataDeclarations;
@@ -27,8 +26,6 @@
     private static final PhysicalOptimizationConfig physicalOptimizationConfig = OptimizationConfUtil
             .getPhysicalOptimizationConfig();
 
-    private static final Logger LOGGER = Logger.getLogger(IndexOperations.class.getName());
-
     public static JobSpecification buildCreateIndexJobSpec(CompiledCreateIndexStatement createIndexStmt,
             AqlCompiledMetadataDeclarations metadata) throws AsterixException, AlgebricksException {
         SecondaryIndexCreator secondaryIndexCreator = SecondaryIndexCreator.createIndexCreator(createIndexStmt.getIndexType(), physicalOptimizationConfig);
@@ -41,13 +38,13 @@
         String indexName = deleteStmt.getIndexName();
 
         JobSpecification spec = new JobSpecification();
-        IIndexRegistryProvider<IIndex> btreeRegistryProvider = AsterixTreeRegistryProvider.INSTANCE;
+        IIndexRegistryProvider<IIndex> indexRegistryProvider = AsterixIndexRegistryProvider.INSTANCE;
         IStorageManagerInterface storageManager = AsterixStorageManagerInterface.INSTANCE;
 
         Pair<IFileSplitProvider, AlgebricksPartitionConstraint> splitsAndConstraint = datasetDecls
                 .splitProviderAndPartitionConstraintsForInternalOrFeedDataset(datasetName, indexName);
         TreeIndexDropOperatorDescriptor btreeDrop = new TreeIndexDropOperatorDescriptor(spec, storageManager,
-                btreeRegistryProvider, splitsAndConstraint.first);
+                indexRegistryProvider, splitsAndConstraint.first);
         AlgebricksPartitionConstraintHelper
                 .setPartitionConstraintInJobSpec(spec, btreeDrop, splitsAndConstraint.second);
         spec.addRoot(btreeDrop);
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryIndexCreator.java b/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryIndexCreator.java
index 7b01858..d9585fd 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryIndexCreator.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryIndexCreator.java
@@ -5,8 +5,8 @@
 
 import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
 import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType;
+import edu.uci.ics.asterix.common.context.AsterixIndexRegistryProvider;
 import edu.uci.ics.asterix.common.context.AsterixStorageManagerInterface;
-import edu.uci.ics.asterix.common.context.AsterixTreeRegistryProvider;
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.formats.nontagged.AqlBinaryBooleanInspectorImpl;
 import edu.uci.ics.asterix.formats.nontagged.AqlBinaryComparatorFactoryProvider;
@@ -207,7 +207,7 @@
         // +Infinity
         int[] highKeyFields = null;
         BTreeSearchOperatorDescriptor primarySearchOp = new BTreeSearchOperatorDescriptor(spec, primaryRecDesc,
-                AsterixStorageManagerInterface.INSTANCE, AsterixTreeRegistryProvider.INSTANCE,
+                AsterixStorageManagerInterface.INSTANCE, AsterixIndexRegistryProvider.INSTANCE,
                 primaryFileSplitProvider, primaryRecDesc.getTypeTraits(), primaryComparatorFactories, lowKeyFields,
                 highKeyFields, true, true, new BTreeDataflowHelperFactory(), NoOpOperationCallbackProvider.INSTANCE);
         AlgebricksPartitionConstraintHelper.setPartitionConstraintInJobSpec(spec, primarySearchOp,
@@ -261,7 +261,7 @@
         Pair<IFileSplitProvider, AlgebricksPartitionConstraint> secondarySplitsAndConstraint = metadata
                 .splitProviderAndPartitionConstraintsForInternalOrFeedDataset(datasetName, secondaryIndexName);
         TreeIndexBulkLoadOperatorDescriptor treeIndexBulkLoadOp = new TreeIndexBulkLoadOperatorDescriptor(spec,
-                AsterixStorageManagerInterface.INSTANCE, AsterixTreeRegistryProvider.INSTANCE,
+                AsterixStorageManagerInterface.INSTANCE, AsterixIndexRegistryProvider.INSTANCE,
                 secondarySplitsAndConstraint.first, secondaryRecDesc.getTypeTraits(), secondaryComparatorFactories,
                 fieldPermutation, fillFactor, dataflowHelperFactory, NoOpOperationCallbackProvider.INSTANCE);
         AlgebricksPartitionConstraintHelper.setPartitionConstraintInJobSpec(spec, treeIndexBulkLoadOp,
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryInvertedIndexCreator.java b/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryInvertedIndexCreator.java
index a5268b2..4f0d3a5 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryInvertedIndexCreator.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryInvertedIndexCreator.java
@@ -4,8 +4,8 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
+import edu.uci.ics.asterix.common.context.AsterixIndexRegistryProvider;
 import edu.uci.ics.asterix.common.context.AsterixStorageManagerInterface;
-import edu.uci.ics.asterix.common.context.AsterixTreeRegistryProvider;
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.formats.nontagged.AqlBinaryComparatorFactoryProvider;
 import edu.uci.ics.asterix.formats.nontagged.AqlBinaryTokenizerFactoryProvider;
@@ -100,7 +100,7 @@
 
         // ---------- START GENERAL BTREE STUFF
 
-        IIndexRegistryProvider<IIndex> treeRegistryProvider = AsterixTreeRegistryProvider.INSTANCE;
+        IIndexRegistryProvider<IIndex> treeRegistryProvider = AsterixIndexRegistryProvider.INSTANCE;
         IStorageManagerInterface storageManager = AsterixStorageManagerInterface.INSTANCE;
 
         // ---------- END GENERAL BTREE STUFF
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/file/TestKeywordIndexJob.java b/asterix-app/src/main/java/edu/uci/ics/asterix/file/TestKeywordIndexJob.java
index a96ccee..f755752 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/file/TestKeywordIndexJob.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/file/TestKeywordIndexJob.java
@@ -6,8 +6,8 @@
 import java.util.HashMap;
 import java.util.List;
 
+import edu.uci.ics.asterix.common.context.AsterixIndexRegistryProvider;
 import edu.uci.ics.asterix.common.context.AsterixStorageManagerInterface;
-import edu.uci.ics.asterix.common.context.AsterixTreeRegistryProvider;
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.dataflow.data.nontagged.comparators.AObjectAscBinaryComparatorFactory;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AObjectSerializerDeserializer;
@@ -66,7 +66,7 @@
 
         // ---------- START GENERAL BTREE STUFF
 
-        IIndexRegistryProvider<IIndex> btreeRegistryProvider = AsterixTreeRegistryProvider.INSTANCE;
+        IIndexRegistryProvider<IIndex> indexRegistryProvider = AsterixIndexRegistryProvider.INSTANCE;
         IStorageManagerInterface storageManager = AsterixStorageManagerInterface.INSTANCE;
 
         // ---------- END GENERAL BTREE STUFF
@@ -104,25 +104,25 @@
 
         ITypeTraits[] secondaryTypeTraits = new ITypeTraits[2];
         secondaryTypeTraits[0] = new ITypeTraits() {
-            
+
             @Override
             public boolean isFixedLength() {
                 return false;
             }
-            
+
             @Override
             public int getFixedLength() {
                 return -1;
             }
         };
-        
+
         secondaryTypeTraits[1] = new ITypeTraits() {
-            
+
             @Override
             public boolean isFixedLength() {
                 return true;
             }
-            
+
             @Override
             public int getFixedLength() {
                 return 5;
@@ -144,8 +144,8 @@
                 new FileSplit("nc1", new FileReference(new File("/tmp/nc1/demo1112/Customers_idx_NameInvIndex"))),
                 new FileSplit("nc2", new FileReference(new File("/tmp/nc2/demo1112/Customers_idx_NameInvIndex"))) });
         BTreeSearchOperatorDescriptor secondarySearchOp = new BTreeSearchOperatorDescriptor(spec, secondaryRecDesc,
-                storageManager, btreeRegistryProvider, secondarySplitProvider, 
-                secondaryTypeTraits, secondaryComparatorFactories, lowKeyFields, highKeyFields, true, true,
+                storageManager, indexRegistryProvider, secondarySplitProvider, secondaryTypeTraits,
+                secondaryComparatorFactories, lowKeyFields, highKeyFields, true, true,
                 new BTreeDataflowHelperFactory(), NoOpOperationCallbackProvider.INSTANCE);
         String[] secondarySearchOpLocationConstraint = new String[nodeGroup.size()];
         for (int p = 0; p < nodeGroup.size(); p++) {
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/file/TestSecondaryIndexJob.java b/asterix-app/src/main/java/edu/uci/ics/asterix/file/TestSecondaryIndexJob.java
index 01279f3..17d8c9f 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/file/TestSecondaryIndexJob.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/file/TestSecondaryIndexJob.java
@@ -6,8 +6,8 @@
 import java.util.HashMap;
 import java.util.List;
 
+import edu.uci.ics.asterix.common.context.AsterixIndexRegistryProvider;
 import edu.uci.ics.asterix.common.context.AsterixStorageManagerInterface;
-import edu.uci.ics.asterix.common.context.AsterixTreeRegistryProvider;
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.dataflow.data.nontagged.comparators.AObjectAscBinaryComparatorFactory;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AObjectSerializerDeserializer;
@@ -66,7 +66,7 @@
 
         // ---------- START GENERAL BTREE STUFF
 
-        IIndexRegistryProvider<IIndex> btreeRegistryProvider = AsterixTreeRegistryProvider.INSTANCE;
+        IIndexRegistryProvider<IIndex> indexRegistryProvider = AsterixIndexRegistryProvider.INSTANCE;
         IStorageManagerInterface storageManager = AsterixStorageManagerInterface.INSTANCE;
 
         // ---------- END GENERAL BTREE STUFF
@@ -143,12 +143,10 @@
         IFileSplitProvider secondarySplitProvider = new ConstantFileSplitProvider(new FileSplit[] {
                 new FileSplit("nc1", new FileReference(new File("/tmp/nc1/demo1112/Customers_idx_NameBtreeIndex"))),
                 new FileSplit("nc2", new FileReference(new File("/tmp/nc2/demo1112/Customers_idx_NameBtreeIndex"))) });
-		BTreeSearchOperatorDescriptor secondarySearchOp = new BTreeSearchOperatorDescriptor(
-				spec, secondaryRecDesc, storageManager, btreeRegistryProvider,
-				secondarySplitProvider, secondaryTypeTraits,
-				secondaryComparatorFactories, lowKeyFields, highKeyFields,
-				true, true, new BTreeDataflowHelperFactory(),
-				NoOpOperationCallbackProvider.INSTANCE);
+        BTreeSearchOperatorDescriptor secondarySearchOp = new BTreeSearchOperatorDescriptor(spec, secondaryRecDesc,
+                storageManager, indexRegistryProvider, secondarySplitProvider, secondaryTypeTraits,
+                secondaryComparatorFactories, lowKeyFields, highKeyFields, true, true,
+                new BTreeDataflowHelperFactory(), NoOpOperationCallbackProvider.INSTANCE);
         String[] secondarySearchOpLocationConstraint = new String[nodeGroup.size()];
         for (int p = 0; p < nodeGroup.size(); p++) {
             secondarySearchOpLocationConstraint[p] = nodeGroup.get(p);
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/CCBootstrapImpl.java b/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/CCBootstrapImpl.java
index c6d38d3..ccba498 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/CCBootstrapImpl.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/CCBootstrapImpl.java
@@ -19,6 +19,7 @@
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.eclipse.jetty.server.Server;
@@ -28,7 +29,6 @@
 import edu.uci.ics.asterix.api.aqlj.server.APIClientThreadFactory;
 import edu.uci.ics.asterix.api.aqlj.server.ThreadedServer;
 import edu.uci.ics.asterix.api.http.servlet.APIServlet;
-import edu.uci.ics.asterix.common.api.AsterixAppContextInfoImpl;
 import edu.uci.ics.asterix.common.config.GlobalConfig;
 import edu.uci.ics.asterix.metadata.MetadataManager;
 import edu.uci.ics.asterix.metadata.api.IAsterixStateProxy;
@@ -41,63 +41,46 @@
     private static final Logger LOGGER = Logger.getLogger(CCBootstrapImpl.class.getName());
 
     private static final int DEFAULT_WEB_SERVER_PORT = 19001;
+
     public static final int DEFAULT_API_SERVER_PORT = 14600;
     private static final int DEFAULT_API_NODEDATA_SERVER_PORT = 14601;
 
-    private Server server;
+    private Server webServer;
     private static IAsterixStateProxy proxy;
     private ICCApplicationContext appCtx;
     private ThreadedServer apiServer;
 
     @Override
     public void start() throws Exception {
-        LOGGER.info("Starting Asterix CC Bootstrap");
-        String portStr = System.getProperty(GlobalConfig.WEB_SERVER_PORT_PROPERTY);
-        int port = DEFAULT_WEB_SERVER_PORT;
-        if (portStr != null) {
-            port = Integer.parseInt(portStr);
+        if (LOGGER.isLoggable(Level.INFO)) {
+            LOGGER.info("Starting Asterix cluster controller");
         }
-        server = new Server(port);
-        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
-        context.setContextPath("/");
-        server.setHandler(context);
 
-        context.addServlet(new ServletHolder(new APIServlet()), "/*");
-        server.start();
+        // Set the AsterixStateProxy to be the distributed object
         proxy = AsterixStateProxy.registerRemoteObject();
         proxy.setAsterixProperties(AsterixProperties.INSTANCE);
-
-        // set the APINodeDataServer ports
-        int startPort = DEFAULT_API_NODEDATA_SERVER_PORT;
-        Map<String, Set<String>> nodeNameMap = new HashMap<String, Set<String>>();
-        try {
-            appCtx.getCCContext().getIPAddressNodeMap(nodeNameMap);
-        } catch (Exception e) {
-            throw new IOException(" unable to obtain IP address node map", e);
-        }
-        AsterixAppContextInfoImpl.setNodeControllerInfo(nodeNameMap);
-        for (Map.Entry<String, Set<String>> entry : nodeNameMap.entrySet()) {
-            Set<String> nodeNames = entry.getValue();
-            Iterator<String> it = nodeNames.iterator();
-            while (it.hasNext()) {
-                AsterixNodeState ns = new AsterixNodeState();
-                ns.setAPINodeDataServerPort(startPort);
-                proxy.setAsterixNodeState(it.next(), ns);
-                startPort++;
-            }
-        }
-
         appCtx.setDistributedState(proxy);
+
+        // Create the metadata manager
         MetadataManager.INSTANCE = new MetadataManager(proxy);
-        apiServer = new ThreadedServer(DEFAULT_API_SERVER_PORT, new APIClientThreadFactory(appCtx));
+
+        // Setup and start the web interface
+        setupWebServer();
+        webServer.start();
+
+        // Setup and start the API server
+        setupAPIServer();
         apiServer.start();
     }
 
     @Override
     public void stop() throws Exception {
-        LOGGER.info("Stopping Asterix CC Bootstrap");
-        AsterixStateProxy.deRegisterRemoteObject();
-        server.stop();
+        if (LOGGER.isLoggable(Level.INFO)) {
+            LOGGER.info("Stopping Asterix cluster controller");
+        }
+        AsterixStateProxy.unregisterRemoteObject();
+        
+        webServer.stop();
         apiServer.shutdown();
     }
 
@@ -106,4 +89,40 @@
         this.appCtx = appCtx;
     }
 
+    private void setupWebServer() throws Exception {
+        String portStr = System.getProperty(GlobalConfig.WEB_SERVER_PORT_PROPERTY);
+        int port = DEFAULT_WEB_SERVER_PORT;
+        if (portStr != null) {
+            port = Integer.parseInt(portStr);
+        }
+        webServer = new Server(port);
+
+        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
+        context.setContextPath("/");
+        webServer.setHandler(context);
+        context.addServlet(new ServletHolder(new APIServlet()), "/*");
+    }
+
+    private void setupAPIServer() throws Exception {
+        // set the APINodeDataServer ports
+        int startPort = DEFAULT_API_NODEDATA_SERVER_PORT;
+        Map<String, Set<String>> nodeNameMap = new HashMap<String, Set<String>>();
+        try {
+            appCtx.getCCContext().getIPAddressNodeMap(nodeNameMap);
+        } catch (Exception e) {
+            throw new IOException("Unable to obtain IP address node map", e);
+        }
+
+        for (Map.Entry<String, Set<String>> entry : nodeNameMap.entrySet()) {
+            Set<String> nodeNames = entry.getValue();
+            Iterator<String> it = nodeNames.iterator();
+            while (it.hasNext()) {
+                AsterixNodeState ns = new AsterixNodeState();
+                ns.setAPINodeDataServerPort(startPort++);
+                proxy.setAsterixNodeState(it.next(), ns);
+            }
+        }
+
+        apiServer = new ThreadedServer(DEFAULT_API_SERVER_PORT, new APIClientThreadFactory(appCtx));
+    }
 }
\ No newline at end of file
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/NCBootstrapImpl.java b/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/NCBootstrapImpl.java
index 7cdca49..b1e7481 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/NCBootstrapImpl.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/NCBootstrapImpl.java
@@ -14,103 +14,96 @@
  */
 package edu.uci.ics.asterix.hyracks.bootstrap;
 
+import java.rmi.RemoteException;
 import java.rmi.server.UnicastRemoteObject;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import edu.uci.ics.asterix.api.aqlj.server.NodeDataClientThreadFactory;
 import edu.uci.ics.asterix.api.aqlj.server.ThreadedServer;
-import edu.uci.ics.asterix.common.api.AsterixAppContextInfoImpl;
-import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.common.context.AsterixAppRuntimeContext;
 import edu.uci.ics.asterix.metadata.MetadataManager;
 import edu.uci.ics.asterix.metadata.MetadataNode;
 import edu.uci.ics.asterix.metadata.api.IAsterixStateProxy;
 import edu.uci.ics.asterix.metadata.api.IMetadataNode;
-import edu.uci.ics.asterix.metadata.bootstrap.AsterixProperties;
 import edu.uci.ics.asterix.metadata.bootstrap.MetadataBootstrap;
-import edu.uci.ics.asterix.transaction.management.exception.ACIDException;
-import edu.uci.ics.asterix.transaction.management.service.transaction.TransactionProvider;
 import edu.uci.ics.hyracks.api.application.INCApplicationContext;
 import edu.uci.ics.hyracks.api.application.INCBootstrap;
 
 public class NCBootstrapImpl implements INCBootstrap {
     private static final Logger LOGGER = Logger.getLogger(NCBootstrapImpl.class.getName());
 
-    public static final int DEFAULT_AQLJ_NODE_DATA_SERVER_PORT = 6061;
-
-    private INCApplicationContext ncAppContext = null;
-
-    private static IMetadataNode metadataNode;
+    private INCApplicationContext ncApplicationContext = null;
+    private AsterixAppRuntimeContext runtimeContext;
     private String nodeId;
-
+    private boolean isMetadataNode = false;
     private ThreadedServer apiNodeDataServer;
 
     @Override
     public void start() throws Exception {
-
-        LOGGER.info("Starting Asterix NC " + nodeId + " Bootstrap");
-        IAsterixStateProxy p = (IAsterixStateProxy) ncAppContext.getDistributedState();
-        LOGGER.info("\nMetadata node " + p.getAsterixProperties().getMetadataNodeName());
-        initializeTransactionSupport(ncAppContext, nodeId);
-        if (nodeId.equals(p.getAsterixProperties().getMetadataNodeName())) {
-            AsterixAppRuntimeContext.initialize(ncAppContext);
-            LOGGER.info("Initialized AsterixRuntimeContext: " + AsterixAppRuntimeContext.getInstance());
-            metadataNode = registerRemoteObject(ncAppContext, p.getAsterixProperties());
-            p.setMetadataNode(metadataNode);
-            MetadataManager.INSTANCE = new MetadataManager(p);
-            LOGGER.info("Bootstrapping Metadata");
-            MetadataManager.INSTANCE.init();
-            MetadataBootstrap.startUniverse(p.getAsterixProperties(), AsterixAppContextInfoImpl.INSTANCE);
-        } else {
-            Thread.sleep(5000);
-            AsterixAppRuntimeContext.initialize(ncAppContext);
-            LOGGER.info("Initialized AsterixRuntimeContext: " + AsterixAppRuntimeContext.getInstance());
+        nodeId = ncApplicationContext.getNodeId();
+        if (LOGGER.isLoggable(Level.INFO)) {
+            LOGGER.info("Starting Asterix node controller: " + nodeId);
         }
 
-        IAsterixStateProxy proxy = (IAsterixStateProxy) ncAppContext.getDistributedState();
-        AsterixNodeState ns = (AsterixNodeState) proxy.getAsterixNodeState(ncAppContext.getNodeId());
+        runtimeContext = new AsterixAppRuntimeContext(ncApplicationContext);
+        runtimeContext.initialize();
+
+        ncApplicationContext.setApplicationObject(runtimeContext);
+
+        // Initialize metadata if this node is the metadata node
+        IAsterixStateProxy proxy = (IAsterixStateProxy) ncApplicationContext.getDistributedState();
+        isMetadataNode = nodeId.equals(proxy.getAsterixProperties().getMetadataNodeName());
+        if (isMetadataNode) {
+            registerRemoteMetadataNode(proxy);
+
+            if (LOGGER.isLoggable(Level.INFO)) {
+                LOGGER.info("Bootstrapping metadata");
+            }
+
+            MetadataManager.INSTANCE = new MetadataManager(proxy);
+            MetadataManager.INSTANCE.init();
+            MetadataBootstrap.startUniverse(proxy.getAsterixProperties(), ncApplicationContext);
+
+        }
+
+        // Start a sub-component for the API server. This server is only connected to by the 
+        // API server that lives on the CC and never by a client wishing to execute AQL.
+        // TODO: The API sub-system will change dramatically in the future and this code will go away, 
+        // but leave it for now.
+        AsterixNodeState ns = (AsterixNodeState) proxy.getAsterixNodeState(nodeId);
         apiNodeDataServer = new ThreadedServer(ns.getAPINodeDataServerPort(), new NodeDataClientThreadFactory());
         apiNodeDataServer.start();
     }
 
-    public static IMetadataNode registerRemoteObject(INCApplicationContext ncAppContext,
-            AsterixProperties asterixProperties) throws AsterixException {
-        try {
-            TransactionProvider factory = (TransactionProvider) ncAppContext.getApplicationObject();
-            MetadataNode.INSTANCE = new MetadataNode(asterixProperties, AsterixAppContextInfoImpl.INSTANCE, factory);
-            IMetadataNode stub = (IMetadataNode) UnicastRemoteObject.exportObject(MetadataNode.INSTANCE, 0);
-            LOGGER.info("MetadataNode bound.");
-            return stub;
-        } catch (Exception e) {
-            LOGGER.info("MetadataNode exception.");
-            throw new AsterixException(e);
+    public void registerRemoteMetadataNode(IAsterixStateProxy proxy) throws RemoteException {
+        IMetadataNode stub = null;
+        MetadataNode.INSTANCE.initialize(runtimeContext);
+        stub = (IMetadataNode) UnicastRemoteObject.exportObject(MetadataNode.INSTANCE, 0);
+        proxy.setMetadataNode(stub);
+
+        if (LOGGER.isLoggable(Level.INFO)) {
+            LOGGER.info("Metadata node bound");
         }
     }
 
     @Override
     public void stop() throws Exception {
-        LOGGER.info("Stopping Asterix NC Bootstrap");
-        IAsterixStateProxy p = (IAsterixStateProxy) ncAppContext.getDistributedState();
-        if (nodeId.equals(p.getAsterixProperties().getMetadataNodeName())) {
+        if (LOGGER.isLoggable(Level.INFO)) {
+            LOGGER.info("Stopping Asterix node controller: " + nodeId);
+        }
+
+        // Quiesce metadata
+        if (isMetadataNode) {
             MetadataBootstrap.stopUniverse();
         }
-        AsterixAppRuntimeContext.deinitialize();
+
         apiNodeDataServer.shutdown();
+        runtimeContext.deinitialize();
     }
 
     @Override
     public void setApplicationContext(INCApplicationContext appCtx) {
-        this.ncAppContext = appCtx;
-        this.nodeId = ncAppContext.getNodeId();
-    }
-
-    private void initializeTransactionSupport(INCApplicationContext ncAppContext, String nodeId) {
-        try {
-            TransactionProvider factory = new TransactionProvider(nodeId);
-            ncAppContext.setApplicationObject(factory);
-        } catch (ACIDException e) {
-            e.printStackTrace();
-            LOGGER.severe(" Could not initialize transaction support ");
-        }
+        this.ncApplicationContext = appCtx;
     }
 }
\ No newline at end of file
diff --git a/asterix-app/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java b/asterix-app/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java
index 1ae6466..4dfe106 100644
--- a/asterix-app/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java
+++ b/asterix-app/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java
@@ -6,8 +6,8 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
-import java.io.FileReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.io.Reader;
 import java.io.UnsupportedEncodingException;
@@ -48,7 +48,7 @@
 
     public static void runScriptAndCompareWithResult(IHyracksClientConnection hcc, File scriptFile, PrintWriter print,
             File expectedFile, File actualFile) throws Exception {
-        Reader query = new BufferedReader(new FileReader(scriptFile));
+        Reader query = new BufferedReader(new InputStreamReader(new FileInputStream(scriptFile), "UTF-8"));
         AsterixJavaClient asterix = new AsterixJavaClient(hcc, query, print);
         try {
             asterix.compile(true, false, true, true, false, true, false);
@@ -58,8 +58,10 @@
             query.close();
         }
         asterix.execute();
-        BufferedReader readerExpected = new BufferedReader(new FileReader(expectedFile));
-        BufferedReader readerActual = new BufferedReader(new FileReader(actualFile));
+        BufferedReader readerExpected = new BufferedReader(new InputStreamReader(new FileInputStream(expectedFile),
+                "UTF-8"));
+        BufferedReader readerActual = new BufferedReader(
+                new InputStreamReader(new FileInputStream(actualFile), "UTF-8"));
         String lineExpected, lineActual;
         int num = 1;
         try {
@@ -122,8 +124,10 @@
         }
         fos.close();
 
-        BufferedReader readerExpected = new BufferedReader(new FileReader(expectedFile));
-        BufferedReader readerActual = new BufferedReader(new FileReader(actualFile));
+        BufferedReader readerExpected = new BufferedReader(new InputStreamReader(new FileInputStream(expectedFile),
+                "UTF-8"));
+        BufferedReader readerActual = new BufferedReader(
+                new InputStreamReader(new FileInputStream(actualFile), "UTF-8"));
         String lineExpected, lineActual;
         int num = 1;
         try {
diff --git a/asterix-app/src/test/java/edu/uci/ics/asterix/test/aqlj/ClientAPITest.java b/asterix-app/src/test/java/edu/uci/ics/asterix/test/aqlj/ClientAPITest.java
index fcc4eaf..0301675 100644
--- a/asterix-app/src/test/java/edu/uci/ics/asterix/test/aqlj/ClientAPITest.java
+++ b/asterix-app/src/test/java/edu/uci/ics/asterix/test/aqlj/ClientAPITest.java
@@ -2,9 +2,10 @@
 
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -48,7 +49,7 @@
         ArrayList<String> list = new ArrayList<String>();
         BufferedReader result;
         try {
-            result = new BufferedReader(new FileReader(PATH_BASE + fileName));
+            result = new BufferedReader(new InputStreamReader(new FileInputStream(PATH_BASE + fileName), "UTF-8"));
             while (true) {
                 String line = result.readLine();
                 if (line == null) {
diff --git a/asterix-app/src/test/java/edu/uci/ics/asterix/test/dml/DmlTest.java b/asterix-app/src/test/java/edu/uci/ics/asterix/test/dml/DmlTest.java
index 3e82ff6..5b88edb 100644
--- a/asterix-app/src/test/java/edu/uci/ics/asterix/test/dml/DmlTest.java
+++ b/asterix-app/src/test/java/edu/uci/ics/asterix/test/dml/DmlTest.java
@@ -2,7 +2,8 @@
 
 import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileReader;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.io.Reader;
 
@@ -34,7 +35,8 @@
         outdir.mkdirs();
 
         AsterixHyracksIntegrationUtil.init();
-        Reader loadReader = new BufferedReader(new FileReader(LOAD_FOR_ENLIST_FILE));
+        Reader loadReader = new BufferedReader(
+                new InputStreamReader(new FileInputStream(LOAD_FOR_ENLIST_FILE), "UTF-8"));
         AsterixJavaClient asterixLoad = new AsterixJavaClient(
                 AsterixHyracksIntegrationUtil.getHyracksClientConnection(), loadReader, ERR);
         try {
diff --git a/asterix-app/src/test/java/edu/uci/ics/asterix/test/metadata/MetadataTest.java b/asterix-app/src/test/java/edu/uci/ics/asterix/test/metadata/MetadataTest.java
index baa91dc..6fec201 100644
--- a/asterix-app/src/test/java/edu/uci/ics/asterix/test/metadata/MetadataTest.java
+++ b/asterix-app/src/test/java/edu/uci/ics/asterix/test/metadata/MetadataTest.java
@@ -1,11 +1,8 @@
 package edu.uci.ics.asterix.test.metadata;
 
 import java.io.BufferedReader;
-import java.io.DataInputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintWriter;
@@ -52,26 +49,6 @@
         return fname.substring(0, dot + 1) + EXTENSION_RESULT;
     }
 
-    public static ArrayList<String> readFile(String fileName) {
-        ArrayList<String> list = new ArrayList<String>();
-        BufferedReader result;
-        try {
-            result = new BufferedReader(new FileReader(PATH_BASE + fileName));
-            while (true) {
-                String line = result.readLine();
-                if (line == null) {
-                    break;
-                } else {
-                    list.add(line);
-                }
-            }
-            result.close();
-        } catch (FileNotFoundException e) {
-        } catch (IOException e) {
-        }
-        return list;
-    }
-
     @BeforeClass
     public static void setUp() throws Exception {
         _oldConfigFileName = System.getProperty(GlobalConfig.CONFIG_FILE_PROPERTY);
@@ -99,11 +76,10 @@
         }
     }
 
-    private static void suiteBuild(File f, Collection<Object[]> testArgs, String path) {
+    private static void suiteBuild(File f, Collection<Object[]> testArgs, String path) throws IOException {
+        BufferedReader br = null;
         try {
-            FileInputStream fstream = new FileInputStream(f);
-            DataInputStream in = new DataInputStream(fstream);
-            BufferedReader br = new BufferedReader(new InputStreamReader(in));
+            br = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));
             String strLine;
             File file;
             while ((strLine = br.readLine()) != null) {
@@ -119,14 +95,18 @@
                     testArgs.add(new Object[] { file, expectedFile, actualFile });
                 }
             }
-            in.close();
+
         } catch (IOException e) {
             e.printStackTrace();
+        } finally {
+            if (br != null) {
+                br.close();
+            }
         }
     }
 
     @Parameters
-    public static Collection<Object[]> tests() {
+    public static Collection<Object[]> tests() throws IOException {
         Collection<Object[]> testArgs = new ArrayList<Object[]>();
         suiteBuild(new File(QUERIES_FILE), testArgs, "");
         return testArgs;
@@ -144,7 +124,7 @@
 
     @Test
     public void test() throws Exception {
-        Reader query = new BufferedReader(new FileReader(queryFile));
+        Reader query = new BufferedReader(new InputStreamReader(new FileInputStream(queryFile), "UTF-8"));
         AsterixJavaClient asterix = new AsterixJavaClient(AsterixHyracksIntegrationUtil.getHyracksClientConnection(),
                 query, ERR);
         try {
@@ -160,8 +140,10 @@
         query.close();
 
         if (actualFile.exists()) {
-            BufferedReader readerExpected = new BufferedReader(new FileReader(expectedFile));
-            BufferedReader readerActual = new BufferedReader(new FileReader(actualFile));
+            BufferedReader readerExpected = new BufferedReader(new InputStreamReader(new FileInputStream(expectedFile),
+                    "UTF-8"));
+            BufferedReader readerActual = new BufferedReader(new InputStreamReader(new FileInputStream(actualFile),
+                    "UTF-8"));
             String lineExpected, lineActual;
             int num = 1;
             try {
diff --git a/asterix-app/src/test/java/edu/uci/ics/asterix/test/metadata/MetadataTransactionsTest.java b/asterix-app/src/test/java/edu/uci/ics/asterix/test/metadata/MetadataTransactionsTest.java
index 6081994..1645a96 100644
--- a/asterix-app/src/test/java/edu/uci/ics/asterix/test/metadata/MetadataTransactionsTest.java
+++ b/asterix-app/src/test/java/edu/uci/ics/asterix/test/metadata/MetadataTransactionsTest.java
@@ -3,11 +3,8 @@
 import static org.junit.Assert.fail;
 
 import java.io.BufferedReader;
-import java.io.DataInputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintWriter;
@@ -55,32 +52,12 @@
         return fname.substring(0, dot + 1) + EXTENSION_RESULT;
     }
 
-    public static ArrayList<String> readFile(String fileName) {
-        ArrayList<String> list = new ArrayList<String>();
-        BufferedReader result;
-        try {
-            result = new BufferedReader(new FileReader(PATH_BASE + fileName));
-            while (true) {
-                String line = result.readLine();
-                if (line == null) {
-                    break;
-                } else {
-                    list.add(line);
-                }
-            }
-            result.close();
-        } catch (FileNotFoundException e) {
-        } catch (IOException e) {
-        }
-        return list;
-    }
-
     private static void executeQueryTuple(Object[] queryTuple, boolean expectFailure, boolean executeQuery) {
         String queryFileName = (String) queryTuple[0];
         String expectedFileName = (String) queryTuple[1];
         String actualFileName = (String) queryTuple[2];
         try {
-            Reader query = new BufferedReader(new FileReader(queryFileName));
+            Reader query = new BufferedReader(new InputStreamReader(new FileInputStream(queryFileName), "UTF-8"));
             AsterixJavaClient asterix = new AsterixJavaClient(
                     AsterixHyracksIntegrationUtil.getHyracksClientConnection(), query, ERR);
             LOGGER.info("Query is: " + queryFileName);
@@ -115,8 +92,10 @@
             File actualFile = new File(actualFileName);
             File expectedFile = new File(expectedFileName);
             if (actualFile.exists()) {
-                BufferedReader readerExpected = new BufferedReader(new FileReader(expectedFile));
-                BufferedReader readerActual = new BufferedReader(new FileReader(actualFile));
+                BufferedReader readerExpected = new BufferedReader(new InputStreamReader(new FileInputStream(
+                        expectedFile), "UTF-8"));
+                BufferedReader readerActual = new BufferedReader(new InputStreamReader(new FileInputStream(actualFile),
+                        "UTF-8"));
                 String lineExpected, lineActual;
                 int num = 1;
                 try {
@@ -204,12 +183,11 @@
     }
 
     private static void prepareQuerySuite(String queryListPath, String queryPath, String expectedPath,
-            String actualPath, Collection<Object[]> output) {
+            String actualPath, Collection<Object[]> output) throws IOException {
+        BufferedReader br = null;
         try {
             File queryListFile = new File(queryListPath);
-            FileInputStream fstream = new FileInputStream(queryListFile);
-            DataInputStream in = new DataInputStream(fstream);
-            BufferedReader br = new BufferedReader(new InputStreamReader(in));
+            br = new BufferedReader(new InputStreamReader(new FileInputStream(queryListFile), "UTF-8"));
             String strLine;
             String queryFileName;
             File queryFile;
@@ -235,14 +213,17 @@
                     output.add(new Object[] { queryFileName, expectedFileName, actualFileName });
                 }
             }
-            in.close();
         } catch (IOException e) {
             e.printStackTrace();
+        } finally {
+            if (br != null) {
+                br.close();
+            }
         }
     }
 
     @Parameters
-    public static Collection<Object[]> tests() {
+    public static Collection<Object[]> tests() throws IOException {
         Collection<Object[]> testArgs = new ArrayList<Object[]>();
         prepareQuerySuite(QUERIES_FILE, TEST_QUERIES_PATH, null, null, testArgs);
         return testArgs;
diff --git a/asterix-app/src/test/java/edu/uci/ics/asterix/test/optimizer/OptimizerTest.java b/asterix-app/src/test/java/edu/uci/ics/asterix/test/optimizer/OptimizerTest.java
index 4c6e301..7e0ff86 100644
--- a/asterix-app/src/test/java/edu/uci/ics/asterix/test/optimizer/OptimizerTest.java
+++ b/asterix-app/src/test/java/edu/uci/ics/asterix/test/optimizer/OptimizerTest.java
@@ -2,7 +2,9 @@
 
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileReader;
+import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.io.Reader;
 import java.util.ArrayList;
@@ -120,8 +122,7 @@
             Assume.assumeTrue(!skipped);
 
             LOGGER.severe("RUN TEST: \"" + queryFile.getPath() + "\"");
-
-            Reader query = new BufferedReader(new FileReader(queryFile));
+            Reader query = new BufferedReader(new InputStreamReader(new FileInputStream(queryFile), "UTF-8"));
             PrintWriter plan = new PrintWriter(actualFile);
             AsterixJavaClient asterix = new AsterixJavaClient(
                     AsterixHyracksIntegrationUtil.getHyracksClientConnection(), query, plan);
@@ -135,8 +136,10 @@
             plan.close();
             query.close();
 
-            BufferedReader readerExpected = new BufferedReader(new FileReader(expectedFile));
-            BufferedReader readerActual = new BufferedReader(new FileReader(actualFile));
+            BufferedReader readerExpected = new BufferedReader(new InputStreamReader(new FileInputStream(expectedFile),
+                    "UTF-8"));
+            BufferedReader readerActual = new BufferedReader(new InputStreamReader(new FileInputStream(actualFile),
+                    "UTF-8"));
 
             String lineExpected, lineActual;
             int num = 1;
diff --git a/asterix-app/src/test/java/edu/uci/ics/asterix/test/runtime/RuntimeTest.java b/asterix-app/src/test/java/edu/uci/ics/asterix/test/runtime/RuntimeTest.java
index 6d33836..b7877a3 100644
--- a/asterix-app/src/test/java/edu/uci/ics/asterix/test/runtime/RuntimeTest.java
+++ b/asterix-app/src/test/java/edu/uci/ics/asterix/test/runtime/RuntimeTest.java
@@ -2,9 +2,10 @@
 
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -53,7 +54,7 @@
         ArrayList<String> list = new ArrayList<String>();
         BufferedReader result;
         try {
-            result = new BufferedReader(new FileReader(PATH_BASE + fileName));
+            result = new BufferedReader(new InputStreamReader(new FileInputStream(PATH_BASE + fileName), "UTF-8"));
             while (true) {
                 String line = result.readLine();
                 if (line == null) {
@@ -86,7 +87,9 @@
         lsn.deleteOnExit();
 
         AsterixHyracksIntegrationUtil.init();
-        HDFSCluster.getInstance().setup();
+
+	// TODO: Uncomment when hadoop version is upgraded and adapters are ported
+        //HDFSCluster.getInstance().setup();
     }
 
     @AfterClass
@@ -108,7 +111,8 @@
         File lsn = new File("last_checkpoint_lsn");
         lsn.deleteOnExit();
         
-        HDFSCluster.getInstance().cleanup();
+	// TODO: Uncomment when hadoop version is upgraded and adapters are ported
+        //HDFSCluster.getInstance().cleanup();
     }
 
     private static void suiteBuild(File dir, Collection<Object[]> testArgs, String path) {
diff --git a/asterix-app/src/test/resources/runtimets/ignore.txt b/asterix-app/src/test/resources/runtimets/ignore.txt
index bfeb30a..0964e88 100644
--- a/asterix-app/src/test/resources/runtimets/ignore.txt
+++ b/asterix-app/src/test/resources/runtimets/ignore.txt
@@ -16,3 +16,5 @@
 failure/q1_pricing_summary_report_failure.aql
 open-closed
 dml/insert-into-empty-dataset-with-index_02.aql
+dml/insert-into-empty-dataset-with-index_01.aql
+dml/load-from-hdfs.aql
diff --git a/asterix-app/src/test/resources/runtimets/only.txt b/asterix-app/src/test/resources/runtimets/only.txt
index e69de29..b399dbe 100644
--- a/asterix-app/src/test/resources/runtimets/only.txt
+++ b/asterix-app/src/test/resources/runtimets/only.txt
@@ -0,0 +1 @@
+dml/insert-into-empty-dataset-with-index_01.aql
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/constructor/primitive-01.aql b/asterix-app/src/test/resources/runtimets/queries/constructor/primitive-01.aql
new file mode 100644
index 0000000..3319d90
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/constructor/primitive-01.aql
@@ -0,0 +1,21 @@
+/*
+ * Test case name : primitive-01.aql
+ * Description    : Test primitive integer type int8 constructor function with boundary values
+ * Success        : Yes
+ * Date           : May 7th 2012
+ *
+ */
+
+write output to nc1:"rttest/constructor_primitive-01.adm";
+
+//Boundary value tests int8().
+//with MIN and MAX supported values.
+
+let $a:=int8("-127")
+let $b:=int8("127")
+let $c:=int8("0")
+let $d:=int8("1")
+let $e:=int8("-1")
+return {"$a":$a,"$b":$b,"$c":$c,"$d":$d,"$e":$e}
+
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/constructor/primitive-02.aql b/asterix-app/src/test/resources/runtimets/queries/constructor/primitive-02.aql
new file mode 100644
index 0000000..3aa1a13
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/constructor/primitive-02.aql
@@ -0,0 +1,23 @@
+/*
+ * Test case name : primitive-02.aql
+ * Description    : Test primitive integer type int16 constructor function with boundary values
+ * Success        : Yes
+ * Date           : May 7th 2012
+ *
+ */
+
+write output to nc1:"rttest/constructor_primitive-02.adm";
+
+//Boundary value tests int16().
+//with MIN and MAX supported values.
+
+let $a:=int16("-32767")
+let $b:=int16("32767")
+let $c:=int16("0")
+let $d:=int16("1")
+let $e:=int16("-1")
+let $f:=int16("16383")
+let $g:=int16("-16383")
+
+return {"$a":$a,"$b":$b,"$c":$c,"$d":$d,"$e":$e,"$f":$f,"$g":$g}
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/constructor/primitive-03.aql b/asterix-app/src/test/resources/runtimets/queries/constructor/primitive-03.aql
new file mode 100644
index 0000000..f3df161
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/constructor/primitive-03.aql
@@ -0,0 +1,23 @@
+/*
+ * Test case name : primitive-03.aql
+ * Description    : Test primitive integer type int32 constructor function with boundary values
+ * Success        : Yes
+ * Date           : May 7th 2012
+ *
+ */
+
+write output to nc1:"rttest/constructor_primitive-03.adm";
+
+//Boundary value tests int32().
+//with MIN and MAX supported values.
+
+let $a:=int32("-2147483647")
+let $b:=int32("2147483647")
+
+let $c:=int32("0")
+let $d:=int32("1")
+let $e:=int32("-1")
+let $f:=int32("1073741828")
+let $g:=int32("-1073741828")
+
+return {"$a":$a,"$b":$b,"$c":$c,"$d":$d,"$e":$e,"$f":$f,"$g":$g}
diff --git a/asterix-app/src/test/resources/runtimets/queries/constructor/primitive-04.aql b/asterix-app/src/test/resources/runtimets/queries/constructor/primitive-04.aql
new file mode 100644
index 0000000..a8e0b02
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/constructor/primitive-04.aql
@@ -0,0 +1,23 @@
+/*
+ * Test case name : primitive-04.aql
+ * Description    : Test primitive integer type int64 constructor functions with boundary values
+ * Success        : Yes
+ * Date           : May 7th 2012
+ *
+ */
+
+write output to nc1:"rttest/constructor_primitive-04.adm";
+
+//Boundary value tests int64().
+//with MIN and MAX supported values.
+
+let $a:=int64("9222872036854775809")
+let $b:=int64("-9222872036854775809")
+
+let $c:=int64("0")
+let $d:=int64("1")
+let $e:=int64("-1")
+let $f:=int64("4611436018427387904")
+let $g:=int64("-4611436018427387904")
+
+return {"$a":$a,"$b":$b,"$c":$c,"$d":$d,"$e":$e,"$f":$f,"$g":$g}
diff --git a/asterix-app/src/test/resources/runtimets/results/constructor/primitive-01.adm b/asterix-app/src/test/resources/runtimets/results/constructor/primitive-01.adm
new file mode 100644
index 0000000..e4f0501
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/constructor/primitive-01.adm
@@ -0,0 +1 @@
+{ "$a": -127i8, "$b": 127i8, "$c": 0i8, "$d": 1i8, "$e": -1i8 }
diff --git a/asterix-app/src/test/resources/runtimets/results/constructor/primitive-02.adm b/asterix-app/src/test/resources/runtimets/results/constructor/primitive-02.adm
new file mode 100644
index 0000000..32b89e7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/constructor/primitive-02.adm
@@ -0,0 +1 @@
+{ "$a": -32767i16, "$b": 32767i16, "$c": 0i16, "$d": 1i16, "$e": -1i16, "$f": 16383i16, "$g": -16383i16 }
diff --git a/asterix-app/src/test/resources/runtimets/results/constructor/primitive-03.adm b/asterix-app/src/test/resources/runtimets/results/constructor/primitive-03.adm
new file mode 100644
index 0000000..f7774d0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/constructor/primitive-03.adm
@@ -0,0 +1 @@
+{ "$a": -2147483647, "$b": 2147483647, "$c": 0, "$d": 1, "$e": -1, "$f": 1073741828, "$g": -1073741828 }
diff --git a/asterix-app/src/test/resources/runtimets/results/constructor/primitive-04.adm b/asterix-app/src/test/resources/runtimets/results/constructor/primitive-04.adm
new file mode 100644
index 0000000..3453e4e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/constructor/primitive-04.adm
@@ -0,0 +1 @@
+{ "$a": 9222872036854775809i64, "$b": -9222872036854775809i64, "$c": 0i64, "$d": 1i64, "$e": -1i64, "$f": 4611436018427387904i64, "$g": -4611436018427387904i64 }
diff --git a/asterix-common/pom.xml b/asterix-common/pom.xml
index 34a73c9..facca1c 100644
--- a/asterix-common/pom.xml
+++ b/asterix-common/pom.xml
@@ -33,6 +33,13 @@
 			<artifactId>hyracks-dataflow-std</artifactId>
 			<version>0.2.1-SNAPSHOT</version>
 		</dependency>
+		<dependency>
+			<groupId>edu.uci.ics.asterix</groupId>
+			<artifactId>asterix-transactions</artifactId>
+			<version>0.0.4-SNAPSHOT</version>
+			<type>jar</type>
+			<scope>compile</scope>
+		</dependency>
 	</dependencies>
 
 </project>
diff --git a/asterix-common/src/main/java/edu/uci/ics/asterix/common/api/AsterixAppContextInfoImpl.java b/asterix-common/src/main/java/edu/uci/ics/asterix/common/api/AsterixAppContextInfoImpl.java
index 39642d1..7102288 100644
--- a/asterix-common/src/main/java/edu/uci/ics/asterix/common/api/AsterixAppContextInfoImpl.java
+++ b/asterix-common/src/main/java/edu/uci/ics/asterix/common/api/AsterixAppContextInfoImpl.java
@@ -4,7 +4,7 @@
 import java.util.Set;
 
 import edu.uci.ics.asterix.common.context.AsterixStorageManagerInterface;
-import edu.uci.ics.asterix.common.context.AsterixTreeRegistryProvider;
+import edu.uci.ics.asterix.common.context.AsterixIndexRegistryProvider;
 import edu.uci.ics.asterix.common.dataflow.IAsterixApplicationContextInfo;
 import edu.uci.ics.hyracks.storage.am.common.dataflow.IIndex;
 import edu.uci.ics.hyracks.storage.am.common.dataflow.IIndexRegistryProvider;
@@ -20,8 +20,8 @@
     }
 
     @Override
-    public IIndexRegistryProvider<IIndex> getTreeRegisterProvider() {
-        return AsterixTreeRegistryProvider.INSTANCE;
+    public IIndexRegistryProvider<IIndex> getIndexRegistryProvider() {
+        return AsterixIndexRegistryProvider.INSTANCE;
     }
 
     @Override
diff --git a/asterix-common/src/main/java/edu/uci/ics/asterix/common/config/GlobalConfig.java b/asterix-common/src/main/java/edu/uci/ics/asterix/common/config/GlobalConfig.java
index 201166e..bb39f90 100644
--- a/asterix-common/src/main/java/edu/uci/ics/asterix/common/config/GlobalConfig.java
+++ b/asterix-common/src/main/java/edu/uci/ics/asterix/common/config/GlobalConfig.java
@@ -3,14 +3,13 @@
 import java.util.logging.Logger;
 
 public class GlobalConfig {
-
     public static final boolean DEBUG = true;
+    
     public static final String ASTERIX_LOGGER_NAME = "edu.uci.ics.asterix";
+    
     public static final Logger ASTERIX_LOGGER = Logger.getLogger(ASTERIX_LOGGER_NAME);
-    // public static Level ASTERIX_LOG_LEVEL = Level.FINEST;
 
     public static final String ASTERIX_LOGFILE_PATTERN = "%t/asterix.log";
-    // "%t/asterix%g.log";
 
     public static final String DEFAULT_CONFIG_FILE_NAME = "test.properties";
 
@@ -22,9 +21,9 @@
 
     public static final String BUFFER_CACHE_PAGE_SIZE_PROPERTY = "BufferCachePageSize";
 
-    public static final String BUFFER_CACHE_SIZE_PROPERTY = "BufferCacheSize";
+    public static final String BUFFER_CACHE_NUM_PAGES_PROPERTY = "BufferCacheNumPages";
 
-    public static final int DEFAULT_BUFFER_CACHE_SIZE = 4096;
+    public static final int DEFAULT_BUFFER_CACHE_NUM_PAGES = 4096;
 
     public static final String HYRACKS_APP_NAME = "asterix";
 
@@ -33,18 +32,6 @@
     public static final String FRAME_SIZE_PROPERTY = "FrameSize";
 
     public static final float DEFAULT_BTREE_FILL_FACTOR = 1.00f;
+    
     public static int DEFAULT_INPUT_DATA_COLUMN = 0;
-
-    // static {
-    // Handler h;
-    // try {
-    // h = new ConsoleHandler();
-    // h.setFormatter(new SysoutFormatter());
-    // } catch (Exception e) {
-    // h = new ConsoleHandler();
-    // }
-    // h.setLevel(ASTERIX_LOG_LEVEL);
-    // ASTERIX_LOGGER.addHandler(h);
-    // ASTERIX_LOGGER.setLevel(ASTERIX_LOG_LEVEL);
-    // }
 }
diff --git a/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixAppRuntimeContext.java b/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixAppRuntimeContext.java
index 949855f..36e8a4c 100644
--- a/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixAppRuntimeContext.java
+++ b/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixAppRuntimeContext.java
@@ -1,12 +1,11 @@
 package edu.uci.ics.asterix.common.context;
 
 import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.logging.Logger;
+import java.util.logging.Level;
 
 import edu.uci.ics.asterix.common.config.GlobalConfig;
-import edu.uci.ics.asterix.common.exceptions.AsterixRuntimeException;
+import edu.uci.ics.asterix.transaction.management.exception.ACIDException;
+import edu.uci.ics.asterix.transaction.management.service.transaction.TransactionProvider;
 import edu.uci.ics.hyracks.api.application.INCApplicationContext;
 import edu.uci.ics.hyracks.api.io.IIOManager;
 import edu.uci.ics.hyracks.storage.am.common.dataflow.IIndex;
@@ -21,90 +20,82 @@
 import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
 
 public class AsterixAppRuntimeContext {
-    private static AsterixAppRuntimeContext INSTANCE;
-
-    private IndexRegistry<IIndex> treeRegistry;
-    private IBufferCache bufferCache;
+    private final INCApplicationContext ncApplicationContext;
+    
+    private IndexRegistry<IIndex> indexRegistry;
     private IFileMapManager fileMapManager;
-    private INCApplicationContext ncAppContext;
+    private IBufferCache bufferCache;
+    private TransactionProvider provider;
 
-    private static Logger LOGGER = Logger.getLogger(AsterixAppRuntimeContext.class.getName());
-
-    private AsterixAppRuntimeContext() {
+    public AsterixAppRuntimeContext(INCApplicationContext ncApplicationContext) {
+        this.ncApplicationContext = ncApplicationContext;
     }
 
-    public static void initialize(INCApplicationContext ncAppContext) throws IOException {
-        if (INSTANCE != null) {
-            LOGGER.info("Asterix instance already initialized");
-            return;
-        }
+    public void initialize() throws IOException, ACIDException {
+        int pageSize = getBufferCachePageSize();
+        int numPages = getBufferCacheNumPages();
 
-        INSTANCE = new AsterixAppRuntimeContext();
-        INSTANCE.ncAppContext = ncAppContext;
-        INSTANCE.start();
-    }
-
-    public static void deinitialize() {
-        if (INSTANCE != null) {
-            INSTANCE.stop();
-            INSTANCE = null;
-        }
-    }
-
-    private void stop() {
-        bufferCache.close();
-    }
-
-    private void start() throws IOException {
+        // Initialize file map manager
         fileMapManager = new AsterixFileMapManager();
+
+        // Initialize the buffer cache
         ICacheMemoryAllocator allocator = new HeapBufferAllocator();
         IPageReplacementStrategy prs = new ClockPageReplacementStrategy();
-        if (ncAppContext == null) {
-            throw new AsterixRuntimeException("NC Application Context has not been set.");
-        }
-        IIOManager ioMgr = ncAppContext.getRootContext().getIOManager();
-        String pgsizeStr = System.getProperty(GlobalConfig.BUFFER_CACHE_PAGE_SIZE_PROPERTY);
-        int pgSize = -1;
-        if (pgsizeStr != null) {
-            try {
-                pgSize = Integer.parseInt(pgsizeStr);
-            } catch (NumberFormatException nfe) {
-                StringWriter sw = new StringWriter();
-                nfe.printStackTrace(new PrintWriter(sw, true));
-                sw.close();
-                GlobalConfig.ASTERIX_LOGGER.warning("Wrong buffer cache page size argument. Picking frame size ("
-                        + ncAppContext.getRootContext().getFrameSize() + ") instead. \n" + sw.toString() + "\n");
-            }
-        }
-        if (pgSize < 0) {
-            // by default, pick the frame size
-            pgSize = ncAppContext.getRootContext().getFrameSize();
-        }
+        IIOManager ioMgr = ncApplicationContext.getRootContext().getIOManager();
+        bufferCache = new BufferCache(ioMgr, allocator, prs, fileMapManager, pageSize, numPages, Integer.MAX_VALUE);
 
-        int cacheSize = GlobalConfig.DEFAULT_BUFFER_CACHE_SIZE;
-        String cacheSizeStr = System.getProperty(GlobalConfig.BUFFER_CACHE_SIZE_PROPERTY);
-        if (cacheSizeStr != null) {
-            int cs = -1;
-            try {
-                cs = Integer.parseInt(cacheSizeStr);
-            } catch (NumberFormatException nfe) {
-                StringWriter sw = new StringWriter();
-                nfe.printStackTrace(new PrintWriter(sw, true));
-                sw.close();
-                GlobalConfig.ASTERIX_LOGGER.warning("Wrong buffer cache size argument. Picking default value ("
-                        + GlobalConfig.DEFAULT_BUFFER_CACHE_SIZE + ") instead.\n");
-            }
-            if (cs >= 0) {
-                cacheSize = cs;
-            }
-        }
-        System.out.println("BC :" + pgSize + " cache " + cacheSize);
-        bufferCache = new BufferCache(ioMgr, allocator, prs, fileMapManager, pgSize, cacheSize, Integer.MAX_VALUE);
-        treeRegistry = new IndexRegistry<IIndex>();
+        // Initialize the index registry
+        indexRegistry = new IndexRegistry<IIndex>();
+
+        // Initialize the transaction sub-system
+        provider = new TransactionProvider(ncApplicationContext.getNodeId());
     }
 
-    public static AsterixAppRuntimeContext getInstance() {
-        return INSTANCE;
+    private int getBufferCachePageSize() {
+        int pageSize = ncApplicationContext.getRootContext().getFrameSize();
+        String pageSizeStr = System.getProperty(GlobalConfig.BUFFER_CACHE_PAGE_SIZE_PROPERTY, null);
+        if (pageSizeStr != null) {
+            try {
+                pageSize = Integer.parseInt(pageSizeStr);
+            } catch (NumberFormatException nfe) {
+                if (GlobalConfig.ASTERIX_LOGGER.isLoggable(Level.WARNING)) {
+                    GlobalConfig.ASTERIX_LOGGER.warning("Wrong buffer cache page size argument. "
+                            + "Using default value: " + pageSize);
+                }
+            }
+        }
+
+        if (GlobalConfig.ASTERIX_LOGGER.isLoggable(Level.INFO)) {
+            GlobalConfig.ASTERIX_LOGGER.info("Buffer cache page size: " + pageSize);
+        }
+
+        return pageSize;
+    }
+
+    private int getBufferCacheNumPages() {
+        int numPages = GlobalConfig.DEFAULT_BUFFER_CACHE_NUM_PAGES;
+        String numPagesStr = System.getProperty(GlobalConfig.BUFFER_CACHE_NUM_PAGES_PROPERTY, null);
+        if (numPagesStr != null) {
+            try {
+                numPages = Integer.parseInt(numPagesStr);
+            } catch (NumberFormatException nfe) {
+                if (GlobalConfig.ASTERIX_LOGGER.isLoggable(Level.WARNING)) {
+                    GlobalConfig.ASTERIX_LOGGER.warning("Wrong buffer cache size argument. " + "Using default value: "
+                            + numPages);
+                }
+                return numPages;
+            }
+        }
+
+        if (GlobalConfig.ASTERIX_LOGGER.isLoggable(Level.INFO)) {
+            GlobalConfig.ASTERIX_LOGGER.info("Buffer cache size (number of pages): " + numPages);
+        }
+
+        return numPages;
+    }
+
+    public void deinitialize() {
+        bufferCache.close();
     }
 
     public IBufferCache getBufferCache() {
@@ -115,8 +106,12 @@
         return fileMapManager;
     }
 
-    public IndexRegistry<IIndex> getTreeRegistry() {
-        return treeRegistry;
+    public IndexRegistry<IIndex> getIndexRegistry() {
+        return indexRegistry;
+    }
+
+    public TransactionProvider getTransactionProvider() {
+        return provider;
     }
 
 }
\ No newline at end of file
diff --git a/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixIndexRegistryProvider.java b/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixIndexRegistryProvider.java
new file mode 100644
index 0000000..bc59291
--- /dev/null
+++ b/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixIndexRegistryProvider.java
@@ -0,0 +1,23 @@
+package edu.uci.ics.asterix.common.context;
+
+import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
+import edu.uci.ics.hyracks.storage.am.common.dataflow.IIndex;
+import edu.uci.ics.hyracks.storage.am.common.dataflow.IIndexRegistryProvider;
+import edu.uci.ics.hyracks.storage.am.common.dataflow.IndexRegistry;
+
+public class AsterixIndexRegistryProvider implements IIndexRegistryProvider<IIndex> {
+
+    private static final long serialVersionUID = 1L;
+
+    public static final AsterixIndexRegistryProvider INSTANCE = new AsterixIndexRegistryProvider();
+
+    private AsterixIndexRegistryProvider() {
+    }
+
+    @Override
+    public IndexRegistry<IIndex> getRegistry(IHyracksTaskContext ctx) {
+        return ((AsterixAppRuntimeContext) ctx.getJobletContext().getApplicationContext().getApplicationObject())
+                .getIndexRegistry();
+    }
+
+}
diff --git a/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixStorageManagerInterface.java b/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixStorageManagerInterface.java
index 67b785e..a1b5a94 100644
--- a/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixStorageManagerInterface.java
+++ b/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixStorageManagerInterface.java
@@ -12,11 +12,13 @@
 
     @Override
     public IBufferCache getBufferCache(IHyracksTaskContext ctx) {
-        return AsterixAppRuntimeContext.getInstance().getBufferCache();
+        return ((AsterixAppRuntimeContext) ctx.getJobletContext().getApplicationContext().getApplicationObject())
+                .getBufferCache();
     }
 
     @Override
     public IFileMapProvider getFileMapProvider(IHyracksTaskContext ctx) {
-        return AsterixAppRuntimeContext.getInstance().getFileMapManager();
+        return ((AsterixAppRuntimeContext) ctx.getJobletContext().getApplicationContext().getApplicationObject())
+                .getFileMapManager();
     }
 }
diff --git a/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixTreeRegistryProvider.java b/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixTreeRegistryProvider.java
deleted file mode 100644
index 3f542ec..0000000
--- a/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixTreeRegistryProvider.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package edu.uci.ics.asterix.common.context;
-
-import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
-import edu.uci.ics.hyracks.storage.am.common.dataflow.IIndex;
-import edu.uci.ics.hyracks.storage.am.common.dataflow.IIndexRegistryProvider;
-import edu.uci.ics.hyracks.storage.am.common.dataflow.IndexRegistry;
-
-public class AsterixTreeRegistryProvider implements IIndexRegistryProvider<IIndex> {
-
-    private static final long serialVersionUID = 1L;
-
-    public static final AsterixTreeRegistryProvider INSTANCE = new AsterixTreeRegistryProvider();
-
-    private AsterixTreeRegistryProvider() {
-    }
-
-    @Override
-    public IndexRegistry<IIndex> getRegistry(IHyracksTaskContext ctx) {
-        return AsterixAppRuntimeContext.getInstance().getTreeRegistry();
-    }
-
-}
diff --git a/asterix-common/src/main/java/edu/uci/ics/asterix/common/dataflow/IAsterixApplicationContextInfo.java b/asterix-common/src/main/java/edu/uci/ics/asterix/common/dataflow/IAsterixApplicationContextInfo.java
index b5033d3..7bb0fd6 100644
--- a/asterix-common/src/main/java/edu/uci/ics/asterix/common/dataflow/IAsterixApplicationContextInfo.java
+++ b/asterix-common/src/main/java/edu/uci/ics/asterix/common/dataflow/IAsterixApplicationContextInfo.java
@@ -5,7 +5,7 @@
 import edu.uci.ics.hyracks.storage.common.IStorageManagerInterface;
 
 public interface IAsterixApplicationContextInfo {
-    public IIndexRegistryProvider<IIndex> getTreeRegisterProvider();
+    public IIndexRegistryProvider<IIndex> getIndexRegistryProvider();
 
     public IStorageManagerInterface getStorageManagerInterface();
 }
diff --git a/asterix-hyracks-glue/pom.xml b/asterix-hyracks-glue/pom.xml
index 012d8f6..5f991a4 100644
--- a/asterix-hyracks-glue/pom.xml
+++ b/asterix-hyracks-glue/pom.xml
@@ -38,9 +38,11 @@
        <scope>compile</scope>
     </dependency>
     <dependency>
-       <groupId>edu.uci.ics.hyracks</groupId>
-       <artifactId>hyracks-storage-am-btree</artifactId>
-       <version>0.2.1-SNAPSHOT</version>
+    	<groupId>edu.uci.ics.asterix</groupId>
+    	<artifactId>asterix-common</artifactId>
+    	<version>0.0.4-SNAPSHOT</version>
+    	<type>jar</type>
+    	<scope>compile</scope>
     </dependency>
   </dependencies>
   <properties>
diff --git a/asterix-hyracks-glue/src/main/java/edu/uci/ics/asterix/runtime/transaction/TreeIndexInsertUpdateDeleteOperatorDescriptor.java b/asterix-hyracks-glue/src/main/java/edu/uci/ics/asterix/runtime/transaction/TreeIndexInsertUpdateDeleteOperatorDescriptor.java
index 1b6daec..85f9fb1 100644
--- a/asterix-hyracks-glue/src/main/java/edu/uci/ics/asterix/runtime/transaction/TreeIndexInsertUpdateDeleteOperatorDescriptor.java
+++ b/asterix-hyracks-glue/src/main/java/edu/uci/ics/asterix/runtime/transaction/TreeIndexInsertUpdateDeleteOperatorDescriptor.java
@@ -15,10 +15,10 @@
 
 package edu.uci.ics.asterix.runtime.transaction;
 
+import edu.uci.ics.asterix.common.context.AsterixAppRuntimeContext;
 import edu.uci.ics.asterix.transaction.management.exception.ACIDException;
 import edu.uci.ics.asterix.transaction.management.service.transaction.ITransactionManager;
 import edu.uci.ics.asterix.transaction.management.service.transaction.TransactionContext;
-import edu.uci.ics.asterix.transaction.management.service.transaction.TransactionProvider;
 import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
 import edu.uci.ics.hyracks.api.dataflow.IOperatorNodePushable;
 import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparatorFactory;
@@ -35,23 +35,27 @@
 import edu.uci.ics.hyracks.storage.am.common.ophelpers.IndexOp;
 import edu.uci.ics.hyracks.storage.common.IStorageManagerInterface;
 
-public class TreeIndexInsertUpdateDeleteOperatorDescriptor extends
-		AbstractTreeIndexOperatorDescriptor {
+public class TreeIndexInsertUpdateDeleteOperatorDescriptor extends AbstractTreeIndexOperatorDescriptor {
 
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-	private final int[] fieldPermutation;
+    private final int[] fieldPermutation;
 
-	private final IndexOp op;
+    private final IndexOp op;
 
-	private final long transactionId;
+    private final long transactionId;
 
-
+    /* TODO: Index operators should live in Hyracks. Right now, they are needed here in Asterix
+     * as a hack to provide transactionIDs. The Asterix verions of this operator will disappear 
+     * and the operator will come from Hyracks once the LSM/Recovery/Transactions world has 
+     * been introduced.
+     */
     public TreeIndexInsertUpdateDeleteOperatorDescriptor(JobSpecification spec, RecordDescriptor recDesc,
             IStorageManagerInterface storageManager, IIndexRegistryProvider<IIndex> indexRegistryProvider,
             IFileSplitProvider fileSplitProvider, ITypeTraits[] typeTraits,
             IBinaryComparatorFactory[] comparatorFactories, int[] fieldPermutation, IndexOp op,
-            IIndexDataflowHelperFactory dataflowHelperFactory, IOperationCallbackProvider opCallbackProvider, long transactionId) {
+            IIndexDataflowHelperFactory dataflowHelperFactory, IOperationCallbackProvider opCallbackProvider,
+            long transactionId) {
         super(spec, 1, 1, recDesc, storageManager, indexRegistryProvider, fileSplitProvider, typeTraits,
                 comparatorFactories, dataflowHelperFactory, opCallbackProvider);
         this.fieldPermutation = fieldPermutation;
@@ -59,24 +63,18 @@
         this.transactionId = transactionId;
     }
 
-	@Override
-	public IOperatorNodePushable createPushRuntime(IHyracksTaskContext ctx,
-			IRecordDescriptorProvider recordDescProvider, int partition,
-			int nPartitions) {
-		TransactionContext txnContext;
-		try {
-			ITransactionManager transactionManager = ((TransactionProvider) (ctx
-					.getJobletContext().getApplicationContext()
-					.getApplicationObject())).getTransactionManager();
-			txnContext = transactionManager
-					.getTransactionContext(transactionId);
-		} catch (ACIDException ae) {
-			throw new RuntimeException(
-					" could not obtain context for invalid transaction id "
-							+ transactionId);
-		}
-		return new TreeIndexInsertUpdateDeleteOperatorNodePushable(txnContext, this, ctx, opCallbackProvider, partition,
-                fieldPermutation, recordDescProvider, op);
-	}
-
+    @Override
+    public IOperatorNodePushable createPushRuntime(IHyracksTaskContext ctx,
+            IRecordDescriptorProvider recordDescProvider, int partition, int nPartitions) {
+        TransactionContext txnContext;
+        try {
+            ITransactionManager transactionManager = ((AsterixAppRuntimeContext) ctx.getJobletContext().getApplicationContext()
+                    .getApplicationObject()).getTransactionProvider().getTransactionManager();
+            txnContext = transactionManager.getTransactionContext(transactionId);
+        } catch (ACIDException ae) {
+            throw new RuntimeException(" could not obtain context for invalid transaction id " + transactionId);
+        }
+        return new TreeIndexInsertUpdateDeleteOperatorNodePushable(txnContext, this, ctx, opCallbackProvider,
+                partition, fieldPermutation, recordDescProvider, op);
+    }
 }
diff --git a/asterix-hyracks-glue/src/main/java/edu/uci/ics/asterix/runtime/transaction/TreeIndexInsertUpdateDeleteOperatorNodePushable.java b/asterix-hyracks-glue/src/main/java/edu/uci/ics/asterix/runtime/transaction/TreeIndexInsertUpdateDeleteOperatorNodePushable.java
index 3af5e91..92d4158 100644
--- a/asterix-hyracks-glue/src/main/java/edu/uci/ics/asterix/runtime/transaction/TreeIndexInsertUpdateDeleteOperatorNodePushable.java
+++ b/asterix-hyracks-glue/src/main/java/edu/uci/ics/asterix/runtime/transaction/TreeIndexInsertUpdateDeleteOperatorNodePushable.java
@@ -16,11 +16,15 @@
 
 import java.nio.ByteBuffer;
 
+import edu.uci.ics.asterix.common.context.AsterixAppRuntimeContext;
 import edu.uci.ics.asterix.transaction.management.exception.ACIDException;
 import edu.uci.ics.asterix.transaction.management.resource.ICloseable;
 import edu.uci.ics.asterix.transaction.management.resource.TransactionalResourceRepository;
 import edu.uci.ics.asterix.transaction.management.service.locking.ILockManager;
 import edu.uci.ics.asterix.transaction.management.service.logging.DataUtil;
+import edu.uci.ics.asterix.transaction.management.service.logging.TreeLogger;
+import edu.uci.ics.asterix.transaction.management.service.logging.TreeResourceManager;
+import edu.uci.ics.asterix.transaction.management.service.transaction.IResourceManager;
 import edu.uci.ics.asterix.transaction.management.service.transaction.TransactionContext;
 import edu.uci.ics.asterix.transaction.management.service.transaction.TransactionManagementConstants;
 import edu.uci.ics.asterix.transaction.management.service.transaction.TransactionProvider;
@@ -50,12 +54,18 @@
     private IIndexAccessor indexAccessor;
     private ILockManager lockManager;
     private final TransactionContext txnContext;
-    private TreeLogger bTreeLogger;
+    private TreeLogger treeLogger;
     private final TransactionProvider transactionProvider;
 
-    public TreeIndexInsertUpdateDeleteOperatorNodePushable(TransactionContext txnContext, AbstractTreeIndexOperatorDescriptor opDesc,
-            IHyracksTaskContext ctx, IOperationCallbackProvider opCallbackProvider, int partition,
-            int[] fieldPermutation, IRecordDescriptorProvider recordDescProvider, IndexOp op) {
+    /* TODO: Index operators should live in Hyracks. Right now, they are needed here in Asterix
+     * as a hack to provide transactionIDs. The Asterix verions of this operator will disappear 
+     * and the operator will come from Hyracks once the LSM/Recovery/Transactions world has 
+     * been introduced.
+     */
+    public TreeIndexInsertUpdateDeleteOperatorNodePushable(TransactionContext txnContext,
+            AbstractTreeIndexOperatorDescriptor opDesc, IHyracksTaskContext ctx,
+            IOperationCallbackProvider opCallbackProvider, int partition, int[] fieldPermutation,
+            IRecordDescriptorProvider recordDescProvider, IndexOp op) {
         boolean createIfNotExists = (op == IndexOp.INSERT);
         treeIndexHelper = (TreeIndexDataflowHelper) opDesc.getIndexDataflowHelperFactory().createIndexDataflowHelper(
                 opDesc, ctx, opCallbackProvider, partition, createIfNotExists);
@@ -63,21 +73,27 @@
         this.op = op;
         tuple.setFieldPermutation(fieldPermutation);
         this.txnContext = txnContext;
-        transactionProvider = (TransactionProvider) ctx.getJobletContext().getApplicationContext()
-                .getApplicationObject();
-    }
-    
-    public void initializeTransactionSupport() {
-        TransactionalResourceRepository.registerTransactionalResourceManager(TreeResourceManager.ID,
-                TreeResourceManager.getInstance());
-        int fileId = treeIndexHelper.getIndexFileId();
-        byte[] resourceId = DataUtil.intToByteArray(fileId);
-        TransactionalResourceRepository.registerTransactionalResource(resourceId, treeIndexHelper.getIndex());
-        lockManager = transactionProvider.getLockManager();
-        bTreeLogger = TreeLoggerRepository.getTreeLogger(resourceId);
+
+        AsterixAppRuntimeContext runtimeContext = (AsterixAppRuntimeContext) ctx.getJobletContext()
+                .getApplicationContext().getApplicationObject();
+        transactionProvider = runtimeContext.getTransactionProvider();
     }
 
-    
+    public void initializeTransactionSupport() {
+        TransactionalResourceRepository resourceRepository = transactionProvider.getTransactionalResourceRepository();
+        IResourceManager resourceMgr = resourceRepository.getTransactionalResourceMgr(TreeResourceManager.ID);
+        if (resourceMgr == null) {
+            resourceRepository.registerTransactionalResourceManager(TreeResourceManager.ID, new TreeResourceManager(
+                    transactionProvider));
+        }
+        int fileId = treeIndexHelper.getIndexFileId();
+        byte[] resourceId = DataUtil.intToByteArray(fileId);
+        transactionProvider.getTransactionalResourceRepository().registerTransactionalResource(resourceId,
+                treeIndexHelper.getIndex());
+        lockManager = transactionProvider.getLockManager();
+        treeLogger = transactionProvider.getTreeLoggerRepository().getTreeLogger(resourceId);
+    }
+
     @Override
     public void open() throws HyracksDataException {
         AbstractTreeIndexOperatorDescriptor opDesc = (AbstractTreeIndexOperatorDescriptor) treeIndexHelper
@@ -97,7 +113,7 @@
             throw new HyracksDataException(e);
         }
     }
-    
+
     @Override
     public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
         final IIndex treeIndex = treeIndexHelper.getIndex();
@@ -113,7 +129,7 @@
                         lockManager.lock(txnContext, resourceId,
                                 TransactionManagementConstants.LockManagerConstants.LockMode.EXCLUSIVE);
                         indexAccessor.insert(tuple);
-                        bTreeLogger.generateLogRecord(transactionProvider, txnContext, op, tuple);
+                        treeLogger.generateLogRecord(transactionProvider, txnContext, op, tuple);
                         break;
                     }
 
@@ -121,9 +137,9 @@
                         lockManager.lock(txnContext, resourceId,
                                 TransactionManagementConstants.LockManagerConstants.LockMode.EXCLUSIVE);
                         indexAccessor.delete(tuple);
-                        bTreeLogger.generateLogRecord(transactionProvider, txnContext, op, tuple);
+                        treeLogger.generateLogRecord(transactionProvider, txnContext, op, tuple);
                         break;
-                    }                        
+                    }
 
                     default: {
                         throw new HyracksDataException("Unsupported operation " + op
diff --git a/asterix-hyracks-glue/src/main/java/edu/uci/ics/asterix/runtime/transaction/TreeLoggerRepository.java b/asterix-hyracks-glue/src/main/java/edu/uci/ics/asterix/runtime/transaction/TreeLoggerRepository.java
deleted file mode 100644
index fbd3cb1..0000000
--- a/asterix-hyracks-glue/src/main/java/edu/uci/ics/asterix/runtime/transaction/TreeLoggerRepository.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2009-2011 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.asterix.runtime.transaction;
-
-import java.nio.ByteBuffer;
-import java.util.HashMap;
-import java.util.Map;
-
-public class TreeLoggerRepository {
-
-    private static final Map<ByteBuffer, TreeLogger> loggers = new HashMap<ByteBuffer, TreeLogger>();
-
-    public static synchronized TreeLogger getTreeLogger(byte[] resourceIdBytes) {
-        ByteBuffer resourceId = ByteBuffer.wrap(resourceIdBytes);
-        TreeLogger logger = loggers.get(resourceId);
-        if (logger == null) {
-            logger = new TreeLogger(resourceIdBytes);
-            loggers.put(resourceId, logger);
-        }
-        return logger;
-    }
-}
\ No newline at end of file
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/MetadataNode.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/MetadataNode.java
index 243fc61..6ac37c3 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/MetadataNode.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/MetadataNode.java
@@ -21,13 +21,12 @@
 
 import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
 import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType;
-import edu.uci.ics.asterix.common.dataflow.IAsterixApplicationContextInfo;
+import edu.uci.ics.asterix.common.context.AsterixAppRuntimeContext;
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.metadata.api.IMetadataIndex;
 import edu.uci.ics.asterix.metadata.api.IMetadataNode;
 import edu.uci.ics.asterix.metadata.api.IValueExtractor;
-import edu.uci.ics.asterix.metadata.bootstrap.AsterixProperties;
 import edu.uci.ics.asterix.metadata.bootstrap.MetadataPrimaryIndexes;
 import edu.uci.ics.asterix.metadata.bootstrap.MetadataSecondaryIndexes;
 import edu.uci.ics.asterix.metadata.entities.Dataset;
@@ -74,29 +73,28 @@
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexFrame;
 import edu.uci.ics.hyracks.storage.am.common.api.TreeIndexException;
 import edu.uci.ics.hyracks.storage.am.common.dataflow.IIndex;
-import edu.uci.ics.hyracks.storage.am.common.dataflow.IIndexRegistryProvider;
+import edu.uci.ics.hyracks.storage.am.common.dataflow.IndexRegistry;
 import edu.uci.ics.hyracks.storage.am.common.ophelpers.IndexOp;
 import edu.uci.ics.hyracks.storage.am.common.ophelpers.MultiComparator;
 
 public class MetadataNode implements IMetadataNode {
-
     private static final long serialVersionUID = 1L;
-    private static IIndexRegistryProvider<IIndex> btreeRegistryProvider;
-    public static MetadataNode INSTANCE;
+
     // TODO: Temporary transactional resource id for metadata.
-    private static byte[] metadataResourceId = MetadataNode.class.toString().getBytes();
+    private static final byte[] metadataResourceId = MetadataNode.class.toString().getBytes();
 
-    @SuppressWarnings("unchecked")
-    private ISerializerDeserializer<AString> stringSerde = AqlSerializerDeserializerProvider.INSTANCE
-            .getSerializerDeserializer(BuiltinType.ASTRING);
-
+    private IndexRegistry<IIndex> indexRegistry;
     private TransactionProvider transactionProvider;
 
-    public MetadataNode(AsterixProperties asterixProperity, IAsterixApplicationContextInfo appContext,
-            TransactionProvider transactionProvider) {
+    public static final MetadataNode INSTANCE = new MetadataNode();
+
+    private MetadataNode() {
         super();
-        this.transactionProvider = transactionProvider;
-        btreeRegistryProvider = appContext.getTreeRegisterProvider();
+    }
+    
+    public void initialize(AsterixAppRuntimeContext runtimeContext) {
+        this.transactionProvider = runtimeContext.getTransactionProvider();
+        this.indexRegistry = runtimeContext.getIndexRegistry();
     }
 
     @Override
@@ -230,28 +228,22 @@
     }
 
     @Override
-	public void addFunction(long txnId, Function function)
-			throws MetadataException, RemoteException {
-		try {
-			// Insert into the 'function' dataset.
-			FunctionTupleTranslator tupleReaderWriter = new FunctionTupleTranslator(
-					true);
-			ITupleReference functionTuple = tupleReaderWriter
-					.getTupleFromMetadataEntity(function);
-			insertTupleIntoIndex(txnId,
-					MetadataPrimaryIndexes.FUNCTION_DATASET, functionTuple);
+    public void addFunction(long txnId, Function function) throws MetadataException, RemoteException {
+        try {
+            // Insert into the 'function' dataset.
+            FunctionTupleTranslator tupleReaderWriter = new FunctionTupleTranslator(true);
+            ITupleReference functionTuple = tupleReaderWriter.getTupleFromMetadataEntity(function);
+            insertTupleIntoIndex(txnId, MetadataPrimaryIndexes.FUNCTION_DATASET, functionTuple);
 
-		} catch (BTreeDuplicateKeyException e) {
-			throw new MetadataException("A dataset with this name "
-					+ function.getFunctionName() + " and arity "
-					+ function.getFunctionArity()
-					+ " already exists in dataverse '"
-					+ function.getDataverseName() + "'.", e);
-		} catch (Exception e) {
-			throw new MetadataException(e);
-		}
-	}
-    
+        } catch (BTreeDuplicateKeyException e) {
+            throw new MetadataException("A dataset with this name " + function.getFunctionName() + " and arity "
+                    + function.getFunctionArity() + " already exists in dataverse '" + function.getDataverseName()
+                    + "'.", e);
+        } catch (Exception e) {
+            throw new MetadataException(e);
+        }
+    }
+
     public void insertIntoDatatypeSecondaryIndex(long txnId, String dataverseName, String nestedTypeName,
             String topTypeName) throws Exception {
         ITupleReference tuple = createTuple(dataverseName, nestedTypeName, topTypeName);
@@ -260,7 +252,7 @@
 
     private void insertTupleIntoIndex(long txnId, IMetadataIndex index, ITupleReference tuple) throws Exception {
         int fileId = index.getFileId();
-        BTree btree = (BTree) btreeRegistryProvider.getRegistry(null).get(fileId);
+        BTree btree = (BTree) indexRegistry.get(fileId);
         btree.open(fileId);
         ITreeIndexAccessor indexAccessor = btree.createAccessor();
         TransactionContext txnCtx = transactionProvider.getTransactionManager().getTransactionContext(txnId);
@@ -505,7 +497,7 @@
 
     private void deleteTupleFromIndex(long txnId, IMetadataIndex index, ITupleReference tuple) throws Exception {
         int fileId = index.getFileId();
-        BTree btree = (BTree) btreeRegistryProvider.getRegistry(null).get(fileId);
+        BTree btree = (BTree) indexRegistry.get(fileId);
         btree.open(fileId);
 
         ITreeIndexAccessor indexAccessor = btree.createAccessor();
@@ -707,65 +699,57 @@
             throw new MetadataException(e);
         }
     }
-    
-    @Override
-	public Function getFunction(long txnId, String dataverseName,
-			String functionName, int arity) throws MetadataException,
-			RemoteException {
-		try {
-			ITupleReference searchKey = createTuple(dataverseName,
-					functionName, "" + arity);
-			FunctionTupleTranslator tupleReaderWriter = new FunctionTupleTranslator(
-					false);
-			List<Function> results = new ArrayList<Function>();
-			IValueExtractor<Function> valueExtractor = new MetadataEntityValueExtractor<Function>(
-					tupleReaderWriter);
-			searchIndex(txnId, MetadataPrimaryIndexes.FUNCTION_DATASET,
-					searchKey, valueExtractor, results);
-			if (results.isEmpty()) {
-				return null;
-			}
-			return results.get(0);
-		} catch (Exception e) {
-			throw new MetadataException(e);
-		}
-	}
 
     @Override
-	public void dropFunction(long txnId, String dataverseName,
-			String functionName, int arity) throws MetadataException,
-			RemoteException {
-		Function function;
-		try {
-			function = getFunction(txnId, dataverseName, functionName, arity);
-		} catch (Exception e) {
-			throw new MetadataException(e);
-		}
-		if (function == null) {
-			throw new MetadataException("Cannot drop function '" + functionName
-					+ " and arity " + arity + "' because it doesn't exist.");
-		}
-		try {
-			// Delete entry from the 'function' dataset.
-			ITupleReference searchKey = createTuple(dataverseName,
-					functionName, "" + arity);
-			// Searches the index for the tuple to be deleted. Acquires an S
-			// lock on the 'function' dataset.
-			ITupleReference datasetTuple = getTupleToBeDeleted(txnId,
-					MetadataPrimaryIndexes.FUNCTION_DATASET, searchKey);
-			deleteTupleFromIndex(txnId, MetadataPrimaryIndexes.FUNCTION_DATASET,
-					datasetTuple);
+    public Function getFunction(long txnId, String dataverseName, String functionName, int arity)
+            throws MetadataException, RemoteException {
+        try {
+            ITupleReference searchKey = createTuple(dataverseName, functionName, "" + arity);
+            FunctionTupleTranslator tupleReaderWriter = new FunctionTupleTranslator(false);
+            List<Function> results = new ArrayList<Function>();
+            IValueExtractor<Function> valueExtractor = new MetadataEntityValueExtractor<Function>(tupleReaderWriter);
+            searchIndex(txnId, MetadataPrimaryIndexes.FUNCTION_DATASET, searchKey, valueExtractor, results);
+            if (results.isEmpty()) {
+                return null;
+            }
+            return results.get(0);
+        } catch (Exception e) {
+            throw new MetadataException(e);
+        }
+    }
 
-			// TODO: Change this to be a BTree specific exception, e.g.,
-			// BTreeKeyDoesNotExistException.
-		} catch (TreeIndexException e) {
-			throw new MetadataException("Cannot drop function '" + functionName
-					+ " and arity " + arity + "' because it doesn't exist.", e);
-		} catch (Exception e) {
-			throw new MetadataException(e);
-		}
-	}
-    
+    @Override
+    public void dropFunction(long txnId, String dataverseName, String functionName, int arity)
+            throws MetadataException, RemoteException {
+        Function function;
+        try {
+            function = getFunction(txnId, dataverseName, functionName, arity);
+        } catch (Exception e) {
+            throw new MetadataException(e);
+        }
+        if (function == null) {
+            throw new MetadataException("Cannot drop function '" + functionName + " and arity " + arity
+                    + "' because it doesn't exist.");
+        }
+        try {
+            // Delete entry from the 'function' dataset.
+            ITupleReference searchKey = createTuple(dataverseName, functionName, "" + arity);
+            // Searches the index for the tuple to be deleted. Acquires an S
+            // lock on the 'function' dataset.
+            ITupleReference datasetTuple = getTupleToBeDeleted(txnId, MetadataPrimaryIndexes.FUNCTION_DATASET,
+                    searchKey);
+            deleteTupleFromIndex(txnId, MetadataPrimaryIndexes.FUNCTION_DATASET, datasetTuple);
+
+            // TODO: Change this to be a BTree specific exception, e.g.,
+            // BTreeKeyDoesNotExistException.
+        } catch (TreeIndexException e) {
+            throw new MetadataException("Cannot drop function '" + functionName + " and arity " + arity
+                    + "' because it doesn't exist.", e);
+        } catch (Exception e) {
+            throw new MetadataException(e);
+        }
+    }
+
     private ITupleReference getTupleToBeDeleted(long txnId, IMetadataIndex metadataIndex, ITupleReference searchKey)
             throws Exception {
         IValueExtractor<ITupleReference> valueExtractor = new TupleCopyValueExtractor(metadataIndex.getTypeTraits());
@@ -786,7 +770,7 @@
         transactionProvider.getLockManager().lock(txnCtx, index.getResourceId(), LockMode.SHARED);
         IBinaryComparatorFactory[] comparatorFactories = index.getKeyBinaryComparatorFactory();
         int fileId = index.getFileId();
-        BTree btree = (BTree) btreeRegistryProvider.getRegistry(null).get(fileId);
+        BTree btree = (BTree) indexRegistry.get(fileId);
         btree.open(fileId);
         ITreeIndexFrame leafFrame = btree.getLeafFrameFactory().createFrame();
         ITreeIndexAccessor indexAccessor = btree.createAccessor();
@@ -815,6 +799,8 @@
     // TODO: Can use Hyrack's TupleUtils for this, once we switch to a newer
     // Hyracks version.
     public ITupleReference createTuple(String... fields) throws HyracksDataException {
+        ISerializerDeserializer<AString> stringSerde = AqlSerializerDeserializerProvider.INSTANCE
+                .getSerializerDeserializer(BuiltinType.ASTRING);
         AMutableString aString = new AMutableString("");
         ArrayTupleBuilder tupleBuilder = new ArrayTupleBuilder(fields.length);
         for (String s : fields) {
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/api/IMetadataIndex.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/api/IMetadataIndex.java
index c752f18..f9e5540 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/api/IMetadataIndex.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/api/IMetadataIndex.java
@@ -18,12 +18,13 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.om.types.ARecordType;
-import edu.uci.ics.asterix.runtime.transaction.TreeLogger;
 import edu.uci.ics.asterix.transaction.management.exception.ACIDException;
+import edu.uci.ics.asterix.transaction.management.service.logging.TreeLogger;
 import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparatorFactory;
 import edu.uci.ics.hyracks.api.dataflow.value.IBinaryHashFunctionFactory;
 import edu.uci.ics.hyracks.api.dataflow.value.ITypeTraits;
 import edu.uci.ics.hyracks.api.dataflow.value.RecordDescriptor;
+import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndex;
 
 /**
  * Descriptor interface for a primary or secondary index on metadata datasets.
@@ -59,7 +60,7 @@
 
     public void setFileId(int fileId);
 
-    public void initTreeLogger() throws ACIDException;
+    public void initTreeLogger(ITreeIndex treeIndex) throws ACIDException;
 
     public int getFileId();
 
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/AsterixStateProxy.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/AsterixStateProxy.java
index c7ed82e..e2c02fa 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/AsterixStateProxy.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/AsterixStateProxy.java
@@ -41,7 +41,7 @@
         return stub;
     }
 
-    public static void deRegisterRemoteObject() throws RemoteException {
+    public static void unregisterRemoteObject() throws RemoteException {
         UnicastRemoteObject.unexportObject(cc, true);
         LOGGER.info("Asterix Distributed State Proxy Unbound");
     }
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/MetadataBootstrap.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/MetadataBootstrap.java
index b2bfaf5..6c388c2 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/MetadataBootstrap.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/MetadataBootstrap.java
@@ -25,7 +25,7 @@
 
 import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
 import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType;
-import edu.uci.ics.asterix.common.dataflow.IAsterixApplicationContextInfo;
+import edu.uci.ics.asterix.common.context.AsterixAppRuntimeContext;
 import edu.uci.ics.asterix.metadata.IDatasetDetails;
 import edu.uci.ics.asterix.metadata.MetadataManager;
 import edu.uci.ics.asterix.metadata.MetadataTransactionContext;
@@ -42,11 +42,12 @@
 import edu.uci.ics.asterix.metadata.entities.NodeGroup;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
-import edu.uci.ics.asterix.runtime.transaction.TreeResourceManager;
 import edu.uci.ics.asterix.transaction.management.exception.ACIDException;
 import edu.uci.ics.asterix.transaction.management.resource.TransactionalResourceRepository;
 import edu.uci.ics.asterix.transaction.management.service.logging.DataUtil;
+import edu.uci.ics.asterix.transaction.management.service.logging.TreeResourceManager;
 import edu.uci.ics.asterix.transaction.management.service.transaction.TransactionManagementConstants.LockManagerConstants.LockMode;
+import edu.uci.ics.hyracks.api.application.INCApplicationContext;
 import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparatorFactory;
 import edu.uci.ics.hyracks.api.dataflow.value.ITypeTraits;
 import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
@@ -77,7 +78,6 @@
  * stopUniverse() should be called upon application undeployment.
  */
 public class MetadataBootstrap {
-
     private static IBufferCache bufferCache;
     private static IFileMapProvider fileMapProvider;
     private static IndexRegistry<IIndex> btreeRegistry;
@@ -102,8 +102,10 @@
                 MetadataSecondaryIndexes.DATATYPENAME_ON_DATATYPE_INDEX };
     }
 
-    public static void startUniverse(AsterixProperties asterixProperities, IAsterixApplicationContextInfo appContext)
+    public static void startUniverse(AsterixProperties asterixProperties, INCApplicationContext ncApplicationContext)
             throws Exception {
+        AsterixAppRuntimeContext runtimeContext = (AsterixAppRuntimeContext) ncApplicationContext
+                .getApplicationObject();
 
         // Initialize static metadata objects, such as record types and metadata
         // index descriptors.
@@ -115,23 +117,25 @@
         initLocalIndexArrays();
 
         boolean isNewUniverse = true;
-        TransactionalResourceRepository.registerTransactionalResourceManager(TreeResourceManager.ID,
-                TreeResourceManager.getInstance());
+        TransactionalResourceRepository resourceRepository = runtimeContext.getTransactionProvider()
+                .getTransactionalResourceRepository();
+        resourceRepository.registerTransactionalResourceManager(TreeResourceManager.ID, new TreeResourceManager(
+                runtimeContext.getTransactionProvider()));
 
-        metadataNodeName = asterixProperities.getMetadataNodeName();
-        isNewUniverse = asterixProperities.isNewUniverse();
-        metadataStore = asterixProperities.getMetadataStore();
-        nodeNames = asterixProperities.getNodeNames();
+        metadataNodeName = asterixProperties.getMetadataNodeName();
+        isNewUniverse = asterixProperties.isNewUniverse();
+        metadataStore = asterixProperties.getMetadataStore();
+        nodeNames = asterixProperties.getNodeNames();
         // nodeStores = asterixProperity.getStores();
 
-        outputDir = asterixProperities.getOutputDir();
+        outputDir = asterixProperties.getOutputDir();
         if (outputDir != null) {
             (new File(outputDir)).mkdirs();
         }
 
-        btreeRegistry = appContext.getTreeRegisterProvider().getRegistry(null);
-        bufferCache = appContext.getStorageManagerInterface().getBufferCache(null);
-        fileMapProvider = appContext.getStorageManagerInterface().getFileMapProvider(null);
+        btreeRegistry = runtimeContext.getIndexRegistry();
+        bufferCache = runtimeContext.getBufferCache();
+        fileMapProvider = runtimeContext.getFileMapManager();
 
         // Create fileRefs to all BTree files and open them in BufferCache.
         for (int i = 0; i < primaryIndexes.length; i++) {
@@ -150,11 +154,11 @@
             if (isNewUniverse) {
                 for (int i = 0; i < primaryIndexes.length; i++) {
                     createIndex(primaryIndexes[i]);
-                    registerTransactionalResource(primaryIndexes[i]);
+                    registerTransactionalResource(primaryIndexes[i], resourceRepository);
                 }
                 for (int i = 0; i < secondaryIndexes.length; i++) {
                     createIndex(secondaryIndexes[i]);
-                    registerTransactionalResource(secondaryIndexes[i]);
+                    registerTransactionalResource(secondaryIndexes[i], resourceRepository);
                 }
                 insertInitialDataverses(mdTxnCtx);
                 insertInitialDatasets(mdTxnCtx);
@@ -166,11 +170,11 @@
             } else {
                 for (int i = 0; i < primaryIndexes.length; i++) {
                     enlistMetadataDataset(primaryIndexes[i]);
-                    registerTransactionalResource(primaryIndexes[i]);
+                    registerTransactionalResource(primaryIndexes[i], resourceRepository);
                 }
                 for (int i = 0; i < secondaryIndexes.length; i++) {
                     enlistMetadataDataset(secondaryIndexes[i]);
-                    registerTransactionalResource(secondaryIndexes[i]);
+                    registerTransactionalResource(secondaryIndexes[i], resourceRepository);
                 }
                 LOGGER.info("FINISHED ENLISTMENT OF METADATA B-TREES.");
             }
@@ -215,12 +219,13 @@
         index.setFileId(fileId);
     }
 
-    private static void registerTransactionalResource(IMetadataIndex index) throws ACIDException {
+    private static void registerTransactionalResource(IMetadataIndex index,
+            TransactionalResourceRepository resourceRepository) throws ACIDException {
         int fileId = index.getFileId();
         ITreeIndex treeIndex = (ITreeIndex) btreeRegistry.get(fileId);
         byte[] resourceId = DataUtil.intToByteArray(fileId);
-        TransactionalResourceRepository.registerTransactionalResource(resourceId, treeIndex);
-        index.initTreeLogger();
+        resourceRepository.registerTransactionalResource(resourceId, treeIndex);
+        index.initTreeLogger(treeIndex);
     }
 
     public static void insertInitialDataverses(MetadataTransactionContext mdTxnCtx) throws Exception {
@@ -308,8 +313,8 @@
         ITreeIndexFrameFactory interiorFrameFactory = new BTreeNSMInteriorFrameFactory(tupleWriterFactory);
         ITreeIndexMetaDataFrameFactory metaDataFrameFactory = new LIFOMetaDataFrameFactory();
         IFreePageManager freePageManager = new LinkedListFreePageManager(bufferCache, 0, metaDataFrameFactory);
-        BTree btree = new BTree(bufferCache, NoOpOperationCallback.INSTANCE, typeTraits.length, comparatorFactories, freePageManager, interiorFrameFactory,
-                leafFrameFactory);
+        BTree btree = new BTree(bufferCache, NoOpOperationCallback.INSTANCE, typeTraits.length, comparatorFactories,
+                freePageManager, interiorFrameFactory, leafFrameFactory);
         btree.create(fileId);
         btreeRegistry.register(fileId, btree);
     }
@@ -323,8 +328,8 @@
         ITreeIndexFrameFactory interiorFrameFactory = new BTreeNSMInteriorFrameFactory(tupleWriterFactory);
         ITreeIndexMetaDataFrameFactory metaDataFrameFactory = new LIFOMetaDataFrameFactory();
         IFreePageManager freePageManager = new LinkedListFreePageManager(bufferCache, 0, metaDataFrameFactory);
-        BTree btree = new BTree(bufferCache, NoOpOperationCallback.INSTANCE, typeTraits.length, comparatorFactories, freePageManager, interiorFrameFactory,
-                leafFrameFactory);
+        BTree btree = new BTree(bufferCache, NoOpOperationCallback.INSTANCE, typeTraits.length, comparatorFactories,
+                freePageManager, interiorFrameFactory, leafFrameFactory);
         btreeRegistry.register(fileId, btree);
     }
 
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/MetadataIndex.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/MetadataIndex.java
index fb55c55..165a605 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/MetadataIndex.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/MetadataIndex.java
@@ -27,15 +27,16 @@
 import edu.uci.ics.asterix.metadata.api.IMetadataIndex;
 import edu.uci.ics.asterix.om.types.ARecordType;
 import edu.uci.ics.asterix.om.types.IAType;
-import edu.uci.ics.asterix.runtime.transaction.TreeLogger;
 import edu.uci.ics.asterix.transaction.management.exception.ACIDException;
 import edu.uci.ics.asterix.transaction.management.service.logging.DataUtil;
+import edu.uci.ics.asterix.transaction.management.service.logging.TreeLogger;
 import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.OrderOperator.IOrder.OrderKind;
 import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparatorFactory;
 import edu.uci.ics.hyracks.api.dataflow.value.IBinaryHashFunctionFactory;
 import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
 import edu.uci.ics.hyracks.api.dataflow.value.ITypeTraits;
 import edu.uci.ics.hyracks.api.dataflow.value.RecordDescriptor;
+import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndex;
 
 /**
  * Descriptor for a primary or secondary index on metadata datasets.
@@ -201,8 +202,8 @@
     }
 
     @Override
-    public void initTreeLogger() throws ACIDException {
-        this.treeLogger = new TreeLogger(indexResourceId);
+    public void initTreeLogger(ITreeIndex treeIndex) throws ACIDException {
+        this.treeLogger = new TreeLogger(indexResourceId, treeIndex);
     }
 
     @Override
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlMetadataProvider.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlMetadataProvider.java
index 8df630b..4eb3456 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlMetadataProvider.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlMetadataProvider.java
@@ -436,7 +436,7 @@
 
 		BTreeSearchOperatorDescriptor btreeSearchOp = new BTreeSearchOperatorDescriptor(
 				jobSpec, recDesc, appContext.getStorageManagerInterface(),
-				appContext.getTreeRegisterProvider(), spPc.first,
+				appContext.getIndexRegistryProvider(), spPc.first,
 				typeTraits,
 				comparatorFactories, lowKeyFields, highKeyFields,
 				lowKeyInclusive, highKeyInclusive,
@@ -558,7 +558,7 @@
 
 		RTreeSearchOperatorDescriptor rtreeSearchOp = new RTreeSearchOperatorDescriptor(
 				jobSpec, recDesc, appContext.getStorageManagerInterface(),
-				appContext.getTreeRegisterProvider(), spPc.first,
+				appContext.getIndexRegistryProvider(), spPc.first,
 				typeTraits,
 				comparatorFactories, keyFields,
 				new RTreeDataflowHelperFactory(valueProviderFactories), NoOpOperationCallbackProvider.INSTANCE);
@@ -694,7 +694,7 @@
 
 		TreeIndexBulkLoadOperatorDescriptor btreeBulkLoad = new TreeIndexBulkLoadOperatorDescriptor(
 				spec, appContext.getStorageManagerInterface(),
-				appContext.getTreeRegisterProvider(),
+				appContext.getIndexRegistryProvider(),
 				splitsAndConstraint.first, typeTraits, comparatorFactories,
 				fieldPermutation, GlobalConfig.DEFAULT_BTREE_FILL_FACTOR,
 				new BTreeDataflowHelperFactory(),
@@ -752,7 +752,7 @@
 
 		TreeIndexInsertUpdateDeleteOperatorDescriptor btreeBulkLoad = new TreeIndexInsertUpdateDeleteOperatorDescriptor(
 				spec, recordDesc, appContext.getStorageManagerInterface(),
-				appContext.getTreeRegisterProvider(),
+				appContext.getIndexRegistryProvider(),
 				splitsAndConstraint.first, typeTraits, comparatorFactories,
 				fieldPermutation, IndexOp.INSERT,
 				new BTreeDataflowHelperFactory(),
@@ -810,7 +810,7 @@
 
 		TreeIndexInsertUpdateDeleteOperatorDescriptor btreeBulkLoad = new TreeIndexInsertUpdateDeleteOperatorDescriptor(
 				spec, recordDesc, appContext.getStorageManagerInterface(),
-				appContext.getTreeRegisterProvider(),
+				appContext.getIndexRegistryProvider(),
 				splitsAndConstraint.first, typeTraits, comparatorFactories,
 				fieldPermutation, IndexOp.DELETE,
 				new BTreeDataflowHelperFactory(),
@@ -950,7 +950,7 @@
 		}
 		TreeIndexInsertUpdateDeleteOperatorDescriptor btreeBulkLoad = new TreeIndexInsertUpdateDeleteOperatorDescriptor(
 				spec, recordDesc, appContext.getStorageManagerInterface(),
-				appContext.getTreeRegisterProvider(),
+				appContext.getIndexRegistryProvider(),
 				splitsAndConstraint.first, typeTraits, comparatorFactories,
 				fieldPermutation, indexOp, new BTreeDataflowHelperFactory(),
 				NoOpOperationCallbackProvider.INSTANCE, txnId);
@@ -1036,7 +1036,7 @@
 		}
 		TreeIndexInsertUpdateDeleteOperatorDescriptor rtreeUpdate = new TreeIndexInsertUpdateDeleteOperatorDescriptor(
 				spec, recordDesc, appContext.getStorageManagerInterface(),
-				appContext.getTreeRegisterProvider(),
+				appContext.getIndexRegistryProvider(),
 				splitsAndConstraint.first, typeTraits, comparatorFactories,
 				fieldPermutation, indexOp, new RTreeDataflowHelperFactory(
 						valueProviderFactories),
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/job/listener/JobEventListenerFactory.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/job/listener/JobEventListenerFactory.java
index 0a1faac..2d49982 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/job/listener/JobEventListenerFactory.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/job/listener/JobEventListenerFactory.java
@@ -1,9 +1,9 @@
 package edu.uci.ics.asterix.runtime.job.listener;
 
+import edu.uci.ics.asterix.common.context.AsterixAppRuntimeContext;
 import edu.uci.ics.asterix.transaction.management.exception.ACIDException;
 import edu.uci.ics.asterix.transaction.management.service.transaction.ITransactionManager;
 import edu.uci.ics.asterix.transaction.management.service.transaction.TransactionContext;
-import edu.uci.ics.asterix.transaction.management.service.transaction.TransactionProvider;
 import edu.uci.ics.asterix.transaction.management.service.transaction.TransactionContext.TransactionType;
 import edu.uci.ics.hyracks.api.context.IHyracksJobletContext;
 import edu.uci.ics.hyracks.api.job.IJobletEventListener;
@@ -28,9 +28,8 @@
             @Override
             public void jobletFinish(JobStatus jobStatus) {
                 try {
-                    TransactionProvider factory = (TransactionProvider) (jobletContext.getApplicationContext()
-                            .getApplicationObject());
-                    ITransactionManager txnManager = factory.getTransactionManager();
+                    ITransactionManager txnManager = ((AsterixAppRuntimeContext) jobletContext.getApplicationContext()
+                            .getApplicationObject()).getTransactionProvider().getTransactionManager();
                     TransactionContext txnContext = txnManager.getTransactionContext(txnId);
                     txnContext.setTransactionType(transactionalWrite ? TransactionType.READ_WRITE
                             : TransactionType.READ);
diff --git a/asterix-transactions/pom.xml b/asterix-transactions/pom.xml
index f646356..d7703fd 100644
--- a/asterix-transactions/pom.xml
+++ b/asterix-transactions/pom.xml
@@ -25,5 +25,12 @@
 	</build>
 
 	<dependencies>
+	    <dependency>
+  		<groupId>edu.uci.ics.hyracks</groupId>
+  		<artifactId>hyracks-storage-am-common</artifactId>
+  		<version>0.2.1-SNAPSHOT</version>
+  		<type>jar</type>
+  		<scope>compile</scope>
+  	</dependency>
 	</dependencies>
 </project>
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/resource/TransactionalResourceRepository.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/resource/TransactionalResourceRepository.java
index 586f6d6..25309e1 100644
--- a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/resource/TransactionalResourceRepository.java
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/resource/TransactionalResourceRepository.java
@@ -32,54 +32,36 @@
  */
 public class TransactionalResourceRepository {
 
-    private static Map<ByteBuffer, Object> resourceRepository = new HashMap<ByteBuffer, Object>(); // repository
-    // containing
-    // resources
-    // that
-    // participate
-    // in
-    // transactions
+    private Map<ByteBuffer, Object> resourceRepository = new HashMap<ByteBuffer, Object>(); // repository
 
-    private static Map<Byte, IResourceManager> resourceMgrRepository = new HashMap<Byte, IResourceManager>(); // repository
+    private Map<Byte, IResourceManager> resourceMgrRepository = new HashMap<Byte, IResourceManager>(); // repository
 
-    // containing
-    // resource
-    // managers
-
-    public static void registerTransactionalResource(byte[] resourceBytes, Object resource) {
+    public void registerTransactionalResource(byte[] resourceBytes, Object resource) {
+        // convert to ByteBuffer so that a byte[] can be used as a key in a hash map.
         ByteBuffer resourceId = ByteBuffer.wrap(resourceBytes); // need to
-        // convert to
-        // ByteBuffer so
-        // that a byte[]
-        // can be used
-        // as a key in a
-        // hash map.
+
         synchronized (resourceRepository) {
             if (resourceRepository.get(resourceId) == null) {
                 resourceRepository.put(resourceId, resource);
-                resourceRepository.notifyAll(); // notify all reader threads
-                // that are waiting to retrieve
-                // a resource from the
-                // repository
-
+                
+                // wake up threads waiting for the resource
+                resourceRepository.notifyAll();
             }
         }
     }
 
-    public static void registerTransactionalResourceManager(byte id, IResourceManager resourceMgr) {
+    public void registerTransactionalResourceManager(byte id, IResourceManager resourceMgr) {
         synchronized (resourceMgrRepository) {
             if (resourceMgrRepository.get(id) == null) {
                 resourceMgrRepository.put(id, resourceMgr);
-                resourceMgrRepository.notifyAll(); // notify all reader threads
-                // that are waiting to
-                // retrieve a resource
-                // manager from the
-                // repository
+                
+                // wake up threads waiting for the resource manager
+                resourceMgrRepository.notifyAll();
             }
         }
     }
 
-    public static Object getTransactionalResource(byte[] resourceIdBytes) {
+    public Object getTransactionalResource(byte[] resourceIdBytes) {
         ByteBuffer buffer = ByteBuffer.wrap(resourceIdBytes);
         synchronized (resourceRepository) {
             while (resourceRepository.get(buffer) == null) {
@@ -95,17 +77,8 @@
         }
     }
 
-    public static IResourceManager getTransactionalResourceMgr(byte id) {
+    public IResourceManager getTransactionalResourceMgr(byte id) {
         synchronized (resourceMgrRepository) {
-            while (resourceMgrRepository.get(id) == null) {
-                try {
-                    resourceMgrRepository.wait();
-                } catch (InterruptedException ie) {
-                    ie.printStackTrace();
-                    break; // the thread might be interrupted due to other
-                    // failures occurring elsewhere, break from the loop
-                }
-            }
             return resourceMgrRepository.get(id);
         }
 
diff --git a/asterix-hyracks-glue/src/main/java/edu/uci/ics/asterix/runtime/transaction/TreeLogger.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/TreeLogger.java
similarity index 91%
rename from asterix-hyracks-glue/src/main/java/edu/uci/ics/asterix/runtime/transaction/TreeLogger.java
rename to asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/TreeLogger.java
index e2b6509..3b923dd 100644
--- a/asterix-hyracks-glue/src/main/java/edu/uci/ics/asterix/runtime/transaction/TreeLogger.java
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/TreeLogger.java
@@ -12,7 +12,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package edu.uci.ics.asterix.runtime.transaction;
+package edu.uci.ics.asterix.transaction.management.service.logging;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -20,13 +20,6 @@
 
 import edu.uci.ics.asterix.transaction.management.exception.ACIDException;
 import edu.uci.ics.asterix.transaction.management.resource.ICloseable;
-import edu.uci.ics.asterix.transaction.management.resource.TransactionalResourceRepository;
-import edu.uci.ics.asterix.transaction.management.service.logging.DataUtil;
-import edu.uci.ics.asterix.transaction.management.service.logging.ILogger;
-import edu.uci.ics.asterix.transaction.management.service.logging.LogActionType;
-import edu.uci.ics.asterix.transaction.management.service.logging.LogType;
-import edu.uci.ics.asterix.transaction.management.service.logging.LogUtil;
-import edu.uci.ics.asterix.transaction.management.service.logging.LogicalLogLocator;
 import edu.uci.ics.asterix.transaction.management.service.transaction.TransactionContext;
 import edu.uci.ics.asterix.transaction.management.service.transaction.TransactionProvider;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.ITupleReference;
@@ -121,9 +114,9 @@
         public static final byte DELETE = 1;
     }
 
-    public TreeLogger(byte[] resourceIdBytes) {
+    public TreeLogger(byte[] resourceIdBytes, ITreeIndex treeIndex) {
         this.resourceIdBytes = resourceIdBytes;
-        treeIndex = (ITreeIndex) TransactionalResourceRepository.getTransactionalResource(resourceIdBytes);
+        this.treeIndex = treeIndex;
         treeIndexTupleWriter = treeIndex.getLeafFrameFactory().getTupleWriterFactory().createTupleWriter();
         this.resourceIdLengthBytes = DataUtil.intToByteArray(resourceIdBytes.length);
     }
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/TreeLoggerRepository.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/TreeLoggerRepository.java
new file mode 100644
index 0000000..34e1466
--- /dev/null
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/TreeLoggerRepository.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2009-2011 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.asterix.transaction.management.service.logging;
+
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.Map;
+
+import edu.uci.ics.asterix.transaction.management.service.transaction.TransactionProvider;
+import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndex;
+
+public class TreeLoggerRepository {
+
+    private final Map<ByteBuffer, TreeLogger> loggers = new HashMap<ByteBuffer, TreeLogger>();
+    private final TransactionProvider provider;
+
+    public TreeLoggerRepository(TransactionProvider provider) {
+        this.provider = provider;
+    }
+
+    public synchronized TreeLogger getTreeLogger(byte[] resourceIdBytes) {
+        ByteBuffer resourceId = ByteBuffer.wrap(resourceIdBytes);
+        TreeLogger logger = loggers.get(resourceId);
+        if (logger == null) {
+            ITreeIndex treeIndex = (ITreeIndex) provider.getTransactionalResourceRepository().getTransactionalResource(
+                    resourceIdBytes);
+            logger = new TreeLogger(resourceIdBytes, treeIndex);
+            loggers.put(resourceId, logger);
+        }
+        return logger;
+    }
+}
\ No newline at end of file
diff --git a/asterix-hyracks-glue/src/main/java/edu/uci/ics/asterix/runtime/transaction/TreeResourceManager.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/TreeResourceManager.java
similarity index 81%
rename from asterix-hyracks-glue/src/main/java/edu/uci/ics/asterix/runtime/transaction/TreeResourceManager.java
rename to asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/TreeResourceManager.java
index 4309618..7c6d05a 100644
--- a/asterix-hyracks-glue/src/main/java/edu/uci/ics/asterix/runtime/transaction/TreeResourceManager.java
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/logging/TreeResourceManager.java
@@ -12,14 +12,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package edu.uci.ics.asterix.runtime.transaction;
+package edu.uci.ics.asterix.transaction.management.service.logging;
 
 import edu.uci.ics.asterix.transaction.management.exception.ACIDException;
-import edu.uci.ics.asterix.transaction.management.resource.TransactionalResourceRepository;
-import edu.uci.ics.asterix.transaction.management.service.logging.DataUtil;
-import edu.uci.ics.asterix.transaction.management.service.logging.ILogRecordHelper;
-import edu.uci.ics.asterix.transaction.management.service.logging.LogicalLogLocator;
 import edu.uci.ics.asterix.transaction.management.service.transaction.IResourceManager;
+import edu.uci.ics.asterix.transaction.management.service.transaction.TransactionProvider;
 import edu.uci.ics.hyracks.storage.am.common.api.IIndexAccessor;
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndex;
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexTupleReference;
@@ -28,13 +25,10 @@
 
     public static final byte ID = (byte) 1;
 
-    private static final TreeResourceManager treeResourceMgr = new TreeResourceManager();
+    private final TransactionProvider provider;
 
-    private TreeResourceManager() {
-    }
-
-    public static TreeResourceManager getInstance() {
-        return treeResourceMgr;
+    public TreeResourceManager(TransactionProvider provider) {
+        this.provider = provider;
     }
 
     public byte getResourceManagerId() {
@@ -53,7 +47,8 @@
         System.arraycopy(logBufferContent, logContentBeginPos + 4, resourceIdBytes, 0, resourceIdLength);
 
         // look up the repository to obtain the resource object
-        ITreeIndex treeIndex = (ITreeIndex) TransactionalResourceRepository.getTransactionalResource(resourceIdBytes);
+        ITreeIndex treeIndex = (ITreeIndex) provider.getTransactionalResourceRepository().getTransactionalResource(
+                resourceIdBytes);
         int operationOffset = logContentBeginPos + 4 + resourceIdLength;
         int tupleBeginPos = operationOffset + 1;
 
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/recovery/RecoveryManager.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/recovery/RecoveryManager.java
index 085a9da..9c78b95 100644
--- a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/recovery/RecoveryManager.java
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/recovery/RecoveryManager.java
@@ -110,7 +110,7 @@
                     break;
                 }
                 byte resourceMgrId = parser.getResourceMgrId(memLSN);
-                IResourceManager resourceMgr = TransactionalResourceRepository
+                IResourceManager resourceMgr = transactionProvider.getTransactionalResourceRepository()
                         .getTransactionalResourceMgr(resourceMgrId);
                 if (resourceMgr == null) {
                     throw new ACIDException("unknown resource mgr with id " + resourceMgrId);
@@ -217,7 +217,7 @@
                     }
 
                     // look up the repository to get the resource manager
-                    IResourceManager resourceMgr = TransactionalResourceRepository
+                    IResourceManager resourceMgr = transactionProvider.getTransactionalResourceRepository()
                             .getTransactionalResourceMgr(resourceMgrId);
                     if (resourceMgr == null) {
                         throw new ACIDException(txnContext, " unknown resource manager " + resourceMgrId);
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/transaction/TransactionProvider.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/transaction/TransactionProvider.java
index ede93a7..ef843f4 100644
--- a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/transaction/TransactionProvider.java
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/transaction/TransactionProvider.java
@@ -15,10 +15,12 @@
 package edu.uci.ics.asterix.transaction.management.service.transaction;
 
 import edu.uci.ics.asterix.transaction.management.exception.ACIDException;
+import edu.uci.ics.asterix.transaction.management.resource.TransactionalResourceRepository;
 import edu.uci.ics.asterix.transaction.management.service.locking.ILockManager;
 import edu.uci.ics.asterix.transaction.management.service.locking.LockManager;
 import edu.uci.ics.asterix.transaction.management.service.logging.ILogManager;
 import edu.uci.ics.asterix.transaction.management.service.logging.LogManager;
+import edu.uci.ics.asterix.transaction.management.service.logging.TreeLoggerRepository;
 import edu.uci.ics.asterix.transaction.management.service.recovery.IRecoveryManager;
 import edu.uci.ics.asterix.transaction.management.service.recovery.RecoveryManager;
 
@@ -32,13 +34,17 @@
     private final ILockManager lockManager;
     private final ITransactionManager transactionManager;
     private final IRecoveryManager recoveryManager;
+    private final TransactionalResourceRepository resourceRepository;
+    private final TreeLoggerRepository loggerRepository;
 
     public TransactionProvider(String id) throws ACIDException {
         this.id = id;
-        transactionManager = new TransactionManager(this);
-        logManager = new LogManager(this);
-        lockManager = new LockManager(this);
-        recoveryManager = new RecoveryManager(this);
+        this.transactionManager = new TransactionManager(this);
+        this.logManager = new LogManager(this);
+        this.lockManager = new LockManager(this);
+        this.recoveryManager = new RecoveryManager(this);
+        this.loggerRepository = new TreeLoggerRepository(this);
+        this.resourceRepository = new TransactionalResourceRepository();
     }
 
     public ILogManager getLogManager() {
@@ -56,6 +62,14 @@
     public IRecoveryManager getRecoveryManager() {
         return recoveryManager;
     }
+    
+    public TransactionalResourceRepository getTransactionalResourceRepository() {
+        return resourceRepository;
+    }
+    
+    public TreeLoggerRepository getTreeLoggerRepository() {
+        return loggerRepository;
+    }
 
     public String getId() {
         return id;
diff --git a/asterix-transactions/src/test/java/edu/uci/ics/asterix/transaction/management/logging/test/TransactionWorkloadSimulator.java b/asterix-transactions/src/test/java/edu/uci/ics/asterix/transaction/management/logging/test/TransactionWorkloadSimulator.java
index 40ee93f..496260d 100644
--- a/asterix-transactions/src/test/java/edu/uci/ics/asterix/transaction/management/logging/test/TransactionWorkloadSimulator.java
+++ b/asterix-transactions/src/test/java/edu/uci/ics/asterix/transaction/management/logging/test/TransactionWorkloadSimulator.java
@@ -51,7 +51,7 @@
         provider = new TransactionProvider("nc1");
         logManager = provider.getLogManager();
         lockManager = provider.getLockManager();
-        TransactionalResourceRepository.registerTransactionalResourceManager(DummyResourceMgr.id,
+        provider.getTransactionalResourceRepository().registerTransactionalResourceManager(DummyResourceMgr.id,
                 new DummyResourceMgr());
         Transaction[] transactions = new Transaction[workload.numActiveThreads];
         long startTime = System.nanoTime();
diff --git a/asterix-transactions/src/test/java/edu/uci/ics/asterix/transaction/management/test/TransactionSimulator.java b/asterix-transactions/src/test/java/edu/uci/ics/asterix/transaction/management/test/TransactionSimulator.java
index fb198fe..ffa5af6 100644
--- a/asterix-transactions/src/test/java/edu/uci/ics/asterix/transaction/management/test/TransactionSimulator.java
+++ b/asterix-transactions/src/test/java/edu/uci/ics/asterix/transaction/management/test/TransactionSimulator.java
@@ -54,8 +54,8 @@
         logManager = transactionProvider.getLogManager();
         lockManager = transactionProvider.getLockManager();
         recoveryManager = transactionProvider.getRecoveryManager();
-        TransactionalResourceRepository.registerTransactionalResourceManager(resourceMgr.getResourceManagerId(),
-                resourceMgr);
+        transactionProvider.getTransactionalResourceRepository().registerTransactionalResourceManager(
+                resourceMgr.getResourceManagerId(), resourceMgr);
         this.resourceMgr = resourceMgr;
         this.logger = resource.getLogger();
         this.resource = resource;