kfaraz commented on code in PR #18436:
URL: https://github.com/apache/druid/pull/18436#discussion_r2304469681


##########
extensions-contrib/rabbit-stream-indexing-service/src/main/java/org/apache/druid/indexing/rabbitstream/RabbitStreamIndexTaskTuningConfig.java:
##########
@@ -100,7 +100,8 @@ public RabbitStreamIndexTaskTuningConfig(
         maxParseExceptions,
         maxSavedParseExceptions,
         numPersistThreads,
-        maxColumnsToMerge
+        maxColumnsToMerge,
+        false

Review Comment:
   Let's pass null here.



##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/AppenderatorConfig.java:
##########
@@ -38,6 +38,14 @@ public interface AppenderatorConfig extends TuningConfig
 
   boolean isSkipBytesInMemoryOverheadCheck();
 
+  /**
+   * Whether the interval locks be released when handing segments have been 
handed off to data nodes.

Review Comment:
   ```suggestion
      * @return true if locks should be released after segments have been 
handed off to Historicals.
   ```



##########
extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/indexing/kafka/test/TestModifiedKafkaIndexTaskTuningConfig.java:
##########
@@ -81,7 +81,8 @@ public TestModifiedKafkaIndexTaskTuningConfig(
         maxParseExceptions,
         maxSavedParseExceptions,
         numPersistThreads,
-        maxColumnsToMerge
+        maxColumnsToMerge,
+        false

Review Comment:
   Pass null here.



##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/TaskIntervalUnlocker.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.druid.segment.realtime.appenderator;
+
+import org.joda.time.Interval;
+
+import java.io.IOException;
+
+/**
+ * This interface provides a callback mechanism to interact with TaskLockbox 
for releasing interval locks when
+ * the segments are handed off. We need this interface to avoid cyclic 
dependencues because the
+ * {@code TaskLockbox} is in druid-indexing-service module

Review Comment:
   ```suggestion
    * Used to release task locks after segments have been handed off, typically 
with long running tasks
    * to avoid holding locks for longer than necessary. This interface is used 
instead of {@code TaskActionClient}
    * to prevent a cyclic dependency with druid-indexing-service module.
   ```



##########
server/src/test/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderatorTest.java:
##########
@@ -2449,6 +2450,110 @@ public void testSchemaAnnouncement() throws Exception
     }
   }
 
+
+  @Test
+  public void test_dropSegment_unlocksInterval() throws Exception
+  {
+    final List<Interval> unlockedIntervals = new ArrayList<>();
+    final TaskIntervalUnlocker intervalUnlocker = interval -> {
+      synchronized (unlockedIntervals) {
+        unlockedIntervals.add(interval);
+      }
+    };
+
+    try (final StreamAppenderatorTester tester = new 
StreamAppenderatorTester.Builder()
+        .basePersistDirectory(temporaryFolder.newFolder())
+        .maxRowsInMemory(2)
+        .releaseLocksOnHandoff(true)
+        .taskIntervalUnlocker(intervalUnlocker)
+        .build()) {
+      final Appenderator appenderator = tester.getAppenderator();
+
+      appenderator.startJob();
+
+      final SegmentIdWithShardSpec segmentId1 = 
si("2000-01-01T00:00/2000-01-01T01:00", "version1", 0);
+      final SegmentIdWithShardSpec segmentId2 = 
si("2000-01-01T01:00/2000-01-01T02:00", "version1", 0);
+
+      final InputRow row1 = new MapBasedInputRow(
+          DateTimes.of("2000"),
+          ImmutableList.of("dim1"),
+          ImmutableMap.of("dim1", "bar", "met1", 1)

Review Comment:
   Prefer using `List.of` and `Map.of`.



##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -1559,6 +1567,22 @@ public Void apply(@Nullable Object input)
     );
   }
 
+  private void unlockIntervalIfApplicable(Sink abandonedSink)
+  {
+    Interval abandonedInterval = abandonedSink.getInterval();
+    boolean isIntervalActive = sinks.entrySet().stream()
+                                    .anyMatch(entry -> {
+                                      Sink sink = entry.getValue();
+                                      return !Objects.equals(sink, 
abandonedSink)
+                                             && sink.isWritable()

Review Comment:
   I think we can remove these extra conditions for now.
   We should not unlock the interval as long as there is any sink that overlaps 
the interval.



##########
extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/indexing/kafka/simulate/EmbeddedKafkaSupervisorTest.java:
##########
@@ -56,28 +59,33 @@ public class EmbeddedKafkaSupervisorTest extends 
EmbeddedClusterTestBase
   private final EmbeddedBroker broker = new EmbeddedBroker();
   private final EmbeddedIndexer indexer = new EmbeddedIndexer();
   private final EmbeddedOverlord overlord = new EmbeddedOverlord();
+  private final EmbeddedHistorical historical = new EmbeddedHistorical();
   private KafkaResource kafkaServer;
 
   @Override
   public EmbeddedDruidCluster createCluster()
   {
     final EmbeddedDruidCluster cluster = 
EmbeddedDruidCluster.withEmbeddedDerbyAndZookeeper();
+    indexer.addProperty("druid.segment.handoff.pollDuration", "PT0.1s");
+    overlord.addProperty("druid.manager.segments.pollDuration", "PT0.1s");

Review Comment:
   Not removed yet.



##########
indexing-service/src/main/java/org/apache/druid/indexing/seekablestream/SeekableStreamIndexTaskTuningConfig.java:
##########
@@ -41,6 +42,7 @@ public abstract class SeekableStreamIndexTaskTuningConfig 
implements TuningConfi
   private static final Period DEFAULT_INTERMEDIATE_PERSIST_PERIOD = new 
Period("PT10M");
   private static final IndexSpec DEFAULT_INDEX_SPEC = IndexSpec.DEFAULT;
   private static final Boolean DEFAULT_REPORT_PARSE_EXCEPTIONS = Boolean.FALSE;
+  private static final Boolean DEFAULT_SHOULD_RELEASE_LOCK_ON_HANDOFF = 
Boolean.FALSE;

Review Comment:
   ```suggestion
     private static final boolean DEFAULT_RELEASE_LOCKS_ON_HANDOFF = false;
   ```



##########
server/src/test/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderatorTest.java:
##########
@@ -2449,6 +2450,118 @@ public void testSchemaAnnouncement() throws Exception
     }
   }
 
+
+  @Test
+  public void test_abandonSegment_unlockIntervalWithOverlap() throws Exception
+  {
+    final List<Interval> unlockedIntervals = new ArrayList<>();
+    final TaskIntervalUnlocker mockUnlocker = interval -> {
+      synchronized (unlockedIntervals) {
+        unlockedIntervals.add(interval);
+      }
+    };
+
+    try (final StreamAppenderatorTester tester = new 
StreamAppenderatorTester.Builder()
+        .basePersistDirectory(temporaryFolder.newFolder())
+        .maxRowsInMemory(2)
+        .releaseLocksOnHandoff(true)
+        .taskIntervalUnlocker(mockUnlocker)
+        .build()) {
+      final Appenderator appenderator = tester.getAppenderator();
+
+      appenderator.startJob();
+
+      final SegmentIdWithShardSpec identifier1 = 
si("2000-01-01T00:00/2000-01-01T01:00", "version1", 0);
+      final SegmentIdWithShardSpec identifier2 = 
si("2000-01-01T01:00/2000-01-01T02:00", "version1", 0);
+
+      final InputRow row1 = new MapBasedInputRow(
+          DateTimes.of("2000"),
+          ImmutableList.of("dim1"),
+          ImmutableMap.of("dim1", "bar", "met1", 1)
+      );
+
+      final InputRow row2 = new MapBasedInputRow(
+          DateTimes.of("2000-01-01T02:30"),
+          ImmutableList.of("dim1"),
+          ImmutableMap.of("dim1", "baz", "met1", 1)
+      );
+
+      appenderator.add(identifier1, row1, 
Suppliers.ofInstance(Committers.nil()), false);
+      appenderator.add(identifier2, row2, 
Suppliers.ofInstance(Committers.nil()), false);
+
+      Assert.assertEquals(2, appenderator.getSegments().size());
+
+      synchronized (unlockedIntervals) {
+        unlockedIntervals.clear();
+      }
+
+      appenderator.drop(identifier1).get();
+
+      synchronized (unlockedIntervals) {

Review Comment:
   Not addressed yet.
   
   Tip: It generally helps to resolve comments after the relevant changes have 
been pushed. 🙂 , so that no updates are missed.



##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/TaskIntervalUnlocker.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.druid.segment.realtime.appenderator;
+
+import org.joda.time.Interval;
+
+/**
+ * This interface provides a callback mechanism to interact with TaskLockbox 
for releasing interval locks when
+ * the segments are handed off. We need this interface to avoid cyclic 
dependencues because the
+ * {@code TaskLockbox} is in druid-indexing-service module
+ */
+@FunctionalInterface
+public interface TaskIntervalUnlocker
+{
+  /**
+   * Releases the lock for the given interval.

Review Comment:
   This still needs to be addressed.



-- 
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: [email protected]

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to