Search in sources :

Example 41 with Record

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

the class ProcRewriteIndex method exec.

public static void exec(Location srcLoc, Location dstLoc, String indexName) {
    FileSet destination = new FileSet(dstLoc, indexName);
    int readCacheSize = 0;
    int writeCacheSize = -1;
    int dftKeyLength;
    int dftValueLength;
    if (indexName.length() == 3) {
        dftKeyLength = SystemTDB.LenIndexTripleRecord;
        dftValueLength = 0;
    } else if (indexName.length() == 4) {
        dftKeyLength = SystemTDB.LenIndexQuadRecord;
        dftValueLength = 0;
    } else {
        System.err.printf("Can't determine record size for %s\n", indexName);
        return;
    }
    RecordFactory recordFactory = null;
    BPlusTreeParams bptParams = null;
    BlockMgr blkMgrNodes;
    BlockMgr blkMgrRecords;
    int blockSize = SystemTDB.BlockSize;
    RangeIndex rangeIndex = SetupIndex.makeRangeIndex(srcLoc, indexName, blockSize, dftKeyLength, dftValueLength, readCacheSize, writeCacheSize);
    BPlusTree bpt = (BPlusTree) rangeIndex;
    bptParams = bpt.getParams();
    recordFactory = bpt.getRecordFactory();
    int blockSizeNodes = blockSize;
    int blockSizeRecords = blockSize;
    blkMgrNodes = BlockMgrFactory.create(destination, Names.bptExtTree, blockSizeNodes, readCacheSize, writeCacheSize);
    blkMgrRecords = BlockMgrFactory.create(destination, Names.bptExtRecords, blockSizeRecords, readCacheSize, writeCacheSize);
    Iterator<Record> iterator = bpt.iterator();
    //            // Fakery.
    //            blkMgrNodes = BlockMgrFactory.create(destination, Names.bptExt1, blockSize, readCacheSize, writeCacheSize) ;
    //            blkMgrRecords = BlockMgrFactory.create(destination, Names.bptExt2, blockSize, readCacheSize, writeCacheSize) ;
    //            recordFactory = new RecordFactory(dftKeyLength, dftValueLength) ;
    //            bptParams = new BPlusTreeParams(3, recordFactory) ;
    //            List<Record> data = TestBPlusTreeRewriter.createData(10, recordFactory) ;
    //            iterator = data.iterator() ;
    //System.out.println("Rewrite: "+srcLoc+" "+indexName+" --> "+destination) ;
    BPlusTree bpt2 = BPlusTreeRewriter.packIntoBPlusTree(iterator, bptParams, recordFactory, blkMgrNodes, blkMgrRecords);
    if (bpt2 == null)
        return;
    //        
    //        Iterator<Record> iter = bpt2.iterator() ;
    //        for ( ; iter.hasNext() ; )
    //        {
    //            Record r = iter.next() ;
    //            System.out.println(r) ;
    //        }
    bpt2.close();
}
Also used : BPlusTreeParams(org.apache.jena.tdb.index.bplustree.BPlusTreeParams) RecordFactory(org.apache.jena.tdb.base.record.RecordFactory) FileSet(org.apache.jena.tdb.base.file.FileSet) BlockMgr(org.apache.jena.tdb.base.block.BlockMgr) Record(org.apache.jena.tdb.base.record.Record) RangeIndex(org.apache.jena.tdb.index.RangeIndex) BPlusTree(org.apache.jena.tdb.index.bplustree.BPlusTree)

Example 42 with Record

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

the class RecordsFromInput method next.

@Override
public Record next() {
    if (!hasNext())
        throw new NoSuchElementException();
    Record r = slot;
    slot = null;
    return r;
}
Also used : Record(org.apache.jena.tdb.base.record.Record) NoSuchElementException(java.util.NoSuchElementException)

Example 43 with Record

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

the class ProcIndexBuild method exec.

