mreutegg commented on a change in pull request #247:
URL: https://github.com/apache/jackrabbit-oak/pull/247#discussion_r496684488



##########
File path: 
oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Sweep2Helper.java
##########
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.document;
+
+import java.util.Map;
+
+import org.apache.jackrabbit.oak.plugins.document.util.Utils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Helper methods for sweep2 functionality introduced with OAK-9176.
+ * Kept separate from DocumentNodeStore to limit its size.
+ */
+public class Sweep2Helper {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(Sweep2Helper.class);
+
+    static boolean isSweep2Necessary(DocumentStore store) {
+        NodeDocument rootNodeDoc = store.find(Collection.NODES, 
Utils.getIdFromPath("/"));
+        if (rootNodeDoc == null) {
+            // that'd be very weird
+            LOG.warn("isSweep2Necessary : cannot get root node - assuming no 
sweep2 needed");
+            return false;
+        }
+    
+        if (rootNodeDoc.get("_sweepRev") == null) {
+            // this indicates a pre 1.8 repository upgrade (case 1).
+            // no sweep2 is needed as it is embedded in the normal sweep[1].
+            return false;
+        }
+    
+        // in this case we have a post (>=) 1.8 repository
+        // which might or might not have previously been a pre (<) 1.8
+        // and we need to distinguish those 2 cases - which, to repeat, are:
+        // 2) Oak >= 1.8 which never did an Oak <= 1.6 upgrade:
+        //    -> no sweep2 is needed as OAK-9176 doesn't apply (the repository
+        //       never ran <= 1.6)
+        // 3) Oak >= 1.8 which was previously doing an Oak <= 1.6 upgrade:
+        //    -> A (full) sweep2 is needed. This is the main case of OAK-9176.
+        Map<Revision, String> bcValueMap = rootNodeDoc.getValueMap("_bc");
+        Map<Revision, String> valueMap = 
rootNodeDoc.getValueMap(NodeDocument.REVISIONS);

Review comment:
       Going through these two maps can be rather expensive. The map not just 
reflects the `_revisions` and `_bc` entries on the root document (`0:/`), but 
also all the previous (aka split) documents associated with the root document. 
Worst case, on a repository that never ran <= 1.6, this will go through all 
`_revisions` entries on the root and its split documents to find out no sweep 
is necessary. If this is intentional, then there might be a faster way.
   IIUC the method tries to find out if there is a branch commit that was 
created with Oak <= 1.6. Not just on the root document itself but also by 
looking at its entire history. Is this correct?
   As an alternative Sweep2Helper could query all split documents with 
`_sdType` DEFAULT(10). On Oak >= 1.8 the majority of split documents for the 
root are of type DEFAULT_NO_BRANCH(70) and those can be ignored. Before 1.8, 
most were created as DEFAULT(10).
   I'm also a bit concerned about the time it takes to perform this check 
because it blocks startup. If the check cannot be implemented cheaply, it may 
be better to just run the sweep and then mark the repository accordingly.

##########
File path: 
oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Sweep2Helper.java
##########
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.document;
+
+import java.util.Map;
+
+import org.apache.jackrabbit.oak.plugins.document.util.Utils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Helper methods for sweep2 functionality introduced with OAK-9176.
+ * Kept separate from DocumentNodeStore to limit its size.
+ */
+public class Sweep2Helper {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(Sweep2Helper.class);
+
+    static boolean isSweep2Necessary(DocumentStore store) {
+        NodeDocument rootNodeDoc = store.find(Collection.NODES, 
Utils.getIdFromPath("/"));
+        if (rootNodeDoc == null) {
+            // that'd be very weird
+            LOG.warn("isSweep2Necessary : cannot get root node - assuming no 
sweep2 needed");
+            return false;
+        }
+    
+        if (rootNodeDoc.get("_sweepRev") == null) {
+            // this indicates a pre 1.8 repository upgrade (case 1).
+            // no sweep2 is needed as it is embedded in the normal sweep[1].
+            return false;
+        }
+    
+        // in this case we have a post (>=) 1.8 repository
+        // which might or might not have previously been a pre (<) 1.8
+        // and we need to distinguish those 2 cases - which, to repeat, are:
+        // 2) Oak >= 1.8 which never did an Oak <= 1.6 upgrade:
+        //    -> no sweep2 is needed as OAK-9176 doesn't apply (the repository
+        //       never ran <= 1.6)
+        // 3) Oak >= 1.8 which was previously doing an Oak <= 1.6 upgrade:
+        //    -> A (full) sweep2 is needed. This is the main case of OAK-9176.
+        Map<Revision, String> bcValueMap = rootNodeDoc.getValueMap("_bc");
+        Map<Revision, String> valueMap = 
rootNodeDoc.getValueMap(NodeDocument.REVISIONS);
+        for (Map.Entry<Revision, String> entry : valueMap.entrySet()) {
+            Revision rev = entry.getKey();
+    
+            // consider all clusterIds..
+            String rawCommitValue = entry.getValue();
+            String cv = rawCommitValue;

Review comment:
       `rawCommitValue` is redundant.
   ```suggestion
               String cv = entry.getValue();
   ```




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to