You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2014/04/09 14:29:12 UTC
svn commit: r1585951 - in /jackrabbit/oak/trunk/oak-core/src:
main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentDocumentStoreTest.java
Author: reschke
Date: Wed Apr 9 12:29:11 2014
New Revision: 1585951
URL: http://svn.apache.org/r1585951
Log:
OAK-1266 - serialize updates to a given key (by re-using the existing lock stripes), change concurrent update test to try harder
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentDocumentStoreTest.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java?rev=1585951&r1=1585950&r2=1585951&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java Wed Apr 9 12:29:11 2014
@@ -364,29 +364,37 @@ public class RDBDocumentStore implements
if (doc == null) {
return null;
} else {
- boolean success = false;
+ Lock l = getAndLock(update.getId());
+ try {
+ boolean success = false;
- int retries = maxRetries;
- while (!success && retries > 0) {
- success = updateDocument(collection, doc, (Long) oldDoc.get(MODCOUNT));
- if (!success) {
- // retry with a fresh document
- retries -= 1;
- oldDoc = readDocumentCached(collection, update.getId(), Integer.MAX_VALUE);
- doc = applyChanges(collection, oldDoc, update, checkConditions);
- if (doc == null) {
- return null;
+ int retries = maxRetries;
+ while (!success && retries > 0) {
+ success = updateDocument(collection, doc, (Long) oldDoc.get(MODCOUNT));
+ if (!success) {
+ // retry with a fresh document
+ retries -= 1;
+ oldDoc = readDocumentCached(collection, update.getId(), Integer.MAX_VALUE);
+ doc = applyChanges(collection, oldDoc, update, checkConditions);
+ if (doc == null) {
+ return null;
+ }
+ } else {
+ if (collection == Collection.NODES) {
+ applyToCache((NodeDocument) oldDoc, (NodeDocument) doc);
+ }
}
- } else {
- applyToCache(collection, oldDoc, doc);
}
- }
- if (!success) {
- throw new MicroKernelException("failed update (race?) after " + maxRetries + " retries");
- }
+ if (!success) {
+ throw new MicroKernelException("failed update (race?) after " + maxRetries + " retries");
+ }
- return oldDoc;
+ return oldDoc;
+ }
+ finally {
+ l.unlock();
+ }
}
}
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentDocumentStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentDocumentStoreTest.java?rev=1585951&r1=1585950&r2=1585951&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentDocumentStoreTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentDocumentStoreTest.java Wed Apr 9 12:29:11 2014
@@ -37,9 +37,9 @@ public class ConcurrentDocumentStoreTest
@Test
public void testConcurrentUpdate() throws Exception {
- int workers = 8; // TODO: this test is going to fail if the number of
- // workers exceeds the number of retries done by
- // RDBDocumentStore
+ int workers = 20; // TODO: this test is going to fail if the number of
+ // workers exceeds the number of retries done by
+ // RDBDocumentStore
String id = this.getClass().getName() + ".testConcurrentUpdate";
UpdateOp up = new UpdateOp(id, true);
up.set("_id", id);