Search in sources :

Example 11 with TDBException

use of org.apache.jena.tdb2.TDBException in project jena by apache.

the class NodeTableTRDF method writeNodeToTable.

@Override
protected NodeId writeNodeToTable(Node node) {
    RDF_Term term = ThriftConvert.convert(node, true);
    try {
        long x = diskFile.length();
        // Paired : [*]
        NodeId nid = NodeIdFactory.createPtr(x);
        term.write(protocol);
        // transport.flush();
        return nid;
    } catch (TransactionException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new TDBException("NodeTableThrift/Write", ex);
    }
}
Also used : TransactionException(org.apache.jena.dboe.transaction.txn.TransactionException) TDBException(org.apache.jena.tdb2.TDBException) NodeId(org.apache.jena.tdb2.store.NodeId) RDF_Term(org.apache.jena.riot.thrift.wire.RDF_Term) RiotThriftException(org.apache.jena.riot.thrift.RiotThriftException) TDBException(org.apache.jena.tdb2.TDBException) TException(org.apache.thrift.TException) TransactionException(org.apache.jena.dboe.transaction.txn.TransactionException)

Example 12 with TDBException

use of org.apache.jena.tdb2.TDBException in project jena by apache.

the class NodeTableTRDF method readNodeFromTable.

@Override
protected Node readNodeFromTable(NodeId id) {
    try {
        // Paired : [*]
        long x = id.getPtrLocation();
        transport.readPosition(x);
        RDF_Term term = new RDF_Term();
        term.read(protocol);
        Node n = ThriftConvert.convert(term);
        return n;
    } catch (TException ex) {
        throw new TDBException("NodeTableTRDF/Read", ex);
    } catch (RiotThriftException ex) {
        Log.error(this, "Bad encoding: NodeId = " + id);
        throw ex;
    }
}
Also used : TException(org.apache.thrift.TException) RiotThriftException(org.apache.jena.riot.thrift.RiotThriftException) Node(org.apache.jena.graph.Node) TDBException(org.apache.jena.tdb2.TDBException) RDF_Term(org.apache.jena.riot.thrift.wire.RDF_Term)

Example 13 with TDBException

use of org.apache.jena.tdb2.TDBException in project jena by apache.

the class BindingTDB method get1.

@Override
public Node get1(Var var) {
    try {
        Node n = cacheGet(var);
        if (n != null)
            return n;
        NodeId id = idBinding.get(var);
        if (id == null)
            return null;
        if (NodeId.isDoesNotExist(id))
            return null;
        n = nodeTable.getNodeForNodeId(id);
        if (n == null)
            // But there was to put it in the BindingNodeId.
            throw new TDBException("No node in NodeTable for NodeId " + id);
        // Update cache.
        cachePut(var, n);
        return n;
    } catch (Exception ex) {
        Log.error(this, String.format("get1(%s)", var), ex);
        return null;
    }
}
Also used : Node(org.apache.jena.graph.Node) TDBException(org.apache.jena.tdb2.TDBException) NodeId(org.apache.jena.tdb2.store.NodeId) TDBException(org.apache.jena.tdb2.TDBException)

Example 14 with TDBException

use of org.apache.jena.tdb2.TDBException in project jena by apache.

the class ProcBuildIndexX method indexBuilder.

