Search in sources :

Example 1 with ForeverLoadRule

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();
}
Also used : DruidServer(org.apache.druid.client.DruidServer) DataSegment(org.apache.druid.timeline.DataSegment) ForeverLoadRule(org.apache.druid.server.coordinator.rules.ForeverLoadRule) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with ForeverLoadRule

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);
}
Also used : ForeverLoadRule(org.apache.druid.server.coordinator.rules.ForeverLoadRule) DruidServer(org.apache.druid.client.DruidServer) DataSegment(org.apache.druid.timeline.DataSegment) Test(org.junit.Test)

Example 3 with ForeverLoadRule

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);
}
Also used : ForeverLoadRule(org.apache.druid.server.coordinator.rules.ForeverLoadRule) DruidServer(org.apache.druid.client.DruidServer) DataSegment(org.apache.druid.timeline.DataSegment) Test(org.junit.Test)

Example 4 with ForeverLoadRule

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);
}
Also used : ForeverBroadcastDistributionRule(org.apache.druid.server.coordinator.rules.ForeverBroadcastDistributionRule) ForeverLoadRule(org.apache.druid.server.coordinator.rules.ForeverLoadRule)

Example 5 with ForeverLoadRule

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);
}
Also used : ArrayList(java.util.ArrayList) ForeverLoadRule(org.apache.druid.server.coordinator.rules.ForeverLoadRule) Rule(org.apache.druid.server.coordinator.rules.Rule) PeriodLoadRule(org.apache.druid.server.coordinator.rules.PeriodLoadRule) ForeverLoadRule(org.apache.druid.server.coordinator.rules.ForeverLoadRule) IntervalDropRule(org.apache.druid.server.coordinator.rules.IntervalDropRule) ForeverDropRule(org.apache.druid.server.coordinator.rules.ForeverDropRule) IntervalDropRule(org.apache.druid.server.coordinator.rules.IntervalDropRule) Test(org.junit.Test)

Aggregations

ForeverLoadRule (org.apache.druid.server.coordinator.rules.ForeverLoadRule)10 Test (org.junit.Test)8 DruidServer (org.apache.druid.client.DruidServer)7 DataSegment (org.apache.druid.timeline.DataSegment)7 ForeverBroadcastDistributionRule (org.apache.druid.server.coordinator.rules.ForeverBroadcastDistributionRule)3 Rule (org.apache.druid.server.coordinator.rules.Rule)3 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)2 Object2LongMap (it.unimi.dsi.fastutil.objects.Object2LongMap)2 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 DruidDataSource (org.apache.druid.client.DruidDataSource)2 ImmutableDruidDataSource (org.apache.druid.client.ImmutableDruidDataSource)2 ImmutableDruidServer (org.apache.druid.client.ImmutableDruidServer)2 ForeverDropRule (org.apache.druid.server.coordinator.rules.ForeverDropRule)2 IntervalDropRule (org.apache.druid.server.coordinator.rules.IntervalDropRule)2 IntervalLoadRule (org.apache.druid.server.coordinator.rules.IntervalLoadRule)2 PeriodLoadRule (org.apache.druid.server.coordinator.rules.PeriodLoadRule)2 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1