Search in sources :

Example 1 with RecordBuffer

use of org.apache.jena.dboe.base.buffer.RecordBuffer in project jena by apache.

the class TestBPTreeRecordsNonTxn method fill.

protected static void fill(BPTreeRecords bpr) {
    int N = bpr.getRecordBuffer().maxSize();
    for (int i = 0; i < N; i++) {
        RecordBuffer rb = bpr.getRecordBuffer();
        insert(bpr, (i + 0x30));
    }
}
Also used : RecordBuffer(org.apache.jena.dboe.base.buffer.RecordBuffer)

Example 2 with RecordBuffer

use of org.apache.jena.dboe.base.buffer.RecordBuffer in project jena by apache.

the class BPTreeNodeBuilder method hasNext.

@Override
public boolean hasNext() {
    if (slot != null)
        return true;
    if (iter == null)
        return false;
    if (!iter.hasNext()) {
        // Start of next block, no more input.
        iter = null;
        return false;
    }
    // At least one element to put in a new node.
    // Unknown parent. Does not matter (parent is only in-memory)
    BPTreeNode bptNode = mgr.createNode(-1);
    bptNode.setIsLeaf(leafLayer);
    RecordBuffer recBuff = bptNode.getRecordBuffer();
    PtrBuffer ptrBuff = bptNode.getPtrBuffer();
    recBuff.setSize(0);
    // Creation leaves this junk.
    ptrBuff.setSize(0);
    final boolean debug = false;
    int rMax = recBuff.maxSize();
    int pMax = ptrBuff.maxSize();
    if (debug)
        System.out.printf("Max: (%d, %d)\n", rMax, pMax);
    for (; iter.hasNext(); ) {
        int X = bptNode.getCount();
        int X2 = bptNode.getMaxSize();
        int P = ptrBuff.size();
        int P2 = ptrBuff.maxSize();
        int R = recBuff.size();
        int R2 = recBuff.maxSize();
        // bptNode.getMaxSize() is drivel
        // System.out.printf("N: %d/%d : P %d/%d : R %d/%d\n", X, X2, P, P2,
        // R, R2);
        Pair<Integer, Record> pair = iter.next();
        if (debug)
            System.out.println("** Item: " + pair);
        Record r = pair.cdr();
        // The record is key-only (which is correct) but until FREC fixed,
        // we need key,value
        r = recordFactory.create(r.getKey());
        // There is always one more ptr than record in a B+Tree node.
        if (ptrBuff.isFull())
            Log.error(this, "PtrBuffer is full");
        // Add pointer.
        ptrBuff.add(pair.car());
        if (ptrBuff.isFull()) {
            // Internal consistency check.
            if (!ptrBuff.isFull())
                Log.error(this, "PtrBuffer is not full");
            // The split point for the next level up.
            slot = new Pair<>(bptNode.getId(), pair.cdr());
            if (debug)
                System.out.printf("Write(1): %d\n", bptNode.getId());
            if (debug)
                System.out.println(bptNode);
            if (debug)
                System.out.println("Slot = " + slot);
            mgr.put(bptNode);
            // No count increment needed.
            return true;
        }
        recBuff.add(r);
        bptNode.setCount(bptNode.getCount() + 1);
    }
    // If we get here, the input stream ran out before we finished a
    // complete block.
    // Fix up block (remove the last record)
    Record r = recBuff.getHigh();
    recBuff.removeTop();
    bptNode.setCount(bptNode.getCount() - 1);
    slot = new Pair<>(bptNode.getId(), r);
    if (debug)
        System.out.printf("Write(2): %d\n", bptNode.getId());
    if (debug)
        System.out.println(bptNode);
    if (debug)
        System.out.println("Slot = " + slot);
    mgr.put(bptNode);
    return true;
}
Also used : BPTreeNode(org.apache.jena.dboe.trans.bplustree.BPTreeNode) Record(org.apache.jena.dboe.base.record.Record) RecordBuffer(org.apache.jena.dboe.base.buffer.RecordBuffer) PtrBuffer(org.apache.jena.dboe.base.buffer.PtrBuffer)

Example 3 with RecordBuffer

use of org.apache.jena.dboe.base.buffer.RecordBuffer in project jena by apache.

the class BPTreeNodeMgr method formatBPTreeNode.

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();
    // Allocate space for record, key and value, despite slight over allocation.
    int recBuffLen = params.MaxRec * params.getRecordLength();
    n.id = block.getId().intValue();
    n.setParent(parent);
    n.setCount(count);
    n.setIsLeaf(leaf);
    int header = BPlusTreeParams.BlockHeaderSize;
    int rStart = header;
    int pStart = header + recBuffLen;
    // Find the number of pointers.
    int numPtrs = -1;
    // Junk when creating a new new node.
    if (n.getCount() < 0) {
        numPtrs = 0;
        n.setCount(decodeCount(n.getCount()));
    } else
        numPtrs = n.getCount() + 1;
    // Block dependent
    n.block = block;
    ByteBuffer byteBuffer = block.getByteBuffer();
    // -- Records area
    byteBuffer.position(rStart);
    byteBuffer.limit(rStart + recBuffLen);
    ByteBuffer bbr = byteBuffer.slice();
    // bbr.limit(recBuffLen);
    n.setRecordBuffer(new RecordBuffer(bbr, n.params.keyFactory, n.getCount()));
    // -- Pointers area
    byteBuffer.position(pStart);
    byteBuffer.limit(pStart + ptrBuffLen);
    ByteBuffer bbi = byteBuffer.slice();
    // bbi.limit(ptrBuffLen);
    n.setPtrBuffer(new PtrBuffer(bbi, numPtrs));
    // Reset
    byteBuffer.rewind();
}
Also used : RecordBuffer(org.apache.jena.dboe.base.buffer.RecordBuffer) ByteBuffer(java.nio.ByteBuffer) PtrBuffer(org.apache.jena.dboe.base.buffer.PtrBuffer)

Example 4 with RecordBuffer

use of org.apache.jena.dboe.base.buffer.RecordBuffer in project jena by apache.

the class RecordBufferPageBase method rebuild.

protected void rebuild(Block block, int count) {
    ByteBuffer bb = block.getByteBuffer();
    bb.clear();
    bb.position(headerLength);
    bb = bb.slice();
    this.recBuff = new RecordBuffer(bb, factory, count);
}
Also used : RecordBuffer(org.apache.jena.dboe.base.buffer.RecordBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 5 with RecordBuffer

use of org.apache.jena.dboe.base.buffer.RecordBuffer 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)

Aggregations

RecordBuffer (org.apache.jena.dboe.base.buffer.RecordBuffer)7 PtrBuffer (org.apache.jena.dboe.base.buffer.PtrBuffer)3 ByteBuffer (java.nio.ByteBuffer)2 Record (org.apache.jena.dboe.base.record.Record)2 IOException (java.io.IOException)1 RecordBufferPage (org.apache.jena.dboe.base.recordbuffer.RecordBufferPage)1 BPTreeNode (org.apache.jena.dboe.trans.bplustree.BPTreeNode)1