Search in sources :

Example 11 with TDBException

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

the class NodeTableCache method testForConsistency.

private void testForConsistency() {
    Iterator<Node> iter1 = Iter.toList(node2id_Cache.keys()).iterator();
    for (; iter1.hasNext(); ) {
        Node n = iter1.next();
        NodeId nId = node2id_Cache.getIfPresent(n);
        if (!id2node_Cache.containsKey(nId))
            throw new TDBException("Inconsistent: " + n + " => " + nId);
        if (notPresent.contains(n))
            throw new TDBException("Inconsistent: " + n + " in notPresent cache (1)");
    }
    Iterator<NodeId> iter2 = Iter.toList(id2node_Cache.keys()).iterator();
    for (; iter2.hasNext(); ) {
        NodeId nId = iter2.next();
        Node n = id2node_Cache.getIfPresent(nId);
        if (!node2id_Cache.containsKey(n))
            throw new TDBException("Inconsistent: " + nId + " => " + n);
        if (notPresent.contains(n))
            throw new TDBException("Inconsistent: " + n + " in notPresent cache (2)");
    }
}
Also used : Node(org.apache.jena.graph.Node) TDBException(org.apache.jena.tdb.TDBException) NodeId(org.apache.jena.tdb.store.NodeId)

Example 12 with TDBException

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

the class NodeTableNative method accessIndex.

protected final NodeId accessIndex(Node node, boolean create) {
    Hash hash = new Hash(nodeHashToId.getRecordFactory().keyLength());
    setHash(hash, node);
    byte[] k = hash.getBytes();
    // Key only.
    Record r = nodeHashToId.getRecordFactory().create(k);
    synchronized (// Pair to readNodeFromTable.
    this) {
        // Key and value, or null
        Record r2 = nodeHashToId.find(r);
        if (r2 != null) {
            // Found.  Get the NodeId.
            NodeId id = NodeId.create(r2.getValue(), 0);
            return id;
        }
        // Not found.
        if (!create)
            return NodeId.NodeDoesNotExist;
        // Write the node, which allocates an id for it.
        NodeId id = writeNodeToTable(node);
        // Update the r record with the new id.
        // r.value := id bytes ; 
        id.toBytes(r.getValue(), 0);
        // Put in index - may appear because of concurrency
        if (!nodeHashToId.add(r))
            throw new TDBException("NodeTableBase::nodeToId - record mysteriously appeared");
        return id;
    }
}
Also used : TDBException(org.apache.jena.tdb.TDBException) NodeId(org.apache.jena.tdb.store.NodeId) Record(org.apache.jena.tdb.base.record.Record) NodeLib.setHash(org.apache.jena.tdb.lib.NodeLib.setHash) Hash(org.apache.jena.tdb.store.Hash)

Example 13 with TDBException

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

the class TupleIndexRecord method findWorker.

