Search in sources :

Example 11 with ServerHolder

use of org.apache.druid.server.coordinator.ServerHolder in project druid by druid-io.

the class LoadRuleTest method testLoadPrimaryAssignDoesNotOverAssign.

@Test
public void testLoadPrimaryAssignDoesNotOverAssign() {
    EasyMock.expect(throttler.canCreateReplicant(EasyMock.anyString())).andReturn(true).anyTimes();
    final LoadQueuePeon mockPeon = createEmptyPeon();
    mockPeon.loadSegment(EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall().atLeastOnce();
    LoadRule rule = createLoadRule(ImmutableMap.of("hot", 1));
    final DataSegment segment = createDataSegment("foo");
    EasyMock.expect(mockBalancerStrategy.findNewSegmentHomeReplicator(EasyMock.anyObject(), EasyMock.anyObject())).andDelegateTo(balancerStrategy).anyTimes();
    EasyMock.replay(throttler, mockPeon, mockBalancerStrategy);
    ImmutableDruidServer server1 = new DruidServer("serverHot", "hostHot", null, 1000, ServerType.HISTORICAL, "hot", 1).toImmutableDruidServer();
    ImmutableDruidServer server2 = new DruidServer("serverHot2", "hostHot2", null, 1000, ServerType.HISTORICAL, "hot", 1).toImmutableDruidServer();
    DruidCluster druidCluster = DruidClusterBuilder.newBuilder().addTier("hot", new ServerHolder(server1, mockPeon), new ServerHolder(server2, mockPeon)).build();
    CoordinatorStats stats = rule.run(null, makeCoordinatorRuntimeParams(druidCluster, segment), segment);
    Assert.assertEquals(1L, stats.getTieredStat(LoadRule.ASSIGNED_COUNT, "hot"));
    // ensure multiple runs don't assign primary segment again if at replication count
    final LoadQueuePeon loadingPeon = createLoadingPeon(ImmutableList.of(segment), false);
    EasyMock.replay(loadingPeon);
    DruidCluster afterLoad = DruidClusterBuilder.newBuilder().addTier("hot", new ServerHolder(server1, loadingPeon), new ServerHolder(server2, mockPeon)).build();
    CoordinatorStats statsAfterLoadPrimary = rule.run(null, makeCoordinatorRuntimeParams(afterLoad, segment), segment);
    Assert.assertEquals(0, statsAfterLoadPrimary.getTieredStat(LoadRule.ASSIGNED_COUNT, "hot"));
    EasyMock.verify(throttler, mockPeon, mockBalancerStrategy);
}
Also used : CoordinatorStats(org.apache.druid.server.coordinator.CoordinatorStats) ServerHolder(org.apache.druid.server.coordinator.ServerHolder) LoadQueuePeon(org.apache.druid.server.coordinator.LoadQueuePeon) DruidServer(org.apache.druid.client.DruidServer) ImmutableDruidServer(org.apache.druid.client.ImmutableDruidServer) DruidCluster(org.apache.druid.server.coordinator.DruidCluster) DataSegment(org.apache.druid.timeline.DataSegment) ImmutableDruidServer(org.apache.druid.client.ImmutableDruidServer) Test(org.junit.Test)

Example 12 with ServerHolder

use of org.apache.druid.server.coordinator.ServerHolder in project druid by druid-io.

the class LoadRuleTest method testOverAssignForTimedOutSegments.

@Test
public void testOverAssignForTimedOutSegments() {
    EasyMock.expect(throttler.canCreateReplicant(EasyMock.anyString())).andReturn(true).anyTimes();
    final LoadQueuePeon emptyPeon = createEmptyPeon();
    emptyPeon.loadSegment(EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall().atLeastOnce();
    LoadRule rule = createLoadRule(ImmutableMap.of("hot", 1));
    final DataSegment segment = createDataSegment("foo");
    EasyMock.expect(mockBalancerStrategy.findNewSegmentHomeReplicator(EasyMock.anyObject(), EasyMock.anyObject())).andDelegateTo(balancerStrategy).anyTimes();
    EasyMock.replay(throttler, emptyPeon, mockBalancerStrategy);
    ImmutableDruidServer server1 = new DruidServer("serverHot", "hostHot", null, 1000, ServerType.HISTORICAL, "hot", 1).toImmutableDruidServer();
    ImmutableDruidServer server2 = new DruidServer("serverHot2", "hostHot2", null, 1000, ServerType.HISTORICAL, "hot", 1).toImmutableDruidServer();
    DruidCluster druidCluster = DruidClusterBuilder.newBuilder().addTier("hot", new ServerHolder(server1, emptyPeon), new ServerHolder(server2, emptyPeon)).build();
    CoordinatorStats stats = rule.run(null, makeCoordinatorRuntimeParamsWithLoadReplicationOnTimeout(druidCluster, segment), segment);
    // Ensure that the segment is assigned to one of the historicals
    Assert.assertEquals(1L, stats.getTieredStat(LoadRule.ASSIGNED_COUNT, "hot"));
    // Ensure that the primary segment is assigned again in case the peon timed out on loading the segment
    final LoadQueuePeon slowLoadingPeon = createLoadingPeon(ImmutableList.of(segment), true);
    EasyMock.replay(slowLoadingPeon);
    DruidCluster withLoadTimeout = DruidClusterBuilder.newBuilder().addTier("hot", new ServerHolder(server1, slowLoadingPeon), new ServerHolder(server2, emptyPeon)).build();
    CoordinatorStats statsAfterLoadPrimary = rule.run(null, makeCoordinatorRuntimeParamsWithLoadReplicationOnTimeout(withLoadTimeout, segment), segment);
    Assert.assertEquals(1L, statsAfterLoadPrimary.getTieredStat(LoadRule.ASSIGNED_COUNT, "hot"));
    EasyMock.verify(throttler, emptyPeon, mockBalancerStrategy);
}
Also used : CoordinatorStats(org.apache.druid.server.coordinator.CoordinatorStats) ServerHolder(org.apache.druid.server.coordinator.ServerHolder) LoadQueuePeon(org.apache.druid.server.coordinator.LoadQueuePeon) DruidServer(org.apache.druid.client.DruidServer) ImmutableDruidServer(org.apache.druid.client.ImmutableDruidServer) DruidCluster(org.apache.druid.server.coordinator.DruidCluster) DataSegment(org.apache.druid.timeline.DataSegment) ImmutableDruidServer(org.apache.druid.client.ImmutableDruidServer) Test(org.junit.Test)

Example 13 with ServerHolder

use of org.apache.druid.server.coordinator.ServerHolder in project druid by druid-io.

the class CachingCostBalancerStrategyTest method createServerHolder.

private ServerHolder createServerHolder(String name, String host, int maxSize, int numberOfSegments, Random random, DateTime referenceTime) {
    DruidServer druidServer = new DruidServer(name, host, null, maxSize, ServerType.HISTORICAL, "normal", 0);
    createDataSegments(numberOfSegments, random, referenceTime).forEach(druidServer::addDataSegment);
    return new ServerHolder(druidServer.toImmutableDruidServer(), new LoadQueuePeonTester());
}
Also used : ServerHolder(org.apache.druid.server.coordinator.ServerHolder) DruidServer(org.apache.druid.client.DruidServer) LoadQueuePeonTester(org.apache.druid.server.coordinator.LoadQueuePeonTester)

Example 14 with ServerHolder

use of org.apache.druid.server.coordinator.ServerHolder in project druid by druid-io.

the class CachingCostBalancerStrategyTest method decisionTest.

@Test
public void decisionTest() {
    CachingCostBalancerStrategy cachingCostBalancerStrategy = createCachingCostBalancerStrategy(serverHolderList, executorService);
    CostBalancerStrategy costBalancerStrategy = createCostBalancerStrategy(executorService);
    int notEqual = segmentQueries.stream().mapToInt(s -> {
        ServerHolder s1 = cachingCostBalancerStrategy.findNewSegmentHomeBalancer(s, serverHolderList);
        ServerHolder s2 = costBalancerStrategy.findNewSegmentHomeBalancer(s, serverHolderList);
        return (s1.getServer().getName().equals(s2.getServer().getName())) ? 0 : 1;
    }).sum();
    Assert.assertTrue(((double) notEqual / (double) segmentQueries.size()) < 0.01);
}
Also used : IntStream(java.util.stream.IntStream) DateTimes(org.apache.druid.java.util.common.DateTimes) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) Execs(org.apache.druid.java.util.common.concurrent.Execs) CostBalancerStrategy(org.apache.druid.server.coordinator.CostBalancerStrategy) DruidServer(org.apache.druid.client.DruidServer) DateTime(org.joda.time.DateTime) Test(org.junit.Test) Random(java.util.Random) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) Interval(org.joda.time.Interval) List(java.util.List) After(org.junit.After) ServerType(org.apache.druid.server.coordination.ServerType) DataSegment(org.apache.druid.timeline.DataSegment) ServerHolder(org.apache.druid.server.coordinator.ServerHolder) CachingCostBalancerStrategy(org.apache.druid.server.coordinator.CachingCostBalancerStrategy) Assert(org.junit.Assert) Collections(java.util.Collections) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) LoadQueuePeonTester(org.apache.druid.server.coordinator.LoadQueuePeonTester) Before(org.junit.Before) CostBalancerStrategy(org.apache.druid.server.coordinator.CostBalancerStrategy) CachingCostBalancerStrategy(org.apache.druid.server.coordinator.CachingCostBalancerStrategy) ServerHolder(org.apache.druid.server.coordinator.ServerHolder) CachingCostBalancerStrategy(org.apache.druid.server.coordinator.CachingCostBalancerStrategy) Test(org.junit.Test)

