You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by GitBox <gi...@apache.org> on 2022/11/15 14:33:02 UTC

[GitHub] [jackrabbit-oak] mreutegg commented on a diff in pull request #753: OAK-9993: Add utility method to remove unmerged branches

mreutegg commented on code in PR #753:
URL: https://github.com/apache/jackrabbit-oak/pull/753#discussion_r1022862174


##########
oak-run/src/main/js/oak-mongo.js:
##########
@@ -452,6 +452,70 @@ var oak = (function(global){
         }
     };
 
+    /**
+     * Removes all unmerged branches on the document with the given path and
+     * clusterId. This method will only remove unmerged branches when the
+     * clusterId is inactive.
+     *
+     * @memberof oak
+     * @method removeUnmergedBranches
+     * @param {string} path the path of a document
+     * @param {number} clusterId collision markers for this clusterId will be removed.
+     * @param {number} [limit=1000000] maximum number of unmerged branches to remove.
+     * @returns {object} the result of the MongoDB update.
+     */
+    api.removeUnmergedBranches = function(path, clusterId, limit) {
+        if (path === undefined) {
+            print("No path specified");
+            return;
+        }
+        if (clusterId === undefined) {
+            print("No clusterId specified");
+            return;
+        }
+        if (limit === undefined) {
+            limit = 1000000;
+        }
+        // refuse to remove when clusterId is marked active
+        var clusterNode = db.clusterNodes.findOne({_id: clusterId.toString()});
+        if (clusterNode && clusterNode.state == "ACTIVE") {
+            print("Cluster node with id " + clusterId + " is active!");
+            print("Can only remove unmerged branches for inactive cluster node.");
+            return;
+        }

Review Comment:
   It's a good point. But even acquiring the clusterId is not 100% correct. A lease timeout of 5 minutes may not be enough depending on the time the remove operation takes. I'd rather keep this simple implement something production grade into oak-store-document or oak-run in Java. Otherwise more logic needs to be duplicated here in oak-mongo.js. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org