public static NodeTable create(NodeTable nodeTable, int nodeToIdCacheSize, int idToNodeCacheSize, int nodeMissesCacheSize) { if ( nodeToIdCacheSize <= 0 && idToNodeCacheSize <= 0 ) return nodeTable ; return new NodeTableCache(nodeTable, nodeToIdCacheSize, idToNodeCacheSize, nodeMissesCacheSize) ; }
/** Find the NodeId for a node, or return NodeId.NodeDoesNotExist */ @Override public NodeId getNodeIdForNode(Node node) { return _idForNode(node, false) ; }
/** Get the Node for this NodeId, or null if none */ @Override public Node getNodeForNodeId(NodeId id) { return _retrieveNodeByNodeId(id) ; }
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 ; } }
@Override public boolean containsNodeId(NodeId nodeId) { Node x = getNodeForNodeId(nodeId) ; return x == null ; }
@Override public boolean containsNode(Node node) { NodeId x = getNodeIdForNode(node) ; return NodeId.isDoesNotExist(x) ; }
private NodeTable buildNodeTable(FileSet fsIndex, FileSet fsObjectFile, StoreParams params) { RecordFactory recordFactory = new RecordFactory(SystemTDB.LenNodeHash, SystemTDB.SizeOfNodeId) ; Index idx = /*indexBuilder.*/buildIndex(fsIndex, recordFactory, params) ; ObjectFile objectFile = objectFileBuilder.buildObjectFile(fsObjectFile, Names.extNodeData) ; NodeTable nodeTable = new NodeTableNative(idx, objectFile) ; nodeTable = NodeTableCache.create(nodeTable, params.getNode2NodeIdCacheSize(), params.getNodeId2NodeCacheSize(), params.getNodeMissCacheSize()) ; nodeTable = NodeTableInline.create(nodeTable) ; return nodeTable ; }
private Node _retrieveNodeByNodeId(NodeId id) { if ( NodeId.isDoesNotExist(id) ) return null ; if ( NodeId.isAny(id) ) return null ; // Try once outside the synchronized // (Cache access is thread-safe) Node n = cacheLookup(id) ; if ( n != null ) return n ; synchronized (lock) { // Lock to update two caches consisently. // Verify cache miss n = cacheLookup(id) ; if ( n != null ) return n ; if ( baseTable == null ) System.err.println(""+this) ; n = baseTable.getNodeForNodeId(id) ; cacheUpdate(n, id) ; return n ; } }
public static NodeTable create(NodeTable nodeTable, StoreParams params) { int nodeToIdCacheSize = params.getNode2NodeIdCacheSize() ; int idToNodeCacheSize = params.getNodeId2NodeCacheSize() ; if ( nodeToIdCacheSize <= 0 && idToNodeCacheSize <= 0 ) return nodeTable ; return new NodeTableCache(nodeTable, nodeToIdCacheSize, idToNodeCacheSize, params.getNodeMissCacheSize()) ; }
/** Find the NodeId for a node, allocating a new NodeId if the Node does not yet have a NodeId */ @Override public NodeId getAllocateNodeId(Node node) { return _idForNode(node, true) ; }