You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by xb...@apache.org on 2024/07/16 01:29:11 UTC
(pinot) branch master updated: missed one util method that should derive partition id from uploaded segment name (#13612)
This is an automated email from the ASF dual-hosted git repository.
xbli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new 3db93ccc21 missed one util method that should derive partition id from uploaded segment name (#13612)
3db93ccc21 is described below
commit 3db93ccc210991ad91b6a5306b3b610d8f5e0507
Author: Xiaobing <61...@users.noreply.github.com>
AuthorDate: Mon Jul 15 18:29:05 2024 -0700
missed one util method that should derive partition id from uploaded segment name (#13612)
* add one util method to derive partition id from uploaded segment names to avoid missing the segment name checks
* add tests
---
.../apache/pinot/common/utils/SegmentUtils.java | 32 +++++++++++++---------
.../pinot/common/utils/SegmentUtilsTest.java | 9 ++++++
2 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/pinot-common/src/main/java/org/apache/pinot/common/utils/SegmentUtils.java b/pinot-common/src/main/java/org/apache/pinot/common/utils/SegmentUtils.java
index 8b89a2b1a5..26d231651d 100644
--- a/pinot-common/src/main/java/org/apache/pinot/common/utils/SegmentUtils.java
+++ b/pinot-common/src/main/java/org/apache/pinot/common/utils/SegmentUtils.java
@@ -39,17 +39,10 @@ public class 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);
@@ -61,13 +54,26 @@ public class SegmentUtils {
@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
diff --git a/pinot-common/src/test/java/org/apache/pinot/common/utils/SegmentUtilsTest.java b/pinot-common/src/test/java/org/apache/pinot/common/utils/SegmentUtilsTest.java
index 1257bc0498..812c6c9959 100644
--- a/pinot-common/src/test/java/org/apache/pinot/common/utils/SegmentUtilsTest.java
+++ b/pinot-common/src/test/java/org/apache/pinot/common/utils/SegmentUtilsTest.java
@@ -88,11 +88,20 @@ public class SegmentUtilsTest {
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");
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org