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);
}
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);
}
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());
}
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);
}
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);
}
Aggregations