- * Calculates the interval for which segments are to be killed in a datasource. - * Since this method compares datetime as strings, it cannot find unused segments that are outside - * the range [{@link DateTimes#COMPARE_DATE_AS_STRING_MIN}, {@link DateTimes#COMPARE_DATE_AS_STRING_MAX}), - * such as {@link org.apache.druid.java.util.common.granularity.Granularities#ALL} partitioned segments - * and segments that end in {@link DateTimes#MAX}. - *
- * For more information, see Issue#15951. - *
- */ @Nullable private Interval findIntervalForKill( final String dataSource, diff --git a/server/src/test/java/org/apache/druid/server/coordinator/DruidCoordinatorConfigTest.java b/server/src/test/java/org/apache/druid/server/coordinator/DruidCoordinatorConfigTest.java index 53c2808aa72..6f1a0504587 100644 --- a/server/src/test/java/org/apache/druid/server/coordinator/DruidCoordinatorConfigTest.java +++ b/server/src/test/java/org/apache/druid/server/coordinator/DruidCoordinatorConfigTest.java @@ -27,35 +27,34 @@ import org.skife.config.ConfigurationObjectFactory; import java.util.Properties; -/** - */ public class DruidCoordinatorConfigTest { @Test - public void testDeserialization() + public void testCoordinatorConfigWithDefaults() { - ConfigurationObjectFactory factory = Config.createFactory(new Properties()); - - //with defaults - DruidCoordinatorConfig config = factory.build(DruidCoordinatorConfig.class); + final ConfigurationObjectFactory factory = Config.createFactory(new Properties()); + final DruidCoordinatorConfig config = factory.build(DruidCoordinatorConfig.class); Assert.assertEquals(new Duration("PT300s"), config.getCoordinatorStartDelay()); Assert.assertEquals(new Duration("PT60s"), config.getCoordinatorPeriod()); Assert.assertEquals(new Duration("PT1800s"), config.getCoordinatorIndexingPeriod()); - Assert.assertEquals(86400000, config.getCoordinatorKillPeriod().getMillis()); - Assert.assertEquals(7776000000L, config.getCoordinatorKillDurationToRetain().getMillis()); + Assert.assertEquals(new Duration("PT1800s"), config.getCoordinatorKillPeriod()); + Assert.assertEquals(new Duration("PT7776000s"), config.getCoordinatorKillDurationToRetain()); Assert.assertEquals(100, config.getCoordinatorKillMaxSegments()); Assert.assertEquals(new Duration(15 * 60 * 1000), config.getLoadTimeoutDelay()); Assert.assertFalse(config.getCoordinatorKillIgnoreDurationToRetain()); Assert.assertEquals("http", config.getLoadQueuePeonType()); + } - //with non-defaults - Properties props = new Properties(); + @Test + public void testCoordinatorConfigWithOverrides() + { + final Properties props = new Properties(); props.setProperty("druid.coordinator.startDelay", "PT1s"); props.setProperty("druid.coordinator.period", "PT1s"); props.setProperty("druid.coordinator.period.indexingPeriod", "PT1s"); props.setProperty("druid.coordinator.kill.on", "true"); - props.setProperty("druid.coordinator.kill.period", "PT1s"); + props.setProperty("druid.coordinator.kill.period", "PT10s"); props.setProperty("druid.coordinator.kill.durationToRetain", "PT1s"); props.setProperty("druid.coordinator.kill.maxSegments", "10000"); props.setProperty("druid.coordinator.kill.pendingSegments.on", "true"); @@ -63,23 +62,28 @@ public class DruidCoordinatorConfigTest props.setProperty("druid.coordinator.loadqueuepeon.repeatDelay", "PT0.100s"); props.setProperty("druid.coordinator.kill.ignoreDurationToRetain", "true"); - factory = Config.createFactory(props); - config = factory.build(DruidCoordinatorConfig.class); + final ConfigurationObjectFactory factory = Config.createFactory(props); + final DruidCoordinatorConfig config = factory.build(DruidCoordinatorConfig.class); Assert.assertEquals(new Duration("PT1s"), config.getCoordinatorStartDelay()); Assert.assertEquals(new Duration("PT1s"), config.getCoordinatorPeriod()); Assert.assertEquals(new Duration("PT1s"), config.getCoordinatorIndexingPeriod()); - Assert.assertEquals(new Duration("PT1s"), config.getCoordinatorKillPeriod()); + Assert.assertEquals(new Duration("PT10s"), config.getCoordinatorKillPeriod()); Assert.assertEquals(new Duration("PT1s"), config.getCoordinatorKillDurationToRetain()); Assert.assertEquals(10000, config.getCoordinatorKillMaxSegments()); Assert.assertEquals(new Duration("PT1s"), config.getLoadTimeoutDelay()); Assert.assertTrue(config.getCoordinatorKillIgnoreDurationToRetain()); + } - // Test negative druid.coordinator.kill.durationToRetain now that it is valid. - props = new Properties(); + @Test + public void testCoordinatorConfigWithNegativeDurationToRetain() + { + final Properties props = new Properties(); props.setProperty("druid.coordinator.kill.durationToRetain", "PT-1s"); - factory = Config.createFactory(props); - config = factory.build(DruidCoordinatorConfig.class); + + final ConfigurationObjectFactory factory = Config.createFactory(props); + final DruidCoordinatorConfig config = factory.build(DruidCoordinatorConfig.class); + Assert.assertEquals(new Duration("PT-1s"), config.getCoordinatorKillDurationToRetain()); } } diff --git a/server/src/test/java/org/apache/druid/server/coordinator/TestDruidCoordinatorConfig.java b/server/src/test/java/org/apache/druid/server/coordinator/TestDruidCoordinatorConfig.java index 6f5e604c3cb..2809c8acff9 100644 --- a/server/src/test/java/org/apache/druid/server/coordinator/TestDruidCoordinatorConfig.java +++ b/server/src/test/java/org/apache/druid/server/coordinator/TestDruidCoordinatorConfig.java @@ -294,7 +294,6 @@ public class TestDruidCoordinatorConfig extends DruidCoordinatorConfig private static final Duration DEFAULT_COORDINATOR_PERIOD = Period.parse("PT60s").toStandardDuration(); private static final Duration DEFAULT_COORDINATOR_INDEXING_PERIOD = Period.parse("PT1800s").toStandardDuration(); private static final Duration DEFAULT_METADATA_STORE_MANAGEMENT_PERIOD = Period.parse("PT1H").toStandardDuration(); - private static final Duration DEFAULT_COORDINATOR_KILL_PERIOD = Period.parse("P1D").toStandardDuration(); private static final Duration DEFAULT_COORDINATOR_KILL_DURATION_TO_RETAIN = Period.parse("P90D").toStandardDuration(); private static final Duration DEFAULT_COORDINATOR_KILL_BUFFER_PERIOD = Period.parse("P30D").toStandardDuration(); private static final boolean DEFAULT_COORDINATOR_KILL_IGNORE_DURATION_TO_RETAIN = false; @@ -497,7 +496,8 @@ public class TestDruidCoordinatorConfig extends DruidCoordinatorConfig coordinatorIndexingPeriod == null ? DEFAULT_COORDINATOR_INDEXING_PERIOD : coordinatorIndexingPeriod, metadataStoreManagementPeriod == null ? DEFAULT_METADATA_STORE_MANAGEMENT_PERIOD : metadataStoreManagementPeriod, loadTimeoutDelay == null ? DEFAULT_LOAD_TIMEOUT_DELAY : loadTimeoutDelay, - coordinatorKillPeriod == null ? DEFAULT_COORDINATOR_KILL_PERIOD : coordinatorKillPeriod, + coordinatorKillPeriod == null ? (coordinatorIndexingPeriod == null ? DEFAULT_COORDINATOR_INDEXING_PERIOD : coordinatorIndexingPeriod) + : coordinatorKillPeriod, coordinatorKillDurationToRetain == null ? DEFAULT_COORDINATOR_KILL_DURATION_TO_RETAIN : coordinatorKillDurationToRetain, coordinatorSupervisorKillPeriod == null ? DEFAULT_COORDINATOR_SUPERVISOR_KILL_PERIOD : coordinatorSupervisorKillPeriod, 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 aa37913734e..6f0cb7d5b4c 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 @@ -90,7 +90,7 @@ public class KillUnusedSegmentsTest private static final String VERSION = "v1"; - private final CoordinatorDynamicConfig.Builder dynamicConfigBuilder = CoordinatorDynamicConfig.builder(); + private CoordinatorDynamicConfig.Builder dynamicConfigBuilder; private TestOverlordClient overlordClient; private TestDruidCoordinatorConfig.Builder configBuilder; private DruidCoordinatorRuntimeParams.Builder paramsBuilder; @@ -126,10 +126,11 @@ public class KillUnusedSegmentsTest overlordClient = new TestOverlordClient(); configBuilder = new TestDruidCoordinatorConfig.Builder() .withCoordinatorIndexingPeriod(Duration.standardSeconds(0)) - .withCoordinatorKillPeriod(Duration.standardSeconds(0)) .withCoordinatorKillDurationToRetain(Duration.standardHours(36)) .withCoordinatorKillMaxSegments(10) .withCoordinatorKillBufferPeriod(Duration.standardSeconds(1)); + dynamicConfigBuilder = CoordinatorDynamicConfig.builder() + .withKillTaskSlotRatio(1.0); paramsBuilder = DruidCoordinatorRuntimeParams.newBuilder(DateTimes.nowUtc()); } @@ -137,6 +138,7 @@ public class KillUnusedSegmentsTest public void testKillWithDefaultCoordinatorConfig() { configBuilder = new TestDruidCoordinatorConfig.Builder(); + dynamicConfigBuilder = CoordinatorDynamicConfig.builder(); final DateTime sixtyDaysAgo = NOW.minusDays(60); @@ -151,9 +153,9 @@ public class KillUnusedSegmentsTest initDuty(); final CoordinatorRunStats stats = runDutyAndGetStats(); - Assert.assertEquals(10, stats.get(Stats.Kill.AVAILABLE_SLOTS)); + Assert.assertEquals(1, stats.get(Stats.Kill.AVAILABLE_SLOTS)); Assert.assertEquals(1, stats.get(Stats.Kill.SUBMITTED_TASKS)); - Assert.assertEquals(10, stats.get(Stats.Kill.MAX_SLOTS)); + Assert.assertEquals(1, stats.get(Stats.Kill.MAX_SLOTS)); Assert.assertEquals(2, stats.get(Stats.Kill.ELIGIBLE_UNUSED_SEGMENTS, DS1_STAT_KEY)); validateLastKillStateAndReset(DS1, Intervals.ETERNITY); @@ -516,13 +518,27 @@ public class KillUnusedSegmentsTest } @Test - public void testKillTaskSlotStat() + public void testDefaultKillTaskSlotStats() { + dynamicConfigBuilder = CoordinatorDynamicConfig.builder(); + paramsBuilder.withDynamicConfigs(dynamicConfigBuilder.build()); + initDuty(); + final CoordinatorRunStats stats = runDutyAndGetStats(); + + Assert.assertEquals(1, stats.get(Stats.Kill.AVAILABLE_SLOTS)); + Assert.assertEquals(0, stats.get(Stats.Kill.SUBMITTED_TASKS)); + Assert.assertEquals(1, stats.get(Stats.Kill.MAX_SLOTS)); + } + + @Test + public void testKillTaskSlotStats1() + { dynamicConfigBuilder.withKillTaskSlotRatio(1.0); dynamicConfigBuilder.withMaxKillTaskSlots(Integer.MAX_VALUE); paramsBuilder.withDynamicConfigs(dynamicConfigBuilder.build()); + initDuty(); final CoordinatorRunStats stats = runDutyAndGetStats(); Assert.assertEquals(10, stats.get(Stats.Kill.AVAILABLE_SLOTS)); @@ -533,11 +549,11 @@ public class KillUnusedSegmentsTest @Test public void testKillTaskSlotStats2() { - initDuty(); dynamicConfigBuilder.withKillTaskSlotRatio(0.0); dynamicConfigBuilder.withMaxKillTaskSlots(Integer.MAX_VALUE); paramsBuilder.withDynamicConfigs(dynamicConfigBuilder.build()); + initDuty(); final CoordinatorRunStats stats = runDutyAndGetStats(); Assert.assertEquals(0, stats.get(Stats.Kill.AVAILABLE_SLOTS)); @@ -548,11 +564,11 @@ public class KillUnusedSegmentsTest @Test public void testKillTaskSlotStats3() { - initDuty(); dynamicConfigBuilder.withKillTaskSlotRatio(1.0); dynamicConfigBuilder.withMaxKillTaskSlots(0); paramsBuilder.withDynamicConfigs(dynamicConfigBuilder.build()); + initDuty(); final CoordinatorRunStats stats = runDutyAndGetStats(); Assert.assertEquals(0, stats.get(Stats.Kill.AVAILABLE_SLOTS)); @@ -563,11 +579,11 @@ public class KillUnusedSegmentsTest @Test public void testKillTaskSlotStats4() { - initDuty(); dynamicConfigBuilder.withKillTaskSlotRatio(0.1); dynamicConfigBuilder.withMaxKillTaskSlots(3); paramsBuilder.withDynamicConfigs(dynamicConfigBuilder.build()); + initDuty(); final CoordinatorRunStats stats = runDutyAndGetStats(); Assert.assertEquals(1, stats.get(Stats.Kill.AVAILABLE_SLOTS)); @@ -800,6 +816,7 @@ public class KillUnusedSegmentsTest private CoordinatorRunStats runDutyAndGetStats() { + paramsBuilder.withDynamicConfigs(dynamicConfigBuilder.build()); final DruidCoordinatorRuntimeParams params = killDuty.run(paramsBuilder.build()); return params.getCoordinatorStats(); } diff --git a/server/src/test/java/org/apache/druid/server/http/CoordinatorDynamicConfigTest.java b/server/src/test/java/org/apache/druid/server/http/CoordinatorDynamicConfigTest.java index 4c6b7cb5587..ba2cc10fe24 100644 --- a/server/src/test/java/org/apache/druid/server/http/CoordinatorDynamicConfigTest.java +++ b/server/src/test/java/org/apache/druid/server/http/CoordinatorDynamicConfigTest.java @@ -19,7 +19,6 @@ package org.apache.druid.server.http; -import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableSet; import org.apache.druid.segment.TestHelper; @@ -31,9 +30,6 @@ import org.junit.Test; import javax.annotation.Nullable; import java.util.Set; -/** - * - */ public class CoordinatorDynamicConfigTest { private static final int EXPECTED_DEFAULT_MAX_SEGMENTS_IN_NODE_LOADING_QUEUE = 500; @@ -190,7 +186,7 @@ public class CoordinatorDynamicConfigTest true ); - actual = CoordinatorDynamicConfig.builder().withKillTaskSlotRatio(1.0).build(actual); + actual = CoordinatorDynamicConfig.builder().withKillTaskSlotRatio(0.1).build(actual); assertConfig( actual, 1, @@ -201,7 +197,7 @@ public class CoordinatorDynamicConfigTest 1, 2, whitelist, - 1.0, + 0.1, 2, false, 1, @@ -221,7 +217,7 @@ public class CoordinatorDynamicConfigTest 1, 2, whitelist, - 1.0, + 0.1, 5, false, 1, @@ -334,7 +330,7 @@ public class CoordinatorDynamicConfigTest 1, 2, whitelist, - 1.0, + 0.1, Integer.MAX_VALUE, false, 1, @@ -354,7 +350,7 @@ public class CoordinatorDynamicConfigTest 1, 2, whitelist, - 1.0, + 0.1, Integer.MAX_VALUE, false, 1, @@ -374,7 +370,7 @@ public class CoordinatorDynamicConfigTest 1, 2, whitelist, - 1.0, + 0.1, Integer.MAX_VALUE, false, 1, @@ -418,7 +414,7 @@ public class CoordinatorDynamicConfigTest 1, 2, ImmutableSet.of("test1", "test2"), - 1.0, + 0.1, Integer.MAX_VALUE, false, 1, @@ -462,7 +458,7 @@ public class CoordinatorDynamicConfigTest 1, 2, whitelist, - 1.0, + 0.1, Integer.MAX_VALUE, false, 1, @@ -504,7 +500,7 @@ public class CoordinatorDynamicConfigTest 1, 2, ImmutableSet.of(), - 1.0, + 0.1, Integer.MAX_VALUE, true, 1, @@ -557,7 +553,7 @@ public class CoordinatorDynamicConfigTest 1, 2, ImmutableSet.of(), - 1.0, + 0.1, Integer.MAX_VALUE, true, EXPECTED_DEFAULT_MAX_SEGMENTS_IN_NODE_LOADING_QUEUE, @@ -582,7 +578,7 @@ public class CoordinatorDynamicConfigTest 500, getDefaultNumBalancerThreads(), emptyList, - 1.0, + 0.1, Integer.MAX_VALUE, true, EXPECTED_DEFAULT_MAX_SEGMENTS_IN_NODE_LOADING_QUEUE, @@ -610,7 +606,7 @@ public class CoordinatorDynamicConfigTest 500, getDefaultNumBalancerThreads(), ImmutableSet.of("DATASOURCE"), - 1.0, + 0.1, Integer.MAX_VALUE, false, EXPECTED_DEFAULT_MAX_SEGMENTS_IN_NODE_LOADING_QUEUE, @@ -653,22 +649,6 @@ public class CoordinatorDynamicConfigTest ); } - private void assertThatDeserializationFailsWithMessage(String json, String message) - { - JsonMappingException e = Assert.assertThrows( - JsonMappingException.class, - () -> mapper.readValue( - mapper.writeValueAsString( - mapper.readValue(json, CoordinatorDynamicConfig.class) - ), - CoordinatorDynamicConfig.class - ) - ); - Assert.assertTrue(e.getCause() instanceof IllegalArgumentException); - IllegalArgumentException cause = (IllegalArgumentException) e.getCause(); - Assert.assertEquals(message, cause.getMessage()); - } - @Test public void testEqualsAndHashCode() { diff --git a/web-console/src/druid-models/coordinator-dynamic-config/coordinator-dynamic-config.mock.ts b/web-console/src/druid-models/coordinator-dynamic-config/coordinator-dynamic-config.mock.ts index 06224afb28b..e46d1f27c96 100644 --- a/web-console/src/druid-models/coordinator-dynamic-config/coordinator-dynamic-config.mock.ts +++ b/web-console/src/druid-models/coordinator-dynamic-config/coordinator-dynamic-config.mock.ts @@ -27,7 +27,7 @@ export const DEFAULT_COORDINATOR_DYNAMIC_CONFIG: CoordinatorDynamicConfig = { replicationThrottleLimit: 500, balancerComputeThreads: 1, killDataSourceWhitelist: [], - killTaskSlotRatio: 1, + killTaskSlotRatio: 0.1, maxKillTaskSlots: 2147483647, killPendingSegmentsSkipList: [], maxSegmentsInNodeLoadingQueue: 500,