Search in sources :

Example 6 with FileSet

use of org.apache.jena.tdb.base.file.FileSet 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 {
        FmtLog.error(ProcRewriteIndex.class, "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 7 with FileSet

use of org.apache.jena.tdb.base.file.FileSet in project jena by apache.

the class TestBPlusTreeRewriter method runOneTest.

static void runOneTest(int order, int N, RecordFactory recordFactory, boolean debug) {
    BPlusTreeParams bptParams = new BPlusTreeParams(order, recordFactory);
    BPlusTreeRewriter.debug = debug;
    // ---- Test data
    List<Record> originaldata = TestBPlusTreeRewriter.createData(N, recordFactory);
    FileSet destination = FileSet.mem();
    // ---- Rewrite
    // Write leaves to ...
    BlockMgr blkMgr1 = BlockMgrFactory.create(destination, Names.bptExtTree, bptParams.getCalcBlockSize(), 10, 10);
    // Write nodes to ...
    BlockMgr blkMgr2 = BlockMgrFactory.create(destination, Names.bptExtTree, bptParams.getCalcBlockSize(), 10, 10);
    BPlusTree bpt2 = BPlusTreeRewriter.packIntoBPlusTree(originaldata.iterator(), bptParams, recordFactory, blkMgr1, blkMgr2);
    if (debug) {
        BPlusTreeRewriterUtils.divider();
        bpt2.dump();
    }
    // ---- Checking
    bpt2.check();
    scanComparision(originaldata, bpt2);
    findComparison(originaldata, bpt2);
    sizeComparison(originaldata, bpt2);
}
Also used : FileSet(org.apache.jena.tdb.base.file.FileSet) BlockMgr(org.apache.jena.tdb.base.block.BlockMgr) Record(org.apache.jena.tdb.base.record.Record)

Example 8 with FileSet

use of org.apache.jena.tdb.base.file.FileSet in project jena by apache.

the class SetupIndex method makeRangeIndex.

public static RangeIndex makeRangeIndex(Location location, String indexName, int blkSize, int dftKeyLength, int dftValueLength, int readCacheSize, int writeCacheSize) {
    FileSet fs = new FileSet(location, indexName);
    RangeIndex rIndex = makeBPlusTree(fs, blkSize, readCacheSize, writeCacheSize, dftKeyLength, dftValueLength);
    return rIndex;
}
Also used : FileSet(org.apache.jena.tdb.base.file.FileSet)

Example 9 with FileSet

use of org.apache.jena.tdb.base.file.FileSet in project jena by apache.

the class SetupTDB method makeTupleIndex.

public static TupleIndex makeTupleIndex(Location location, String primary, String indexOrder, String indexName, int keyLength) {
    FileSet fs = new FileSet(location, indexName);
    int readCacheSize = params.getBlockReadCacheSize();
    int writeCacheSize = params.getBlockWriteCacheSize();
    // Value part is null (zero length)
    RangeIndex rIndex = SetupIndex.makeRangeIndex(location, indexName, params.getBlockSize(), keyLength, 0, readCacheSize, writeCacheSize);
    TupleIndex tupleIndex = new TupleIndexRecord(primary.length(), new ColumnMap(primary, indexOrder), indexOrder, rIndex.getRecordFactory(), rIndex);
    return tupleIndex;
}
Also used : ColumnMap(org.apache.jena.tdb.lib.ColumnMap) TupleIndexRecord(org.apache.jena.tdb.store.tupletable.TupleIndexRecord) FileSet(org.apache.jena.tdb.base.file.FileSet) RangeIndex(org.apache.jena.tdb.index.RangeIndex) TupleIndex(org.apache.jena.tdb.store.tupletable.TupleIndex)

Example 10 with FileSet

use of org.apache.jena.tdb.base.file.FileSet 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)

Aggregations

FileSet (org.apache.jena.tdb.base.file.FileSet)12 BlockMgr (org.apache.jena.tdb.base.block.BlockMgr)5 Record (org.apache.jena.tdb.base.record.Record)5 RecordFactory (org.apache.jena.tdb.base.record.RecordFactory)5 ColumnMap (org.apache.jena.tdb.lib.ColumnMap)5 RangeIndex (org.apache.jena.tdb.index.RangeIndex)4 BPlusTree (org.apache.jena.tdb.index.bplustree.BPlusTree)4 BPlusTreeParams (org.apache.jena.tdb.index.bplustree.BPlusTreeParams)4 InputStream (java.io.InputStream)2 AtlasException (org.apache.jena.atlas.AtlasException)2 Location (org.apache.jena.tdb.base.file.Location)2 NodeTable (org.apache.jena.tdb.store.nodetable.NodeTable)2 TupleIndexRecord (org.apache.jena.tdb.store.tupletable.TupleIndexRecord)2 TDBException (org.apache.jena.tdb.TDBException)1 ObjectFile (org.apache.jena.tdb.base.objectfile.ObjectFile)1 IndexParams (org.apache.jena.tdb.index.IndexParams)1 StoreParams (org.apache.jena.tdb.setup.StoreParams)1 TupleIndex (org.apache.jena.tdb.store.tupletable.TupleIndex)1