use of org.apache.druid.client.ImmutableDruidServer in project druid by druid-io.
the class LoadRuleTest method testLoadUsedSegmentsForAllSegmentGranularityAndCachingCostBalancerStrategy.
@Test
public void testLoadUsedSegmentsForAllSegmentGranularityAndCachingCostBalancerStrategy() {
EasyMock.expect(throttler.canCreateReplicant(EasyMock.anyString())).andReturn(false).anyTimes();
LoadRule rule = createLoadRule(ImmutableMap.of("tier1", 1));
DataSegment segment0 = createDataSegmentWithIntervalAndPartition(createDataSegment("foo"), JodaUtils.MIN_INSTANT, JodaUtils.MAX_INSTANT, 0);
DataSegment segment1 = createDataSegmentWithIntervalAndPartition(createDataSegment("foo"), JodaUtils.MIN_INSTANT, JodaUtils.MAX_INSTANT, 1);
final LoadQueuePeon loadingPeon = createLoadingPeon(ImmutableList.of(segment0), true);
loadingPeon.loadSegment(EasyMock.anyObject(), EasyMock.isNull());
EasyMock.expectLastCall().once();
EasyMock.expect(mockBalancerStrategy.findNewSegmentHomeReplicator(EasyMock.anyObject(), EasyMock.anyObject())).andDelegateTo(cachingCostBalancerStrategy).anyTimes();
EasyMock.replay(throttler, loadingPeon, mockBalancerStrategy);
ImmutableDruidServer server = new DruidServer("serverHot", "hostHot", null, 1000, ServerType.HISTORICAL, "tier1", 1).toImmutableDruidServer();
DruidCluster druidCluster = DruidClusterBuilder.newBuilder().addTier("tier1", new ServerHolder(server, loadingPeon)).build();
final CoordinatorStats stats = rule.run(null, makeCoordinatorRuntimeParamsWithLoadReplicationOnTimeout(druidCluster, segment0, segment1), segment1);
Assert.assertEquals(1L, stats.getTieredStat(LoadRule.ASSIGNED_COUNT, "tier1"));
EasyMock.verify(throttler, loadingPeon, mockBalancerStrategy);
}
use of org.apache.druid.client.ImmutableDruidServer in project druid by druid-io.
the class LoadRuleTest method testSkipReplicationForTimedOutSegments.
@Test
public void testSkipReplicationForTimedOutSegments() {
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, makeCoordinatorRuntimeParams(druidCluster, segment), segment);
// Ensure that the segment is assigned to one of the historicals
Assert.assertEquals(1L, stats.getTieredStat(LoadRule.ASSIGNED_COUNT, "hot"));
// Add the segment to the timed out list to simulate peon timeout 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();
// Default behavior is to not replicate the timed out segments on other servers
CoordinatorStats statsAfterLoadPrimary = rule.run(null, makeCoordinatorRuntimeParams(withLoadTimeout, segment), segment);
Assert.assertEquals(0L, statsAfterLoadPrimary.getTieredStat(LoadRule.ASSIGNED_COUNT, "hot"));
EasyMock.verify(throttler, emptyPeon, mockBalancerStrategy);
}
use of org.apache.druid.client.ImmutableDruidServer in project druid by druid-io.
the class DruidSchemaTest method testAvailableSegmentMetadataNumRows.
/**
* This tests that {@link AvailableSegmentMetadata#getNumRows()} is correct in case
* of multiple replicas i.e. when {@link DruidSchema#addSegment(DruidServerMetadata, DataSegment)}
* is called more than once for same segment
*/
@Test
public void testAvailableSegmentMetadataNumRows() {
Map<SegmentId, AvailableSegmentMetadata> segmentsMetadata = schema.getSegmentMetadataSnapshot();
final List<DataSegment> segments = segmentsMetadata.values().stream().map(AvailableSegmentMetadata::getSegment).collect(Collectors.toList());
Assert.assertEquals(4, segments.size());
// find the only segment with datasource "foo2"
final DataSegment existingSegment = segments.stream().filter(segment -> segment.getDataSource().equals("foo2")).findFirst().orElse(null);
Assert.assertNotNull(existingSegment);
final AvailableSegmentMetadata existingMetadata = segmentsMetadata.get(existingSegment.getId());
// update AvailableSegmentMetadata of existingSegment with numRows=5
AvailableSegmentMetadata updatedMetadata = AvailableSegmentMetadata.from(existingMetadata).withNumRows(5).build();
schema.setAvailableSegmentMetadata(existingSegment.getId(), updatedMetadata);
// find a druidServer holding existingSegment
final Pair<ImmutableDruidServer, DataSegment> pair = druidServers.stream().flatMap(druidServer -> druidServer.iterateAllSegments().stream().filter(segment -> segment.getId().equals(existingSegment.getId())).map(segment -> Pair.of(druidServer, segment))).findAny().orElse(null);
Assert.assertNotNull(pair);
final ImmutableDruidServer server = pair.lhs;
Assert.assertNotNull(server);
final DruidServerMetadata druidServerMetadata = server.getMetadata();
// invoke DruidSchema#addSegment on existingSegment
schema.addSegment(druidServerMetadata, existingSegment);
segmentsMetadata = schema.getSegmentMetadataSnapshot();
// get the only segment with datasource "foo2"
final DataSegment currentSegment = segments.stream().filter(segment -> segment.getDataSource().equals("foo2")).findFirst().orElse(null);
final AvailableSegmentMetadata currentMetadata = segmentsMetadata.get(currentSegment.getId());
Assert.assertEquals(updatedMetadata.getSegment().getId(), currentMetadata.getSegment().getId());
Assert.assertEquals(updatedMetadata.getNumRows(), currentMetadata.getNumRows());
// numreplicas do not change here since we addSegment with the same server which was serving existingSegment before
Assert.assertEquals(updatedMetadata.getNumReplicas(), currentMetadata.getNumReplicas());
}
use of org.apache.druid.client.ImmutableDruidServer in project druid by druid-io.
the class ServerHolderTest method testEquals.
@Test
public void testEquals() {
final ServerHolder h1 = new ServerHolder(new ImmutableDruidServer(new DruidServerMetadata("name1", "host1", null, 100L, ServerType.HISTORICAL, "tier1", 0), 0L, ImmutableMap.of("src1", DATA_SOURCES.get("src1")), 1), new LoadQueuePeonTester());
final ServerHolder h2 = new ServerHolder(new ImmutableDruidServer(new DruidServerMetadata("name2", "host1", null, 200L, ServerType.HISTORICAL, "tier1", 0), 100L, ImmutableMap.of("src1", DATA_SOURCES.get("src1")), 1), new LoadQueuePeonTester());
final ServerHolder h3 = new ServerHolder(new ImmutableDruidServer(new DruidServerMetadata("name1", "host2", null, 200L, ServerType.HISTORICAL, "tier1", 0), 100L, ImmutableMap.of("src1", DATA_SOURCES.get("src1")), 1), new LoadQueuePeonTester());
final ServerHolder h4 = new ServerHolder(new ImmutableDruidServer(new DruidServerMetadata("name1", "host1", null, 200L, ServerType.HISTORICAL, "tier2", 0), 100L, ImmutableMap.of("src1", DATA_SOURCES.get("src1")), 1), new LoadQueuePeonTester());
final ServerHolder h5 = new ServerHolder(new ImmutableDruidServer(new DruidServerMetadata("name1", "host1", null, 100L, ServerType.REALTIME, "tier1", 0), 0L, ImmutableMap.of("src1", DATA_SOURCES.get("src1")), 1), new LoadQueuePeonTester());
Assert.assertEquals(h1, h2);
Assert.assertNotEquals(h1, h3);
Assert.assertNotEquals(h1, h4);
Assert.assertNotEquals(h1, h5);
}
use of org.apache.druid.client.ImmutableDruidServer in project druid by druid-io.
the class ServerHolderTest method testIsServingSegment.
@Test
public void testIsServingSegment() {
final ServerHolder h1 = new ServerHolder(new ImmutableDruidServer(new DruidServerMetadata("name1", "host1", null, 100L, ServerType.HISTORICAL, "tier1", 0), 0L, ImmutableMap.of("src1", DATA_SOURCES.get("src1")), 1), new LoadQueuePeonTester());
Assert.assertTrue(h1.isServingSegment(SEGMENTS.get(0)));
Assert.assertFalse(h1.isServingSegment(SEGMENTS.get(1)));
Assert.assertTrue(h1.isServingSegment(SEGMENTS.get(0).getId()));
Assert.assertFalse(h1.isServingSegment(SEGMENTS.get(1).getId()));
}
Aggregations