use of org.apache.jena.tdb.base.record.Record in project jena by apache.
the class BPlusTree method addAndReturnOld.
/**
* Add a record into the B+Tree
*/
public Record addAndReturnOld(Record record) {
startUpdateBlkMgr();
BPTreeNode root = getRoot();
Record r = BPTreeNode.insert(root, record);
if (CheckingTree)
root.checkNodeDeep();
releaseRoot(root);
finishUpdateBlkMgr();
return r;
}
use of org.apache.jena.tdb.base.record.Record in project jena by apache.
the class BPlusTree method clear.
@Override
public void clear() {
Record[] records = new Record[SLICE];
while (true) {
Iterator<Record> iter = iterator();
int i = 0;
for (i = 0; i < SLICE; i++) {
if (!iter.hasNext())
break;
Record r = iter.next();
records[i] = r;
}
if (i == 0)
break;
for (int j = 0; j < i; j++) {
delete(records[j]);
records[j] = null;
}
}
}
use of org.apache.jena.tdb.base.record.Record in project jena by apache.
the class BPlusTree method find.
@Override
public Record find(Record record) {
startReadBlkMgr();
BPTreeNode root = getRoot();
Record v = BPTreeNode.search(root, record);
releaseRoot(root);
finishReadBlkMgr();
return v;
}
use of org.apache.jena.tdb.base.record.Record in project jena by apache.
the class BPlusTreeRewriter method writePackedDataBlocks.
// **** data block phase
/**
* Pack record blocks into linked RecordBufferPages
*/
private static Iterator<Pair<Integer, Record>> writePackedDataBlocks(Iterator<Record> records, final BPlusTree bpt) {
if (debug) {
divider();
System.out.println("---- Data level");
}
final RecordBufferPageMgr mgr = bpt.getRecordsMgr().getRecordBufferPageMgr();
Iterator<RecordBufferPage> iter = new RecordBufferPageLinker(new RecordBufferPagePacker(records, mgr));
Function<RecordBufferPage, Pair<Integer, Record>> transform = rbp -> {
mgr.put(rbp);
Record r = rbp.getRecordBuffer().getHigh();
r = bpt.getRecordFactory().createKeyOnly(r);
return new Pair<>(rbp.getId(), r);
};
// Write and convert to split pairs.
Iterator<Pair<Integer, Record>> iter2 = Iter.map(iter, transform);
if (debug) {
if (rebalance)
System.out.println("Before rebalance (data)");
iter2 = summarizeDataBlocks(iter2, bpt.getRecordsMgr().getRecordBufferPageMgr());
// iter2 = printDataBlocks(iter2, bpt.getRecordsMgr().getRecordBufferPageMgr()) ;
}
if (rebalance)
iter2 = new RebalenceDataEnd(iter2, bpt);
// Testing - materialize - debug wil have done this
if (materialize && !debug)
iter2 = Iter.toList(iter2).iterator();
if (debug && rebalance) {
System.out.println("After rebalance (data)");
iter2 = summarizeDataBlocks(iter2, bpt.getRecordsMgr().getRecordBufferPageMgr());
// iter2 = printDataBlocks(iter2, bpt.getRecordsMgr().getRecordBufferPageMgr()) ;
}
return iter2;
}
use of org.apache.jena.tdb.base.record.Record in project jena by apache.
the class BPlusTreeRewriterUtils method summarizeDataBlocks.
static Iterator<Pair<Integer, Record>> summarizeDataBlocks(Iterator<Pair<Integer, Record>> iter, RecordBufferPageMgr recordPageMgr) {
divider();
List<Pair<Integer, Record>> x = Iter.toList(iter);
for (Pair<Integer, Record> pair : x) {
RecordBufferPage rbp = recordPageMgr.getRead(pair.car());
System.out.printf("%s -- RecordBufferPage[id=%d,link=%d] (%d) -> [%s]\n", pair, rbp.getId(), rbp.getLink(), rbp.getCount(), rbp.getRecordBuffer().getHigh());
recordPageMgr.release(rbp);
}
return x.iterator();
}
Aggregations