ASTERIXDB-1053: change IndexLifecycleManager API to use resource name

Change-Id: I2e8e974fc2f746959639ce94351f8e419a7f9093
Reviewed-on: https://asterix-gerrit.ics.uci.edu/343
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>
diff --git a/hyracks/hyracks-examples/btree-example/btreehelper/src/main/java/org/apache/hyracks/examples/btree/helper/RuntimeContext.java b/hyracks/hyracks-examples/btree-example/btreehelper/src/main/java/org/apache/hyracks/examples/btree/helper/RuntimeContext.java
index 0f96c19..6fde446 100644
--- a/hyracks/hyracks-examples/btree-example/btreehelper/src/main/java/org/apache/hyracks/examples/btree/helper/RuntimeContext.java
+++ b/hyracks/hyracks-examples/btree-example/btreehelper/src/main/java/org/apache/hyracks/examples/btree/helper/RuntimeContext.java
@@ -60,10 +60,10 @@
         IPageReplacementStrategy prs = new ClockPageReplacementStrategy(allocator, 32768, 50);
         bufferCache = new BufferCache(appCtx.getRootContext().getIOManager(), prs, new DelayPageCleanerPolicy(1000),
                 fileMapManager, 100, threadFactory);
-        lcManager = new IndexLifecycleManager();
         ILocalResourceRepositoryFactory localResourceRepositoryFactory = new TransientLocalResourceRepositoryFactory();
         localResourceRepository = localResourceRepositoryFactory.createRepository();
         resourceIdFactory = (new ResourceIdFactoryProvider(localResourceRepository)).createResourceIdFactory();
+        lcManager = new IndexLifecycleManager(localResourceRepository);
     }
 
     public void close() throws HyracksDataException {
diff --git a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/IIndexDataflowHelper.java b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/IIndexDataflowHelper.java
index 0906efe..81d7834 100644
--- a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/IIndexDataflowHelper.java
+++ b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/IIndexDataflowHelper.java
@@ -36,6 +36,8 @@
     public FileReference getFileReference();
 
     public long getResourceID() throws HyracksDataException;
-    
+
     public IHyracksTaskContext getTaskContext();
+
+    public String getResourceName();
 }
diff --git a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/IIndexLifecycleManager.java b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/IIndexLifecycleManager.java
index ad0fcef..41eb5d5 100644
--- a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/IIndexLifecycleManager.java
+++ b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/IIndexLifecycleManager.java
@@ -23,16 +23,17 @@
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 
 public interface IIndexLifecycleManager {
-    public IIndex getIndex(long resourceID) throws HyracksDataException;
-
-    public void register(long resourceID, IIndex index) throws HyracksDataException;
-
-    public void unregister(long resourceID) throws HyracksDataException;
-
-    public void open(long resourceID) throws HyracksDataException;
-
-    public void close(long resourceID) throws HyracksDataException;
-
     public List<IIndex> getOpenIndexes();
-    
+
+    public void register(String resourceName, IIndex index) throws HyracksDataException;
+
+    public void open(String resourceName) throws HyracksDataException;
+
+    public void close(String resourceName) throws HyracksDataException;
+
+    public IIndex getIndex(String resourceName) throws HyracksDataException;
+
+    public void unregister(String resourceName) throws HyracksDataException;
+
+    public IIndex getIndex(int datasetID, long resourceID) throws HyracksDataException;
 }
\ No newline at end of file
diff --git a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/IModificationOperationCallbackFactory.java b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/IModificationOperationCallbackFactory.java
index 9d8093f..212190c 100644
--- a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/IModificationOperationCallbackFactory.java
+++ b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/api/IModificationOperationCallbackFactory.java
@@ -24,6 +24,6 @@
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 
 public interface IModificationOperationCallbackFactory extends Serializable {
-    public IModificationOperationCallback createModificationOperationCallback(long resourceId, Object resource, IHyracksTaskContext ctx)
-            throws HyracksDataException;
+    public IModificationOperationCallback createModificationOperationCallback(String resourceName, long resourceId,
+            Object resource, IHyracksTaskContext ctx) throws HyracksDataException;
 }
