kfaraz commented on code in PR #16380:
URL: https://github.com/apache/druid/pull/16380#discussion_r1588756852
##########
server/src/main/java/org/apache/druid/metadata/IndexerSQLMetadataStorageCoordinator.java:
##########
@@ -1013,33 +1012,6 @@ private Map<SegmentCreateRequest,
SegmentIdWithShardSpec> allocatePendingSegment
return allocatedSegmentIds;
}
- @SuppressWarnings("UnstableApiUsage")
- private String getSequenceNameAndPrevIdSha(
Review Comment:
unused method?
##########
server/src/test/java/org/apache/druid/metadata/IndexerSQLMetadataStorageCoordinatorTest.java:
##########
@@ -3192,4 +3192,59 @@ public void testTimelineWith1CorePartitionTombstone()
throws IOException
SegmentTimeline segmentTimeline =
SegmentTimeline.forSegments(allUsedSegments);
Assert.assertEquals(0, segmentTimeline.lookup(interval).size());
}
+
+ @Test
+ public void testSegmentIdMustNotBeReused() throws IOException
Review Comment:
This test should probably live in `SegmentAllocateActionTest` next to the
sister test `testSegmentIsAllocatedForLatestUsedSegmentVersion`. It should also
be renamed to include some more info, such as
`testSegmentIsNotAllocatedForUnusedSegmentVersion`.
##########
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:
Rather than doing unusedMaxId + 1, we should probably not use this version
at all, if there is any existing unused segment for that version.
I think it would be better to filter out all the invalid versions:
- used but overshadowed versions (fixed in #15459 )
- unused versions
--
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]