private Iterator<Tuple<NodeId>> findWorker(Tuple<NodeId> patternNaturalOrder, boolean partialScanAllowed, boolean fullScanAllowed) {
    if (Check) {
        if (tupleLength != patternNaturalOrder.len())
            throw new TDBException(String.format("Mismatch: tuple length %d / index for length %d", patternNaturalOrder.len(), tupleLength));
    }
    // Convert to index order.
    Tuple<NodeId> pattern = colMap.map(patternNaturalOrder);
    // Canonical form.
    int numSlots = 0;
    // Index of last leading pattern NodeId. Start less
    int leadingIdx = -2;
    // than numSlots-1
    boolean leading = true;
    // Records.
    Record minRec = factory.createKeyOnly();
    Record maxRec = factory.createKeyOnly();
    // Set the prefixes.
    for (int i = 0; i < pattern.len(); i++) {
        NodeId X = pattern.get(i);
        if (NodeId.isAny(X)) {
            X = null;
            // No longer seting leading key slots.
            leading = false;
            continue;
        }
        numSlots++;
        if (leading) {
            leadingIdx = i;
            Bytes.setLong(X.getId(), minRec.getKey(), i * SizeOfNodeId);
            Bytes.setLong(X.getId(), maxRec.getKey(), i * SizeOfNodeId);
        }
    }
    // Is it a simple existence test?
    if (numSlots == pattern.len()) {
        if (index.contains(minRec))
            return new SingletonIterator<>(pattern);
        else
            return new NullIterator<>();
    }
    Iterator<Record> iter = null;
    if (leadingIdx < 0) {
        if (!fullScanAllowed)
            return null;
        // System.out.println("Full scan") ;
        // Full scan necessary
        iter = index.iterator();
    } else {
        // Adjust the maxRec.
        NodeId X = pattern.get(leadingIdx);
        // Set the max Record to the leading NodeIds, +1.
        // Example, SP? inclusive to S(P+1)? exclusive where ? is zero.
        Bytes.setLong(X.getId() + 1, maxRec.getKey(), leadingIdx * SizeOfNodeId);
        iter = index.iterator(minRec, maxRec);
    }
    Iterator<Tuple<NodeId>> tuples = Iter.map(iter, item -> TupleLib.tuple(item, colMap));
    if (leadingIdx < numSlots - 1) {
        if (!partialScanAllowed)
            return null;
        // Didn't match all defined slots in request.
        // Partial or full scan needed.
        // pattern.unmap(colMap) ;
        tuples = TupleIndex.scan(tuples, patternNaturalOrder);
    }
    return tuples;
}
Also used : TDBException(org.apache.jena.tdb.TDBException) SizeOfNodeId(org.apache.jena.tdb.sys.SystemTDB.SizeOfNodeId) NodeId(org.apache.jena.tdb.store.NodeId) Record(org.apache.jena.tdb.base.record.Record) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 14 with TDBException

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

the class LocationLock method takeLock.

private void takeLock(int pid) {
    File lockFile = getLockFile();
    checkLockFileForWrite(lockFile);
    // Write our PID to the lock file
    try (BufferedWriter writer = new BufferedWriter(new FileWriter(lockFile))) {
        writer.write(Integer.toString(pid));
        writer.close();
    } catch (IOException e) {
        throw new TDBException("Failed to obtain a lock on the location " + location.getDirectoryPath(), e);
    }
    // Mark lock for deletion on JVM exit
    // This does not guarantee that the lock file gets cleaned up because
    // such deletions only succeed for normal JVM termination but it should
    // clean up the lock for normal JVM terminations
    lockFile.deleteOnExit();
}
Also used : FileWriter(java.io.FileWriter) TDBException(org.apache.jena.tdb.TDBException) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 15 with TDBException

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

the class StoreParamsCodec method getStringArray.

private static String[] getStringArray(JsonObject json, String key) {
    if (!json.hasKey(key))
        throw new TDBException("StoreParamsCodec.getStringArray: no such key: " + key);
    JsonArray a = json.get(key).getAsArray();
    String[] x = new String[a.size()];
    for (int i = 0; i < a.size(); i++) {
        x[i] = a.get(i).getAsString().value();
    }
    return x;
}
Also used : JsonArray(org.apache.jena.atlas.json.JsonArray) TDBException(org.apache.jena.tdb.TDBException)

Aggregations

TDBException (org.apache.jena.tdb.TDBException)21 NodeId (org.apache.jena.tdb.store.NodeId)5 Node (org.apache.jena.graph.Node)4 File (java.io.File)2 Record (org.apache.jena.tdb.base.record.Record)2 NodeTable (org.apache.jena.tdb.store.nodetable.NodeTable)2 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 HashSet (java.util.HashSet)1 JsonArray (org.apache.jena.atlas.json.JsonArray)1 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)1 Triple (org.apache.jena.graph.Triple)1 RiotException (org.apache.jena.riot.RiotException)1 Token (org.apache.jena.riot.tokens.Token)1 Tokenizer (org.apache.jena.riot.tokens.Tokenizer)1 Binding (org.apache.jena.sparql.engine.binding.Binding)1 Block (org.apache.jena.tdb.base.block.Block)1 FileSet (org.apache.jena.tdb.base.file.FileSet)1