From 52dc479ae3494f8c402cb62ac2b1be8366231a01 Mon Sep 17 00:00:00 2001 From: Abhishek Balaji Radhakrishnan Date: Fri, 26 Jul 2024 00:45:07 -0700 Subject: [PATCH] Make advanceCursor private for now. --- .../apache/druid/collections/CircularList.java | 17 +++++++---------- .../druid/collections/CircularListTest.java | 17 ----------------- .../coordinator/duty/KillUnusedSegments.java | 1 - .../duty/KillUnusedSegmentsTest.java | 4 ++-- 4 files changed, 9 insertions(+), 30 deletions(-) diff --git a/processing/src/main/java/org/apache/druid/collections/CircularList.java b/processing/src/main/java/org/apache/druid/collections/CircularList.java index 737bb3c060e2..338340062b39 100644 --- a/processing/src/main/java/org/apache/druid/collections/CircularList.java +++ b/processing/src/main/java/org/apache/druid/collections/CircularList.java @@ -75,17 +75,14 @@ private T peekNext() int nextPosition = currentPosition < collection.size() ? currentPosition : 0; return collection.get(nextPosition); } - }; - } - /** - * Advances the cursor position in the circular list. If the position reaches the end of the list, it wraps around. - */ - public void advanceCursor() - { - if (++currentPosition >= collection.size()) { - currentPosition = 0; - } + private void advanceCursor() + { + if (++currentPosition >= collection.size()) { + currentPosition = 0; + } + } + }; } /** diff --git a/processing/src/test/java/org/apache/druid/collections/CircularListTest.java b/processing/src/test/java/org/apache/druid/collections/CircularListTest.java index 40a38be612dd..ab66aeb0bcb3 100644 --- a/processing/src/test/java/org/apache/druid/collections/CircularListTest.java +++ b/processing/src/test/java/org/apache/druid/collections/CircularListTest.java @@ -66,23 +66,6 @@ public void testIterateInReverseOrder() Assert.assertEquals(ImmutableList.of(100, 0, -1, -4, 100, 0, -1, -4), observedElements); } - @Test - public void testAdvanceCursor() - { - final Set input = ImmutableSet.of(1, 10, 35, 50); - final CircularList circularList = new CircularList<>(input, Comparator.naturalOrder()); - final Iterator iterator = circularList.iterator(); - - circularList.advanceCursor(); - Assert.assertTrue(iterator.hasNext()); - Assert.assertEquals((Integer) 10, iterator.next()); - - circularList.advanceCursor(); - circularList.advanceCursor(); - Assert.assertTrue(iterator.hasNext()); - Assert.assertEquals((Integer) 1, iterator.next()); - } - @Test public void testEqualsSet() { diff --git a/server/src/main/java/org/apache/druid/server/coordinator/duty/KillUnusedSegments.java b/server/src/main/java/org/apache/druid/server/coordinator/duty/KillUnusedSegments.java index 3b552f00acf2..77abee91c980 100644 --- a/server/src/main/java/org/apache/druid/server/coordinator/duty/KillUnusedSegments.java +++ b/server/src/main/java/org/apache/druid/server/coordinator/duty/KillUnusedSegments.java @@ -231,7 +231,6 @@ private void killUnusedSegments( ++submittedTasks; datasourceToLastKillIntervalEnd.put(dataSource, intervalToKill.getEnd()); - // Check for termination conditions. if (remainingDatasourcesToKill.isEmpty() || submittedTasks >= availableKillTaskSlots) { break; } diff --git a/server/src/test/java/org/apache/druid/server/coordinator/duty/KillUnusedSegmentsTest.java b/server/src/test/java/org/apache/druid/server/coordinator/duty/KillUnusedSegmentsTest.java index e2cbbdf5e434..bdb7a773b09d 100644 --- a/server/src/test/java/org/apache/druid/server/coordinator/duty/KillUnusedSegmentsTest.java +++ b/server/src/test/java/org/apache/druid/server/coordinator/duty/KillUnusedSegmentsTest.java @@ -556,7 +556,7 @@ public void testLowerMaxSegmentsToKill() } @Test - public void testDatasourcesFoundButNoUnusedSegments() + public void testKillDatasourceWithNoUnusedSegmentsInInitialRun() { configBuilder.withMaxSegmentsToKill(1); @@ -643,10 +643,10 @@ public void testKillTaskSlotAtCapacity() initDuty(); final CoordinatorRunStats stats = runDutyAndGetStats(); + Assert.assertEquals(2, stats.get(Stats.Kill.AVAILABLE_SLOTS)); Assert.assertEquals(2, stats.get(Stats.Kill.SUBMITTED_TASKS)); Assert.assertEquals(2, stats.get(Stats.Kill.MAX_SLOTS)); - Assert.assertEquals(2, stats.get(Stats.Kill.ELIGIBLE_UNUSED_SEGMENTS, DS1_STAT_KEY)); Assert.assertEquals(1, stats.get(Stats.Kill.ELIGIBLE_UNUSED_SEGMENTS, DS2_STAT_KEY));