Skip to content

Commit

Permalink
missed one util method that should derive partition id from uploaded …
Browse files Browse the repository at this point in the history
…segment name (apache#13612)

* add one util method to derive partition id from uploaded segment names to avoid missing the segment name checks

* add tests
  • Loading branch information
klsince authored Jul 16, 2024
1 parent 3015b2e commit 3db93cc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,10 @@ private SegmentUtils() {
@Nullable
public static Integer getRealtimeSegmentPartitionId(String segmentName, String realtimeTableName,
HelixManager helixManager, @Nullable String partitionColumn) {
// A fast path if the segmentName is an LLC segment name: get the partition id from the name directly
LLCSegmentName llcSegmentName = LLCSegmentName.of(segmentName);
if (llcSegmentName != null) {
return llcSegmentName.getPartitionGroupId();
Integer partitionId = getPartitionIdFromRealtimeSegmentName(segmentName);
if (partitionId != null) {
return partitionId;
}

UploadedRealtimeSegmentName uploadedRealtimeSegmentName = UploadedRealtimeSegmentName.of(segmentName);
if (uploadedRealtimeSegmentName != null) {
return uploadedRealtimeSegmentName.getPartitionId();
}

// Otherwise, retrieve the partition id from the segment zk metadata.
SegmentZKMetadata segmentZKMetadata =
ZKMetadataProvider.getSegmentZKMetadata(helixManager.getHelixPropertyStore(), realtimeTableName, segmentName);
Expand All @@ -61,13 +54,26 @@ public static Integer getRealtimeSegmentPartitionId(String segmentName, String r
@Nullable
public static Integer getRealtimeSegmentPartitionId(String segmentName, SegmentZKMetadata segmentZKMetadata,
@Nullable String partitionColumn) {
// A fast path if the segmentName is an LLC segment name: get the partition id from the name directly
Integer partitionId = getPartitionIdFromRealtimeSegmentName(segmentName);
if (partitionId != null) {
return partitionId;
}
// Otherwise, retrieve the partition id from the segment zk metadata.
return getRealtimeSegmentPartitionId(segmentZKMetadata, partitionColumn);
}

@Nullable
private static Integer getPartitionIdFromRealtimeSegmentName(String segmentName) {
// A fast path to get partition id if the segmentName is in a known format like LLC.
LLCSegmentName llcSegmentName = LLCSegmentName.of(segmentName);
if (llcSegmentName != null) {
return llcSegmentName.getPartitionGroupId();
}
// Otherwise, retrieve the partition id from the segment zk metadata.
return getRealtimeSegmentPartitionId(segmentZKMetadata, partitionColumn);
UploadedRealtimeSegmentName uploadedRealtimeSegmentName = UploadedRealtimeSegmentName.of(segmentName);
if (uploadedRealtimeSegmentName != null) {
return uploadedRealtimeSegmentName.getPartitionId();
}
return null;
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,20 @@ void testGetRealtimeSegmentPartitionIdForUploadedRealtimeSegment() {
String segmentName = "uploaded__table_name__3__100__1716185755000";

try {
// Check the util method that gets segmentZKMetadata via HelixManager for partition id.
Integer partitionId =
SegmentUtils.getRealtimeSegmentPartitionId(segmentName, "realtimeTableName", null, "partitionColumn");
assertEquals(partitionId, 3);
} catch (Exception e) {
fail("Exception should not be thrown");
}

try {
// Check the util method that has segmentZKMetadata passed in directly for partition id.
Integer partitionId = SegmentUtils.getRealtimeSegmentPartitionId(segmentName, null, "partitionColumn");
assertEquals(partitionId, 3);
} catch (Exception e) {
fail("Exception should not be thrown");
}
}
}

0 comments on commit 3db93cc

Please sign in to comment.