Search in sources :

Example 1 with ServerType

use of org.apache.druid.server.coordination.ServerType in project druid by druid-io.

the class BroadcastDistributionRule method run.

@Override
public CoordinatorStats run(DruidCoordinator coordinator, DruidCoordinatorRuntimeParams params, DataSegment segment) {
    final Set<ServerHolder> dropServerHolders = new HashSet<>();
    // Find servers where we need to load the broadcast segments
    final Set<ServerHolder> loadServerHolders = params.getDruidCluster().getAllServers().stream().filter((serverHolder) -> {
        ServerType serverType = serverHolder.getServer().getType();
        if (!serverType.isSegmentBroadcastTarget()) {
            return false;
        }
        final boolean isServingSegment = serverHolder.isServingSegment(segment);
        if (serverHolder.isDecommissioning()) {
            if (isServingSegment && !serverHolder.isDroppingSegment(segment)) {
                dropServerHolders.add(serverHolder);
            }
            return false;
        }
        return !isServingSegment && !serverHolder.isLoadingSegment(segment);
    }).collect(Collectors.toSet());
    final CoordinatorStats stats = new CoordinatorStats();
    return stats.accumulate(assign(loadServerHolders, segment)).accumulate(drop(dropServerHolders, segment));
}
Also used : EmittingLogger(org.apache.druid.java.util.emitter.EmittingLogger) DruidCoordinatorRuntimeParams(org.apache.druid.server.coordinator.DruidCoordinatorRuntimeParams) Set(java.util.Set) DruidCoordinator(org.apache.druid.server.coordinator.DruidCoordinator) CoordinatorStats(org.apache.druid.server.coordinator.CoordinatorStats) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) SegmentReplicantLookup(org.apache.druid.server.coordinator.SegmentReplicantLookup) Object2LongMap(it.unimi.dsi.fastutil.objects.Object2LongMap) Map(java.util.Map) ServerType(org.apache.druid.server.coordination.ServerType) DataSegment(org.apache.druid.timeline.DataSegment) DruidCluster(org.apache.druid.server.coordinator.DruidCluster) ServerHolder(org.apache.druid.server.coordinator.ServerHolder) Object2LongOpenHashMap(it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap) ServerType(org.apache.druid.server.coordination.ServerType) CoordinatorStats(org.apache.druid.server.coordinator.CoordinatorStats) ServerHolder(org.apache.druid.server.coordinator.ServerHolder) HashSet(java.util.HashSet)

Example 2 with ServerType

use of org.apache.druid.server.coordination.ServerType 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

ServerType (org.apache.druid.server.coordination.ServerType)2 CoordinatorStats (org.apache.druid.server.coordinator.CoordinatorStats)2 DruidCoordinatorRuntimeParams (org.apache.druid.server.coordinator.DruidCoordinatorRuntimeParams)2 ServerHolder (org.apache.druid.server.coordinator.ServerHolder)2 Object2LongMap (it.unimi.dsi.fastutil.objects.Object2LongMap)1 Object2LongOpenHashMap (it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Parameters (junitparams.Parameters)1 EmittingLogger (org.apache.druid.java.util.emitter.EmittingLogger)1 DruidCluster (org.apache.druid.server.coordinator.DruidCluster)1 DruidCoordinator (org.apache.druid.server.coordinator.DruidCoordinator)1 RunRulesTest (org.apache.druid.server.coordinator.RunRulesTest)1 SegmentReplicantLookup (org.apache.druid.server.coordinator.SegmentReplicantLookup)1 DataSegment (org.apache.druid.timeline.DataSegment)1 Test (org.junit.Test)1