/** return the size of a block */ public static int calcBlockSize(int bpTreeOrder, RecordFactory factory) { BPlusTreeParams p = new BPlusTreeParams(bpTreeOrder, factory) ; int x = p.getMaxRec() * factory.recordLength() + p.getMaxPtr() * SizeOfPointer ; x += BlockHeaderSize ; return x ; }
public int getCalcBlockSize() { return calcBlockSize(order, recordFactory) ; }
/** * Return the best fit for the blocksize and the record length. Knows about * block header space. */ public static int calcOrder(int blockSize, RecordFactory factory) { return calcOrder(blockSize, factory.recordLength()) ; }
/** (Testing mainly) Make an in-memory B+Tree, with copy-in, copy-out block managers */ public static BPlusTree makeMem(String name, int order, int minDataRecords, int keyLength, int valueLength) { if ( name == null ) name = "Mem" ; BPlusTreeParams params = new BPlusTreeParams(order, keyLength, valueLength) ; int blkSize ; if ( minDataRecords > 0 ) { int maxDataRecords = 2 * minDataRecords ; // int rSize = RecordBufferPage.HEADER+(maxRecords*params.getRecordLength()) ; blkSize = RecordBufferPage.calcBlockSize(params.getRecordFactory(), maxDataRecords) ; } else blkSize = params.getCalcBlockSize() ; // By FileSet BufferChannel chan = BufferChannelMem.create(name+"(root)") ; BlockMgr mgr1 = BlockMgrFactory.createMem(name + "(nodes)", params.getCalcBlockSize()) ; BlockMgr mgr2 = BlockMgrFactory.createMem(name + "(records)", blkSize) ; ComponentId cid = ComponentId.allocLocal() ; BPlusTree bpTree = BPlusTreeFactory.create(cid, params, chan, mgr1, mgr2) ; return bpTree ; }
/** Knowing all the parameters, create a B+Tree */ public static BPlusTree createBPTree(ComponentId cid, FileSet fileset, int order, int blockSize, int readCacheSize, int writeCacheSize, RecordFactory factory) { // ---- Checking if (blockSize < 0 && order < 0) throw new IllegalArgumentException("Neither blocksize nor order specified") ; if (blockSize >= 0 && order < 0) order = BPlusTreeParams.calcOrder(blockSize, factory.recordLength()) ; if (blockSize >= 0 && order >= 0) { int order2 = BPlusTreeParams.calcOrder(blockSize, factory.recordLength()) ; if (order != order2) throw new IllegalArgumentException("Wrong order (" + order + "), calculated = " + order2) ; } // Iffy - does not allow for slop. if (blockSize < 0 && order >= 0) { // Only in-memory. blockSize = BPlusTreeParams.calcBlockSize(order, factory) ; } BPlusTreeParams params = new BPlusTreeParams(order, factory) ; BufferChannel bptState = FileFactory.createBufferChannel(fileset, Names.extBptState) ; BlockMgr blkMgrNodes = BlockMgrFactory.create(fileset, Names.extBptTree, blockSize, readCacheSize, writeCacheSize) ; BlockMgr blkMgrRecords = BlockMgrFactory.create(fileset, Names.extBptRecords, blockSize, readCacheSize, writeCacheSize) ; return BPlusTreeFactory.create(cid, params, bptState, blkMgrNodes, blkMgrRecords) ; }
public static void runOneTest(int order, int N, RecordFactory recordFactory, boolean debug) BPlusTreeParams bptParams = new BPlusTreeParams(order, recordFactory) ; BPlusTreeRewriter.debug = debug ; BlockMgr blkMgr1 = BlockMgrFactory.create(destination, Names.extBptTree, bptParams.getCalcBlockSize(), 10, 10) ; BlockMgr blkMgr2 = BlockMgrFactory.create(destination, Names.extBptTree, bptParams.getCalcBlockSize(), 10, 10) ;
public static BPlusTreeParams readMeta(MetaFile mf) { try { int pOrder = mf.getPropertyAsInteger(ParamOrder) ; int pKeyLen = mf.getPropertyAsInteger(ParamKeyLength) ; int pRecLen = mf.getPropertyAsInteger(ParamValueLength) ; return new BPlusTreeParams(pOrder, pKeyLen, pRecLen) ; } catch (NumberFormatException ex) { Log.error(BPlusTreeParams.class, "Badly formed metadata for B+Tree") ; throw new DBOpEnvException("Failed to read metadata") ; } }
static void formatBPTreeNode(BPTreeNode n, BPlusTree bpTree, Block block, boolean leaf, int parent, int count) { BPlusTreeParams params = bpTree.getParams() ; int ptrBuffLen = params.MaxPtr * params.getPtrLength() ; int recBuffLen = params.MaxRec * params.getRecordLength() ;
@Override final boolean isMinSize() { int min = params.getMinRec() ; if ( BPT.CheckingNode && count < min ) BPT.error("isMinSize: Dwarf block: %s", this) ; return count <= min ; }
@Override public final int getMaxSize() { return bpTree.getParams().getOrder() ; }
RecordBufferPageMgr recordPageMgr = new RecordBufferPageMgr(params.getRecordFactory(), blkMgrRecords) ; BPTreeRecordsMgr recordsMgr = new BPTreeRecordsMgr(bpt, params.getRecordFactory(), recordPageMgr) ;
/** (Testing mainly) Make an in-memory B+Tree, with copy-in, copy-out block managers */ public static BPlusTree makeMem(String name, int order, int minDataRecords, int keyLength, int valueLength) { if ( name == null ) name = "Mem" ; BPlusTreeParams params = new BPlusTreeParams(order, keyLength, valueLength) ; int blkSize ; if ( minDataRecords > 0 ) { int maxDataRecords = 2 * minDataRecords ; // int rSize = RecordBufferPage.HEADER+(maxRecords*params.getRecordLength()) ; blkSize = RecordBufferPage.calcBlockSize(params.getRecordFactory(), maxDataRecords) ; } else blkSize = params.getCalcBlockSize() ; // By FileSet BufferChannel chan = BufferChannelMem.create(name+"(root)") ; BlockMgr mgr1 = BlockMgrFactory.createMem(name + "(nodes)", params.getCalcBlockSize()) ; BlockMgr mgr2 = BlockMgrFactory.createMem(name + "(records)", blkSize) ; ComponentId cid = ComponentId.allocLocal() ; BPlusTree bpTree = BPlusTreeFactory.create(cid, params, chan, mgr1, mgr2) ; return bpTree ; }
/** Knowing all the parameters, create a B+Tree */ public static BPlusTree createBPTree(ComponentId cid, FileSet fileset, int order, int blockSize, int readCacheSize, int writeCacheSize, RecordFactory factory) { // ---- Checking if (blockSize < 0 && order < 0) throw new IllegalArgumentException("Neither blocksize nor order specified") ; if (blockSize >= 0 && order < 0) order = BPlusTreeParams.calcOrder(blockSize, factory.recordLength()) ; if (blockSize >= 0 && order >= 0) { int order2 = BPlusTreeParams.calcOrder(blockSize, factory.recordLength()) ; if (order != order2) throw new IllegalArgumentException("Wrong order (" + order + "), calculated = " + order2) ; } // Iffy - does not allow for slop. if (blockSize < 0 && order >= 0) { // Only in-memory. blockSize = BPlusTreeParams.calcBlockSize(order, factory) ; } BPlusTreeParams params = new BPlusTreeParams(order, factory) ; BufferChannel bptState = FileFactory.createBufferChannel(fileset, Names.extBptState) ; BlockMgr blkMgrNodes = BlockMgrFactory.create(fileset, Names.extBptTree, blockSize, readCacheSize, writeCacheSize) ; BlockMgr blkMgrRecords = BlockMgrFactory.create(fileset, Names.extBptRecords, blockSize, readCacheSize, writeCacheSize) ; return BPlusTreeFactory.create(cid, params, bptState, blkMgrNodes, blkMgrRecords) ; }
public static void runOneTest(int order, int N, RecordFactory recordFactory, boolean debug) BPlusTreeParams bptParams = new BPlusTreeParams(order, recordFactory) ; BPlusTreeRewriter.debug = debug ; BlockMgr blkMgr1 = BlockMgrFactory.create(destination, Names.extBptTree, bptParams.getCalcBlockSize(), 10, 10) ; BlockMgr blkMgr2 = BlockMgrFactory.create(destination, Names.extBptTree, bptParams.getCalcBlockSize(), 10, 10) ;
public static BPlusTreeParams readMeta(MetaFile mf) { try { int pOrder = mf.getPropertyAsInteger(ParamOrder) ; int pKeyLen = mf.getPropertyAsInteger(ParamKeyLength) ; int pRecLen = mf.getPropertyAsInteger(ParamValueLength) ; return new BPlusTreeParams(pOrder, pKeyLen, pRecLen) ; } catch (NumberFormatException ex) { Log.error(BPlusTreeParams.class, "Badly formed metadata for B+Tree") ; throw new DBOpEnvException("Failed to read metadata") ; } }
static void formatBPTreeNode(BPTreeNode n, BPlusTree bpTree, Block block, boolean leaf, int parent, int count) { BPlusTreeParams params = bpTree.getParams() ; int ptrBuffLen = params.MaxPtr * params.getPtrLength() ; int recBuffLen = params.MaxRec * params.getRecordLength() ;
@Override final boolean isMinSize() { int min = params.getMinRec() ; if ( BPT.CheckingNode && count < min ) BPT.error("isMinSize: Dwarf block: %s", this) ; return count <= min ; }
@Override public final int getMaxSize() { return bpTree.getParams().getOrder() ; }
RecordBufferPageMgr recordPageMgr = new RecordBufferPageMgr(params.getRecordFactory(), blkMgrRecords) ; BPTreeRecordsMgr recordsMgr = new BPTreeRecordsMgr(bpt, params.getRecordFactory(), recordPageMgr) ;
/** return the size of a block */ public static int calcBlockSize(int bpTreeOrder, RecordFactory factory) { BPlusTreeParams p = new BPlusTreeParams(bpTreeOrder, factory) ; int x = p.getMaxRec() * factory.recordLength() + p.getMaxPtr() * SizeOfPointer ; x += BlockHeaderSize ; return x ; }