Search in sources :

Example 21 with NodeDocument

use of org.apache.jackrabbit.oak.plugins.document.NodeDocument in project jackrabbit-oak by apache.

the class RDBDocumentStore method getIfCached.

@Override
public <T extends Document> T getIfCached(Collection<T> collection, String id) {
    if (collection != Collection.NODES) {
        return null;
    } else {
        NodeDocument doc = nodesCache.getIfPresent(id);
        doc = (doc != null) ? unwrap(doc) : null;
        return castAsT(doc);
    }
}
Also used : NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument)

Example 22 with NodeDocument

use of org.apache.jackrabbit.oak.plugins.document.NodeDocument in project jackrabbit-oak by apache.

the class RDBDocumentStore method invalidateNodesCache.

private void invalidateNodesCache(String id, boolean remove) {
    Lock lock = locks.acquire(id);
    try {
        if (remove) {
            nodesCache.invalidate(id);
        } else {
            nodesCache.markChanged(id);
            NodeDocument entry = nodesCache.getIfPresent(id);
            if (entry != null) {
                entry.markUpToDate(0);
            }
        }
    } finally {
        lock.unlock();
    }
}
Also used : NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) Lock(java.util.concurrent.locks.Lock)

Example 23 with NodeDocument

use of org.apache.jackrabbit.oak.plugins.document.NodeDocument in project jackrabbit-oak by apache.

the class RDBDocumentStore method readDocumentCached.

private <T extends Document> Map<String, T> readDocumentCached(Collection<T> collection, Set<String> keys) {
    Map<String, T> documents = new HashMap<String, T>();
    if (collection == Collection.NODES) {
        for (String key : keys) {
            NodeDocument cached = nodesCache.getIfPresent(key);
            if (cached != null && cached != NodeDocument.NULL) {
                T doc = castAsT(unwrap(cached));
                documents.put(doc.getId(), doc);
            }
        }
    }
    Set<String> documentsToRead = Sets.difference(keys, documents.keySet());
    Map<String, T> readDocuments = readDocumentsUncached(collection, documentsToRead);
    documents.putAll(readDocuments);
    if (collection == Collection.NODES) {
        for (T doc : readDocuments.values()) {
            nodesCache.putIfAbsent((NodeDocument) doc);
        }
    }
    return documents;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument)

Example 24 with NodeDocument

use of org.apache.jackrabbit.oak.plugins.document.NodeDocument in project jackrabbit-oak by apache.

the class Utils method internalGetSelectedDocuments.

private static Iterable<NodeDocument> internalGetSelectedDocuments(final DocumentStore store, final String indexedProperty, final long startValue, final int batchSize) {
    if (batchSize < 2) {
        throw new IllegalArgumentException("batchSize must be > 1");
    }
    return new Iterable<NodeDocument>() {

        @Override
        public Iterator<NodeDocument> iterator() {
            return new AbstractIterator<NodeDocument>() {

                private String startId = NodeDocument.MIN_ID_VALUE;

                private Iterator<NodeDocument> batch = nextBatch();

                @Override
                protected NodeDocument computeNext() {
                    // read next batch if necessary
                    if (!batch.hasNext()) {
                        batch = nextBatch();
                    }
                    NodeDocument doc;
                    if (batch.hasNext()) {
                        doc = batch.next();
                        // remember current id
                        startId = doc.getId();
                    } else {
                        doc = endOfData();
                    }
                    return doc;
                }

                private Iterator<NodeDocument> nextBatch() {
                    List<NodeDocument> result = indexedProperty == null ? store.query(Collection.NODES, startId, NodeDocument.MAX_ID_VALUE, batchSize) : store.query(Collection.NODES, startId, NodeDocument.MAX_ID_VALUE, indexedProperty, startValue, batchSize);
                    return result.iterator();
                }
            };
        }
    };
}
Also used : Iterator(java.util.Iterator) AbstractIterator(com.google.common.collect.AbstractIterator) AbstractIterator(com.google.common.collect.AbstractIterator) NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument)

Example 25 with NodeDocument

use of org.apache.jackrabbit.oak.plugins.document.NodeDocument in project jackrabbit-oak by apache.

the class MemoryDocumentStore method toString.

@Override
public String toString() {
    StringBuilder buff = new StringBuilder();
    buff.append("Nodes:\n");
    for (String p : nodes.keySet()) {
        buff.append("Path: ").append(p).append('\n');
        NodeDocument doc = nodes.get(p);
        for (Map.Entry<String, Object> entry : doc.entrySet()) {
            buff.append(entry.getKey()).append('=').append(entry.getValue()).append('\n');
        }
        buff.append("\n");
    }
    return buff.toString();
}
Also used : NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Aggregations

NodeDocument (org.apache.jackrabbit.oak.plugins.document.NodeDocument)43 Test (org.junit.Test)14 Lock (java.util.concurrent.locks.Lock)11 UpdateOp (org.apache.jackrabbit.oak.plugins.document.UpdateOp)8 DBObject (com.mongodb.DBObject)6 ArrayList (java.util.ArrayList)6 Nonnull (javax.annotation.Nonnull)6 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)6 BasicDBObject (com.mongodb.BasicDBObject)5 ExecutionException (java.util.concurrent.ExecutionException)5 Stopwatch (com.google.common.base.Stopwatch)4 DBCollection (com.mongodb.DBCollection)4 Revision (org.apache.jackrabbit.oak.plugins.document.Revision)4 DBCursor (com.mongodb.DBCursor)3 QueryBuilder (com.mongodb.QueryBuilder)3 Callable (java.util.concurrent.Callable)3 AbstractDocumentStoreTest (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentStoreTest)3 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)2 MongoException (com.mongodb.MongoException)2 ReadPreference (com.mongodb.ReadPreference)2