private static long indexBuilder(DatasetGraph dsg, InputStream input, String indexName) {
    long tickPoint = BulkLoaderX.DataTick;
    int superTick = BulkLoaderX.DataSuperTick;
    // Location of storage, not the DB.
    DatasetGraphTDB dsgtdb = TDBInternal.getDatasetGraphTDB(dsg);
    Location location = dsgtdb.getLocation();
    int keyLength = SystemTDB.SizeOfNodeId * indexName.length();
    int valueLength = 0;
    // The name is the order.
    String primary = indexName;
    String primaryOrder;
    int dftKeyLength;
    int dftValueLength;
    int tupleLength = indexName.length();
    TupleIndex index;
    if (tupleLength == 3) {
        primaryOrder = Names.primaryIndexTriples;
        dftKeyLength = SystemTDB.LenIndexTripleRecord;
        dftValueLength = 0;
        // Find index.
        index = findIndex(dsgtdb.getTripleTable().getNodeTupleTable().getTupleTable().getIndexes(), indexName);
    } else if (tupleLength == 4) {
        primaryOrder = Names.primaryIndexQuads;
        dftKeyLength = SystemTDB.LenIndexQuadRecord;
        dftValueLength = 0;
        index = findIndex(dsgtdb.getQuadTable().getNodeTupleTable().getTupleTable().getIndexes(), indexName);
    } else {
        throw new TDBException("Index name: " + indexName);
    }
    TupleMap colMap = TupleMap.create(primaryOrder, indexName);
    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);
    BufferChannel blkState = FileFactory.createBufferChannel(destination, Names.extBptState);
    BlockMgr blkMgrNodes = BlockMgrFactory.create(destination, Names.extBptTree, blockSizeNodes, readCacheSize, writeCacheSize);
    BlockMgr blkMgrRecords = BlockMgrFactory.create(destination, Names.extBptRecords, blockSizeRecords, readCacheSize, writeCacheSize);
    int rowBlock = 1000;
    Iterator<Record> iter = new RecordsFromInput(input, tupleLength, colMap, rowBlock);
    // ProgressMonitor.
    ProgressMonitor monitor = ProgressMonitorOutput.create(BulkLoaderX.LOG_Index, indexName, tickPoint, superTick);
    ProgressIterator<Record> iter2 = new ProgressIterator<>(iter, monitor);
    monitor.start();
    BPlusTree bpt2 = BPlusTreeRewriter.packIntoBPlusTree(iter2, bptParams, recordFactory, blkState, blkMgrNodes, blkMgrRecords);
    bpt2.close();
    monitor.finish();
    // [BULK] End stage.
    long count = monitor.getTicks();
    return count;
}
Also used : BPlusTreeParams(org.apache.jena.dboe.trans.bplustree.BPlusTreeParams) FileSet(org.apache.jena.dboe.base.file.FileSet) TDBException(org.apache.jena.tdb2.TDBException) BufferChannel(org.apache.jena.dboe.base.file.BufferChannel) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB) TupleMap(org.apache.jena.atlas.lib.tuple.TupleMap) ProgressIterator(org.apache.jena.system.progress.ProgressIterator) ProgressMonitor(org.apache.jena.system.progress.ProgressMonitor) RecordFactory(org.apache.jena.dboe.base.record.RecordFactory) BlockMgr(org.apache.jena.dboe.base.block.BlockMgr) Record(org.apache.jena.dboe.base.record.Record) TupleIndex(org.apache.jena.tdb2.store.tupletable.TupleIndex) BPlusTree(org.apache.jena.dboe.trans.bplustree.BPlusTree) Location(org.apache.jena.dboe.base.file.Location)

Example 15 with TDBException

use of org.apache.jena.tdb2.TDBException in project jena by apache.

the class ThreadBufferingCache method getOrFill.

@Override
public Value getOrFill(Key key, Callable<Value> callable) {
    if (!buffering())
        return baseCache.getOrFill(key, callable);
    // Not thread safe but this overlay cache is for single-thread use.
    Value item = localCache().getIfPresent(key);
    if (item != null)
        return item;
    item = baseCache.getIfPresent(key);
    if (item != null)
        return item;
    // Add to cache so new data hence place in localCache.
    try {
        item = callable.call();
        localCache().put(key, item);
    } catch (Exception ex) {
        throw new TDBException("Exception filling cache", ex);
    }
    return item;
}
Also used : TDBException(org.apache.jena.tdb2.TDBException) TDBException(org.apache.jena.tdb2.TDBException)

Aggregations

TDBException (org.apache.jena.tdb2.TDBException)20 NodeId (org.apache.jena.tdb2.store.NodeId)6 Node (org.apache.jena.graph.Node)4 DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)4 Location (org.apache.jena.dboe.base.file.Location)3 Record (org.apache.jena.dboe.base.record.Record)3 RiotThriftException (org.apache.jena.riot.thrift.RiotThriftException)2 RDF_Term (org.apache.jena.riot.thrift.wire.RDF_Term)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 TException (org.apache.thrift.TException)2 ArrayList (java.util.ArrayList)1 RuntimeIOException (org.apache.jena.atlas.RuntimeIOException)1 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)1 TupleMap (org.apache.jena.atlas.lib.tuple.TupleMap)1 BlockMgr (org.apache.jena.dboe.base.block.BlockMgr)1 BufferChannel (org.apache.jena.dboe.base.file.BufferChannel)1 FileSet (org.apache.jena.dboe.base.file.FileSet)1 ProcessFileLock (org.apache.jena.dboe.base.file.ProcessFileLock)1 RecordFactory (org.apache.jena.dboe.base.record.RecordFactory)1 BPlusTree (org.apache.jena.dboe.trans.bplustree.BPlusTree)1