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


##########
indexing-service/src/main/java/org/apache/druid/indexing/common/actions/SegmentTransactionalAppendAction.java:
##########
@@ -148,65 +146,58 @@ public SegmentPublishResult perform(Task task, 
TaskActionToolbox toolbox)
           task.getType()
       );
     }
-    // Verify that all the locks are of expected type
-    final List<TaskLock> locks = 
toolbox.getTaskLockbox().findLocksForTask(task);
-    for (TaskLock lock : locks) {
-      if (lock.getType() != TaskLockType.APPEND) {
-        throw InvalidInput.exception(
-            "Cannot use action[%s] for task[%s] as it is holding a lock of 
type[%s] instead of [APPEND].",
-            "SegmentTransactionalAppendAction", task.getId(), lock.getType()
+    final TaskLockbox taskLockbox = toolbox.getTaskLockbox();
+    TaskLocks.checkLockCoversSegments(task, taskLockbox, segments);
+    taskLockbox.acquireTransactionalAppendLock(task, 
TaskLockbox.LOCK_ACQUIRE_TIMEOUT_MILLIS);
+    try {
+      final String datasource = task.getDataSource();
+      final Map<DataSegment, ReplaceTaskLock> segmentToReplaceLock
+          = TaskLocks.findReplaceLocksCoveringSegments(datasource, 
toolbox.getTaskLockbox(), segments);
+
+      final CriticalAction.Action<SegmentPublishResult> publishAction;
+      final String taskAllocatorId = ((PendingSegmentAllocatingTask) 
task).getTaskAllocatorId();
+      if (startMetadata == null) {
+        publishAction = () -> 
toolbox.getIndexerMetadataStorageCoordinator().commitAppendSegments(
+            segments,
+            segmentToReplaceLock,
+            taskAllocatorId,
+            segmentSchemaMapping
+        );
+      } else {
+        publishAction = () -> 
toolbox.getIndexerMetadataStorageCoordinator().commitAppendSegmentsAndMetadata(
+            segments,
+            segmentToReplaceLock,
+            startMetadata,
+            endMetadata,
+            taskAllocatorId,
+            segmentSchemaMapping
         );
       }
-    }
-
-    TaskLocks.checkLockCoversSegments(task, toolbox.getTaskLockbox(), 
segments);
 
-    final String datasource = task.getDataSource();
-    final Map<DataSegment, ReplaceTaskLock> segmentToReplaceLock
-        = TaskLocks.findReplaceLocksCoveringSegments(datasource, 
toolbox.getTaskLockbox(), segments);
-
-    final CriticalAction.Action<SegmentPublishResult> publishAction;
-    final String taskAllocatorId = ((PendingSegmentAllocatingTask) 
task).getTaskAllocatorId();
-    if (startMetadata == null) {
-      publishAction = () -> 
toolbox.getIndexerMetadataStorageCoordinator().commitAppendSegments(
-          segments,
-          segmentToReplaceLock,
-          taskAllocatorId,
-          segmentSchemaMapping
-      );
-    } else {
-      publishAction = () -> 
toolbox.getIndexerMetadataStorageCoordinator().commitAppendSegmentsAndMetadata(
-          segments,
-          segmentToReplaceLock,
-          startMetadata,
-          endMetadata,
-          taskAllocatorId,
-          segmentSchemaMapping
-      );
-    }
-
-    final SegmentPublishResult retVal;
-    try {
+      final SegmentPublishResult retVal;
       retVal = toolbox.getTaskLockbox().doInCriticalSection(
           task,
           
segments.stream().map(DataSegment::getInterval).collect(Collectors.toSet()),
           CriticalAction.<SegmentPublishResult>builder()
-              .onValidLocks(publishAction)
-              .onInvalidLocks(
-                  () -> SegmentPublishResult.fail(
-                      "Invalid task locks. Maybe they are revoked by a higher 
priority task."
-                      + " Please check the overlord log for details."
-                  )
-              )
-              .build()
+                        .onValidLocks(publishAction)
+                        .onInvalidLocks(
+                            () -> SegmentPublishResult.fail(
+                                "Invalid task locks. Maybe they are revoked by 
a higher priority task."
+                                + " Please check the overlord log for details."
+                            )
+                        )
+                        .build()

Review Comment:
   Seems like the original indentation was correct.



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