private static void reduceRoot(BPTreeNode root) { if ( logging(log) ) log(log, "reduceRoot >> %s", root) ; BPT.error("Not an empty root") ; if ( logging(log) ) log(log, "reduceRoot << leaf root") ; return ; promoteRoot(root) ; promote1(sub, root, 0) ; BPTreeNode n = cast(sub) ; root.internalCheckNodeDeep() ; if ( logging(log) ) log(log, "reduceRoot << %s", root) ;
private void shiftRight(BPTreePage left, BPTreePage right, int i) { if ( logging(log) ) { log(log, ">> shiftRight: this: %s", this) ; log(log, ">> shiftRight: left: %s", left) ; log(log, ">> shiftRight: right: %s", right) ; } Record r1 = records.get(i) ; Record r2 = left.shiftRight(right, r1) ; r2 = keyRecord(r2) ; this.records.set(i, r2) ; left.write() ; right.write() ; // Do later -- this.put(); if ( logging(log) ) { log(log, "<< shiftRight: this: %s", this) ; log(log, "<< shiftRight: left: %s", left) ; log(log, "<< shiftRight: right: %s", right) ; } }
private void shuffleDown(int x) { // x is the index in the parent and may be on eover the end. if ( logging(log) ) { log(log, "ShuffleDown: i=%d count=%d MaxRec=%d", x, count, maxRecords()) ; log(log, "ShuffleDown >> %s", this) ; } if ( BPT.CheckingNode && x >= count ) BPT.error("shuffleDown out of bounds") ; // Just the top to clear if ( x == count - 1 ) { records.removeTop() ; ptrs.removeTop() ; count-- ; if ( logging(log) ) { log(log, "shuffleDown << Clear top") ; log(log, "shuffleDown << %s", this) ; } internalCheckNode() ; return ; } // Shuffle down. Removes key and pointer just above key. records.shiftDown(x) ; ptrs.shiftDown(x + 1) ; count-- ; if ( logging(log) ) log(log, "shuffleDown << %s", this) ; internalCheckNode() ; }
private BPTreePage rebalance(AccessPath path, BPTreePage node, int idx) { if ( logging(log) ) { log(log, "rebalance(id=%d, idx=%d)", node.getId(), idx) ; log(log, ">> this: %s", this) ; log(log, ">> node: %s", node) ; promotePage(path, node) ; if ( logging(log) ) log(log, "rebalance/shiftRight") ; promote1(left, this, idx-1) ; if ( logging(log) ) log(log, "<< rebalance: %s", this) ; if ( BPT.CheckingNode ) { left.checkNode() ; if ( logging(log) ) log(log, "rebalance/shiftLeft") ; promote1(right, this, idx+1) ; if ( logging(log) ) log(log, "<< rebalance: %s", this) ; if ( BPT.CheckingNode ) { right.checkNode() ; BPT.error("No siblings") ;
@Override final Record internalDelete(AccessPath path, Record rec) { if ( logging(log) ) log(log, ">> internalDelete(%s) : %s", rec, this) ; internalCheckNode() ; int y = apply(x) ; BPTreePage page = get(y) ; trackPath(path, this, y, page) ; y = apply(x) ; page = get(y) ; promote1(page, this, y) ; resetTrackPath(path, this, y, page) ; if ( BPT.CheckingNode ) { this.write() ; if ( logging(log) ) log(log, "<< internalDelete(%s) : %s", rec, this) ;
@Override final Record internalInsert(AccessPath path, Record record) { if ( logging(log) ) log(log, "internalInsert: %s [%s]", record, this) ; if ( logging(log) ) log(log, "internalInsert: idx=%d (=>%d)", idx, apply(idx)) ; idx = apply(idx) ; BPTreePage page = get(idx) ; trackPath(path, this, idx, page) ; if ( logging(log) ) log(log, "internalInsert: next: %s", page) ;
private static final BPTreeNode cast(BPTreePage other) { try { return (BPTreeNode)other ; } catch (ClassCastException ex) { BPT.error("Wrong type: " + other) ; return null ; } }
@Override Record internalDelete(AccessPath path, Record record) { int i = rBuff.find(record) ; if ( i < 0 ) return null ; promotePage(path, this) ; Record r2 = rBuff.get(i) ; rBuff.remove(i) ; write() ; return r2 ; }
/** Find the next page to look at as we walk down the tree */ private final BPTreePage findHere(AccessPath path, Record rec) { int idx = findSlot(rec) ; idx = apply(idx) ; // Find index, or insertion point (immediate higher slot) as (-i-1) // A key is the highest element of the records up to this point // so we search down at slot idx (between something smaller and // something larger). BPTreePage page = get(idx) ; trackPath(path, this, idx, page) ; return page ; }
static void log(Logger log, String fmt, Object... args) { if ( logging(log) ) { FmtLog.debug(log, fmt, args); } }
BPlusTree bpt2 = BPT.createRootOnlyBPTree(bptParams, bptState, blkMgrNodes, blkMgrRecords) ;
private BPTreePage rebalance(AccessPath path, BPTreePage node, int idx) { if ( logging(log) ) { log(log, "rebalance(id=%d, idx=%d)", node.getId(), idx) ; log(log, ">> this: %s", this) ; log(log, ">> node: %s", node) ; promotePage(path, node) ; if ( logging(log) ) log(log, "rebalance/shiftRight") ; promote1(left, this, idx-1) ; if ( logging(log) ) log(log, "<< rebalance: %s", this) ; if ( BPT.CheckingNode ) { left.checkNode() ; if ( logging(log) ) log(log, "rebalance/shiftLeft") ; promote1(right, this, idx+1) ; if ( logging(log) ) log(log, "<< rebalance: %s", this) ; if ( BPT.CheckingNode ) { right.checkNode() ; BPT.error("No siblings") ;
private void shuffleDown(int x) { // x is the index in the parent and may be on eover the end. if ( logging(log) ) { log(log, "ShuffleDown: i=%d count=%d MaxRec=%d", x, count, maxRecords()) ; log(log, "ShuffleDown >> %s", this) ; } if ( BPT.CheckingNode && x >= count ) BPT.error("shuffleDown out of bounds") ; // Just the top to clear if ( x == count - 1 ) { records.removeTop() ; ptrs.removeTop() ; count-- ; if ( logging(log) ) { log(log, "shuffleDown << Clear top") ; log(log, "shuffleDown << %s", this) ; } internalCheckNode() ; return ; } // Shuffle down. Removes key and pointer just above key. records.shiftDown(x) ; ptrs.shiftDown(x + 1) ; count-- ; if ( logging(log) ) log(log, "shuffleDown << %s", this) ; internalCheckNode() ; }
@Override final Record internalDelete(AccessPath path, Record rec) { if ( logging(log) ) log(log, ">> internalDelete(%s) : %s", rec, this) ; internalCheckNode() ; int y = apply(x) ; BPTreePage page = get(y) ; trackPath(path, this, y, page) ; y = apply(x) ; page = get(y) ; promote1(page, this, y) ; resetTrackPath(path, this, y, page) ; if ( BPT.CheckingNode ) { this.write() ; if ( logging(log) ) log(log, "<< internalDelete(%s) : %s", rec, this) ;
private void shiftLeft(BPTreePage left, BPTreePage right, int i) { if ( logging(log) ) { log(log, ">> shiftLeft: this: %s", this) ; log(log, ">> shiftLeft: left: %s", left) ; log(log, ">> shiftLeft: right: %s", right) ; } Record r1 = records.get(i) ; Record r2 = left.shiftLeft(right, r1) ; r2 = keyRecord(r2) ; this.records.set(i, r2) ; left.write() ; right.write() ; // Do this later - this.put(); if ( logging(log) ) { log(log, "<< shiftLeft: this: %s", this) ; log(log, "<< shiftLeft: left: %s", left) ; log(log, "<< shiftLeft: right: %s", right) ; } }
@Override final Record internalInsert(AccessPath path, Record record) { if ( logging(log) ) log(log, "internalInsert: %s [%s]", record, this) ; if ( logging(log) ) log(log, "internalInsert: idx=%d (=>%d)", idx, apply(idx)) ; idx = apply(idx) ; BPTreePage page = get(idx) ; trackPath(path, this, idx, page) ; if ( logging(log) ) log(log, "internalInsert: next: %s", page) ;
private static final BPTreeNode cast(BPTreePage other) { try { return (BPTreeNode)other ; } catch (ClassCastException ex) { BPT.error("Wrong type: " + other) ; return null ; } }
@Override Record internalDelete(AccessPath path, Record record) { int i = rBuff.find(record) ; if ( i < 0 ) return null ; promotePage(path, this) ; Record r2 = rBuff.get(i) ; rBuff.remove(i) ; write() ; return r2 ; }
/** Find the next page to look at as we walk down the tree */ private final BPTreePage findHere(AccessPath path, Record rec) { int idx = findSlot(rec) ; idx = apply(idx) ; // Find index, or insertion point (immediate higher slot) as (-i-1) // A key is the highest element of the records up to this point // so we search down at slot idx (between something smaller and // something larger). BPTreePage page = get(idx) ; trackPath(path, this, idx, page) ; return page ; }
static void log(Logger log, String fmt, Object... args) { if ( logging(log) ) { FmtLog.debug(log, fmt, args); } }