Search in sources :

Example 6 with RecordBufferPage

use of org.apache.jena.dboe.base.recordbuffer.RecordBufferPage in project jena by apache.

the class TestRecordBufferPage method recBufferPage01.

@Test
public void recBufferPage01() {
    BlockMgr blkMgr = makeBlockMgr();
    blkMgr.beginUpdate();
    RecordBufferPageMgr rpm = new RecordBufferPageMgr(factory, blkMgr);
    RecordBufferPage page = rpm.create();
    fill(page.getRecordBuffer(), 10, 20, 30);
    assertEquals(10, get(page, 0));
    assertEquals(20, get(page, 1));
    assertEquals(30, get(page, 2));
    rpm.release(page);
    blkMgr.endUpdate();
}
Also used : RecordBufferPageMgr(org.apache.jena.dboe.base.recordbuffer.RecordBufferPageMgr) BlockMgr(org.apache.jena.dboe.base.block.BlockMgr) RecordBufferPage(org.apache.jena.dboe.base.recordbuffer.RecordBufferPage) Test(org.junit.Test)

Example 7 with RecordBufferPage

use of org.apache.jena.dboe.base.recordbuffer.RecordBufferPage in project jena by apache.

the class BPlusTreeTools method bpt_scan_record_buffer.

// /** Scan/dump a file of RecordBuffers */
// /*public*/private static void bpt_scan_record_buffer(String filename, boolean verbose)
// {
// BlockMgr blkMgr = BlockMgrFactory.createStdFileNoCache(filename, SystemIndex.BlockSize);
// bpt_scan_record_buffer(blkMgr, verbose);
// blkMgr.close();
// }
// 
// /*public*/private static void bpt_scan_record_buffer(BPlusTree bpt, boolean verbose)
// {
// bpt_scan_record_buffer(bpt.getRecordsMgr().getBlockMgr(), verbose);
// }
// 
// /*public*/private static void bpt_scan_record_buffer(BlockMgr blkMgr, boolean verbose)
// {
// RecordFactory f = SystemIndex.indexRecordTripleFactory;
// RecordBufferPageMgr recordPageMgr = new RecordBufferPageMgr(f, blkMgr);
// bpt_scan_record_buffer(recordPageMgr,verbose);
// }
/*public*/
private static void bpt_scan_record_buffer(RecordBufferPageMgr recordPageMgr, boolean verbose) {
    System.out.print("[Scan Records] start\n");
    int idx = 0;
    int n = 0;
    int total = 0;
    if (verbose)
        System.out.printf("recordPageMgr = %s\n", recordPageMgr);
    // Blocks in scan order
    try {
        while (idx >= 0) {
            if (verbose)
                System.out.printf("idx = %d\n", idx);
            RecordBufferPage page = recordPageMgr.getRead(idx);
            if (verbose)
                System.out.printf("%04d :: id=%04d -> link=%04d [count=%d, max=%d]\n", n, page.getId(), page.getLink(), page.getCount(), page.getMaxSize());
            RecordBuffer rb = page.getRecordBuffer();
            if (verbose)
                System.out.printf("     :: %d %d\n", rb.getSize(), rb.maxSize());
            total += rb.size();
            idx = page.getLink();
            n++;
            recordPageMgr.release(page);
        }
    } catch (Exception ex) {
        System.out.println("Exception: " + ex);
    }
    System.out.printf("[Scan Records] Count = %d in %d blocks (avg: %.2f)\n", total, n, ((float) total) / n);
}
Also used : RecordBuffer(org.apache.jena.dboe.base.buffer.RecordBuffer) IOException(java.io.IOException) RecordBufferPage(org.apache.jena.dboe.base.recordbuffer.RecordBufferPage)

Example 8 with RecordBufferPage

use of org.apache.jena.dboe.base.recordbuffer.RecordBufferPage 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));
    // Write and convert to split pairs.
    Iterator<Pair<Integer, Record>> iter2 = Iter.map(iter, rbp -> {
        mgr.put(rbp);
        Record r = rbp.getRecordBuffer().getHigh();
        r = bpt.getRecordFactory().createKeyOnly(r);
        return new Pair<>(rbp.getId(), r);
    });
    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 will 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;
}
Also used : RecordBufferPageMgr(org.apache.jena.dboe.base.recordbuffer.RecordBufferPageMgr) Record(org.apache.jena.dboe.base.record.Record) RecordBufferPage(org.apache.jena.dboe.base.recordbuffer.RecordBufferPage) Pair(org.apache.jena.atlas.lib.Pair)

Example 9 with RecordBufferPage

use of org.apache.jena.dboe.base.recordbuffer.RecordBufferPage in project jena by apache.

the class RecordBufferPageLinker method next.

@Override
public RecordBufferPage next() {
    if (!hasNext())
        throw new NoSuchElementException();
    RecordBufferPage rbp = slot;
    slot = null;
    return rbp;
}
Also used : NoSuchElementException(java.util.NoSuchElementException) RecordBufferPage(org.apache.jena.dboe.base.recordbuffer.RecordBufferPage)

Example 10 with RecordBufferPage

use of org.apache.jena.dboe.base.recordbuffer.RecordBufferPage 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>> pairs = Iter.toList(iter);
    System.out.println("summarizeDataBlocks: " + pairs);
    for (Pair<Integer, Record> pair : pairs) {
        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 pairs.iterator();
}
Also used : Record(org.apache.jena.dboe.base.record.Record) Pair(org.apache.jena.atlas.lib.Pair) RecordBufferPage(org.apache.jena.dboe.base.recordbuffer.RecordBufferPage)

Aggregations

RecordBufferPage (org.apache.jena.dboe.base.recordbuffer.RecordBufferPage)10 Pair (org.apache.jena.atlas.lib.Pair)3 Record (org.apache.jena.dboe.base.record.Record)3 RecordBufferPageMgr (org.apache.jena.dboe.base.recordbuffer.RecordBufferPageMgr)3 NoSuchElementException (java.util.NoSuchElementException)2 BlockMgr (org.apache.jena.dboe.base.block.BlockMgr)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 RecordBuffer (org.apache.jena.dboe.base.buffer.RecordBuffer)1