@Nullable T oldDoc,
@Nonnull UpdateOp updateOp) {
// cache the new document
if (collection == Collection.NODES) {
CacheValue key = new StringValue(updateOp.getId());
NodeDocument newDoc = (NodeDocument) collection.newDocument(this);
if (oldDoc != null) {
// we can only update the cache based on the oldDoc if we
// still have the oldDoc in the cache, otherwise we may
// update the cache with an outdated document
NodeDocument cached = nodesCache.getIfPresent(key);
if (cached == null) {
// cannot use oldDoc to update cache
return;
}
oldDoc.deepCopy(newDoc);
}
UpdateUtils.applyChanges(newDoc, updateOp, comparator);
newDoc.seal();
NodeDocument cached = addToCache(newDoc);
if (cached == newDoc) {
// successful
return;
}
if (oldDoc == null) {
// this is an insert and some other thread was quicker
// loading it into the cache -> return now
return;
}
// this is an update (oldDoc != null)
if (Objects.equal(cached.getModCount(), oldDoc.getModCount())) {
nodesCache.put(key, newDoc);
} else {
// the cache entry was modified by some other thread in
// the meantime. the updated cache entry may or may not
// include this update. we cannot just apply our update