Search in sources :

Example 1 with RecordFactory

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

the class BPlusTreeTools method bpt_scan_nodes.

//    /*public*/private static void bpt_scan_nodes(String filename, boolean verbose)
//    {
//        RecordFactory f = FactoryGraphTDB.indexRecordTripleFactory ;
//        BPlusTree.
//        BlockMgr blkMgr = BlockMgrFactory.createStdFileNoCache(filename, SystemTDB.BlockSize) ;
//        bpt_scan_nodes(bpt, blkMgr, verbose) ;
//        blkMgr.close();
//    }
/*public*/
private static void bpt_scan_nodes(BPlusTree bpt, boolean verbose) {
    System.out.print("[Scan Nodes] start\n");
    RecordFactory f = SystemTDB.indexRecordTripleFactory;
    BPTreeNodeMgr nodeMgr = new BPTreeNodeMgr(bpt, bpt.getNodeManager().getBlockMgr());
    int idx = 0;
    int n = 0;
    int total = 0;
    if (verbose)
        System.out.printf("BPTreeNodeMgr = %s\n", nodeMgr);
    // Blocks in file order
    try {
        while (idx >= 0) {
            if (verbose)
                System.out.printf("idx = %d\n", idx);
            BPTreeNode node = nodeMgr.getRead(idx, 0);
            if (node == null)
                break;
            System.out.println(node);
            //            if ( verbose ) 
            //                System.out.printf("%04d :: id=%04d -> link=%04d [count=%d, max=%d]\n", n, page.getId(), page.getLink(), page.getCount(), page.getMaxSize()) ;
            n++;
            idx++;
            nodeMgr.release(node);
        }
    } catch (Exception ex) {
        System.out.println("Exception: " + ex);
        ex.printStackTrace();
    }
    System.out.printf("[Scan Nodes] Count = %d in %d blocks (avg: %.2f)\n", total, n, ((float) total) / n);
}
Also used : RecordFactory(org.apache.jena.tdb.base.record.RecordFactory) IOException(java.io.IOException)

Example 2 with RecordFactory

use of org.apache.jena.tdb.base.record.RecordFactory 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 3 with RecordFactory

use of org.apache.jena.tdb.base.record.RecordFactory 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 4 with RecordFactory

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

the class IndexAssembler method open.

@Override
public TupleIndex open(Assembler a, Resource root, Mode mode) {
    exactlyOneProperty(root, pDescription);
    String desc = getAsStringValue(root, pDescription).toUpperCase(Locale.ENGLISH);
    exactlyOneProperty(root, pFile);
    String filename = getAsStringValue(root, pFile);
    // Need to get location from the enclosing PGraphAssembler
    if (location != null)
        filename = location.absolute(filename);
    String primary = null;
    RecordFactory rf = null;
    switch(desc.length()) {
        case 3:
            primary = Names.primaryIndexTriples;
            rf = SystemTDB.indexRecordTripleFactory;
            break;
        case 4:
            primary = Names.primaryIndexQuads;
            rf = SystemTDB.indexRecordQuadFactory;
            break;
        default:
            throw new TDBException("Bad length for index description: " + desc);
    }
    // Problems with spotting the index technology.
    //FileSet.fromFilename(filename) ;
    FileSet fileset = null;
    IndexParams idxParams = StoreParams.getDftStoreParams();
    RangeIndex rIndex = IndexFactory.buildRangeIndex(fileset, rf, idxParams);
    return new TupleIndexRecord(desc.length(), new ColumnMap(primary, desc), desc, rf, rIndex);
}
Also used : ColumnMap(org.apache.jena.tdb.lib.ColumnMap) RecordFactory(org.apache.jena.tdb.base.record.RecordFactory) TupleIndexRecord(org.apache.jena.tdb.store.tupletable.TupleIndexRecord) FileSet(org.apache.jena.tdb.base.file.FileSet) TDBException(org.apache.jena.tdb.TDBException) IndexParams(org.apache.jena.tdb.index.IndexParams) RangeIndex(org.apache.jena.tdb.index.RangeIndex)

Example 5 with RecordFactory

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

the class SetupIndex method makeBPlusTree.

public static RangeIndex makeBPlusTree(FileSet fs, int blkSize, int readCacheSize, int writeCacheSize, int dftKeyLength, int dftValueLength) {
    RecordFactory recordFactory = makeRecordFactory(dftKeyLength, dftValueLength);
    int order = BPlusTreeParams.calcOrder(blkSize, recordFactory.recordLength());
    RangeIndex rIndex = createBPTree(fs, order, blkSize, readCacheSize, writeCacheSize, recordFactory);
    return rIndex;
}
Also used : RecordFactory(org.apache.jena.tdb.base.record.RecordFactory)

Aggregations

RecordFactory (org.apache.jena.tdb.base.record.RecordFactory)12 BlockMgr (org.apache.jena.tdb.base.block.BlockMgr)3 FileSet (org.apache.jena.tdb.base.file.FileSet)3 Record (org.apache.jena.tdb.base.record.Record)3 RangeIndex (org.apache.jena.tdb.index.RangeIndex)3 BPlusTree (org.apache.jena.tdb.index.bplustree.BPlusTree)3 BPlusTreeParams (org.apache.jena.tdb.index.bplustree.BPlusTreeParams)3 ColumnMap (org.apache.jena.tdb.lib.ColumnMap)3 Location (org.apache.jena.tdb.base.file.Location)2 ObjectFile (org.apache.jena.tdb.base.objectfile.ObjectFile)2 RecordBufferPageMgr (org.apache.jena.tdb.base.recordbuffer.RecordBufferPageMgr)2 IndexMap (org.apache.jena.tdb.index.IndexMap)2 TupleIndexRecord (org.apache.jena.tdb.store.tupletable.TupleIndexRecord)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 AtlasException (org.apache.jena.atlas.AtlasException)1 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)1 TDBException (org.apache.jena.tdb.TDBException)1 BufferChannelFile (org.apache.jena.tdb.base.file.BufferChannelFile)1