jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1583890 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document: MissingLastRevSeeker.java mongo/MongoMissingLastRevSeeker.java
Date Wed, 02 Apr 2014 06:13:22 GMT
Author: chetanm
Date: Wed Apr  2 06:13:22 2014
New Revision: 1583890

URL: http://svn.apache.org/r1583890
Log:
OAK-1295 - Recovery for missing _lastRev updates (WIP)

Added specific method for acquiring recovery lock and releasing recovery lock. For Mongo the
acquire logic use a conditional update

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/MissingLastRevSeeker.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoMissingLastRevSeeker.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/MissingLastRevSeeker.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/MissingLastRevSeeker.java?rev=1583890&r1=1583889&r2=1583890&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/MissingLastRevSeeker.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/MissingLastRevSeeker.java
Wed Apr  2 06:13:22 2014
@@ -27,6 +27,8 @@ import com.google.common.collect.Iterabl
 
 import org.apache.jackrabbit.oak.plugins.document.util.Utils;
 
+import static org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfo.RecoverLockState;
+
 /**
  * Utils to retrieve _lastRev missing update candidates.
  */
@@ -88,6 +90,21 @@ public class MissingLastRevSeeker {
         });
     }
 
+    public boolean acquireRecoveryLock(int clusterId){
+        //This approach has a race condition where two different cluster nodes
+        //can acquire the lock simultaneously.
+        UpdateOp update = new UpdateOp(Integer.toString(clusterId), true);
+        update.set(ClusterNodeInfo.REV_RECOVERY_LOCK, RecoverLockState.ACQUIRED);
+        store.createOrUpdate(Collection.CLUSTER_NODES, update);
+        return true;
+    }
+
+    public void releaseRecoveryLock(int clusterId){
+        UpdateOp update = new UpdateOp(Integer.toString(clusterId), true);
+        update.set(ClusterNodeInfo.REV_RECOVERY_LOCK, null);
+        store.createOrUpdate(Collection.CLUSTER_NODES, update);
+    }
+
     public NodeDocument getRoot() {
         return store.find(Collection.NODES, Utils.getIdFromPath(ROOT_PATH));
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoMissingLastRevSeeker.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoMissingLastRevSeeker.java?rev=1583890&r1=1583889&r2=1583890&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoMissingLastRevSeeker.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoMissingLastRevSeeker.java
Wed Apr  2 06:13:22 2014
@@ -20,6 +20,7 @@
 package org.apache.jackrabbit.oak.plugins.document.mongo;
 
 import static com.google.common.collect.Iterables.transform;
+import static org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfo.RecoverLockState;
 
 import com.google.common.base.Function;
 import com.mongodb.BasicDBObject;
@@ -29,9 +30,11 @@ import com.mongodb.DBObject;
 import com.mongodb.QueryBuilder;
 import com.mongodb.ReadPreference;
 
+import org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfo;
 import org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfoDocument;
 import org.apache.jackrabbit.oak.plugins.document.Collection;
 import org.apache.jackrabbit.oak.plugins.document.Commit;
+import org.apache.jackrabbit.oak.plugins.document.Document;
 import org.apache.jackrabbit.oak.plugins.document.MissingLastRevSeeker;
 import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
 import org.apache.jackrabbit.oak.plugins.document.util.CloseableIterable;
@@ -94,6 +97,28 @@ public class MongoMissingLastRevSeeker e
         }), cursor);
     }
 
+    @Override
+    public boolean acquireRecoveryLock(int clusterId) {
+        QueryBuilder query = QueryBuilder.start(Document.ID)
+                .is(Integer.toString(clusterId))
+                .put(ClusterNodeInfo.REV_RECOVERY_LOCK).is(RecoverLockState.ACQUIRED.name());
+
+        DBObject returnFields = new BasicDBObject();
+        returnFields.put("_id", 1);
+
+        BasicDBObject setUpdates = new BasicDBObject();
+        setUpdates.append(ClusterNodeInfo.REV_RECOVERY_LOCK, RecoverLockState.ACQUIRED.name());
+
+        BasicDBObject update = new BasicDBObject();
+        update.append("$set", setUpdates);
+
+        DBObject oldNode = getClusterNodeCollection().findAndModify(query.get(), returnFields,
+                null /*sort*/, false /*remove*/, update, false /*returnNew*/,
+                false /*upsert*/);
+
+        return oldNode != null;
+    }
+
     private DBCollection getNodeCollection() {
         return store.getDBCollection(Collection.NODES);
     }



Mime
View raw message