use of javax.annotation.CheckForNull in project jackrabbit-oak by apache.
the class SecondaryStoreCache method getDocumentNodeState.
@CheckForNull
@Override
public AbstractDocumentNodeState getDocumentNodeState(String path, RevisionVector rootRevision, RevisionVector lastRev) {
//TODO We might need skip the calls if they occur due to SecondaryStoreObserver
//doing the diff or in the startup when we try to sync the state
PathFilter.Result result = pathFilter.filter(path);
if (result != PathFilter.Result.INCLUDE) {
unknownPaths.mark();
return null;
}
if (!DelegatingDocumentNodeState.hasMetaProps(store.getRoot())) {
return null;
}
AbstractDocumentNodeState currentRoot = DelegatingDocumentNodeState.wrap(store.getRoot(), differ);
//not have the matching result
if (lastRev.compareTo(currentRoot.getLastRevision()) > 0) {
return null;
}
AbstractDocumentNodeState nodeState = findByMatchingLastRev(currentRoot, path, lastRev);
if (nodeState != null) {
headRevMatched.mark();
return nodeState;
}
AbstractDocumentNodeState matchingRoot = findMatchingRoot(rootRevision);
if (matchingRoot != null) {
NodeState state = NodeStateUtils.getNode(matchingRoot, path);
if (state.exists()) {
AbstractDocumentNodeState docState = asDocState(state);
prevRevMatched.mark();
return docState;
}
}
knownMissed.mark();
return null;
}
use of javax.annotation.CheckForNull in project jackrabbit-oak by apache.
the class SecondaryStoreCache method findByMatchingLastRev.
@CheckForNull
private AbstractDocumentNodeState findByMatchingLastRev(AbstractDocumentNodeState root, String path, RevisionVector lastRev) {
NodeState state = root;
for (String name : PathUtils.elements(path)) {
state = state.getChildNode(name);
if (!state.exists()) {
return null;
}
//requested lastRev is > current node lastRev then no need to check further
if (lastRev.compareTo(asDocState(state).getLastRevision()) > 0) {
return null;
}
}
AbstractDocumentNodeState docState = asDocState(state);
if (lastRev.equals(docState.getLastRevision())) {
headRevMatched.mark();
return docState;
}
return null;
}
use of javax.annotation.CheckForNull in project jackrabbit-oak by apache.
the class IndexUtils method getAsyncLaneName.
@CheckForNull
public static String getAsyncLaneName(NodeState idxState, String indexPath) {
PropertyState async = idxState.getProperty(IndexConstants.ASYNC_PROPERTY_NAME);
if (async != null) {
Set<String> asyncNames = Sets.newHashSet(async.getValue(Type.STRINGS));
asyncNames.remove(IndexConstants.INDEXING_MODE_NRT);
asyncNames.remove(IndexConstants.INDEXING_MODE_SYNC);
checkArgument(!asyncNames.isEmpty(), "No valid async name found for " + "index [%s], definition %s", indexPath, idxState);
return Iterables.getOnlyElement(asyncNames);
}
return null;
}
use of javax.annotation.CheckForNull in project jackrabbit-oak by apache.
the class MongoDocumentStore method findAndModify.
@SuppressWarnings("unchecked")
@CheckForNull
private <T extends Document> T findAndModify(Collection<T> collection, UpdateOp updateOp, boolean upsert, boolean checkConditions) {
DBCollection dbCollection = getDBCollection(collection);
// make sure we don't modify the original updateOp
updateOp = updateOp.copy();
DBObject update = createUpdate(updateOp, false);
Lock lock = null;
if (collection == Collection.NODES) {
lock = nodeLocks.acquire(updateOp.getId());
}
final Stopwatch watch = startWatch();
boolean newEntry = false;
try {
// get modCount of cached document
Long modCount = null;
T cachedDoc = null;
if (collection == Collection.NODES) {
cachedDoc = (T) nodesCache.getIfPresent(updateOp.getId());
if (cachedDoc != null) {
modCount = cachedDoc.getModCount();
}
}
// if we have a matching modCount
if (modCount != null) {
QueryBuilder query = createQueryForUpdate(updateOp.getId(), updateOp.getConditions());
query.and(Document.MOD_COUNT).is(modCount);
WriteResult result = dbCollection.update(query.get(), update);
if (result.getN() > 0) {
// success, update cached document
if (collection == Collection.NODES) {
NodeDocument newDoc = (NodeDocument) applyChanges(collection, cachedDoc, updateOp);
nodesCache.put(newDoc);
}
// return previously cached document
return cachedDoc;
}
}
// conditional update failed or not possible
// perform operation and get complete document
QueryBuilder query = createQueryForUpdate(updateOp.getId(), updateOp.getConditions());
DBObject oldNode = dbCollection.findAndModify(query.get(), null, null, /*sort*/
false, /*remove*/
update, false, /*returnNew*/
upsert);
if (oldNode == null) {
newEntry = true;
}
if (checkConditions && oldNode == null) {
return null;
}
T oldDoc = convertFromDBObject(collection, oldNode);
if (oldDoc != null) {
if (collection == Collection.NODES) {
NodeDocument newDoc = (NodeDocument) applyChanges(collection, oldDoc, updateOp);
nodesCache.put(newDoc);
updateLocalChanges(newDoc);
}
oldDoc.seal();
} else if (upsert) {
if (collection == Collection.NODES) {
NodeDocument doc = (NodeDocument) collection.newDocument(this);
UpdateUtils.applyChanges(doc, updateOp);
nodesCache.putIfAbsent(doc);
updateLocalChanges(doc);
}
} else {
// updateOp without conditions and not an upsert
// this means the document does not exist
}
return oldDoc;
} catch (Exception e) {
throw handleException(e, collection, updateOp.getId());
} finally {
if (lock != null) {
lock.unlock();
}
stats.doneFindAndModify(watch.elapsed(TimeUnit.NANOSECONDS), collection, updateOp.getId(), newEntry, true, 0);
}
}
use of javax.annotation.CheckForNull in project jackrabbit-oak by apache.
the class MongoDocumentStore method findUncachedWithRetry.
/**
* Finds a document and performs a number of retries if the read fails with
* an exception.
*
* @param collection the collection to read from.
* @param key the key of the document to find.
* @param docReadPref the read preference.
* @param retries the number of retries. Must not be negative.
* @param <T> the document type of the given collection.
* @return the document or {@code null} if the document doesn't exist.
*/
@CheckForNull
private <T extends Document> T findUncachedWithRetry(Collection<T> collection, String key, DocumentReadPreference docReadPref, int retries) {
checkArgument(retries >= 0, "retries must not be negative");
if (key.equals("0:/")) {
LOG.trace("root node");
}
int numAttempts = retries + 1;
MongoException ex = null;
for (int i = 0; i < numAttempts; i++) {
if (i > 0) {
LOG.warn("Retrying read of " + key);
}
try {
return findUncached(collection, key, docReadPref);
} catch (MongoException e) {
ex = e;
}
}
if (ex != null) {
throw ex;
} else {
// impossible to get here
throw new IllegalStateException();
}
}
Aggregations