Search in sources :

Example 41 with NodeId

use of org.apache.jena.tdb.store.NodeId in project jena by apache.

the class StatsCollectorNodeId method convert.

@Override
protected Map<Node, Integer> convert(Map<NodeId, Integer> stats) {
    Map<Node, Integer> statsNodes = new HashMap<>(1000);
    for (NodeId p : stats.keySet()) {
        Node n = nodeTable.getNodeForNodeId(p);
        statsNodes.put(n, stats.get(p));
    }
    return statsNodes;
}
Also used : HashMap(java.util.HashMap) Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb.store.NodeId)

Example 42 with NodeId

use of org.apache.jena.tdb.store.NodeId 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 43 with NodeId

use of org.apache.jena.tdb.store.NodeId in project jena by apache.

the class NodeTableCache method _idForNode.

// Node ==> NodeId
private NodeId _idForNode(Node node, boolean allocate) {
    if (node == Node.ANY)
        return NodeId.NodeIdAny;
    // Try once outside the synchronized
    // (Cache access is thread-safe.) 
    NodeId nodeId = cacheLookup(node);
    if (nodeId != null)
        return nodeId;
    synchronized (lock) {
        // Update two caches inside synchronized.
        // Check stil valid.
        nodeId = cacheLookup(node);
        if (nodeId != null)
            return nodeId;
        if (allocate)
            nodeId = baseTable.getAllocateNodeId(node);
        else
            nodeId = baseTable.getNodeIdForNode(node);
        // Ensure caches have it.  Includes recording "no such node"
        cacheUpdate(node, nodeId);
        return nodeId;
    }
}
Also used : NodeId(org.apache.jena.tdb.store.NodeId)

Example 44 with NodeId

use of org.apache.jena.tdb.store.NodeId in project jena by apache.

the class NodeTableLogger method getNodeIdForNode.

@Override
public NodeId getNodeIdForNode(Node node) {
    //info("getNodeIdForNode("+node+") =>") ;
    NodeId nId = nodeTable.getNodeIdForNode(node);
    info("getNodeIdForNode(" + node + ") => " + nId);
    return nId;
}
Also used : NodeId(org.apache.jena.tdb.store.NodeId)

Example 45 with NodeId

use of org.apache.jena.tdb.store.NodeId 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)

Aggregations

NodeId (org.apache.jena.tdb.store.NodeId)76 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)29 BaseTest (org.apache.jena.atlas.junit.BaseTest)28 Test (org.junit.Test)28 TupleIndex (org.apache.jena.tdb.store.tupletable.TupleIndex)20 Node (org.apache.jena.graph.Node)18 NodeTable (org.apache.jena.tdb.store.nodetable.NodeTable)10 Pair (org.apache.jena.atlas.lib.Pair)5 Var (org.apache.jena.sparql.core.Var)5 TDBException (org.apache.jena.tdb.TDBException)5 Record (org.apache.jena.tdb.base.record.Record)5 StatsCollectorNodeId (org.apache.jena.tdb.solver.stats.StatsCollectorNodeId)5 NodeTableTrans (org.apache.jena.tdb.transaction.NodeTableTrans)5 Transaction (org.apache.jena.tdb.transaction.Transaction)5 Predicate (java.util.function.Predicate)2 Location (org.apache.jena.tdb.base.file.Location)2 RangeIndex (org.apache.jena.tdb.index.RangeIndex)2 StatsResults (org.apache.jena.tdb.solver.stats.StatsResults)2 DatasetGraphTDB (org.apache.jena.tdb.store.DatasetGraphTDB)2 Hash (org.apache.jena.tdb.store.Hash)2