/** Find a record, using the active comparator */ public static Record search(BPTreeNode root, Record rec) { root.internalCheckNodeDeep() ; if ( ! root.isRoot() ) throw new BPTreeException("Search not starting from the root: " + root) ; AccessPath path = new AccessPath(root) ; Record r = root.internalSearch(path, rec) ; return r ; }
/** Debugging */ public static BPlusTree addTracking(BPlusTree bpTree) { BufferChannel mgrRoot = null ; BlockMgr mgr1 = bpTree.getNodeManager().getBlockMgr() ; BlockMgr mgr2 = bpTree.getRecordsMgr().getBlockMgr() ; mgr1 = BlockTracker.track(mgr1) ; mgr2 = BlockTracker.track(mgr2) ; return BPlusTreeFactory.rebuild(bpTree, mgrRoot, mgr1, mgr2) ; }
public void newRoot(BPTreeNode newRoot) { if ( isTransactional() ) getDataState().setRoot(newRoot.getId()) ; else rootIdx = newRoot.getId() ; }
/** Reset an existing B+Tree with different storage units. * For each, null means "use same as original" */ public static BPlusTree rebuild(BPlusTree bpt, BufferChannel chan, BlockMgr blkMgrNodes, BlockMgr blkMgrLeaves) { if ( chan == null ) chan = bpt.getStateManager().getBufferChannel() ; if ( blkMgrNodes == null ) blkMgrNodes = bpt.getNodeManager().getBlockMgr() ; if ( blkMgrLeaves == null ) blkMgrLeaves = bpt.getNodeManager().getBlockMgr() ; BPlusTree bpt2 = attach(bpt.getComponentId(), bpt.getParams(), true, chan, blkMgrNodes, blkMgrLeaves) ; return bpt2 ; }
@Override protected ByteBuffer _commitPrepare(TxnId txnId, BptTxnState state) { nodeManager.getBlockMgr().sync(); recordsMgr.getBlockMgr().sync(); long nodeLimit = nodeManager.allocLimit() ; long recordsLimit = recordsMgr.allocLimit() ; // But don't write it yet. stateManager.setState(state.getRoot(), nodeLimit, recordsLimit); return stateManager.getState() ; }
@Override public void recover(ByteBuffer ref) { stateManager.setState(ref) ; rootIdx = stateManager.getRoot() ; nodeManager.resetAlloc(stateManager.getNodeBlocksLimit()) ; recordsMgr.resetAlloc(stateManager.getRecordsBlocksLimit()) ; }
/** Create the java structures to correspond to * the supplied block managers for the persistent storage. * Initialize the persistent storage to the empty B+Tree if it does not exist. */ public static BPlusTree createNonTxn(BPlusTreeParams params, BufferChannel chan, BlockMgr blkMgrNodes, BlockMgr blkMgrLeaves) { // Allocate a random ComponentId BPlusTree bpt = create(null, params, chan, blkMgrNodes, blkMgrLeaves) ; bpt.nonTransactional() ; return bpt ; }
/** Add a record into the B+Tree */ public Record insertAndReturnOld(Record record) { startUpdateBlkMgr() ; BPTreeNode root = getRootWrite() ; Record r = BPTreeNode.insert(root, record) ; releaseRootWrite(root) ; finishUpdateBlkMgr() ; return r ; }
@Override public Record maxKey() { startReadBlkMgr() ; BPTreeNode root = getRootRead() ; Record r = BPTreeNode.maxRecord(root) ; releaseRootRead(root) ; finishReadBlkMgr() ; return r ; }
public Record deleteAndReturnOld(Record record) { startUpdateBlkMgr() ; BPTreeNode root = getRootWrite() ; Record r = BPTreeNode.delete(root, record) ; releaseRootWrite(root) ; finishUpdateBlkMgr() ; return r ; }
@Override public Iterator<Record> iterator(Record fromRec, Record toRec) { startReadBlkMgr() ; BPTreeNode root = getRootRead() ; releaseRootRead(root) ; finishReadBlkMgr() ; return BPTreeRangeIterator.create(root, fromRec, toRec) ; //return iterator(fromRec, toRec, RecordFactory.mapperRecord) ; }
@Override protected void _abort(TxnId txnId, BptTxnState state) { rootIdx = state.initialroot ; // Truncate - logically in block manager space. nodeManager.resetAlloc(state.boundaryBlocksNode) ; recordsMgr.resetAlloc(state.boundaryBlocksRecord) ; stateManager.setState(state.initialroot, state.boundaryBlocksNode, state.boundaryBlocksRecord); stateManager.sync(); }
@Override protected void _commit(TxnId txnId, BptTxnState state) { if ( isWriteTxn() ) { rootIdx = state.getRoot() ; stateManager.sync(); } }
private BptTxnState createState() { return new BptTxnState(rootIdx, nodeManager.allocLimit(), recordsMgr.allocLimit()) ; }
@Override final boolean isFull() { if ( BPT.CheckingNode && count > maxRecords() ) BPT.error("isFull: Moby block: %s", this) ; // Count is number of records. return count >= maxRecords() ; }
/** Debugging */ public static BPlusTree addTracking(BPlusTree bpTree) { BufferChannel mgrRoot = null ; BlockMgr mgr1 = bpTree.getNodeManager().getBlockMgr() ; BlockMgr mgr2 = bpTree.getRecordsMgr().getBlockMgr() ; mgr1 = BlockTracker.track(mgr1) ; mgr2 = BlockTracker.track(mgr2) ; return BPlusTreeFactory.rebuild(bpTree, mgrRoot, mgr1, mgr2) ; }
@Override protected void _commit(TxnId txnId, BptTxnState state) { if ( isWriteTxn() ) { rootIdx = state.getRoot() ; stateManager.sync(); } }
private BptTxnState createState() { return new BptTxnState(rootIdx, nodeManager.allocLimit(), recordsMgr.allocLimit()) ; }