AmatyaAvadhanula commented on code in PR #16380:
URL: https://github.com/apache/druid/pull/16380#discussion_r1588768115


##########
server/src/main/java/org/apache/druid/metadata/IndexerSQLMetadataStorageCoordinator.java:
##########
@@ -1886,7 +1856,67 @@ private SegmentIdWithShardSpec createNewSegment(
               committedMaxId == null ? 0 : 
committedMaxId.getShardSpec().getNumCorePartitions()
           )
       );
+      return getTrueAllocatedId(allocatedId);
+    }
+  }
+
+  private SegmentIdWithShardSpec getTrueAllocatedId(
+      SegmentIdWithShardSpec allocatedId
+  )
+  {
+    // Check if there is a conflict with an existing entry in the segments 
table
+    if (retrieveSegmentForId(allocatedId.asSegmentId().toString(), true) == 
null) {
+      return allocatedId;
+    }
+
+    // If yes, try to compute allocated partition num using the max unused 
segment shard spec
+    SegmentIdWithShardSpec unusedMaxId = getUnusedMaxId(
+        allocatedId.getDataSource(),
+        allocatedId.getInterval(),
+        allocatedId.getVersion()
+    );
+    // No unused segment. Just return the allocated id
+    if (unusedMaxId == null) {
+      return allocatedId;
+    }
+
+    int maxPartitionNum = Math.max(
+        allocatedId.getShardSpec().getPartitionNum(),
+        unusedMaxId.getShardSpec().getPartitionNum() + 1

Review Comment:
   Isn't it possible that someone dropped the last segment and there's a 
conflict because of that one segment?



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