@Override public MemoryAware getMemoryManager() throws JasDBStorageException { openIndex(); return persister; }
protected LockManager getLockManager() throws JasDBStorageException { openIndex(); return lockManager; }
RootBlock getRootBlock() throws JasDBStorageException { openIndex(); return rootBlock; }
protected BlockPersister getPersister() throws JasDBStorageException { openIndex(); return persister; }
@Override public IndexIterator getIndexIterator() throws JasDBStorageException { openIndex(); return new FullIndexIterator(rootBlock, lockManager, persister); }
@Override public void flushIndex() throws JasDBStorageException { openIndex(); persister.flush(); }
@Override public IndexScanReport scan(ScanIntent intent, Iterator<IndexableItem> indexableItems) throws JasDBStorageException { try { openIndex(); fullLock.lock(); try { if(intent == ScanIntent.RESCAN || intent == ScanIntent.DETECT_INCOMPLETE || scanReport == null) { scanReport = IndexScanner.doIndexScan(this, keyInfo, indexableItems, intent != ScanIntent.DETECT_INCOMPLETE); } return scanReport; } finally { fullLock.unlock(); } } catch(JasDBStorageException e) { scanReport = new IndexScanReportImpl(IndexState.INVALID, System.currentTimeMillis(), 0); return scanReport; } }
@Override public void close() throws JasDBStorageException { openIndex(); fullLock.lock(); resourceLockManager.exclusiveLock(); try { if(channel != null) { closeIndexResources(); } } finally { resourceLockManager.exclusiveUnlock(true); fullLock.unlock(); } }
@Override public IndexSearchResultIteratorCollection searchIndex(SearchCondition searchCondition, SearchLimit searchLimit) throws JasDBStorageException { openIndex(); SearchOperation searchOperation; SearchCondition condition = searchCondition; if(searchCondition instanceof RangeCondition) { searchOperation = rangeSearchOperation; } else if(searchCondition instanceof NotEqualsCondition) { searchOperation = notEqualsSearchOperation; } else if(searchCondition instanceof EqualsCondition){ condition = handleEqualsToRange((EqualsCondition) searchCondition); if(condition == searchCondition) { searchOperation = equalsSearchOperation; } else { searchOperation = rangeSearchOperation; } } else { throw new JasDBStorageException("Search Condition is not supported by Btree"); } StatRecord searchRecord = StatisticsMonitor.createRecord("btree:search"); resourceLockManager.sharedLock(); try { return searchOperation.search(condition, searchLimit); } finally { resourceLockManager.sharedUnlock(); searchRecord.stop(); } }
@Override public void updateKey(Key oldKey, Key newKey) throws JasDBStorageException { openIndex(); StatRecord updateIndex = StatisticsMonitor.createRecord("btree:update"); resourceLockManager.sharedLock(); lockManager.startLockChain(); lockManager.acquireLock(LockIntentType.UPDATE, rootBlock); try { LeaveBlock leaveBlock = rootBlock.findLeaveBlock(LockIntentType.UPDATE, oldKey); doLeaveBlockUpdate(leaveBlock, newKey); } finally { lockManager.releaseLockChain(); resourceLockManager.sharedUnlock(); updateIndex.stop(); } }
@Override public void removeFromIndex(Key key) throws JasDBStorageException { openIndex(); resourceLockManager.sharedLock(); lockManager.startLockChain(); lockManager.acquireLock(LockIntentType.LEAVELOCK_OPTIMISTIC, rootBlock); try { LeaveBlock leaveBlock = rootBlock.findLeaveBlock(LockIntentType.LEAVELOCK_OPTIMISTIC, key); if(leaveBlock.size() == persister.getMinKeys()) { lockManager.releaseLockChain(); lockManager.startLockChain(); lockManager.acquireLock(LockIntentType.WRITE_EXCLUSIVE, rootBlock); leaveBlock = rootBlock.findLeaveBlock(LockIntentType.WRITE_EXCLUSIVE, key); doLeaveBlockRemove(leaveBlock, key); } else { doLeaveBlockRemove(leaveBlock, key); } } finally { lockManager.releaseLockChain(); resourceLockManager.sharedUnlock(); } }
@Override public void insertIntoIndex(Key key) throws JasDBStorageException { openIndex(); StatRecord btreeInsertRecord = StatisticsMonitor.createRecord("btree:insert"); resourceLockManager.sharedLock(); lockManager.startLockChain(); lockManager.acquireLock(LockIntentType.LEAVELOCK_OPTIMISTIC, rootBlock); try { LeaveBlock leaveBlock = rootBlock.findLeaveBlock(LockIntentType.LEAVELOCK_OPTIMISTIC, key); if(leaveBlock.size() == persister.getMaxKeys()) { lockManager.releaseLockChain(); lockManager.startLockChain(); lockManager.acquireLock(LockIntentType.WRITE_EXCLUSIVE, rootBlock); leaveBlock = rootBlock.findLeaveBlock(LockIntentType.WRITE_EXCLUSIVE, key); doLeaveBlockInsert(leaveBlock, key); } else { //no overflow, we can just write into the leave doLeaveBlockInsert(leaveBlock, key); } } finally { lockManager.releaseLockChain(); resourceLockManager.sharedUnlock(); btreeInsertRecord.stop(); } }