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 2021/08/19 08:21:28 UTC

[GitHub] [jackrabbit-oak] thomasmueller commented on a change in pull request #340: OAK - 9536 | Add support in oak run for incremental indexing

thomasmueller commented on a change in pull request #340:
URL: https://github.com/apache/jackrabbit-oak/pull/340#discussion_r691891231



##########
File path: oak-run-elastic/src/main/java/org/apache/jackrabbit/oak/index/ElasticIndexCommand.java
##########
@@ -38,6 +39,7 @@
 import org.apache.jackrabbit.oak.run.cli.Options;
 import org.apache.jackrabbit.oak.run.commons.Command;
 import org.apache.jackrabbit.oak.run.commons.LoggingInitializer;
+import org.apache.jackrabbit.oak.segment.file.tar.index.Index;

Review comment:
       As we are anyway changing this... could you change the import org.apache.jackrabbit.oak.spi.commit.* (I would avoid star imports)

##########
File path: oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/async/AsyncIndexerBase.java
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.index.async;
+
+import com.google.common.io.Closer;
+import org.apache.jackrabbit.oak.index.IndexHelper;
+import org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate;
+import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
+import org.apache.jackrabbit.oak.stats.StatisticsProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+public abstract class AsyncIndexerBase implements Closeable {
+
+    private static final Logger log = LoggerFactory.getLogger(AsyncIndexerBase.class);
+    private final IndexHelper indexHelper;
+    protected final Closer closer;
+    private final List<String> names;
+    private final long INIT_DELAY = 0;
+    private final long delay;
+    private ScheduledExecutorService pool;
+    private CountDownLatch latch;
+
+    public AsyncIndexerBase(IndexHelper indexHelper, Closer closer, List<String> names, long delay) {
+        this.indexHelper = indexHelper;
+        this.closer = closer;
+        this.names = names;
+        this.delay = delay;
+        pool = Executors.newScheduledThreadPool(names.size());
+        latch = new CountDownLatch(1);
+    }
+
+    public void execute() throws InterruptedException, IOException {
+        addShutDownHook();
+        IndexEditorProvider editorProvider = getIndexEditorProvider();
+        // This can be null in case of any exception while initializing index copier in lucene.
+        if (editorProvider == null) {
+            log.error("EditorProvider is null, can't proceed further. Exiting");
+            closer.close();
+        }
+        // Register async tasks for all lanes to the ScheduledThreadPoolExecutor
+        for (String name : names) {
+            log.info("Setting up Async executor for lane - " + name);
+            AsyncIndexUpdate task = new AsyncIndexUpdate(name, indexHelper.getNodeStore(),
+                    editorProvider, StatisticsProvider.NOOP, false);
+            closer.register(task);
+
+            pool.scheduleWithFixedDelay(task, INIT_DELAY, delay, TimeUnit.SECONDS);
+        }
+        // Make the main thread wait now, since we want this to run continuously
+        // Although ScheduledExecutorService would still keep executing even if we let the main thread exit
+        // but it will cleanup logging resources and other closeables and create problems.
+        latch.await();
+    }
+
+    @Override
+    public void close() throws IOException {
+        log.info("Closing down Async Indexer Service...");
+        latch.countDown();
+        pool.shutdown();
+    }
+
+    /*
+    Since this would be running continuously in a loop, we can't possibly call closures in a normal conventional manner

Review comment:
       Nit: for such cases, I usually use a Javadoc comment (** instead of *). But it's really unimportant.

##########
File path: oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/IndexOptions.java
##########
@@ -183,10 +197,16 @@ public int consistencyCheckLevel(){
         return consistencyCheck.value(options);
     }
 
+    public long aysncDelay() {
+        return  asyncDelay.value(options);
+    }
+
     public boolean isReindex() {
         return options.has(reindex);
     }
 
+    public boolean isAsyncIndex() {return options.has(asyncIndex);}

Review comment:
       Could you re-format (multiple lines, same as isReindex)?




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