diff --git a/indexing-service/src/main/java/org/apache/druid/indexing/common/task/CachingLocalSegmentAllocatorHelper.java b/indexing-service/src/main/java/org/apache/druid/indexing/common/task/CachingLocalSegmentAllocatorHelper.java index 1963fb4c2fdc..3c9bab2d9f5c 100644 --- a/indexing-service/src/main/java/org/apache/druid/indexing/common/task/CachingLocalSegmentAllocatorHelper.java +++ b/indexing-service/src/main/java/org/apache/druid/indexing/common/task/CachingLocalSegmentAllocatorHelper.java @@ -26,7 +26,6 @@ import org.apache.druid.indexing.common.actions.SurrogateAction; import org.apache.druid.indexing.common.task.IndexTask.ShardSpecs; import org.apache.druid.java.util.common.ISE; -import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.segment.realtime.appenderator.SegmentIdWithShardSpec; import org.apache.druid.timeline.partition.ShardSpec; import org.joda.time.Interval; @@ -133,6 +132,8 @@ public String getSequenceName(Interval interval, InputRow inputRow) */ private String getSequenceName(Interval interval, ShardSpec shardSpec) { - return StringUtils.format("%s_%s_%d", taskId, interval, shardSpec.getPartitionNum()); + // Note: We do not use String format here since this can be called in a tight loop + // and it's faster to add strings together than it is to use String#format + return taskId + "_" + interval + "_" + shardSpec.getPartitionNum(); } } diff --git a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/RangePartitionCachingLocalSegmentAllocatorTest.java b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/RangePartitionCachingLocalSegmentAllocatorTest.java index 6e91d10066af..dad9893a6b04 100644 --- a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/RangePartitionCachingLocalSegmentAllocatorTest.java +++ b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/RangePartitionCachingLocalSegmentAllocatorTest.java @@ -28,6 +28,7 @@ import org.apache.druid.indexing.common.task.batch.parallel.distribution.PartitionBoundaries; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.Intervals; +import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.segment.realtime.appenderator.SegmentIdWithShardSpec; import org.apache.druid.timeline.SegmentId; import org.apache.druid.timeline.partition.SingleDimensionShardSpec; @@ -141,6 +142,17 @@ public void allocatesCorrectShardSpecsForLastPartition() testAllocate(row, interval, partitionNum, null); } + @Test + public void getSequenceName() + { + // getSequenceName_forIntervalAndRow_shouldUseISOFormatAndPartitionNumForRow + Interval interval = INTERVAL_NORMAL; + InputRow row = createInputRow(interval, PARTITION9); + String sequenceName = target.getSequenceName(interval, row); + String expectedSequenceName = StringUtils.format("%s_%s_%d", TASKID, interval, 1); + Assert.assertEquals(expectedSequenceName, sequenceName); + } + @SuppressWarnings("SameParameterValue") private void testAllocate(InputRow row, Interval interval, int partitionNum) { diff --git a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/HashPartitionCachingLocalSegmentAllocatorTest.java b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/HashPartitionCachingLocalSegmentAllocatorTest.java index e82101d7386a..6230c8a888c6 100644 --- a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/HashPartitionCachingLocalSegmentAllocatorTest.java +++ b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/HashPartitionCachingLocalSegmentAllocatorTest.java @@ -31,6 +31,7 @@ import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.Pair; +import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.segment.realtime.appenderator.SegmentIdWithShardSpec; import org.apache.druid.timeline.SegmentId; import org.apache.druid.timeline.partition.HashBasedNumberedShardSpec; @@ -101,6 +102,17 @@ public void allocatesCorrectShardSpec() throws IOException Assert.assertEquals(PARTITION_NUM, shardSpec.getPartitionNum()); } + + @Test + public void getSequenceName() + { + // getSequenceName_forIntervalAndRow_shouldUseISOFormatAndPartitionNumForRow + InputRow row = createInputRow(); + String sequenceName = target.getSequenceName(INTERVAL, row); + String expectedSequenceName = StringUtils.format("%s_%s_%d", TASKID, INTERVAL, PARTITION_NUM); + Assert.assertEquals(expectedSequenceName, sequenceName); + } + private static TaskToolbox createToolbox() { TaskToolbox toolbox = EasyMock.mock(TaskToolbox.class);