use of org.apache.druid.server.coordinator.rules.ForeverLoadRule in project druid by druid-io.
the class RunRulesTest method testRulesRunOnNonOvershadowedSegmentsOnly.
@Test
public void testRulesRunOnNonOvershadowedSegmentsOnly() {
Set<DataSegment> usedSegments = new HashSet<>();
DataSegment v1 = new DataSegment("test", Intervals.of("2012-01-01/2012-01-02"), "1", new HashMap<>(), new ArrayList<>(), new ArrayList<>(), NoneShardSpec.instance(), IndexIO.CURRENT_VERSION_ID, 1);
DataSegment v2 = new DataSegment("test", Intervals.of("2012-01-01/2012-01-02"), "2", new HashMap<>(), new ArrayList<>(), new ArrayList<>(), NoneShardSpec.instance(), IndexIO.CURRENT_VERSION_ID, 1);
usedSegments.add(v1);
usedSegments.add(v2);
mockCoordinator();
mockPeon.loadSegment(EasyMock.eq(v2), EasyMock.anyObject());
EasyMock.expectLastCall().once();
mockEmptyPeon();
EasyMock.expect(databaseRuleManager.getRulesWithDefault(EasyMock.anyObject())).andReturn(Collections.singletonList(new ForeverLoadRule(ImmutableMap.of(DruidServer.DEFAULT_TIER, 1)))).atLeastOnce();
EasyMock.replay(databaseRuleManager);
DruidCluster druidCluster = DruidClusterBuilder.newBuilder().addTier(DruidServer.DEFAULT_TIER, new ServerHolder(new DruidServer("serverHot", "hostHot", null, 1000, ServerType.HISTORICAL, DruidServer.DEFAULT_TIER, 0).toImmutableDruidServer(), mockPeon)).build();
ListeningExecutorService exec = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1));
BalancerStrategy balancerStrategy = new CostBalancerStrategyFactory().createBalancerStrategy(exec);
DruidCoordinatorRuntimeParams params = CoordinatorRuntimeParamsTestHelpers.newBuilder().withDruidCluster(druidCluster).withUsedSegmentsInTest(usedSegments).withDatabaseRuleManager(databaseRuleManager).withSegmentReplicantLookup(SegmentReplicantLookup.make(new DruidCluster(), false)).withBalancerStrategy(balancerStrategy).withDynamicConfigs(CoordinatorDynamicConfig.builder().withMaxSegmentsToMove(5).build()).build();
DruidCoordinatorRuntimeParams afterParams = ruleRunner.run(params);
CoordinatorStats stats = afterParams.getCoordinatorStats();
Assert.assertEquals(1, stats.getTiers("assignedCount").size());
Assert.assertEquals(1, stats.getTieredStat("assignedCount", "_default_tier"));
Assert.assertTrue(stats.getTiers("unassignedCount").isEmpty());
Assert.assertTrue(stats.getTiers("unassignedSize").isEmpty());
Assert.assertEquals(2, usedSegments.size());
Assert.assertEquals(usedSegments, params.getUsedSegments());
Assert.assertEquals(usedSegments, afterParams.getUsedSegments());
EasyMock.verify(mockPeon);
exec.shutdown();
}
use of org.apache.druid.server.coordinator.rules.ForeverLoadRule in project druid by druid-io.
the class RunRulesTest method testTwoNodesOneTierThreeReplicantsRandomStrategyNotEnoughNodes.
/**
* Tier - __default_tier
* Nodes - 2
* Replicants - 3
* Random balancer strategy should not assign anything and not get into loop as there are not enough nodes for replication
*/
@Test(timeout = 5000L)
public void testTwoNodesOneTierThreeReplicantsRandomStrategyNotEnoughNodes() {
mockCoordinator();
mockEmptyPeon();
EasyMock.expect(databaseRuleManager.getRulesWithDefault(EasyMock.anyObject())).andReturn(Collections.singletonList(new ForeverLoadRule(ImmutableMap.of(DruidServer.DEFAULT_TIER, 3)))).atLeastOnce();
EasyMock.replay(databaseRuleManager);
DataSegment dataSegment = new DataSegment("test", Intervals.utc(0, 1), DateTimes.nowUtc().toString(), new HashMap<>(), new ArrayList<>(), new ArrayList<>(), NoneShardSpec.instance(), IndexIO.CURRENT_VERSION_ID, 1);
DruidCluster druidCluster = DruidClusterBuilder.newBuilder().addTier(DruidServer.DEFAULT_TIER, new ServerHolder(new DruidServer("server1", "host1", null, 1000, ServerType.HISTORICAL, DruidServer.DEFAULT_TIER, 0).addDataSegment(dataSegment).toImmutableDruidServer(), mockPeon), new ServerHolder(new DruidServer("server2", "host2", null, 1000, ServerType.HISTORICAL, DruidServer.DEFAULT_TIER, 0).addDataSegment(dataSegment).toImmutableDruidServer(), mockPeon)).build();
RandomBalancerStrategy balancerStrategy = new RandomBalancerStrategy();
DruidCoordinatorRuntimeParams params = makeCoordinatorRuntimeParams(druidCluster, balancerStrategy, Collections.singletonList(dataSegment)).withDynamicConfigs(CoordinatorDynamicConfig.builder().withMaxSegmentsToMove(5).build()).build();
DruidCoordinatorRuntimeParams afterParams = ruleRunner.run(params);
CoordinatorStats stats = afterParams.getCoordinatorStats();
Assert.assertEquals(0L, stats.getTieredStat("assignedCount", DruidServer.DEFAULT_TIER));
Assert.assertTrue(stats.getTiers("unassignedCount").isEmpty());
Assert.assertTrue(stats.getTiers("unassignedSize").isEmpty());
EasyMock.verify(mockPeon);
}
use of org.apache.druid.server.coordinator.rules.ForeverLoadRule in project druid by druid-io.
the class RunRulesTest method testOneNodesOneTierOneReplicantRandomStrategyEnoughSpace.
/**
* Tier - __default_tier
* Nodes - 1
* Replicants - 1
* Random balancer strategy should select the only node
*/
@Test(timeout = 5000L)
public void testOneNodesOneTierOneReplicantRandomStrategyEnoughSpace() {
mockCoordinator();
mockPeon.loadSegment(EasyMock.anyObject(), EasyMock.anyObject());
EasyMock.expectLastCall().atLeastOnce();
mockEmptyPeon();
EasyMock.expect(databaseRuleManager.getRulesWithDefault(EasyMock.anyObject())).andReturn(Collections.singletonList(new ForeverLoadRule(ImmutableMap.of(DruidServer.DEFAULT_TIER, 1)))).atLeastOnce();
EasyMock.replay(databaseRuleManager);
DataSegment dataSegment = new DataSegment("test", Intervals.utc(0, 1), DateTimes.nowUtc().toString(), new HashMap<>(), new ArrayList<>(), new ArrayList<>(), NoneShardSpec.instance(), IndexIO.CURRENT_VERSION_ID, 1);
DruidCluster druidCluster = DruidClusterBuilder.newBuilder().addTier(DruidServer.DEFAULT_TIER, new ServerHolder(new DruidServer("server1", "host1", null, 1000, ServerType.HISTORICAL, DruidServer.DEFAULT_TIER, 0).toImmutableDruidServer(), mockPeon)).build();
RandomBalancerStrategy balancerStrategy = new RandomBalancerStrategy();
DruidCoordinatorRuntimeParams params = makeCoordinatorRuntimeParams(druidCluster, balancerStrategy, Collections.singletonList(dataSegment)).withDynamicConfigs(CoordinatorDynamicConfig.builder().withMaxSegmentsToMove(5).build()).build();
DruidCoordinatorRuntimeParams afterParams = ruleRunner.run(params);
CoordinatorStats stats = afterParams.getCoordinatorStats();
Assert.assertEquals(1L, stats.getTieredStat("assignedCount", DruidServer.DEFAULT_TIER));
Assert.assertTrue(stats.getTiers("unassignedCount").isEmpty());
Assert.assertTrue(stats.getTiers("unassignedSize").isEmpty());
EasyMock.verify(mockPeon);
}
use of org.apache.druid.server.coordinator.rules.ForeverLoadRule in project druid by druid-io.
the class UnloadUnusedSegmentsTest method mockRuleManager.
private static void mockRuleManager(MetadataRuleManager metadataRuleManager) {
EasyMock.expect(metadataRuleManager.getRulesWithDefault("datasource1")).andReturn(Collections.singletonList(new ForeverLoadRule(ImmutableMap.of(DruidServer.DEFAULT_TIER, 1, "tier2", 1)))).anyTimes();
EasyMock.expect(metadataRuleManager.getRulesWithDefault("datasource2")).andReturn(Collections.singletonList(new ForeverLoadRule(ImmutableMap.of(DruidServer.DEFAULT_TIER, 1, "tier2", 1)))).anyTimes();
EasyMock.expect(metadataRuleManager.getRulesWithDefault("broadcastDatasource")).andReturn(Collections.singletonList(new ForeverBroadcastDistributionRule())).anyTimes();
EasyMock.replay(metadataRuleManager);
}
use of org.apache.druid.server.coordinator.rules.ForeverLoadRule in project druid by druid-io.
the class CoordinatorRuleManagerTest method testGetRulesWithKnownDatasourceReturningAllRulesWithDefaultRule.
@Test
public void testGetRulesWithKnownDatasourceReturningAllRulesWithDefaultRule() {
final CoordinatorRuleManager manager = new CoordinatorRuleManager(objectMapper, () -> tieredBrokerConfig, mockClient());
manager.poll();
final List<Rule> rules = manager.getRulesWithDefault(DATASOURCE2);
final List<Rule> expectedRules = new ArrayList<>();
expectedRules.add(new ForeverLoadRule(null));
expectedRules.add(new IntervalDropRule(Intervals.of("2020-01-01/2020-01-02")));
expectedRules.addAll(DEFAULT_RULES);
Assert.assertEquals(expectedRules, rules);
}
Aggregations