public static void exec(String locationStr, String indexName, String dataFile) {
    // Argument processing
    Location location = Location.create(locationStr);
    //InputStream input = System.in ;
    InputStream input = IO.openFile(dataFile);
    int keyLength = SystemTDB.SizeOfNodeId * indexName.length();
    int valueLength = 0;
    // The name is the order.
    String primary = indexName;
    // Scope for optimization:
    // Null column map => no churn.
    // Do record -> record copy, not Tuple, Tuple copy.
    String primaryOrder;
    int dftKeyLength;
    int dftValueLength;
    int tupleLength = indexName.length();
    if (tupleLength == 3) {
        primaryOrder = Names.primaryIndexTriples;
        dftKeyLength = SystemTDB.LenIndexTripleRecord;
        dftValueLength = 0;
    } else if (tupleLength == 4) {
        primaryOrder = Names.primaryIndexQuads;
        dftKeyLength = SystemTDB.LenIndexQuadRecord;
        dftValueLength = 0;
    } else {
        throw new AtlasException("Index name: " + indexName);
    }
    ColumnMap colMap = new ColumnMap(primaryOrder, indexName);
    // -1? Write only.
    // Also flush cache every so often => block writes (but not sequential so boring).
    int readCacheSize = 10;
    int writeCacheSize = 100;
    int blockSize = SystemTDB.BlockSize;
    RecordFactory recordFactory = new RecordFactory(dftKeyLength, dftValueLength);
    int order = BPlusTreeParams.calcOrder(blockSize, recordFactory);
    BPlusTreeParams bptParams = new BPlusTreeParams(order, recordFactory);
    int blockSizeNodes = blockSize;
    int blockSizeRecords = blockSize;
    FileSet destination = new FileSet(location, indexName);
    BlockMgr blkMgrNodes = BlockMgrFactory.create(destination, Names.bptExtTree, blockSizeNodes, readCacheSize, writeCacheSize);
    BlockMgr blkMgrRecords = BlockMgrFactory.create(destination, Names.bptExtRecords, blockSizeRecords, readCacheSize, writeCacheSize);
    int rowBlock = 1000;
    Iterator<Record> iter = new RecordsFromInput(input, tupleLength, colMap, rowBlock);
    BPlusTree bpt2 = BPlusTreeRewriter.packIntoBPlusTree(iter, bptParams, recordFactory, blkMgrNodes, blkMgrRecords);
    bpt2.close();
}
Also used : ColumnMap(org.apache.jena.tdb.lib.ColumnMap) BPlusTreeParams(org.apache.jena.tdb.index.bplustree.BPlusTreeParams) FileSet(org.apache.jena.tdb.base.file.FileSet) InputStream(java.io.InputStream) AtlasException(org.apache.jena.atlas.AtlasException) RecordFactory(org.apache.jena.tdb.base.record.RecordFactory) BlockMgr(org.apache.jena.tdb.base.block.BlockMgr) Record(org.apache.jena.tdb.base.record.Record) BPlusTree(org.apache.jena.tdb.index.bplustree.BPlusTree) Location(org.apache.jena.tdb.base.file.Location)

Example 44 with Record

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

the class BPTreeNode method checkNodeDeep.

