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/09/22 10:27:51 UTC

[GitHub] [jackrabbit-oak] rishabhdaim commented on a diff in pull request #708: OAK-9946: Consistency check for versionable nodes

rishabhdaim commented on code in PR #708:
URL: https://github.com/apache/jackrabbit-oak/pull/708#discussion_r977480174


##########
oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/check/AsyncNodeStateProcessor.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.check;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
+import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
+import org.apache.jackrabbit.oak.plugins.document.Path;
+import org.apache.jackrabbit.oak.plugins.document.RevisionVector;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.jackrabbit.oak.spi.state.NodeStateUtils.getNode;
+
+/**
+ * A {@link DocumentProcessor} that processes {@link NodeState}s.
+ */
+public abstract class AsyncNodeStateProcessor extends AsyncDocumentProcessor {
+
+
+    protected final DocumentNodeStore ns;
+
+    protected final RevisionVector headRevision;
+
+    protected final NodeState uuidIndex;
+
+    protected AsyncNodeStateProcessor(DocumentNodeStore ns,
+                                      RevisionVector headRevision,
+                                      ExecutorService executorService) {
+        super(executorService);
+        this.ns = ns;
+        this.headRevision = headRevision;
+        this.uuidIndex = getNode(ns.getRoot(), "/oak:index/uuid/:index");
+    }
+
+    /**
+     * Decide early whether a {@link NodeDocument} should be processed or not.
+     * This implementation returns {@code true} if the document not a split
+     * document, otherwise {@code false}. This method can be overridden by
+     * subclasses.
+     *
+     * @param doc the document to process.
+     * @return whether the document should be processed or ignored.
+     */
+    protected boolean process(NodeDocument doc) {
+        return !doc.isSplitDocument();
+    }
+
+    /**
+     * Utility method that resolves he {@code uuid} into a {@link NodeState}
+     * with the help of the UUID index.
+     *
+     * @param uuid the UUID to resolve.
+     * @param resolvedPath will be set to the resolved path if available.
+     * @return the {@link NodeState} with the given UUID or {@code null} if it
+     *         cannot be resolved or doesn't exist.
+     */
+    protected final @Nullable NodeState getNodeByUUID(@NotNull String uuid,
+                                                      @NotNull AtomicReference<String> resolvedPath) {
+        PropertyState entry = uuidIndex.getChildNode(uuid).getProperty("entry");

Review Comment:
   Is there s a possibility of `uuidIndex.getChildNode(uuid)` returning `null`? if yes, then we need to handle that case as well.



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