Index: oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java =================================================================== --- oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java (revision 1818888) +++ oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java (working copy) @@ -493,61 +493,64 @@ missingDocs.add(op.getId()); } } - for (T doc : readDocumentsUncached(collection, missingDocs).values()) { - oldDocs.put(doc.getId(), doc); - if (collection == Collection.NODES) { - nodesCache.putIfAbsent((NodeDocument) doc); - } - } + oldDocs.putAll(readDocumentsUncached(collection, missingDocs)); - List docsToUpdate = new ArrayList(updates.size()); - Set keysToUpdate = new HashSet(); - for (UpdateOp update : updates) { - String id = update.getId(); - T modifiedDoc = collection.newDocument(this); - if (oldDocs.containsKey(id)) { - oldDocs.get(id).deepCopy(modifiedDoc); - } - UpdateUtils.applyChanges(modifiedDoc, update); - docsToUpdate.add(modifiedDoc); - keysToUpdate.add(id); + CacheChangesTracker tracker = null; + if (collection == Collection.NODES) { + tracker = nodesCache.registerTracker(Sets.union(oldDocs.keySet(), missingDocs)); } - Connection connection = null; - RDBTableMetaData tmd = getTable(collection); try { - connection = this.ch.getRWConnection(); - Set successfulUpdates = db.update(connection, tmd, docsToUpdate, upsert); - connection.commit(); + List docsToUpdate = new ArrayList(updates.size()); + Set keysToUpdate = new HashSet(); + for (UpdateOp update : updates) { + String id = update.getId(); + T modifiedDoc = collection.newDocument(this); + if (oldDocs.containsKey(id)) { + oldDocs.get(id).deepCopy(modifiedDoc); + } + UpdateUtils.applyChanges(modifiedDoc, update); + docsToUpdate.add(modifiedDoc); + keysToUpdate.add(id); + } - Set failedUpdates = Sets.difference(keysToUpdate, successfulUpdates); - oldDocs.keySet().removeAll(failedUpdates); + Connection connection = null; + RDBTableMetaData tmd = getTable(collection); + try { + connection = this.ch.getRWConnection(); + Set successfulUpdates = db.update(connection, tmd, docsToUpdate, upsert); + connection.commit(); - if (collection == Collection.NODES) { - for (T doc : docsToUpdate) { - String id = doc.getId(); - if (successfulUpdates.contains(id)) { - if (oldDocs.containsKey(id)) { - nodesCache.replaceCachedDocument((NodeDocument) oldDocs.get(id), (NodeDocument) doc); - } else { - nodesCache.putIfAbsent((NodeDocument) doc); + Set failedUpdates = Sets.difference(keysToUpdate, successfulUpdates); + oldDocs.keySet().removeAll(failedUpdates); + + if (collection == Collection.NODES) { + List docsToCache = new ArrayList<>(); + for(T doc : docsToUpdate) { + if (successfulUpdates.contains(doc.getId())) { + docsToCache.add((NodeDocument) doc); } } + nodesCache.putNonConflictingDocs(tracker, docsToCache); } - } - Map result = new HashMap(); - for (UpdateOp op : updates) { - if (successfulUpdates.contains(op.getId())) { - result.put(op, oldDocs.get(op.getId())); + Map result = new HashMap(); + for (UpdateOp op : updates) { + if (successfulUpdates.contains(op.getId())) { + result.put(op, oldDocs.get(op.getId())); + } } + return result; + } catch (SQLException ex) { + this.ch.rollbackConnection(connection); + throw handleException("update failed for: " + keysToUpdate, ex, collection, keysToUpdate); + } finally { + this.ch.closeConnection(connection); } - return result; - } catch (SQLException ex) { - this.ch.rollbackConnection(connection); - throw handleException("update failed for: " + keysToUpdate, ex, collection, keysToUpdate); } finally { - this.ch.closeConnection(connection); + if (tracker != null) { + tracker.close(); + } } } Index: oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBCacheConsistencyIT.java =================================================================== --- oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBCacheConsistencyIT.java (revision 1818888) +++ oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBCacheConsistencyIT.java (working copy) @@ -31,7 +31,6 @@ import org.apache.jackrabbit.oak.plugins.document.UpdateOp; import org.apache.jackrabbit.oak.plugins.document.util.Utils; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; @@ -40,7 +39,6 @@ import static org.apache.jackrabbit.oak.plugins.document.util.Utils.getKeyUpperLimit; import static org.junit.Assert.assertEquals; -@Ignore("OAK-7101") public class RDBCacheConsistencyIT extends AbstractRDBConnectionTest { private static final long CACHE_SIZE = 128 * 1024;