Example 15 with ServerHolder

use of org.apache.druid.server.coordinator.ServerHolder in project druid by druid-io.

the class MarkAsUnusedOvershadowedSegmentsTest method testRun.

@Test
@Parameters({ "historical", "broker" })
public void testRun(String serverTypeString) {
    ServerType serverType = ServerType.fromString(serverTypeString);
    markAsUnusedOvershadowedSegments = new MarkAsUnusedOvershadowedSegments(coordinator);
    usedSegments = ImmutableList.of(segmentV1, segmentV0, segmentV2);
    // Dummy values for comparisons in TreeSet
    EasyMock.expect(mockPeon.getLoadQueueSize()).andReturn(0L).anyTimes();
    EasyMock.expect(druidServer.getMaxSize()).andReturn(0L).anyTimes();
    EasyMock.expect(druidServer.getCurrSize()).andReturn(0L).anyTimes();
    EasyMock.expect(druidServer.getName()).andReturn("").anyTimes();
    EasyMock.expect(druidServer.getHost()).andReturn("").anyTimes();
    EasyMock.expect(druidServer.getTier()).andReturn("").anyTimes();
    EasyMock.expect(druidServer.getType()).andReturn(serverType).anyTimes();
    EasyMock.expect(druidServer.getDataSources()).andReturn(ImmutableList.of(druidDataSource)).anyTimes();
    EasyMock.expect(druidDataSource.getSegments()).andReturn(ImmutableSet.of(segmentV1, segmentV2)).anyTimes();
    EasyMock.expect(druidDataSource.getName()).andReturn("test").anyTimes();
    coordinator.markSegmentAsUnused(segmentV1);
    coordinator.markSegmentAsUnused(segmentV0);
    EasyMock.expectLastCall();
    EasyMock.replay(mockPeon, coordinator, druidServer, druidDataSource);
    druidCluster = DruidClusterBuilder.newBuilder().addTier("normal", new ServerHolder(druidServer, mockPeon)).build();
    DruidCoordinatorRuntimeParams params = CoordinatorRuntimeParamsTestHelpers.newBuilder().withUsedSegmentsInTest(usedSegments).withCoordinatorStats(new CoordinatorStats()).withDruidCluster(druidCluster).withDynamicConfigs(RunRulesTest.COORDINATOR_CONFIG_WITH_ZERO_LEADING_TIME_BEFORE_CAN_MARK_AS_UNUSED_OVERSHADOWED_SEGMENTS).build();
    markAsUnusedOvershadowedSegments.run(params);
    EasyMock.verify(coordinator, druidDataSource, druidServer);
}
Also used : DruidCoordinatorRuntimeParams(org.apache.druid.server.coordinator.DruidCoordinatorRuntimeParams) ServerType(org.apache.druid.server.coordination.ServerType) CoordinatorStats(org.apache.druid.server.coordinator.CoordinatorStats) ServerHolder(org.apache.druid.server.coordinator.ServerHolder) Parameters(junitparams.Parameters) Test(org.junit.Test) RunRulesTest(org.apache.druid.server.coordinator.RunRulesTest)

Aggregations

ServerHolder (org.apache.druid.server.coordinator.ServerHolder)32 CoordinatorStats (org.apache.druid.server.coordinator.CoordinatorStats)22 DataSegment (org.apache.druid.timeline.DataSegment)22 DruidCluster (org.apache.druid.server.coordinator.DruidCluster)18 Test (org.junit.Test)16 DruidServer (org.apache.druid.client.DruidServer)15 ImmutableDruidServer (org.apache.druid.client.ImmutableDruidServer)15 LoadQueuePeon (org.apache.druid.server.coordinator.LoadQueuePeon)15 DruidCoordinatorRuntimeParams (org.apache.druid.server.coordinator.DruidCoordinatorRuntimeParams)7 LoadQueuePeonTester (org.apache.druid.server.coordinator.LoadQueuePeonTester)5 HashMap (java.util.HashMap)4 Object2IntMap (it.unimi.dsi.fastutil.objects.Object2IntMap)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 ServerType (org.apache.druid.server.coordination.ServerType)3 DruidCoordinator (org.apache.druid.server.coordinator.DruidCoordinator)3 SegmentId (org.apache.druid.timeline.SegmentId)3 Object2LongMap (it.unimi.dsi.fastutil.objects.Object2LongMap)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2