You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by fj...@apache.org on 2019/05/23 22:58:47 UTC

[incubator-druid] branch master updated: use memoized supplier for lazy singleton in SeekableStreamIndexTask.java (#7740)

This is an automated email from the ASF dual-hosted git repository.

fjy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-druid.git


The following commit(s) were added to refs/heads/master by this push:
     new daf20b4  use memoized supplier for lazy singleton in SeekableStreamIndexTask.java (#7740)
daf20b4 is described below

commit daf20b4b864bd6618150d6a7b2185b5677e8c406
Author: Himanshu <g....@gmail.com>
AuthorDate: Thu May 23 15:58:38 2019 -0700

    use memoized supplier for lazy singleton in SeekableStreamIndexTask.java (#7740)
---
 .../indexing/seekablestream/SeekableStreamIndexTask.java | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/indexing-service/src/main/java/org/apache/druid/indexing/seekablestream/SeekableStreamIndexTask.java b/indexing-service/src/main/java/org/apache/druid/indexing/seekablestream/SeekableStreamIndexTask.java
index 37d472b..11ed7d4 100644
--- a/indexing-service/src/main/java/org/apache/druid/indexing/seekablestream/SeekableStreamIndexTask.java
+++ b/indexing-service/src/main/java/org/apache/druid/indexing/seekablestream/SeekableStreamIndexTask.java
@@ -24,6 +24,8 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Joiner;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
 import org.apache.druid.data.input.InputRow;
 import org.apache.druid.indexer.TaskStatus;
 import org.apache.druid.indexing.appenderator.ActionBasedSegmentAllocator;
@@ -77,8 +79,7 @@ public abstract class SeekableStreamIndexTask<PartitionIdType, SequenceOffsetTyp
   // Lazily initialized, to avoid calling it on the overlord when tasks are instantiated.
   // See https://github.com/apache/incubator-druid/issues/7724 for issues that can cause.
   // By the way, lazily init is synchronized because the runner may be needed in multiple threads.
-  private final Object runnerInitLock = new Object();
-  private volatile SeekableStreamIndexTaskRunner<PartitionIdType, SequenceOffsetType> runner;
+  private final Supplier<SeekableStreamIndexTaskRunner<PartitionIdType, SequenceOffsetType>> runnerSupplier;
 
   public SeekableStreamIndexTask(
       final String id,
@@ -112,6 +113,7 @@ public abstract class SeekableStreamIndexTask<PartitionIdType, SequenceOffsetTyp
     this.context = context;
     this.authorizerMapper = authorizerMapper;
     this.rowIngestionMetersFactory = rowIngestionMetersFactory;
+    this.runnerSupplier = Suppliers.memoize(this::createTaskRunner);
   }
 
   private static String makeTaskId(String dataSource, String type)
@@ -288,14 +290,6 @@ public abstract class SeekableStreamIndexTask<PartitionIdType, SequenceOffsetTyp
   @VisibleForTesting
   public SeekableStreamIndexTaskRunner<PartitionIdType, SequenceOffsetType> getRunner()
   {
-    if (runner == null) {
-      synchronized (runnerInitLock) {
-        if (runner == null) {
-          runner = createTaskRunner();
-        }
-      }
-    }
-
-    return runner;
+    return runnerSupplier.get();
   }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org