private void checkNodeDeep(Record min, Record max) {
    checkNode(min, max);
    // Check pointers.
    int limit = (count == 0) ? 0 : count + 1;
    for (int i = 0; i < limit; i++) {
        Record min1 = min;
        Record max1 = max;
        BPTreePage n = get(i, READ);
        if (i != count) {
            // high key in immediate child 
            Record keySubTree = n.getHighRecord();
            // key in this
            Record keyHere = records.get(i);
            if (keySubTree == null)
                error("Node: %d: Can't get high record from %d", id, n.getId());
            if (keySubTree.getKey() == null)
                error("Node: %d: Can't get high record is missing it's key from %d", id, n.getId());
            if (keyHere == null)
                error("Node: %d: record is null", id);
            if (keyHere.getKey() == null)
                error("Node: %d: Record key is null", id);
            if (keyGT(keySubTree, keyHere))
                error("Node: %d: Child key %s is greater than this key %s", id, keySubTree, keyHere);
            // max key in subTree
            Record keyMax = n.maxRecord();
            Record keyMin = n.minRecord();
            if (keyNE(keyHere, keyMax))
                error("Node: %d: Key %s is not the max [%s] of the sub-tree idx=%d", id, keyHere, keyMax, i);
            if (min != null && keyGT(min, keyMin))
                error("Node: %d: Minimun for this node should be %s but it's %s", id, min, keyMin);
            if (max != null && keyLT(max, keyMax))
                error("Node: %d: Maximum for this node should be %s but it's %s", id, max, keyMax);
            if (min != null && keyGT(min, keyHere))
                error("Node: %d: Key too small: %s - min should be %s", id, keyHere, min);
            // keyHere == keyMax ??
            if (max != null && keyLT(max, keyHere))
                error("Node: %d: Key too large: %s - max should be %s", id, keyHere, max);
        }
        // Look deeper.
        if (!(n instanceof BPTreeNode)) {
            // Records.
            n.checkNodeDeep();
            n.release();
            continue;
        }
        // Valid pointer?
        if (isLeaf) {
            if (!bpTree.getRecordsMgr().getBlockMgr().valid(ptrs.get(i)))
                error("Node: %d: Dangling ptr (records) in block @%d :: %s", id, i, this);
        } else {
            if (!bpTree.getNodeManager().valid(ptrs.get(i)))
                error("Node: %d: Dangling ptr in block @%d :: %s", id, i, this);
        }
        // Calc new min/max.
        if (i == 0)
            max1 = records.get(0);
        else if (i == count) {
            min1 = records.get(count - 1);
            max1 = null;
        } else {
            min1 = records.get(i - 1);
            max1 = records.get(i);
        }
        //            if ( n.parent != id )
        //                error("Node: %d [%d]: Parent/child mismatch :: %s", id, n.parent, this) ;
        ((BPTreeNode) n).checkNodeDeep(min1, max1);
        n.release();
    }
}
Also used : Record(org.apache.jena.tdb.base.record.Record)

Example 45 with Record

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

the class RecordBuffer method toString.

@Override
public String toString() {
    StringBuilder str = new StringBuilder(40000);
    str.append(format("Len=%d Max=%d: ", numSlot, bb.limit() / slotLen));
    // Print active slots as records.
    for (int i = 0; i < numSlot; i++) {
        if (i != 0)
            str.append(" ");
        Record r = _get(i);
        str.append(r.toString());
    }
    //        // Print empty slots
    //        for ( int i = numSlot*slotLen ; i < maxSlot*slotLen ; i++ )
    //        {
    //            if ( i != 0 && i%slotLen == 0 )
    //                str.append(" ") ;
    //            byte b = bb.get(i) ;
    //            str.append(format("%02x", b)) ;
    //        }
    String s = str.toString();
    return s;
}
Also used : Record(org.apache.jena.tdb.base.record.Record)

Aggregations

Record (org.apache.jena.tdb.base.record.Record)96 BaseTest (org.apache.jena.atlas.junit.BaseTest)25 Test (org.junit.Test)25 RecordLib.intToRecord (org.apache.jena.tdb.base.record.RecordLib.intToRecord)20 RecordBuffer (org.apache.jena.tdb.base.buffer.RecordBuffer)15 RangeIndex (org.apache.jena.tdb.index.RangeIndex)8 BPTreeRecords (org.apache.jena.tdb.index.bplustree.BPTreeRecords)5 NodeId (org.apache.jena.tdb.store.NodeId)5 NoSuchElementException (java.util.NoSuchElementException)4 Pair (org.apache.jena.atlas.lib.Pair)4 BlockMgr (org.apache.jena.tdb.base.block.BlockMgr)4 RecordFactory (org.apache.jena.tdb.base.record.RecordFactory)4 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)3 StorageException (org.apache.jena.tdb.base.StorageException)3 FileSet (org.apache.jena.tdb.base.file.FileSet)3 Location (org.apache.jena.tdb.base.file.Location)3 RecordBufferPage (org.apache.jena.tdb.base.recordbuffer.RecordBufferPage)3 Index (org.apache.jena.tdb.index.Index)3 BPlusTree (org.apache.jena.tdb.index.bplustree.BPlusTree)3 TupleIndexRecord (org.apache.jena.tdb.store.tupletable.TupleIndexRecord)3