kfaraz commented on code in PR #17863:
URL: https://github.com/apache/druid/pull/17863#discussion_r2028151193
##########
server/src/main/java/org/apache/druid/server/coordinator/loading/SegmentReplicaCountMap.java:
##########
@@ -49,6 +49,10 @@ private void initReplicaCounts(DruidCluster cluster)
cluster.getHistoricals().forEach(
(tier, historicals) -> historicals.forEach(
serverHolder -> {
+ if (serverHolder.isUnmanaged()) {
+ // Don't manage
Review Comment:
```suggestion
// Don't count replicas since this is an unmanaged server
```
##########
server/src/main/java/org/apache/druid/server/coordinator/loading/HttpLoadQueuePeon.java:
##########
@@ -150,8 +150,7 @@ public HttpLoadQueuePeon(
this.serverCapabilities = fetchSegmentLoadingCapabilities();
}
- @VisibleForTesting
- SegmentLoadingCapabilities fetchSegmentLoadingCapabilities()
+ private SegmentLoadingCapabilities fetchSegmentLoadingCapabilities()
Review Comment:
Thanks!
##########
server/src/main/java/org/apache/druid/server/coordinator/loading/StrategicSegmentAssigner.java:
##########
@@ -446,7 +446,7 @@ private int dropReplicas(
for (ServerHolder server : eligibleServers) {
if (server.isDecommissioning()) {
eligibleDyingServers.add(server);
- } else {
+ } else if (!server.isUnmanaged()) {
Review Comment:
```suggestion
} else if (!server.isUnmanaged()) {
// Do not assign or drop segments if the server is unmanaged
```
##########
server/src/main/java/org/apache/druid/server/coordinator/duty/HistoricalCloningDuty.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.server.coordinator.duty;
+
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.coordinator.DruidCoordinatorRuntimeParams;
+import org.apache.druid.server.coordinator.ServerHolder;
+import org.apache.druid.server.coordinator.loading.SegmentAction;
+import org.apache.druid.server.coordinator.stats.CoordinatorRunStats;
+import org.apache.druid.server.coordinator.stats.Dimension;
+import org.apache.druid.server.coordinator.stats.RowKey;
+import org.apache.druid.server.coordinator.stats.Stats;
+import org.apache.druid.timeline.DataSegment;
+
+import javax.annotation.Nullable;
+import java.util.Collection;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class HistoricalCloningDuty implements CoordinatorDuty
+{
+ private static final Logger log = new Logger(HistoricalCloningDuty.class);
+
+ @Nullable
+ @Override
+ public DruidCoordinatorRuntimeParams run(DruidCoordinatorRuntimeParams
params)
+ {
+ final Map<String, String> cloneServers =
params.getCoordinatorDynamicConfig().getCloneServers();
+ if (cloneServers.isEmpty()) {
+ return params;
+ }
+
+ final CoordinatorRunStats stats = params.getCoordinatorStats();
+ // TODO: clean up
+ final Map<String, ServerHolder> historicalMap = params.getDruidCluster()
+ .getHistoricals()
+ .values()
+ .stream()
+
.flatMap(Collection::stream)
+
.collect(Collectors.toMap(
+ serverHolder ->
serverHolder.getServer().getHost(),
+ serverHolder ->
serverHolder
+ ));
+
+ for (Map.Entry<String, String> entry : cloneServers.entrySet()) {
+ String sourceHistoricalName = entry.getKey();
+ ServerHolder sourceServer = historicalMap.get(sourceHistoricalName);
+
+ String targetHistorical = entry.getValue();
+ ServerHolder targetServer = historicalMap.get(targetHistorical);
+
+ for (DataSegment segment :
sourceServer.getProjectedSegments().getSegments()) {
+ if (!targetServer.getServedSegments().contains(segment)) {
Review Comment:
```suggestion
if (!targetServer.isProjectedSegment(segment)) {
```
##########
server/src/main/java/org/apache/druid/server/coordinator/stats/Stats.java:
##########
@@ -137,6 +137,10 @@ public static class CoordinatorRun
= CoordinatorStat.toDebugAndEmit("dutyRunTime", "coordinator/time");
public static final CoordinatorStat GROUP_RUN_TIME
= CoordinatorStat.toDebugAndEmit("groupRunTime",
"coordinator/global/time");
+ public static final CoordinatorStat CLONE_LOAD
+ = CoordinatorStat.toDebugAndEmit("cloneLoad",
"coordinator/clone/load");
+ public static final CoordinatorStat CLONE_DROP
+ = CoordinatorStat.toDebugAndEmit("cloneDrop",
"coordinator/clone/drop");
Review Comment:
These metrics should go under `Stats.Segments` to adhere to the scheme
currently followed
- `segment/clone/assigned/count`
- `segment/clone/dropped/count`
##########
server/src/main/java/org/apache/druid/server/coordinator/duty/HistoricalCloningDuty.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.server.coordinator.duty;
+
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.coordinator.DruidCoordinatorRuntimeParams;
+import org.apache.druid.server.coordinator.ServerHolder;
+import org.apache.druid.server.coordinator.loading.SegmentAction;
+import org.apache.druid.server.coordinator.stats.CoordinatorRunStats;
+import org.apache.druid.server.coordinator.stats.Dimension;
+import org.apache.druid.server.coordinator.stats.RowKey;
+import org.apache.druid.server.coordinator.stats.Stats;
+import org.apache.druid.timeline.DataSegment;
+
+import javax.annotation.Nullable;
+import java.util.Collection;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class HistoricalCloningDuty implements CoordinatorDuty
+{
+ private static final Logger log = new Logger(HistoricalCloningDuty.class);
+
+ @Nullable
+ @Override
+ public DruidCoordinatorRuntimeParams run(DruidCoordinatorRuntimeParams
params)
+ {
+ final Map<String, String> cloneServers =
params.getCoordinatorDynamicConfig().getCloneServers();
+ if (cloneServers.isEmpty()) {
+ return params;
+ }
+
+ final CoordinatorRunStats stats = params.getCoordinatorStats();
+ // TODO: clean up
+ final Map<String, ServerHolder> historicalMap = params.getDruidCluster()
+ .getHistoricals()
+ .values()
+ .stream()
+
.flatMap(Collection::stream)
+
.collect(Collectors.toMap(
+ serverHolder ->
serverHolder.getServer().getHost(),
+ serverHolder ->
serverHolder
+ ));
+
+ for (Map.Entry<String, String> entry : cloneServers.entrySet()) {
+ String sourceHistoricalName = entry.getKey();
+ ServerHolder sourceServer = historicalMap.get(sourceHistoricalName);
+
+ String targetHistorical = entry.getValue();
+ ServerHolder targetServer = historicalMap.get(targetHistorical);
+
+ for (DataSegment segment :
sourceServer.getProjectedSegments().getSegments()) {
+ if (!targetServer.getServedSegments().contains(segment)) {
+ targetServer.getPeon().loadSegment(segment, SegmentAction.LOAD,
null);
+ stats.add(
+ Stats.CoordinatorRun.CLONE_LOAD,
+ RowKey.of(Dimension.SERVER, targetServer.getServer().getHost()),
+ 1L
+ );
+ }
+ }
+
+ for (DataSegment segment :
targetServer.getProjectedSegments().getSegments()) {
+ if (!sourceServer.getServedSegments().contains(segment)) {
Review Comment:
```suggestion
if (!sourceServer.isProjectedSegment(segment)) {
```
##########
server/src/test/java/org/apache/druid/server/coordinator/simulate/HistoricalCloningTest.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.server.coordinator.simulate;
+
+import org.apache.druid.client.DruidServer;
+import org.apache.druid.segment.TestDataSource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.apache.druid.server.coordinator.stats.Stats;
+import org.apache.druid.timeline.DataSegment;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class HistoricalCloningTest extends CoordinatorSimulationBaseTest
+{
+ private DruidServer historicalT11;
+ private DruidServer historicalT12;
+
+ private final String datasource = TestDataSource.WIKI;
+ private final List<DataSegment> segments = Segments.WIKI_10X1D;
+
+ @Override
+ public void setUp()
+ {
+ // Setup historicals for 2 tiers, size 10 GB each
+ historicalT11 = createHistorical(1, Tier.T1, 10_000);
+ historicalT12 = createHistorical(2, Tier.T1, 10_000);
+ }
+
+ @Test
+ public void testCloningHistorical()
+ {
+ final CoordinatorSimulation sim =
+ CoordinatorSimulation.builder()
+ .withSegments(segments)
+ .withServers(historicalT11, historicalT12)
+ .withRules(datasource, Load.on(Tier.T1,
1).forever())
+ .withDynamicConfig(
+ withCloneServers(
+ Map.of(
+ historicalT11.getHost(),
historicalT12.getHost()
+ )
+ ))
+ .build();
+
+ startSimulation(sim);
+ runCoordinatorCycle();
+ loadQueuedSegments();
+
+ verifyValue(Metric.ASSIGNED_COUNT, 10L);
+ verifyValue(
+ Stats.CoordinatorRun.CLONE_LOAD.getMetricName(),
+ Map.of("server", historicalT12.getName()),
+ 10L
+ );
+
+ runCoordinatorCycle();
+ verifyValue(
+ Metric.SUCCESS_ACTIONS,
+ Map.of("server", historicalT11.getName(), "description", "LOAD:
NORMAL"),
+ 10L
+ );
+ verifyValue(
+ Metric.SUCCESS_ACTIONS,
+ Map.of("server", historicalT12.getName(), "description", "LOAD:
TURBO"),
+ 10L
+ );
+
+ loadQueuedSegments();
+ Assert.assertEquals(10, historicalT11.getTotalSegments());
+ Assert.assertEquals(10, historicalT12.getTotalSegments());
+ }
+
+ /**
+ * Creates a dynamic config with unlimited load queue, balancing disabled and
+ * the given {@code replicationThrottleLimit}.
+ */
+ private CoordinatorDynamicConfig withCloneServers(Map<String, String>
cloneServers)
Review Comment:
It's more readable to define the dynamic config in the test itself, rather
than a separate private method.
##########
server/src/main/java/org/apache/druid/server/coordinator/duty/HistoricalCloningDuty.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.server.coordinator.duty;
+
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.coordinator.DruidCoordinatorRuntimeParams;
+import org.apache.druid.server.coordinator.ServerHolder;
+import org.apache.druid.server.coordinator.loading.SegmentAction;
+import org.apache.druid.server.coordinator.stats.CoordinatorRunStats;
+import org.apache.druid.server.coordinator.stats.Dimension;
+import org.apache.druid.server.coordinator.stats.RowKey;
+import org.apache.druid.server.coordinator.stats.Stats;
+import org.apache.druid.timeline.DataSegment;
+
+import javax.annotation.Nullable;
+import java.util.Collection;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class HistoricalCloningDuty implements CoordinatorDuty
Review Comment:
```suggestion
public class CloneHistoricals implements CoordinatorDuty
```
##########
server/src/test/java/org/apache/druid/server/coordinator/simulate/HistoricalCloningTest.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.server.coordinator.simulate;
+
+import org.apache.druid.client.DruidServer;
+import org.apache.druid.segment.TestDataSource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.apache.druid.server.coordinator.stats.Stats;
+import org.apache.druid.timeline.DataSegment;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class HistoricalCloningTest extends CoordinatorSimulationBaseTest
+{
+ private DruidServer historicalT11;
+ private DruidServer historicalT12;
+
+ private final String datasource = TestDataSource.WIKI;
+ private final List<DataSegment> segments = Segments.WIKI_10X1D;
+
+ @Override
+ public void setUp()
+ {
+ // Setup historicals for 2 tiers, size 10 GB each
+ historicalT11 = createHistorical(1, Tier.T1, 10_000);
+ historicalT12 = createHistorical(2, Tier.T1, 10_000);
+ }
+
+ @Test
+ public void testCloningHistorical()
+ {
+ final CoordinatorSimulation sim =
+ CoordinatorSimulation.builder()
+ .withSegments(segments)
+ .withServers(historicalT11, historicalT12)
+ .withRules(datasource, Load.on(Tier.T1,
1).forever())
+ .withDynamicConfig(
+ withCloneServers(
+ Map.of(
+ historicalT11.getHost(),
historicalT12.getHost()
+ )
+ ))
+ .build();
+
+ startSimulation(sim);
+ runCoordinatorCycle();
+ loadQueuedSegments();
+
+ verifyValue(Metric.ASSIGNED_COUNT, 10L);
+ verifyValue(
+ Stats.CoordinatorRun.CLONE_LOAD.getMetricName(),
+ Map.of("server", historicalT12.getName()),
+ 10L
+ );
+
+ runCoordinatorCycle();
+ verifyValue(
+ Metric.SUCCESS_ACTIONS,
+ Map.of("server", historicalT11.getName(), "description", "LOAD:
NORMAL"),
+ 10L
+ );
+ verifyValue(
+ Metric.SUCCESS_ACTIONS,
+ Map.of("server", historicalT12.getName(), "description", "LOAD:
TURBO"),
+ 10L
+ );
+
+ loadQueuedSegments();
+ Assert.assertEquals(10, historicalT11.getTotalSegments());
+ Assert.assertEquals(10, historicalT12.getTotalSegments());
+ }
+
+ /**
+ * Creates a dynamic config with unlimited load queue, balancing disabled and
+ * the given {@code replicationThrottleLimit}.
+ */
+ private CoordinatorDynamicConfig withCloneServers(Map<String, String>
cloneServers)
+ {
+ final Set<String> unmanagedServers = new HashSet<>(cloneServers.values());
+
+ return CoordinatorDynamicConfig.builder()
+ .withSmartSegmentLoading(true)
+ .withCloneServers(cloneServers)
+ .withUnmanagedNodes(unmanagedServers)
+ .withTurboLoadingNodes(unmanagedServers)
Review Comment:
I think we can leave out the turbo loading here.
##########
server/src/main/java/org/apache/druid/server/coordinator/SegmentCountsPerInterval.java:
##########
@@ -61,6 +66,11 @@ public long getTotalSegmentBytes()
return totalSegmentBytes;
}
+ public Set<DataSegment> getSegments()
Review Comment:
@adarshsanjeev , I took a look at the code and I feel there is another way
to do this instead of maintaining a new set here.
- Rename the `ServerHolder.getProjectedSegments()` method to
`ServerHolder.getProjectedSegmentCounts()`
- Add a new method `ServerHolder.getProjectedSegments()`
- This way the methods `isProjectedSegment()` and `getProjectedSegments()`
will be aligned with each other better.
```java
public Set<DataSegment> getProjectedSegments()
{
final Set<DataSegment> projectedSegments = new
HashSet<>(getServedSegments());
queuedSegments.forEach((segment, action) -> {
if (action.isLoad()) {
projectedSegments.add(segment);
}
});
return projectedSegments;
}
```
Let me know if this makes sense.
##########
server/src/main/java/org/apache/druid/server/coordinator/ServerHolder.java:
##########
@@ -213,6 +227,11 @@ public boolean isDecommissioning()
return isDecommissioning;
}
+ public boolean isUnmanaged()
Review Comment:
Please add a short javadoc:
```
Returns true if this server is unmanaged and should not participate in
segment assignment, drop or balancing.
```
##########
server/src/main/java/org/apache/druid/server/coordinator/duty/HistoricalCloningDuty.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.server.coordinator.duty;
+
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.coordinator.DruidCoordinatorRuntimeParams;
+import org.apache.druid.server.coordinator.ServerHolder;
+import org.apache.druid.server.coordinator.loading.SegmentAction;
+import org.apache.druid.server.coordinator.stats.CoordinatorRunStats;
+import org.apache.druid.server.coordinator.stats.Dimension;
+import org.apache.druid.server.coordinator.stats.RowKey;
+import org.apache.druid.server.coordinator.stats.Stats;
+import org.apache.druid.timeline.DataSegment;
+
+import javax.annotation.Nullable;
+import java.util.Collection;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class HistoricalCloningDuty implements CoordinatorDuty
+{
+ private static final Logger log = new Logger(HistoricalCloningDuty.class);
+
+ @Nullable
+ @Override
+ public DruidCoordinatorRuntimeParams run(DruidCoordinatorRuntimeParams
params)
+ {
+ final Map<String, String> cloneServers =
params.getCoordinatorDynamicConfig().getCloneServers();
+ if (cloneServers.isEmpty()) {
+ return params;
+ }
+
+ final CoordinatorRunStats stats = params.getCoordinatorStats();
+ // TODO: clean up
+ final Map<String, ServerHolder> historicalMap = params.getDruidCluster()
+ .getHistoricals()
+ .values()
+ .stream()
+
.flatMap(Collection::stream)
+
.collect(Collectors.toMap(
+ serverHolder ->
serverHolder.getServer().getHost(),
+ serverHolder ->
serverHolder
+ ));
+
+ for (Map.Entry<String, String> entry : cloneServers.entrySet()) {
+ String sourceHistoricalName = entry.getKey();
+ ServerHolder sourceServer = historicalMap.get(sourceHistoricalName);
+
+ String targetHistorical = entry.getValue();
+ ServerHolder targetServer = historicalMap.get(targetHistorical);
+
+ for (DataSegment segment :
sourceServer.getProjectedSegments().getSegments()) {
+ if (!targetServer.getServedSegments().contains(segment)) {
+ targetServer.getPeon().loadSegment(segment, SegmentAction.LOAD,
null);
Review Comment:
Load and drop should go via the `LoadQueueManager`.
See `StrategicSegmentAssigner.loadSegment` for reference.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]