Search in sources :

Example 1 with Record

use of org.apache.jena.dboe.base.record.Record in project jena by apache.

the class TestBPTreeRecordsNonTxn method check.

protected static void check(BPTreeRecords bpr) {
    assertTrue(bpr.getCount() >= 0);
    assertTrue(bpr.getCount() <= bpr.getMaxSize());
    assertEquals(bpr.getRecordBuffer().getLow(), bpr.getLowRecord());
    assertEquals(bpr.getRecordBuffer().getHigh(), bpr.getHighRecord());
    for (int i = 1; i < bpr.getCount(); i++) {
        Record r1 = bpr.getRecordBuffer().get(i - 1);
        Record r2 = bpr.getRecordBuffer().get(i);
        assertTrue(Record.keyLE(r1, r2));
    }
}
Also used : Record(org.apache.jena.dboe.base.record.Record)

Example 2 with Record

use of org.apache.jena.dboe.base.record.Record in project jena by apache.

the class TestBPTreeRecordsNonTxn method bpt_shift_2.

@Test
public void bpt_shift_2() {
    BPTreeRecords bpr1 = make();
    BPTreeRecords bpr2 = make();
    insert(bpr1, 10);
    Record r = bpr2.shiftLeft(bpr1, null);
    assertTrue(Record.keyEQ(r, RecordLib.intToRecord(10)));
    contains(bpr1);
    contains(bpr2, 10);
    bpr1.release();
    bpr2.release();
}
Also used : Record(org.apache.jena.dboe.base.record.Record)

Example 3 with Record

use of org.apache.jena.dboe.base.record.Record in project jena by apache.

the class TestBPTreeRecordsNonTxn method bpt_records_6.

@Test
public void bpt_records_6() {
    BPTreeRecords bpr = make();
    fill(bpr);
    // No match.
    assertNull(search(bpr, RecordLib.intToRecord(0x20)));
    Record r = RecordLib.intToRecord(0x32);
    Record r2 = search(bpr, r);
    assertTrue(Record.keyEQ(r, r2));
    r = bpr.getLowRecord();
    r2 = search(bpr, r);
    assertTrue(Record.keyEQ(r, r2));
    r = bpr.getHighRecord();
    r2 = search(bpr, r);
    assertTrue(Record.keyEQ(r, r2));
    bpr.release();
}
Also used : Record(org.apache.jena.dboe.base.record.Record)

Example 4 with Record

use of org.apache.jena.dboe.base.record.Record in project jena by apache.

the class TestBPTreeRecordsNonTxn method bpt_shift_1.

@Test
public void bpt_shift_1() {
    BPTreeRecords bpr1 = make();
    BPTreeRecords bpr2 = make();
    insert(bpr1, 10);
    Record r = bpr1.shiftRight(bpr2, null);
    assertNull(r);
    // assertTrue(Record.keyEQ(r, RecordTestLib.intToRecord(10)));
    contains(bpr1);
    contains(bpr2, 10);
    bpr1.release();
    bpr2.release();
}
Also used : Record(org.apache.jena.dboe.base.record.Record)

Example 5 with Record

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

Aggregations

Record (org.apache.jena.dboe.base.record.Record)71 RecordLib.intToRecord (org.apache.jena.dboe.test.RecordLib.intToRecord)6 Pair (org.apache.jena.atlas.lib.Pair)5 NoSuchElementException (java.util.NoSuchElementException)3 BufferChannel (org.apache.jena.dboe.base.file.BufferChannel)3 FileSet (org.apache.jena.dboe.base.file.FileSet)3 RecordBufferPage (org.apache.jena.dboe.base.recordbuffer.RecordBufferPage)3 BPTreeNode (org.apache.jena.dboe.trans.bplustree.BPTreeNode)3 BPlusTree (org.apache.jena.dboe.trans.bplustree.BPlusTree)3 BPlusTreeParams (org.apache.jena.dboe.trans.bplustree.BPlusTreeParams)3 NodeId (org.apache.jena.tdb2.store.NodeId)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 StorageException (org.apache.jena.dboe.base.StorageException)2 BlockMgr (org.apache.jena.dboe.base.block.BlockMgr)2 RecordBuffer (org.apache.jena.dboe.base.buffer.RecordBuffer)2 RecordFactory (org.apache.jena.dboe.base.record.RecordFactory)2 Index (org.apache.jena.dboe.index.Index)2 RangeIndex (org.apache.jena.dboe.index.RangeIndex)2 TDBException (org.apache.jena.tdb2.TDBException)2