diff --git a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexDataflowHelper.java b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexDataflowHelper.java
index 932994d..2b6b208 100644
--- a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexDataflowHelper.java
+++ b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexDataflowHelper.java
@@ -45,7 +45,7 @@
     protected final int partition;
     protected final int ioDeviceId;
     protected final boolean durable;
-
+    protected final String resourceName;
     protected IIndex index;
 
     public IndexDataflowHelper(IIndexOperatorDescriptor opDesc, final IHyracksTaskContext ctx, int partition,
@@ -60,6 +60,7 @@
         this.file = new FileReference(new File(IndexFileNameUtil.prepareFileName(opDesc.getFileSplitProvider()
                 .getFileSplits()[partition].getLocalFile().getFile().getPath(), ioDeviceId)));
         this.durable = durable;
+        this.resourceName = file.getFile().getPath();
     }
 
     protected abstract IIndex createIndexInstance() throws HyracksDataException;
@@ -72,10 +73,9 @@
     @Override
     public void create() throws HyracksDataException {
         synchronized (lcManager) {
-            long resourceID = getResourceID();
-            index = lcManager.getIndex(resourceID);
+            index = lcManager.getIndex(resourceName);
             if (index != null) {
-                lcManager.unregister(resourceID);
+                lcManager.unregister(resourceName);
             } else {
                 index = createIndexInstance();
             }
@@ -83,62 +83,59 @@
             // The previous resource ID needs to be removed since calling IIndex.create() may possibly destroy 
             // any physical artifact that the LocalResourceRepository is managing (e.g. a file containing the resource ID). 
             // Once the index has been created, a new resource ID can be generated.
+            long resourceID = getResourceID();
             if (resourceID != -1) {
-                localResourceRepository.deleteResourceByName(file.getFile().getPath());
+                localResourceRepository.deleteResourceByName(resourceName);
             }
             index.create();
             try {
-                //TODO Create LocalResource through LocalResourceFactory interface
                 resourceID = resourceIdFactory.createId();
                 ILocalResourceFactory localResourceFactory = opDesc.getLocalResourceFactoryProvider()
                         .getLocalResourceFactory();
-                localResourceRepository.insert(localResourceFactory.createLocalResource(resourceID, file.getFile()
-                        .getPath(), partition));
+                localResourceRepository.insert(localResourceFactory.createLocalResource(resourceID, resourceName,
+                        partition));
             } catch (IOException e) {
                 throw new HyracksDataException(e);
             }
-            lcManager.register(resourceID, index);
+            lcManager.register(resourceName, index);
         }
     }
 
     @Override
     public void open() throws HyracksDataException {
         synchronized (lcManager) {
-            long resourceID = getResourceID();
-
-            if (resourceID == -1) {
+            if (getResourceID() == -1) {
                 throw new HyracksDataException("Index does not have a valid resource ID. Has it been created yet?");
             }
 
-            index = lcManager.getIndex(resourceID);
+            index = lcManager.getIndex(resourceName);
             if (index == null) {
                 index = createIndexInstance();
-                lcManager.register(resourceID, index);
+                lcManager.register(resourceName, index);
             }
-            lcManager.open(resourceID);
+            lcManager.open(resourceName);
         }
     }
 
     @Override
     public void close() throws HyracksDataException {
         synchronized (lcManager) {
-            lcManager.close(getResourceID());
+            lcManager.close(resourceName);
         }
     }
 
     @Override
     public void destroy() throws HyracksDataException {
         synchronized (lcManager) {
-            long resourceID = getResourceID();
-            index = lcManager.getIndex(resourceID);
+            index = lcManager.getIndex(resourceName);
             if (index != null) {
-                lcManager.unregister(resourceID);
+                lcManager.unregister(resourceName);
             } else {
                 index = createIndexInstance();
             }
 
-            if (resourceID != -1) {
-                localResourceRepository.deleteResourceByName(file.getFile().getPath());
+            if (getResourceID() != -1) {
+                localResourceRepository.deleteResourceByName(resourceName);
             }
             index.destroy();
         }
@@ -151,16 +148,17 @@
 
     @Override
     public long getResourceID() throws HyracksDataException {
-        LocalResource localResource = localResourceRepository.getResourceByName(file.getFile().getPath());
-        if (localResource == null) {
-            return -1;
-        } else {
-            return localResource.getResourceId();
-        }
+        LocalResource lr = localResourceRepository.getResourceByName(resourceName);
+        return lr == null ? -1 : lr.getResourceId();
     }
 
     @Override
     public IHyracksTaskContext getTaskContext() {
         return ctx;
     }
+
+    @Override
+    public String getResourceName() {
+        return resourceName;
+    }
 }
\ No newline at end of file
diff --git a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexInsertUpdateDeleteOperatorNodePushable.java b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexInsertUpdateDeleteOperatorNodePushable.java
index da32f87..4434871 100644
--- a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexInsertUpdateDeleteOperatorNodePushable.java
+++ b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexInsertUpdateDeleteOperatorNodePushable.java
@@ -75,7 +75,7 @@
         indexHelper.open();
         IIndex index = indexHelper.getIndexInstance();
         try {
-            modCallback = opDesc.getModificationOpCallbackFactory().createModificationOperationCallback(
+            modCallback = opDesc.getModificationOpCallbackFactory().createModificationOperationCallback(indexHelper.getResourceName(),
                     indexHelper.getResourceID(), index, ctx);
             indexAccessor = index.createAccessor(modCallback, NoOpOperationCallback.INSTANCE);
             ITupleFilterFactory tupleFilterFactory = opDesc.getTupleFilterFactory();
diff --git a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexLifecycleManager.java b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexLifecycleManager.java
index b3213d1..00ae8c2 100644
--- a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexLifecycleManager.java
+++ b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexLifecycleManager.java
@@ -30,20 +30,23 @@
 import org.apache.hyracks.api.lifecycle.ILifeCycleComponent;
 import org.apache.hyracks.storage.am.common.api.IIndex;
 import org.apache.hyracks.storage.am.common.api.IIndexLifecycleManager;
+import org.apache.hyracks.storage.common.file.ILocalResourceRepository;
+import org.apache.hyracks.storage.common.file.LocalResource;
 
 public class IndexLifecycleManager implements IIndexLifecycleManager, ILifeCycleComponent {
     private static final long DEFAULT_MEMORY_BUDGET = 1024 * 1024 * 100; // 100 megabytes
 
     private final Map<Long, IndexInfo> indexInfos;
     private final long memoryBudget;
-
+    private final ILocalResourceRepository localResourcesRepository;
     private long memoryUsed;
 
-    public IndexLifecycleManager() {
-        this(DEFAULT_MEMORY_BUDGET);
+    public IndexLifecycleManager(ILocalResourceRepository localResourcesRepository) {
+        this(localResourcesRepository, DEFAULT_MEMORY_BUDGET);
     }
 
-    public IndexLifecycleManager(long memoryBudget) {
+    public IndexLifecycleManager(ILocalResourceRepository localResourcesRepository, long memoryBudget) {
+        this.localResourcesRepository = localResourcesRepository;
         this.indexInfos = new HashMap<Long, IndexInfo>();
         this.memoryBudget = memoryBudget;
         this.memoryUsed = 0;
@@ -67,66 +70,6 @@
         return true;
     }
 
-    @Override
-    public IIndex getIndex(long resourceID) {
-        IndexInfo info = indexInfos.get(resourceID);
-        return info == null ? null : info.index;
-    }
-
-    @Override
-    public void register(long resourceID, IIndex index) throws HyracksDataException {
-        if (indexInfos.containsKey(resourceID)) {
-            throw new HyracksDataException("Index with resource ID " + resourceID + " already exists.");
-        }
-
-        indexInfos.put(resourceID, new IndexInfo(index));
-    }
-
-    @Override
-    public void unregister(long resourceID) throws HyracksDataException {
-        IndexInfo info = indexInfos.remove(resourceID);
-        if (info == null) {
-            throw new HyracksDataException("Index with resource ID " + resourceID + " does not exist.");
-        }
-
-        if (info.referenceCount != 0) {
-            indexInfos.put(resourceID, info);
-            throw new HyracksDataException("Cannot remove index while it is open.");
-        }
-
-        if (info.isOpen) {
-            info.index.deactivate();
-            memoryUsed -= info.index.getMemoryAllocationSize();
-        }
-    }
-
-    @Override
-    public void open(long resourceID) throws HyracksDataException {
-        IndexInfo info = indexInfos.get(resourceID);
-        if (info == null) {
-            throw new HyracksDataException("Failed to open index with resource ID " + resourceID
-                    + " since it does not exist.");
-        }
-
-        if (!info.isOpen) {
-            long inMemorySize = info.index.getMemoryAllocationSize();
-            while (memoryUsed + inMemorySize > memoryBudget) {
-                if (!evictCandidateIndex()) {
-                    throw new HyracksDataException("Cannot activate index since memory budget would be exceeded.");
-                }
-            }
-            info.index.activate();
-            info.isOpen = true;
-            memoryUsed += inMemorySize;
-        }
-        info.touch();
-    }
-
-    @Override
-    public void close(long resourceID) {
-        indexInfos.get(resourceID).untouch();
-    }
-
     private class IndexInfo implements Comparable<IndexInfo> {
         private final IIndex index;
         private int referenceCount;
@@ -235,4 +178,79 @@
         }
         os.write(sb.toString().getBytes());
     }
+
+    @Override
+    public void register(String resourceName, IIndex index) throws HyracksDataException {
+        long resourceID = getResourceID(resourceName);
+        if (indexInfos.containsKey(resourceID)) {
+            throw new HyracksDataException("Index with resource ID " + resourceID + " already exists.");
+        }
+
+        indexInfos.put(resourceID, new IndexInfo(index));
+    }
+
+    @Override
+    public void open(String resourceName) throws HyracksDataException {
+        long resourceID = getResourceID(resourceName);
+        IndexInfo info = indexInfos.get(resourceID);
+        if (info == null) {
+            throw new HyracksDataException("Failed to open index with resource ID " + resourceID
+                    + " since it does not exist.");
+        }
+
+        if (!info.isOpen) {
+            long inMemorySize = info.index.getMemoryAllocationSize();
+            while (memoryUsed + inMemorySize > memoryBudget) {
+                if (!evictCandidateIndex()) {
+                    throw new HyracksDataException("Cannot activate index since memory budget would be exceeded.");
+                }
+            }
+            info.index.activate();
+            info.isOpen = true;
+            memoryUsed += inMemorySize;
+        }
+        info.touch();
+    }
+
+    @Override
+    public void close(String resourceName) throws HyracksDataException {
+        long resourceID = getResourceID(resourceName);
+        indexInfos.get(resourceID).untouch();
+    }
+
+    @Override
+    public IIndex getIndex(String resourceName) throws HyracksDataException {
+        long resourceID = getResourceID(resourceName);
+        IndexInfo info = indexInfos.get(resourceID);
+        return info == null ? null : info.index;
+    }
+
+    @Override
+    public void unregister(String resourceName) throws HyracksDataException {
+        long resourceID = getResourceID(resourceName);
+        IndexInfo info = indexInfos.remove(resourceID);
+        if (info == null) {
+            throw new HyracksDataException("Index with resource ID " + resourceID + " does not exist.");
+        }
+
+        if (info.referenceCount != 0) {
+            indexInfos.put(resourceID, info);
+            throw new HyracksDataException("Cannot remove index while it is open.");
+        }
+
+        if (info.isOpen) {
+            info.index.deactivate();
+            memoryUsed -= info.index.getMemoryAllocationSize();
+        }
+    }
+
+    private long getResourceID(String resourceName) throws HyracksDataException {
+        LocalResource lr = localResourcesRepository.getResourceByName(resourceName);
+        return lr == null ? -1 : lr.getResourceId();
+    }
+
+    @Override
+    public IIndex getIndex(int datasetID, long resourceID) throws HyracksDataException {
+        throw new UnsupportedOperationException();
+    }
 }
\ No newline at end of file
diff --git a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/impls/NoOpOperationCallbackFactory.java b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/impls/NoOpOperationCallbackFactory.java
index 4f855e4..076f7f8 100644
--- a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/impls/NoOpOperationCallbackFactory.java
+++ b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/impls/NoOpOperationCallbackFactory.java
@@ -19,6 +19,7 @@
 package org.apache.hyracks.storage.am.common.impls;
 
 import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.storage.am.common.api.IModificationOperationCallback;
 import org.apache.hyracks.storage.am.common.api.IModificationOperationCallbackFactory;
 import org.apache.hyracks.storage.am.common.api.ISearchOperationCallback;
@@ -33,12 +34,13 @@
     INSTANCE;
 
     @Override
-    public IModificationOperationCallback createModificationOperationCallback(long resourceId, Object resource, IHyracksTaskContext ctx) {
+    public ISearchOperationCallback createSearchOperationCallback(long resourceId, IHyracksTaskContext ctx) {
         return NoOpOperationCallback.INSTANCE;
     }
 
     @Override
-    public ISearchOperationCallback createSearchOperationCallback(long resourceId, IHyracksTaskContext ctx) {
+    public IModificationOperationCallback createModificationOperationCallback(String resourceName, long resourceId,
+            Object resource, IHyracksTaskContext ctx) throws HyracksDataException {
         return NoOpOperationCallback.INSTANCE;
     }
 }
diff --git a/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeDataflowHelper.java b/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeDataflowHelper.java
index 45522ce..0e23fa4 100644
--- a/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeDataflowHelper.java
+++ b/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeDataflowHelper.java
@@ -40,8 +40,7 @@
     public ExternalBTreeDataflowHelper(IIndexOperatorDescriptor opDesc, IHyracksTaskContext ctx, int partition,
             double bloomFilterFalsePositiveRate, ILSMMergePolicy mergePolicy,
             ILSMOperationTrackerProvider opTrackerFactory, ILSMIOOperationScheduler ioScheduler,
-            ILSMIOOperationCallbackFactory ioOpCallbackFactory, boolean needKeyDupCheck, int version,
-            boolean durable) {
+            ILSMIOOperationCallbackFactory ioOpCallbackFactory, boolean needKeyDupCheck, int version, boolean durable) {
         super(opDesc, ctx, partition, null, bloomFilterFalsePositiveRate, mergePolicy, opTrackerFactory, ioScheduler,
                 ioOpCallbackFactory, false, null, null, null, null, durable);
         this.version = version;
@@ -50,8 +49,7 @@
     public ExternalBTreeDataflowHelper(IIndexOperatorDescriptor opDesc, IHyracksTaskContext ctx, int partition,
             List<IVirtualBufferCache> virtualBufferCaches, ILSMMergePolicy mergePolicy,
             ILSMOperationTrackerProvider opTrackerFactory, ILSMIOOperationScheduler ioScheduler,
-            ILSMIOOperationCallbackFactory ioOpCallbackFactory, boolean needKeyDupCheck, int version,
-            boolean durable) {
+            ILSMIOOperationCallbackFactory ioOpCallbackFactory, boolean needKeyDupCheck, int version, boolean durable) {
         this(opDesc, ctx, partition, DEFAULT_BLOOM_FILTER_FALSE_POSITIVE_RATE, mergePolicy, opTrackerFactory,
                 ioScheduler, ioOpCallbackFactory, needKeyDupCheck, version, durable);
     }
@@ -61,14 +59,8 @@
         if (index != null)
             return index;
         synchronized (lcManager) {
-            long resourceID;
             try {
-                resourceID = getResourceID();
-            } catch (HyracksDataException e) {
-                return null;
-            }
-            try {
-                index = lcManager.getIndex(resourceID);
+                index = lcManager.getIndex(resourceName);
             } catch (HyracksDataException e) {
                 return null;
             }
diff --git a/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeWithBuddyDataflowHelper.java b/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeWithBuddyDataflowHelper.java
index a5d4892..325ff91 100644
--- a/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeWithBuddyDataflowHelper.java
+++ b/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeWithBuddyDataflowHelper.java
@@ -48,8 +48,7 @@
     public ExternalBTreeWithBuddyDataflowHelper(IIndexOperatorDescriptor opDesc, IHyracksTaskContext ctx,
             int partition, double bloomFilterFalsePositiveRate, ILSMMergePolicy mergePolicy,
             ILSMOperationTrackerProvider opTrackerFactory, ILSMIOOperationScheduler ioScheduler,
-            ILSMIOOperationCallbackFactory ioOpCallbackFactory, int[] buddyBtreeFields, int version,
-            boolean durable) {
+            ILSMIOOperationCallbackFactory ioOpCallbackFactory, int[] buddyBtreeFields, int version, boolean durable) {
         super(opDesc, ctx, partition, null, bloomFilterFalsePositiveRate, mergePolicy, opTrackerFactory, ioScheduler,
                 ioOpCallbackFactory, null, null, null, durable);
         this.buddyBtreeFields = buddyBtreeFields;
@@ -61,14 +60,8 @@
         if (index != null)
             return index;
         synchronized (lcManager) {
-            long resourceID;
             try {
-                resourceID = getResourceID();
-            } catch (HyracksDataException e) {
-                return null;
-            }
-            try {
-                index = lcManager.getIndex(resourceID);
+                index = lcManager.getIndex(resourceName);
             } catch (HyracksDataException e) {
                 return null;
             }
diff --git a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/dataflow/ExternalRTreeDataflowHelper.java b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/dataflow/ExternalRTreeDataflowHelper.java
index e8c918a..b6f5941 100644
--- a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/dataflow/ExternalRTreeDataflowHelper.java
+++ b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/dataflow/ExternalRTreeDataflowHelper.java
@@ -75,14 +75,8 @@
         if (index != null)
             return index;
         synchronized (lcManager) {
-            long resourceID;
             try {
-                resourceID = getResourceID();
-            } catch (HyracksDataException e) {
-                return null;
-            }
-            try {
-                index = lcManager.getIndex(resourceID);
+                index = lcManager.getIndex(resourceName);
             } catch (HyracksDataException e) {
                 return null;
             }
@@ -99,11 +93,11 @@
             ITypeTraits[] filterTypeTraits, IBinaryComparatorFactory[] filterCmpFactories, int[] filterFields)
             throws HyracksDataException {
         try {
-            return LSMRTreeUtils.createExternalRTree(file, diskBufferCache, diskFileMapProvider, typeTraits,
-                    rtreeCmpFactories, btreeCmpFactories, valueProviderFactories, rtreePolicyType,
-                    bloomFilterFalsePositiveRate, mergePolicy, opTracker, ioScheduler,
-                    ioOpCallbackFactory.createIOOperationCallback(), linearizeCmpFactory, btreeFields, version,
-                    durable);
+            return LSMRTreeUtils
+                    .createExternalRTree(file, diskBufferCache, diskFileMapProvider, typeTraits, rtreeCmpFactories,
+                            btreeCmpFactories, valueProviderFactories, rtreePolicyType, bloomFilterFalsePositiveRate,
+                            mergePolicy, opTracker, ioScheduler, ioOpCallbackFactory.createIOOperationCallback(),
+                            linearizeCmpFactory, btreeFields, version, durable);
         } catch (TreeIndexException e) {
             throw new HyracksDataException(e);
         }
diff --git a/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/ILocalResourceRepository.java b/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/ILocalResourceRepository.java
index a826226..6f2e285 100644
--- a/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/ILocalResourceRepository.java
+++ b/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/ILocalResourceRepository.java
@@ -18,21 +18,15 @@
  */
 package org.apache.hyracks.storage.common.file;
 
-import java.util.List;
-
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 
 public interface ILocalResourceRepository {
 
-    public LocalResource getResourceById(long id) throws HyracksDataException;
-
     public LocalResource getResourceByName(String name) throws HyracksDataException;
 
     public void insert(LocalResource resource) throws HyracksDataException;
 
-    public void deleteResourceById(long id) throws HyracksDataException;
-
     public void deleteResourceByName(String name) throws HyracksDataException;
 
-    public List<LocalResource> getAllResources() throws HyracksDataException;
+    public long getMaxResourceID() throws HyracksDataException;
 }
diff --git a/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/ResourceIdFactory.java b/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/ResourceIdFactory.java
index 3b5ea03..0adf998 100644
--- a/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/ResourceIdFactory.java
+++ b/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/ResourceIdFactory.java
@@ -30,8 +30,4 @@
     public long createId() {
         return id.getAndIncrement();
     }
-    
-    public void initId(long id) {
-        this.id.set(id);
-    }
 }
diff --git a/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/ResourceIdFactoryProvider.java b/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/ResourceIdFactoryProvider.java
index bbbc581..c30ba4d 100644
--- a/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/ResourceIdFactoryProvider.java
+++ b/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/ResourceIdFactoryProvider.java
@@ -18,8 +18,6 @@
  */
 package org.apache.hyracks.storage.common.file;
 
-import java.util.List;
-
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 
 public class ResourceIdFactoryProvider {
@@ -30,13 +28,7 @@
     }
 
     public ResourceIdFactory createResourceIdFactory() throws HyracksDataException {
-        List<LocalResource> localResources = localResourceRepository.getAllResources();
-        long largestResourceId = 0;
-        for (LocalResource localResource : localResources) {
-            if (largestResourceId < localResource.getResourceId()) {
-                largestResourceId = localResource.getResourceId();
-            }
-        }
+        long largestResourceId = localResourceRepository.getMaxResourceID();
         return new ResourceIdFactory(largestResourceId);
     }
 }
diff --git a/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/TransientLocalResourceRepository.java b/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/TransientLocalResourceRepository.java
index b3e9db0..3bc763d 100644
--- a/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/TransientLocalResourceRepository.java
+++ b/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/file/TransientLocalResourceRepository.java
@@ -18,9 +18,7 @@
  */
 package org.apache.hyracks.storage.common.file;
 
-import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 import org.apache.hyracks.api.exceptions.HyracksDataException;
@@ -31,11 +29,6 @@
     private Map<Long, LocalResource> id2ResourceMap = new HashMap<Long, LocalResource>();
 
     @Override
-    public LocalResource getResourceById(long id) throws HyracksDataException {
-        return id2ResourceMap.get(id);
-    }
-
-    @Override
     public LocalResource getResourceByName(String name) throws HyracksDataException {
         return name2ResourceMap.get(name);
     }
@@ -52,16 +45,6 @@
     }
 
     @Override
-    public synchronized void deleteResourceById(long id) throws HyracksDataException {
-        LocalResource resource = id2ResourceMap.get(id);
-        if (resource == null) {
-            throw new HyracksDataException("Resource doesn't exist");
-        }
-        id2ResourceMap.remove(id);
-        name2ResourceMap.remove(resource.getResourceName());
-    }
-
-    @Override
     public synchronized void deleteResourceByName(String name) throws HyracksDataException {
         LocalResource resource = name2ResourceMap.get(name);
         if (resource == null) {
@@ -72,11 +55,12 @@
     }
 
     @Override
-    public List<LocalResource> getAllResources() throws HyracksDataException {
-        List<LocalResource> resources = new ArrayList<LocalResource>();
-        for (LocalResource resource : id2ResourceMap.values()) {
-            resources.add(resource);
+    public long getMaxResourceID() throws HyracksDataException {
+        long maxResourceId = 0;
+
+        for (Long resourceId : id2ResourceMap.keySet()) {
+            maxResourceId = Math.max(maxResourceId, resourceId);
         }
-        return resources;
+        return maxResourceId;
     }
 }
diff --git a/hyracks/hyracks-test-support/src/main/java/org/apache/hyracks/test/support/TestStorageManagerComponentHolder.java b/hyracks/hyracks-test-support/src/main/java/org/apache/hyracks/test/support/TestStorageManagerComponentHolder.java
index d987501..671c479 100644
--- a/hyracks/hyracks-test-support/src/main/java/org/apache/hyracks/test/support/TestStorageManagerComponentHolder.java
+++ b/hyracks/hyracks-test-support/src/main/java/org/apache/hyracks/test/support/TestStorageManagerComponentHolder.java
@@ -75,7 +75,7 @@
 
     public synchronized static IIndexLifecycleManager getIndexLifecycleManager(IHyracksTaskContext ctx) {
         if (lcManager == null) {
-            lcManager = new IndexLifecycleManager();
+            lcManager = new IndexLifecycleManager(getLocalResourceRepository(ctx));
         }
         return lcManager;
     }