public synchronized static IResourceLifecycleManager<IIndex> getIndexLifecycleManager() { if (lcManager == null) { lcManager = new IndexLifecycleManager(); } return lcManager; }
private boolean evictCandidateIndex() throws HyracksDataException { // Why min()? As a heuristic for eviction, we will take an open index // (an index consuming memory) // that is not being used (refcount == 0) and has been least recently // used. The sort order defined // for IndexInfo maintains this. See IndexInfo.compareTo(). IndexInfo info = Collections.min(indexInfos.values()); if (info.referenceCount != 0 || !info.isOpen) { return false; } info.index.deactivate(); //find resource name and deallocate its memory for (Entry<String, IndexInfo> entry : indexInfos.entrySet()) { if (entry.getValue() == info) { deallocateMemory(entry.getKey()); break; } } info.isOpen = false; return true; }
@Override public void stop(boolean dumpState, OutputStream outputStream) throws IOException { if (dumpState) { dumpState(outputStream); } for (IndexInfo i : indexInfos.values()) { if (i.isOpen) { i.index.deactivate(); } } }
@Override public void open(String resourcePath) throws HyracksDataException { IndexInfo info = indexInfos.get(resourcePath); if (info == null) { throw new HyracksDataException( "Failed to open index with resource name " + resourcePath + " since it does not exist."); } if (!info.isOpen) { allocateMemory(resourcePath); info.index.activate(); info.isOpen = true; } info.touch(); }
@Override public void allocateMemory(String resourcePath) throws HyracksDataException { IndexInfo info = indexInfos.get(resourcePath); if (info == null) { throw new HyracksDataException("Failed to allocate memory for index with resource ID " + resourcePath + " since it does not exist."); } if (!info.memoryAllocated) { long inMemorySize = info.index.getMemoryAllocationSize(); while (memoryUsed + inMemorySize > memoryBudget) { if (!evictCandidateIndex()) { throw new HyracksDataException( "Cannot allocate memory for index since memory budget would be exceeded."); } } memoryUsed += inMemorySize; info.memoryAllocated = true; } }
public RuntimeContext(INCServiceContext appCtx) throws HyracksDataException { fileMapManager = new FileMapManager(); ICacheMemoryAllocator allocator = new HeapBufferAllocator(); IPageReplacementStrategy prs = new ClockPageReplacementStrategy(allocator, 32768, 50); bufferCache = new BufferCache(appCtx.getIoManager(), prs, new DelayPageCleanerPolicy(1000), fileMapManager, 100, threadFactory); ILocalResourceRepositoryFactory localResourceRepositoryFactory = new TransientLocalResourceRepositoryFactory(); localResourceRepository = localResourceRepositoryFactory.createRepository(); resourceIdFactory = (new ResourceIdFactoryProvider(localResourceRepository)).createResourceIdFactory(); lcManager = new IndexLifecycleManager(); }
@Override public void unregister(String resourcePath) throws HyracksDataException { IndexInfo info = indexInfos.get(resourcePath); if (info == null) { throw HyracksDataException.create(ErrorCode.INDEX_DOES_NOT_EXIST); } if (info.referenceCount != 0) { indexInfos.put(resourcePath, info); throw HyracksDataException.create(ErrorCode.CANNOT_DROP_IN_USE_INDEX, resourcePath); } if (info.isOpen) { info.index.deactivate(); deallocateMemory(resourcePath); } indexInfos.remove(resourcePath); }
public RuntimeContext(INCApplicationContext appCtx) throws HyracksDataException { fileMapManager = new TransientFileMapManager(); ICacheMemoryAllocator allocator = new HeapBufferAllocator(); 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(); }