You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "adarshsanjeev (via GitHub)" <gi...@apache.org> on 2025/04/10 10:56:05 UTC
[PR] Add changes to prevent Broker from querying cloned Historicals (druid)
adarshsanjeev opened a new pull request, #17899:
URL: https://github.com/apache/druid/pull/17899
<!-- Thanks for trying to help us make Apache Druid be the best it can be! Please fill out as much of the following information as is possible (where relevant, and remove it when irrelevant) to help make the intention and scope of this PR clear in order to ease review. -->
<!-- Please read the doc for contribution (https://github.com/apache/druid/blob/master/CONTRIBUTING.md) before making this PR. Also, once you open a PR, please _avoid using force pushes and rebasing_ since these make it difficult for reviewers to see what you've changed in response to their reviews. See [the 'If your pull request shows conflicts with master' section](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#if-your-pull-request-shows-conflicts-with-master) for more details. -->
<!-- Replace XXXX with the id of the issue fixed in this PR. Remove this section if there is no corresponding issue. Don't reference the issue in the title of this pull-request. -->
<!-- If you are a committer, follow the PR action item checklist for committers:
https://github.com/apache/druid/blob/master/dev/committer-instructions.md#pr-and-issue-action-item-checklist-for-committers. -->
### Description
TODO: Add description
<!-- Describe the goal of this PR, what problem are you fixing. If there is a corresponding issue (referenced above), it's not necessary to repeat the description here, however, you may choose to keep one summary sentence. -->
<!-- Describe your patch: what did you change in code? How did you fix the problem? -->
<!-- If there are several relatively logically separate changes in this PR, create a mini-section for each of them. For example: -->
<!--
In each section, please describe design decisions made, including:
- Choice of algorithms
- Behavioral aspects. What configuration values are acceptable? How are corner cases and error conditions handled, such as when there are insufficient resources?
- Class organization and design (how the logic is split between classes, inheritance, composition, design patterns)
- Method organization and design (how the logic is split between methods, parameters and return types)
- Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
-->
<!-- It's good to describe an alternative design (or mention an alternative name) for every design (or naming) decision point and compare the alternatives with the designs that you've implemented (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
<!-- If there was a discussion of the design of the feature implemented in this PR elsewhere (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), link to that discussion from this PR description and explain what have changed in your final design compared to your original proposal or the consensus version in the end of the discussion. If something hasn't changed since the original discussion, you can omit a detailed discussion of those aspects of the design here, perhaps apart from brief mentioning for the sake of readability of this PR description. -->
<!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
#### Release note
TODO: Add release notes
<!-- Give your best effort to summarize your changes in a couple of sentences aimed toward Druid users.
If your change doesn't have end user impact, you can skip this section.
For tips about how to write a good release note, see [Release notes](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#release-notes).
-->
<hr>
<!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
This PR has:
- [ ] been self-reviewed.
- [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
- [ ] added documentation for new or modified features or behaviors.
- [ ] a release note entry in the PR description.
- [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
- [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
- [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
- [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
- [ ] added integration tests.
- [ ] been tested in a test Druid cluster.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2051992590
##########
docs/querying/query-context.md:
##########
@@ -66,6 +66,7 @@ See [SQL query context](sql-query-context.md) for other query context parameters
|`debug`| `false` | Flag indicating whether to enable debugging outputs for the query. When set to false, no additional logs will be produced (logs produced will be entirely dependent on your logging level). When set to true, the following addition logs will be produced:<br />- Log the stack trace of the exception (if any) produced by the query |
|`setProcessingThreadNames`|`true`| Whether processing thread names will be set to `queryType_dataSource_intervals` while processing a query. This aids in interpreting thread dumps, and is on by default. Query overhead can be reduced slightly by setting this to `false`. This has a tiny effect in most scenarios, but can be meaningful in high-QPS, low-per-segment-processing-time scenarios. |
|`sqlPlannerBloat`|`1000`|Calcite parameter which controls whether to merge two Project operators when inlining expressions causes complexity to increase. Implemented as a workaround to exception `There are not enough rules to produce a node with desired properties: convention=DRUID, sort=[]` thrown after rejecting the merge of two projects.|
+|`cloneQueryMode`|`EXCLUDE`| Indicates whether clone Historicals should be queried by brokers. Clone servers are created by the `cloneServers` Coordinator dynamic configuration. Possible values are `EXCLUDE`, `INCLUDE` and `CLONE_PREFERRED`. `EXCLUDE` means that clone Historicals are not queried by the broker. `CLONE_PREFERRED` indicates that when given a choice between the clone Historical and the original Historical which is being cloned, the broker chooses the clones; Historicals which are not involved in the cloning process will still be queried. `INCLUDE` means that broker queries any Historical without regarding clone status. This parameter only affects native queries; MSQ does not query Historicals directly, and Dart will not respect this context parameter.|
Review Comment:
I think `ClonesPreferred` makes more sense. `onlyClones` implies that no non clone server is queried. This is not true, Servers which are not at all in the clone mapping are queried either way. If this were not the case, many queries would not be possible as segments would be missing.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2053317704
##########
server/src/main/java/org/apache/druid/server/DruidInternalDynamicConfigResource.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import com.google.inject.Inject;
+import com.sun.jersey.spi.container.ResourceFilters;
+import org.apache.druid.client.CoordinatorDynamicConfigView;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.apache.druid.server.http.security.ConfigResourceFilter;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@Path("/druid-internal/v1/dynamicConfiguration")
+public class DruidInternalDynamicConfigResource
+{
+ private final CoordinatorDynamicConfigView coordinatorDynamicConfigView;
+
+ @Inject
+ public DruidInternalDynamicConfigResource(CoordinatorDynamicConfigView coordinatorDynamicConfigView)
+ {
+ this.coordinatorDynamicConfigView = coordinatorDynamicConfigView;
+ }
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @ResourceFilters(ConfigResourceFilter.class)
+ @Path("/coordinatorDynamicConfig")
+ public Response getDynamicConfig()
+ {
+ return Response.ok(coordinatorDynamicConfigView.getDynamicConfiguration()).build();
+ }
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @ResourceFilters(ConfigResourceFilter.class)
+ @Path("/coordinatorDynamicConfig")
+ public Response setDynamicConfig(final CoordinatorDynamicConfig dynamicConfig)
+ {
+ coordinatorDynamicConfigView.setDynamicConfiguration(dynamicConfig);
+ return Response.ok("OK").build();
Review Comment:
Dropped the "OK"
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on PR #17899:
URL: https://github.com/apache/druid/pull/17899#issuecomment-2801301278
Will update documentation regarding the context parameter and APIs soon.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052104015
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
Review Comment:
We shouldn't need to pre-compute the lists. Do you want to do that for perf reasons?
This class should ideally not have the `getSourceServers` and `getTargetServers` methods at all. The caller can just get the dynamic config and perform any required operation on it.
Having separate methods for `getConfig`, `getSource` and `getTarget` makes it more error prone.
A caller may make calls to these methods in subsequent lines and still get back inconsistent results, since another thread updated the config meanwhile.
Let me know if this makes sense.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052106580
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
Review Comment:
Once this class becomes an implementation of the interface `HistoricalFilter`, then we could actually keep pre-computed lists since we would never need to expose them for the purposes of filtration. We would then be able to put stuff in a synchronized block in a more consistent manner.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2051468921
##########
server/src/test/java/org/apache/druid/client/TestCoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.client;
+
+import java.util.Set;
+
+public class TestCoordinatorDynamicConfigView extends CoordinatorDynamicConfigView
+{
+ private final Set<String> targetServers;
+ private final Set<String> sourceServers;
+
+ public TestCoordinatorDynamicConfigView(
+ Set<String> targetServers,
+ Set<String> sourceServers
+ )
+ {
+ super(null);
+ this.targetServers = targetServers;
+ this.sourceServers = sourceServers;
+ }
+
+ @Override
+ public Set<String> getTargetCloneServers()
Review Comment:
## Non-synchronized override of synchronized method
Method 'getTargetCloneServers' overrides a synchronized method in [org.apache.druid.client.CoordinatorDynamicConfigView](1) but is not synchronized.
[Show more details](https://github.com/apache/druid/security/code-scanning/8923)
##########
server/src/test/java/org/apache/druid/client/TestCoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.client;
+
+import java.util.Set;
+
+public class TestCoordinatorDynamicConfigView extends CoordinatorDynamicConfigView
+{
+ private final Set<String> targetServers;
+ private final Set<String> sourceServers;
+
+ public TestCoordinatorDynamicConfigView(
+ Set<String> targetServers,
+ Set<String> sourceServers
+ )
+ {
+ super(null);
+ this.targetServers = targetServers;
+ this.sourceServers = sourceServers;
+ }
+
+ @Override
+ public Set<String> getTargetCloneServers()
+ {
+ return targetServers;
+ }
+
+ @Override
+ public Set<String> getSourceCloneServers()
Review Comment:
## Non-synchronized override of synchronized method
Method 'getSourceCloneServers' overrides a synchronized method in [org.apache.druid.client.CoordinatorDynamicConfigView](1) but is not synchronized.
[Show more details](https://github.com/apache/druid/security/code-scanning/8922)
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2051944243
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorDynamicConfigSyncer.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import org.apache.druid.discovery.DiscoveryDruidNode;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHandler;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHolder;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.RequestBuilder;
+import org.apache.druid.rpc.ServiceClient;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.StandardRetryPolicy;
+import org.apache.druid.server.coordinator.CoordinatorConfigManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.jboss.netty.handler.codec.http.HttpMethod;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+
+import java.net.URL;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+/**
+ * Updates all brokers with the latest coordinator dynamic config.
+ */
+public class CoordinatorDynamicConfigSyncer
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigSyncer.class);
+
+ private final CoordinatorConfigManager configManager;
+ private final ObjectMapper jsonMapper;
+ private final DruidNodeDiscoveryProvider druidNodeDiscovery;
+
+ private final AtomicReference<CoordinatorDynamicConfig> lastKnownConfig = new AtomicReference<>();
+ private final ServiceClientFactory clientFactory;
+ private final ExecutorService exec;
+ private final Set<String> inSyncBrokers;
+
+ @Inject
+ public CoordinatorDynamicConfigSyncer(
+ @EscalatedGlobal final ServiceClientFactory clientFactory,
Review Comment:
The Broker client is a client to a random single broker from service discovery, as I understand it. Is it possible to send the request to a specific broker with it?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052193147
##########
server/src/main/java/org/apache/druid/client/selector/ServerSelector.java:
##########
@@ -121,13 +122,17 @@
}
}
- public List<DruidServerMetadata> getCandidates(final int numCandidates)
+ public List<DruidServerMetadata> getCandidates(
+ final int numCandidates,
+ final HistoricalFilter filter,
+ final CloneQueryMode cloneQueryMode
+ )
{
List<DruidServerMetadata> candidates;
synchronized (this) {
if (numCandidates > 0) {
candidates = new ArrayList<>(numCandidates);
- strategy.pick(historicalServers, segment.get(), numCandidates)
+ strategy.pick(filter.getQueryableServers(historicalServers, cloneQueryMode), segment.get(), numCandidates)
Review Comment:
## Deprecated method or constructor invocation
Invoking [TierSelectorStrategy.pick](1) should be avoided because it has been deprecated.
[Show more details](https://github.com/apache/druid/security/code-scanning/8925)
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052325542
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
Review Comment:
> Once this class becomes an implementation of the interface HistoricalFilter, then we could actually keep pre-computed lists
Changed.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052025599
##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/dart/controller/DartTableInputSpecSlicer.java:
##########
@@ -162,7 +163,7 @@ public List<InputSlice> sliceDynamic(
*/
int findWorkerForServerSelector(final ServerSelector serverSelector, final int maxNumSlices)
{
- final QueryableDruidServer server = serverSelector.pick(null);
+ final QueryableDruidServer server = serverSelector.pick(null, HistoricalFilter.IDENTITY_FILTER);
Review Comment:
Added a note in the query context docs
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052057334
##########
server/src/main/java/org/apache/druid/client/selector/HistoricalFilter.java:
##########
@@ -0,0 +1,39 @@
+package org.apache.druid.client.selector;
+
+import com.google.common.collect.ImmutableSet;
+import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
+import org.apache.druid.client.QueryableDruidServer;
+
+import java.util.Set;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+
+public class HistoricalFilter implements Function<Int2ObjectRBTreeMap<Set<QueryableDruidServer>>, Int2ObjectRBTreeMap<Set<QueryableDruidServer>>>
Review Comment:
Changing the function to Set has some issues, as mentioned in https://github.com/apache/druid/pull/17899#discussion_r2039275089.
Regarding changing `DynamicConfigManager` to an implementation of `HistoricalFilter`, this means that the cloneQueryMode enum would need to be added as an additional argument to each function in ServerSelector. Is this still the cleaner option?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2063066336
##########
docs/querying/query-context.md:
##########
@@ -66,6 +66,7 @@ See [SQL query context](sql-query-context.md) for other query context parameters
|`debug`| `false` | Flag indicating whether to enable debugging outputs for the query. When set to false, no additional logs will be produced (logs produced will be entirely dependent on your logging level). When set to true, the following addition logs will be produced:<br />- Log the stack trace of the exception (if any) produced by the query |
|`setProcessingThreadNames`|`true`| Whether processing thread names will be set to `queryType_dataSource_intervals` while processing a query. This aids in interpreting thread dumps, and is on by default. Query overhead can be reduced slightly by setting this to `false`. This has a tiny effect in most scenarios, but can be meaningful in high-QPS, low-per-segment-processing-time scenarios. |
|`sqlPlannerBloat`|`1000`|Calcite parameter which controls whether to merge two Project operators when inlining expressions causes complexity to increase. Implemented as a workaround to exception `There are not enough rules to produce a node with desired properties: convention=DRUID, sort=[]` thrown after rejecting the merge of two projects.|
+|`cloneQueryMode`|`excludeClones`| Indicates whether clone Historicals should be queried by brokers. Clone servers are created by the `cloneServers` Coordinator dynamic configuration. Possible values are `excludeClones`, `includeClones` and `clonesPreferred`. `excludeClones` means that clone Historicals are not queried by the broker. `clonesPreferred` indicates that when given a choice between the clone Historical and the original Historical which is being cloned, the broker chooses the clones; Historicals which are not involved in the cloning process will still be queried. `includeClones` means that broker queries any Historical without regarding clone status. This parameter only affects native queries; MSQ does not query Historicals directly, and Dart will not respect this context parameter.|
Review Comment:
For follow up: Use `preferClones` instead of `clonesPreferred`.
##########
server/src/main/java/org/apache/druid/server/http/BrokerSyncStatus.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.druid.rpc.ServiceLocation;
+
+import java.util.Objects;
+
+public class BrokerSyncStatus
+{
+ private final String host;
+ private final int port;
+ private final long syncTimeInMs;
Review Comment:
cc: @adarshsanjeev , note for follow up
##########
server/src/main/java/org/apache/druid/client/BrokerViewOfCoordinatorConfig.java:
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.client;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
+import org.apache.druid.client.coordinator.Coordinator;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.client.coordinator.CoordinatorClientImpl;
+import org.apache.druid.client.selector.HistoricalFilter;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.error.DruidException;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.query.CloneQueryMode;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocator;
+import org.apache.druid.rpc.StandardRetryPolicy;
+import org.apache.druid.server.BrokerDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link BrokerDynamicConfigResource}.
+ */
+public class BrokerViewOfCoordinatorConfig implements HistoricalFilter
+{
+ private static final Logger log = new Logger(BrokerViewOfCoordinatorConfig.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
+ @GuardedBy("this")
+ private Set<String> targetCloneServers;
+ @GuardedBy("this")
+ private Set<String> sourceCloneServers;
+
+ @Inject
+ public BrokerViewOfCoordinatorConfig(
+ @Json final ObjectMapper jsonMapper,
+ @EscalatedGlobal final ServiceClientFactory clientFactory,
+ @Coordinator final ServiceLocator serviceLocator
+ )
+ {
+ this.coordinatorClient =
+ new CoordinatorClientImpl(
+ clientFactory.makeClient(
+ NodeRole.COORDINATOR.getJsonName(),
+ serviceLocator,
+ StandardRetryPolicy.builder().maxAttempts(15).build()
+ ),
+ jsonMapper
+ );
+ }
+
+ @VisibleForTesting
+ public BrokerViewOfCoordinatorConfig(CoordinatorClient coordinatorClient)
+ {
+ this.coordinatorClient = coordinatorClient;
+ }
+
+ /**
+ * Return the latest {@link CoordinatorDynamicConfig}.
+ */
+ public synchronized CoordinatorDynamicConfig getDynamicConfig()
+ {
+ return config;
+ }
+
+ /**
+ * Update the config view with a new coordinator dynamic config snapshot. Also updates the source and target clone
+ * servers based on the new dynamic configuration.
+ */
+ public synchronized void setDynamicConfig(@NotNull CoordinatorDynamicConfig updatedConfig)
+ {
+ config = updatedConfig;
+ final Map<String, String> cloneServers = config.getCloneServers();
+ this.targetCloneServers = ImmutableSet.copyOf(cloneServers.keySet());
+ this.sourceCloneServers = ImmutableSet.copyOf(cloneServers.values());
+ }
+
+ @LifecycleStart
+ public void start()
+ {
+ try {
+ log.info("Fetching coordinator dynamic configuration.");
+
+ CoordinatorDynamicConfig coordinatorDynamicConfig = coordinatorClient.getCoordinatorDynamicConfig().get();
+ setDynamicConfig(coordinatorDynamicConfig);
+
+ log.info("Successfully fetched coordinator dynamic config[%s].", coordinatorDynamicConfig);
+ }
+ catch (Exception e) {
+ // If the fetch fails, the broker should not serve queries. Throw the exception and try again on restart.
+ throw new RuntimeException("Failed to initialize coordinator dynamic config", e);
+ }
+ }
+
+ @Override
+ public Int2ObjectRBTreeMap<Set<QueryableDruidServer>> getQueryableServers(
+ Int2ObjectRBTreeMap<Set<QueryableDruidServer>> historicalServers,
+ CloneQueryMode mode
+ )
+ {
+ final Set<String> serversToIgnore = getCurrentServersToIgnore(mode);
+
+ if (serversToIgnore.isEmpty()) {
+ return historicalServers;
+ }
+
+ final Int2ObjectRBTreeMap<Set<QueryableDruidServer>> filteredHistoricals = new Int2ObjectRBTreeMap<>();
+ for (int priority : historicalServers.keySet()) {
+ Set<QueryableDruidServer> servers = historicalServers.get(priority);
+ filteredHistoricals.put(priority,
+ servers.stream()
+ .filter(server -> !serversToIgnore.contains(server.getServer().getHost()))
+ .collect(Collectors.toSet())
+ );
+ }
+
+ return filteredHistoricals;
+ }
+
+ /**
+ * Get the list of servers that should not be queried based on the cloneQueryMode parameter.
+ */
+ private synchronized Set<String> getCurrentServersToIgnore(CloneQueryMode cloneQueryMode)
+ {
+ switch (cloneQueryMode) {
+ case PREFERCLONES:
+ // Remove servers being cloned targets, so that clones are queried.
+ return sourceCloneServers;
+ case EXCLUDECLONES:
+ // Remove clones, so that only source servers are queried.
+ return targetCloneServers;
+ case INCLUDECLONES:
+ // Don't remove either.
+ return Set.of();
+ default:
+ throw DruidException.defensive("Unexpected value: [%s]", cloneQueryMode);
Review Comment:
follow up:
```suggestion
throw DruidException.defensive("Unexpected value of cloneQueryMode[%s]", cloneQueryMode);
```
##########
processing/src/main/java/org/apache/druid/query/QueryContexts.java:
##########
@@ -149,6 +150,7 @@ public class QueryContexts
public static final boolean DEFAULT_ENABLE_JOIN_FILTER_PUSH_DOWN = true;
public static final boolean DEFAULT_ENABLE_JOIN_FILTER_REWRITE = true;
public static final boolean DEFAULT_ENABLE_JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS = false;
+ public static final CloneQueryMode DEFAULT_CLONE_QUERY_MODE = CloneQueryMode.EXCLUDECLONES;
Review Comment:
Note for follow-up: Should the default be exclude or include?
##########
server/src/main/java/org/apache/druid/server/http/BrokerSyncStatus.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.druid.rpc.ServiceLocation;
+
+import java.util.Objects;
+
+public class BrokerSyncStatus
+{
+ private final String host;
+ private final int port;
+ private final long syncTimeInMs;
Review Comment:
No, unfortunately, it is not documented anywhere.
I agree that calling out the units removes the ambiguity, esp. when it comes to specifying durations.
(Side note: when writing configs for durations, we should either just call out the unit in the config name or accept a `Duration` or `Period` in the config value. We should probably document this somewhere as a Druid coding guideline.)
But I actually had other concerns with this field name.
`syncTimeInMs` sounds more like the _duration_ it took to finish a sync, rather than the last sync timestamp.
So we should definitely call it `lastSyncTimestamp`.
For clarity, we can add the unit suffix and calling it `lastSyncTimestampMillis`.
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorDynamicConfigSyncer.java:
##########
@@ -0,0 +1,221 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import org.apache.druid.client.broker.BrokerClient;
+import org.apache.druid.client.broker.BrokerClientImpl;
+import org.apache.druid.discovery.DiscoveryDruidNode;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.StandardRetryPolicy;
+import org.apache.druid.server.DruidNode;
+import org.apache.druid.server.coordinator.CoordinatorConfigManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.annotation.Nullable;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+/**
+ * Updates all brokers with the latest coordinator dynamic config.
+ */
+public class CoordinatorDynamicConfigSyncer
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigSyncer.class);
+
+ private final CoordinatorConfigManager configManager;
+ private final ObjectMapper jsonMapper;
+ private final DruidNodeDiscoveryProvider druidNodeDiscovery;
+
+ private final ServiceClientFactory clientFactory;
+ private final ScheduledExecutorService exec;
+ private @Nullable Future<?> syncFuture = null;
+
+ @GuardedBy("this")
+ private final Set<BrokerSyncStatus> inSyncBrokers;
+ private final AtomicReference<CoordinatorDynamicConfig> lastKnownConfig = new AtomicReference<>();
+
+ @Inject
+ public CoordinatorDynamicConfigSyncer(
+ @EscalatedGlobal final ServiceClientFactory clientFactory,
+ final CoordinatorConfigManager configManager,
+ @Json final ObjectMapper jsonMapper,
+ final DruidNodeDiscoveryProvider druidNodeDiscoveryProvider
+ )
+ {
+ this.clientFactory = clientFactory;
+ this.configManager = configManager;
+ this.jsonMapper = jsonMapper;
+ this.druidNodeDiscovery = druidNodeDiscoveryProvider;
+ this.exec = Execs.scheduledSingleThreaded("CoordinatorDynamicConfigSyncer-%d");
Review Comment:
Note for follow up: There should preferably be a lifecycle stop method which shuts down this executor, as it allows for nicer cleanup of the resources used by this class.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2057654118
##########
server/src/main/java/org/apache/druid/server/http/BrokerSyncStatus.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.druid.rpc.ServiceLocation;
+
+import java.util.Objects;
+
+public class BrokerSyncStatus
Review Comment:
nit: javadocs please
##########
server/src/main/java/org/apache/druid/client/CachingClusteredClient.java:
##########
@@ -126,11 +128,13 @@ public class CachingClusteredClient implements QuerySegmentWalker
private final ForkJoinPool pool;
private final QueryScheduler scheduler;
private final ServiceEmitter emitter;
+ private final BrokerViewOfCoordinatorConfig brokerViewOfCoordinatorConfig;
@Inject
public CachingClusteredClient(
QueryRunnerFactoryConglomerate conglomerate,
TimelineServerView serverView,
+ BrokerViewOfCoordinatorConfig brokerViewOfCoordinatorConfig,
Review Comment:
why does `CachingClusteredClient` need this to just pass into `ServerSelector` instead of creating `ServerSelector` with it? And since we pass the query into `pick` anyway it seems like nothing here would have to change if we did that instead
##########
server/src/main/java/org/apache/druid/client/ServerViewUtil.java:
##########
@@ -42,17 +44,21 @@ public static List<LocatedSegmentDescriptor> getTargetLocations(
TimelineServerView serverView,
String datasource,
List<Interval> intervals,
- int numCandidates
+ int numCandidates,
+ HistoricalFilter historicalFilter,
+ CloneQueryMode cloneQueryMode
)
{
- return getTargetLocations(serverView, new TableDataSource(datasource), intervals, numCandidates);
+ return getTargetLocations(serverView, new TableDataSource(datasource), intervals, numCandidates, historicalFilter, cloneQueryMode);
Review Comment:
this also would only need `cloneQueryMode` if the config was already on `ServerSelector`
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2037383844
##########
server/src/main/java/org/apache/druid/client/CachingClusteredClient.java:
##########
@@ -598,7 +605,18 @@ private SortedMap<DruidServer, List<SegmentDescriptor>> groupSegmentsByServer(Se
{
final SortedMap<DruidServer, List<SegmentDescriptor>> serverSegments = new TreeMap<>();
for (SegmentServerSelector segmentServer : segments) {
- final QueryableDruidServer queryableDruidServer = segmentServer.getServer().pick(query);
+ Supplier<Set<String>> supplier = () -> {
+ boolean queryUnmanagedServers = query.context().getQueryUnmanagedServers();
+ if (queryUnmanagedServers) {
+ // If this is a test query, ignore source servers.
Review Comment:
I think it need not be a test query.
```suggestion
```
##########
server/src/main/java/org/apache/druid/client/CachingClusteredClient.java:
##########
@@ -598,7 +605,18 @@ private SortedMap<DruidServer, List<SegmentDescriptor>> groupSegmentsByServer(Se
{
final SortedMap<DruidServer, List<SegmentDescriptor>> serverSegments = new TreeMap<>();
for (SegmentServerSelector segmentServer : segments) {
- final QueryableDruidServer queryableDruidServer = segmentServer.getServer().pick(query);
+ Supplier<Set<String>> supplier = () -> {
+ boolean queryUnmanagedServers = query.context().getQueryUnmanagedServers();
+ if (queryUnmanagedServers) {
+ // If this is a test query, ignore source servers.
+ return dynamicConfigurationManager.getSourceClusterServers();
+ } else {
+ return dynamicConfigurationManager.getTargetCloneServers();
Review Comment:
Currently this is getting the list of historicals from na atom reference. Since this is the hot code, can we change the dynamic configuration manager to a read write lock and see the impact. I see you have a benchmark here as well. What are the results ?
##########
server/src/main/java/org/apache/druid/client/selector/ServerSelector.java:
##########
@@ -122,12 +122,17 @@
}
public List<DruidServerMetadata> getCandidates(final int numCandidates)
+ {
+ return getCandidates(numCandidates, HistoricalFilter.IDENTITIY_FILTER);
+ }
+
+ public List<DruidServerMetadata> getCandidates(final int numCandidates, HistoricalFilter filter)
{
List<DruidServerMetadata> candidates;
synchronized (this) {
if (numCandidates > 0) {
candidates = new ArrayList<>(numCandidates);
- strategy.pick(historicalServers, segment.get(), numCandidates)
+ strategy.pick(filter.apply(historicalServers), segment.get(), numCandidates)
Review Comment:
Currently I am not sure which is cheaper. Making changes here or : https://github.com/implydata/druid/blob/ef72cff603cac88c0eca6da7ed1f4a5f814d87bc/server/src/main/java/org/apache/druid/client/selector/AbstractTierSelectorStrategy.java#L65.
I guess creating a new Int2ObjectRBTreeMap might be more expensive.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052068438
##########
server/src/main/java/org/apache/druid/server/coordinator/CoordinatorDynamicConfig.java:
##########
@@ -191,6 +192,30 @@ private Map<Dimension, String> validateDebugDimensions(Map<String, String> debug
return validDebugDimensions;
}
+ public CoordinatorDynamicConfig snapshot()
Review Comment:
Is editing the sets or maps not a concern even if the config is immutable?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052325989
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorDynamicConfigSyncer.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import org.apache.druid.discovery.DiscoveryDruidNode;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHandler;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHolder;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.RequestBuilder;
+import org.apache.druid.rpc.ServiceClient;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.StandardRetryPolicy;
+import org.apache.druid.server.coordinator.CoordinatorConfigManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.jboss.netty.handler.codec.http.HttpMethod;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+
+import java.net.URL;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+/**
+ * Updates all brokers with the latest coordinator dynamic config.
+ */
+public class CoordinatorDynamicConfigSyncer
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigSyncer.class);
+
+ private final CoordinatorConfigManager configManager;
+ private final ObjectMapper jsonMapper;
+ private final DruidNodeDiscoveryProvider druidNodeDiscovery;
+
+ private final AtomicReference<CoordinatorDynamicConfig> lastKnownConfig = new AtomicReference<>();
+ private final ServiceClientFactory clientFactory;
+ private final ExecutorService exec;
+ private final Set<String> inSyncBrokers;
+
+ @Inject
+ public CoordinatorDynamicConfigSyncer(
+ @EscalatedGlobal final ServiceClientFactory clientFactory,
Review Comment:
Makes sense! I misunderstood. Made this change
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2058178026
##########
docs/api-reference/service-status-api.md:
##########
@@ -658,6 +658,135 @@ Host: http://COORDINATOR_IP:COORDINATOR_PORT
</details>
+
+### Get Historical Cloning Status
+
+Retrieves the current status of Historical cloning from the Coordinator.
+
+#### URL
+
+`GET` `/druid/coordinator/v1/config/cloneStatus`
+
+#### Responses
+
+<Tabs>
+
+<TabItem value="56" label="200 SUCCESS">
+
+
+<br/>
+
+*Successfully retrieved cloning status*
+
+</TabItem>
+</Tabs>
+
+#### Sample request
+
+<Tabs>
+
+<TabItem value="58" label="cURL">
+
+
+```shell
+curl "http://COORDINATOR_IP:COORDINATOR_PORT/druid/coordinator/v1/config/cloneStatus"
+```
+
+</TabItem>
+<TabItem value="59" label="HTTP">
+
+
+```http
+GET /druid/coordinator/v1/config/cloneStatus HTTP/1.1
+Host: http://COORDINATOR_IP:COORDINATOR_PORT
+```
+
+</TabItem>
+</Tabs>
+
+#### Sample response
+
+<details>
+ <summary>View the response</summary>
+
+```json
+{
+ "localhost:8083": {
Review Comment:
As suggested earlier, the response should contain a list of clone status objects rather than a map.
##########
processing/src/main/java/org/apache/druid/query/CloneQueryMode.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.query;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import org.apache.druid.error.InvalidInput;
+
+/**
+ * Enum used in the query context to determine if clone queries should be used by native queries.
+ */
+public enum CloneQueryMode
+{
+ /**
+ * For each ongoing cloning, do not query the source server that is being cloned. Other servers which are not
+ * participating in any cloning will still be queried.
+ */
+ CLONES_PREFERRED("clonesPreferred"),
Review Comment:
```suggestion
PREFER_CLONES("preferClones"),
```
##########
processing/src/main/java/org/apache/druid/query/CloneQueryMode.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.query;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import org.apache.druid.error.InvalidInput;
+
+/**
+ * Enum used in the query context to determine if clone queries should be used by native queries.
+ */
+public enum CloneQueryMode
+{
+ /**
+ * For each ongoing cloning, do not query the source server that is being cloned. Other servers which are not
+ * participating in any cloning will still be queried.
+ */
+ CLONES_PREFERRED("clonesPreferred"),
+ /**
+ * Consider both clones and their source servers for querying.
+ */
+ INCLUDE("includeClones"),
Review Comment:
```suggestion
INCLUDE_CLONES("includeClones"),
```
##########
server/src/main/java/org/apache/druid/client/selector/HistoricalFilter.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.client.selector;
+
+import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
+import org.apache.druid.client.QueryableDruidServer;
+import org.apache.druid.query.CloneQueryMode;
+
+import java.util.Set;
+
+public interface HistoricalFilter
Review Comment:
Needs a short javadoc.
##########
server/src/main/java/org/apache/druid/server/ClientQuerySegmentWalker.java:
##########
@@ -607,7 +607,7 @@ private <T> QueryRunner<T> decorateClusterRunner(Query<T> query, QueryRunner<T>
* @param parentQueryResourceId Parent Query's Query Resource ID
* @return DataSource populated with the subqueries
*/
- private DataSource generateSubqueryIds(
+ public static DataSource generateSubqueryIds(
Review Comment:
Thanks!
##########
server/src/main/java/org/apache/druid/client/BrokerViewOfCoordinatorConfig.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.client.selector.HistoricalFilter;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.query.CloneQueryMode;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class BrokerViewOfCoordinatorConfig implements HistoricalFilter
+{
+ private static final Logger log = new Logger(BrokerViewOfCoordinatorConfig.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
+ @GuardedBy("this")
+ private Set<String> cloneServers;
+ @GuardedBy("this")
+ private Set<String> serversBeingCloned;
+
+ @Inject
+ public BrokerViewOfCoordinatorConfig(CoordinatorClient coordinatorClient)
+ {
+ this.coordinatorClient = coordinatorClient;
+ }
+
+ public synchronized CoordinatorDynamicConfig getDynamicConfiguration()
+ {
+ return config;
+ }
+
+ /**
+ * Update the config view with a new coordinator dynamic config snapshot. Also updates the source and target clone
+ * servers based on the new dynamic configuration.
+ */
+ public synchronized void setDynamicConfig(@NotNull CoordinatorDynamicConfig updatedConfig)
+ {
+ config = updatedConfig;
+ final Map<String, String> cloneServers = config.getCloneServers();
+ this.cloneServers = ImmutableSet.copyOf(cloneServers.keySet());
+ this.serversBeingCloned = ImmutableSet.copyOf(cloneServers.values());
+ }
+
+ @LifecycleStart
+ public void start()
+ {
+ try {
+ log.info("Fetching coordinator dynamic configuration.");
+
+ CoordinatorDynamicConfig coordinatorDynamicConfig = coordinatorClient.getCoordinatorDynamicConfig().get();
+ setDynamicConfig(coordinatorDynamicConfig);
+
+ log.info("Successfully initialized dynamic config: [%s]", coordinatorDynamicConfig);
+ }
+ catch (Exception e) {
+ // If the fetch fails, the broker should not serve queries. Throw the exception and try again on restart.
+ log.error(e, "Failed to initialize coordinator dynamic config");
+ throw new RuntimeException(e);
Review Comment:
No need for the additional log since we are throwing the exception anyway.
```suggestion
throw new RuntimeException(e, "Failed to initialize coordinator dynamic config");
```
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorDynamicConfigSyncer.java:
##########
@@ -0,0 +1,191 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import org.apache.druid.client.broker.BrokerClient;
+import org.apache.druid.client.broker.BrokerClientImpl;
+import org.apache.druid.discovery.DiscoveryDruidNode;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.StandardRetryPolicy;
+import org.apache.druid.server.DruidNode;
+import org.apache.druid.server.coordinator.CoordinatorConfigManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.annotation.Nullable;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+/**
+ * Updates all brokers with the latest coordinator dynamic config.
+ */
+public class CoordinatorDynamicConfigSyncer
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigSyncer.class);
+
+ private final CoordinatorConfigManager configManager;
+ private final ObjectMapper jsonMapper;
+ private final DruidNodeDiscoveryProvider druidNodeDiscovery;
+
+ private final AtomicReference<CoordinatorDynamicConfig> lastKnownConfig = new AtomicReference<>();
+ private final ServiceClientFactory clientFactory;
+ private final Set<BrokerSyncStatus> inSyncBrokers;
+ private final ScheduledExecutorService exec;
+ private @Nullable Future<?> syncFuture = null;
+
+ @Inject
+ public CoordinatorDynamicConfigSyncer(
+ @EscalatedGlobal final ServiceClientFactory clientFactory,
+ final CoordinatorConfigManager configManager,
+ @Json final ObjectMapper jsonMapper,
+ final DruidNodeDiscoveryProvider druidNodeDiscoveryProvider
+ )
+ {
+ this.clientFactory = clientFactory;
+ this.configManager = configManager;
+ this.jsonMapper = jsonMapper;
+ this.druidNodeDiscovery = druidNodeDiscoveryProvider;
+ this.exec = Execs.scheduledSingleThreaded("CoordinatorDynamicConfigSyncer-%d");
+ this.inSyncBrokers = ConcurrentHashMap.newKeySet();
+ }
+
+ public void triggerBroadcastConfigToBrokers()
+ {
+ exec.submit(this::broadcastConfigToBrokers);
+ }
+
+ public void broadcastConfigToBrokers()
Review Comment:
Is this public for testing?
##########
server/src/main/java/org/apache/druid/client/broker/BrokerClient.java:
##########
@@ -53,4 +54,9 @@ public interface BrokerClient
* @param sqlQuery the SQL query for which the {@code EXPLAIN PLAN FOR} information is to be fetched
*/
ListenableFuture<List<ExplainPlan>> fetchExplainPlan(ClientSqlQuery sqlQuery);
+
+ /**
+ * Updates the broker with the given {@link CoordinatorDynamicConfig}.
+ */
+ ListenableFuture<Boolean> updateDynamicConfig(CoordinatorDynamicConfig config);
Review Comment:
```suggestion
ListenableFuture<Boolean> updateCoordinatorDynamicConfig(CoordinatorDynamicConfig config);
```
##########
server/src/main/java/org/apache/druid/client/BrokerViewOfCoordinatorConfig.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.client.selector.HistoricalFilter;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.query.CloneQueryMode;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class BrokerViewOfCoordinatorConfig implements HistoricalFilter
+{
+ private static final Logger log = new Logger(BrokerViewOfCoordinatorConfig.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
+ @GuardedBy("this")
+ private Set<String> cloneServers;
+ @GuardedBy("this")
+ private Set<String> serversBeingCloned;
+
+ @Inject
+ public BrokerViewOfCoordinatorConfig(CoordinatorClient coordinatorClient)
+ {
+ this.coordinatorClient = coordinatorClient;
+ }
+
+ public synchronized CoordinatorDynamicConfig getDynamicConfiguration()
Review Comment:
To align with the name of the returned class:
```suggestion
public synchronized CoordinatorDynamicConfig getDynamicConfig()
```
##########
server/src/main/java/org/apache/druid/server/http/ConfigSyncStatus.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.Objects;
+import java.util.Set;
+
+public class ConfigSyncStatus
Review Comment:
Needs a javadoc
##########
server/src/main/java/org/apache/druid/client/BrokerViewOfCoordinatorConfig.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.client.selector.HistoricalFilter;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.query.CloneQueryMode;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class BrokerViewOfCoordinatorConfig implements HistoricalFilter
+{
+ private static final Logger log = new Logger(BrokerViewOfCoordinatorConfig.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
+ @GuardedBy("this")
+ private Set<String> cloneServers;
+ @GuardedBy("this")
+ private Set<String> serversBeingCloned;
Review Comment:
The source and target nomenclature was easier to follow since it made the code more consistent.
##########
server/src/main/java/org/apache/druid/client/BrokerViewOfCoordinatorConfig.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.client.selector.HistoricalFilter;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.query.CloneQueryMode;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class BrokerViewOfCoordinatorConfig implements HistoricalFilter
+{
+ private static final Logger log = new Logger(BrokerViewOfCoordinatorConfig.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
+ @GuardedBy("this")
+ private Set<String> cloneServers;
+ @GuardedBy("this")
+ private Set<String> serversBeingCloned;
+
+ @Inject
+ public BrokerViewOfCoordinatorConfig(CoordinatorClient coordinatorClient)
+ {
+ this.coordinatorClient = coordinatorClient;
+ }
+
+ public synchronized CoordinatorDynamicConfig getDynamicConfiguration()
+ {
+ return config;
+ }
+
+ /**
+ * Update the config view with a new coordinator dynamic config snapshot. Also updates the source and target clone
+ * servers based on the new dynamic configuration.
+ */
+ public synchronized void setDynamicConfig(@NotNull CoordinatorDynamicConfig updatedConfig)
+ {
+ config = updatedConfig;
+ final Map<String, String> cloneServers = config.getCloneServers();
+ this.cloneServers = ImmutableSet.copyOf(cloneServers.keySet());
+ this.serversBeingCloned = ImmutableSet.copyOf(cloneServers.values());
+ }
+
+ @LifecycleStart
+ public void start()
+ {
+ try {
+ log.info("Fetching coordinator dynamic configuration.");
+
+ CoordinatorDynamicConfig coordinatorDynamicConfig = coordinatorClient.getCoordinatorDynamicConfig().get();
+ setDynamicConfig(coordinatorDynamicConfig);
+
+ log.info("Successfully initialized dynamic config: [%s]", coordinatorDynamicConfig);
+ }
+ catch (Exception e) {
+ // If the fetch fails, the broker should not serve queries. Throw the exception and try again on restart.
+ log.error(e, "Failed to initialize coordinator dynamic config");
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public Int2ObjectRBTreeMap<Set<QueryableDruidServer>> getQueryableServers(
+ Int2ObjectRBTreeMap<Set<QueryableDruidServer>> historicalServers,
+ CloneQueryMode mode
+ )
+ {
+ final Set<String> serversToIgnore = getCurrentServersToIgnore(mode);
+
+ if (serversToIgnore.isEmpty()) {
+ return historicalServers;
+ }
+
+ final Int2ObjectRBTreeMap<Set<QueryableDruidServer>> filteredHistoricals = new Int2ObjectRBTreeMap<>();
+ for (int priority : historicalServers.keySet()) {
+ Set<QueryableDruidServer> servers = historicalServers.get(priority);
+ filteredHistoricals.put(priority,
+ servers.stream()
+ .filter(server -> !serversToIgnore.contains(server.getServer().getHost()))
+ .collect(Collectors.toSet())
+ );
+ }
+
+ return filteredHistoricals;
+ }
+
+ private synchronized Set<String> getCurrentServersToIgnore(CloneQueryMode cloneQueryMode)
+ {
+ switch (cloneQueryMode) {
+ case CLONES_PREFERRED:
+ // Remove servers being cloned targets, so that clones are queried.
+ return serversBeingCloned;
+ case EXCLUDE:
+ // Remove clones, so that targets are queried.
+ return cloneServers;
+ case INCLUDE:
+ // Don't remove either
+ return ImmutableSet.of();
+ default:
+ throw new IllegalStateException("Unexpected value: " + cloneQueryMode);
Review Comment:
throw `DruidException.defensive` instead.
##########
server/src/main/java/org/apache/druid/client/BrokerViewOfCoordinatorConfig.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.client.selector.HistoricalFilter;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.query.CloneQueryMode;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class BrokerViewOfCoordinatorConfig implements HistoricalFilter
+{
+ private static final Logger log = new Logger(BrokerViewOfCoordinatorConfig.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
+ @GuardedBy("this")
+ private Set<String> cloneServers;
+ @GuardedBy("this")
+ private Set<String> serversBeingCloned;
+
+ @Inject
+ public BrokerViewOfCoordinatorConfig(CoordinatorClient coordinatorClient)
+ {
+ this.coordinatorClient = coordinatorClient;
+ }
+
+ public synchronized CoordinatorDynamicConfig getDynamicConfiguration()
+ {
+ return config;
+ }
+
+ /**
+ * Update the config view with a new coordinator dynamic config snapshot. Also updates the source and target clone
+ * servers based on the new dynamic configuration.
+ */
+ public synchronized void setDynamicConfig(@NotNull CoordinatorDynamicConfig updatedConfig)
+ {
+ config = updatedConfig;
+ final Map<String, String> cloneServers = config.getCloneServers();
+ this.cloneServers = ImmutableSet.copyOf(cloneServers.keySet());
+ this.serversBeingCloned = ImmutableSet.copyOf(cloneServers.values());
+ }
+
+ @LifecycleStart
+ public void start()
+ {
+ try {
+ log.info("Fetching coordinator dynamic configuration.");
+
+ CoordinatorDynamicConfig coordinatorDynamicConfig = coordinatorClient.getCoordinatorDynamicConfig().get();
+ setDynamicConfig(coordinatorDynamicConfig);
+
+ log.info("Successfully initialized dynamic config: [%s]", coordinatorDynamicConfig);
+ }
+ catch (Exception e) {
+ // If the fetch fails, the broker should not serve queries. Throw the exception and try again on restart.
+ log.error(e, "Failed to initialize coordinator dynamic config");
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public Int2ObjectRBTreeMap<Set<QueryableDruidServer>> getQueryableServers(
+ Int2ObjectRBTreeMap<Set<QueryableDruidServer>> historicalServers,
+ CloneQueryMode mode
+ )
+ {
+ final Set<String> serversToIgnore = getCurrentServersToIgnore(mode);
+
+ if (serversToIgnore.isEmpty()) {
+ return historicalServers;
+ }
+
+ final Int2ObjectRBTreeMap<Set<QueryableDruidServer>> filteredHistoricals = new Int2ObjectRBTreeMap<>();
+ for (int priority : historicalServers.keySet()) {
+ Set<QueryableDruidServer> servers = historicalServers.get(priority);
+ filteredHistoricals.put(priority,
+ servers.stream()
+ .filter(server -> !serversToIgnore.contains(server.getServer().getHost()))
+ .collect(Collectors.toSet())
+ );
+ }
+
+ return filteredHistoricals;
+ }
+
+ private synchronized Set<String> getCurrentServersToIgnore(CloneQueryMode cloneQueryMode)
+ {
+ switch (cloneQueryMode) {
+ case CLONES_PREFERRED:
+ // Remove servers being cloned targets, so that clones are queried.
+ return serversBeingCloned;
+ case EXCLUDE:
+ // Remove clones, so that targets are queried.
Review Comment:
```suggestion
// Remove clones, so that only source servers are queried.
```
##########
server/src/main/java/org/apache/druid/client/BrokerViewOfCoordinatorConfig.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.client.selector.HistoricalFilter;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.query.CloneQueryMode;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class BrokerViewOfCoordinatorConfig implements HistoricalFilter
+{
+ private static final Logger log = new Logger(BrokerViewOfCoordinatorConfig.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
+ @GuardedBy("this")
+ private Set<String> cloneServers;
+ @GuardedBy("this")
+ private Set<String> serversBeingCloned;
+
+ @Inject
+ public BrokerViewOfCoordinatorConfig(CoordinatorClient coordinatorClient)
+ {
+ this.coordinatorClient = coordinatorClient;
+ }
+
+ public synchronized CoordinatorDynamicConfig getDynamicConfiguration()
+ {
+ return config;
+ }
+
+ /**
+ * Update the config view with a new coordinator dynamic config snapshot. Also updates the source and target clone
+ * servers based on the new dynamic configuration.
+ */
+ public synchronized void setDynamicConfig(@NotNull CoordinatorDynamicConfig updatedConfig)
+ {
+ config = updatedConfig;
+ final Map<String, String> cloneServers = config.getCloneServers();
+ this.cloneServers = ImmutableSet.copyOf(cloneServers.keySet());
+ this.serversBeingCloned = ImmutableSet.copyOf(cloneServers.values());
+ }
+
+ @LifecycleStart
+ public void start()
+ {
+ try {
+ log.info("Fetching coordinator dynamic configuration.");
+
+ CoordinatorDynamicConfig coordinatorDynamicConfig = coordinatorClient.getCoordinatorDynamicConfig().get();
+ setDynamicConfig(coordinatorDynamicConfig);
+
+ log.info("Successfully initialized dynamic config: [%s]", coordinatorDynamicConfig);
Review Comment:
```suggestion
log.info("Successfully fetched coordinator dynamic config[%s].", coordinatorDynamicConfig);
```
##########
server/src/main/java/org/apache/druid/server/http/BrokerSyncStatus.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.druid.rpc.ServiceLocation;
+
+import java.util.Objects;
+
+public class BrokerSyncStatus
+{
+ private final String host;
+ private final int port;
+ private final long syncTimeInMs;
Review Comment:
Since this represents a timestamp since epoch, it is expected to be in millis (since that is the convention followed in the rest of Druid).
We can just call this `lastSyncTime` or `lastSyncTimestamp`.
```suggestion
private final long syncTimeInMs;
```
##########
docs/api-reference/service-status-api.md:
##########
@@ -658,6 +658,135 @@ Host: http://COORDINATOR_IP:COORDINATOR_PORT
</details>
+
+### Get Historical Cloning Status
+
+Retrieves the current status of Historical cloning from the Coordinator.
+
+#### URL
+
+`GET` `/druid/coordinator/v1/config/cloneStatus`
+
+#### Responses
+
+<Tabs>
+
+<TabItem value="56" label="200 SUCCESS">
+
+
+<br/>
+
+*Successfully retrieved cloning status*
+
+</TabItem>
+</Tabs>
+
+#### Sample request
+
+<Tabs>
+
+<TabItem value="58" label="cURL">
+
+
+```shell
+curl "http://COORDINATOR_IP:COORDINATOR_PORT/druid/coordinator/v1/config/cloneStatus"
+```
+
+</TabItem>
+<TabItem value="59" label="HTTP">
+
+
+```http
+GET /druid/coordinator/v1/config/cloneStatus HTTP/1.1
+Host: http://COORDINATOR_IP:COORDINATOR_PORT
+```
+
+</TabItem>
+</Tabs>
+
+#### Sample response
+
+<details>
+ <summary>View the response</summary>
+
+```json
+{
+ "localhost:8083": {
+ "sourceServer": "localhost:8089",
+ "state": "LOADING",
+ "segmentLoadsRemaining": 0,
+ "segmentDropsRemaining": 0,
+ "bytesRemaining": 0
+ }
+}
+```
+
+</details>
+
+### Get Broker dynamic configuration view
+
+Retrieves the list of Brokers which have an up-to-date view of Coordinator dynamic configuration.
+
+#### URL
+
+`GET` `/druid/coordinator/v1/config/syncedBrokers`
+
+#### Responses
+
+<Tabs>
+
+<TabItem value="56" label="200 SUCCESS">
+
+
+<br/>
+
+*Successfully retrieved Broker Configuration view*
+
+</TabItem>
+</Tabs>
+
+#### Sample request
+
+<Tabs>
+
+<TabItem value="58" label="cURL">
+
+
+```shell
+curl "http://COORDINATOR_IP:COORDINATOR_PORT/druid/coordinator/v1/config/syncedBrokers"
+```
+
+</TabItem>
+<TabItem value="59" label="HTTP">
+
+
+```http
+GET /druid/coordinator/v1/config/syncedBrokers HTTP/1.1
+Host: http://COORDINATOR_IP:COORDINATOR_PORT
+```
+
+</TabItem>
+</Tabs>
+
+#### Sample response
+
+<details>
+ <summary>View the response</summary>
+
+```json
+{
+ "inSyncBrokers": [
Review Comment:
```suggestion
"syncedBrokers": [
```
##########
server/src/main/java/org/apache/druid/server/coordinator/ServerCloneStatus.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.Objects;
+
+/**
+ * Immutable class which represents the current status of a single clone server.
+ */
+public class ServerCloneStatus
+{
+ private final String sourceServer;
+ private final State state;
+ private final long segmentLoadsRemaining;
+ private final long segmentDropsRemaining;
+ private final long bytesRemaining;
+
+ @JsonCreator
+ public ServerCloneStatus(
+ @JsonProperty("sourceServer") String sourceServer,
+ @JsonProperty("state") State state,
+ @JsonProperty("segmentLoadsRemaining") long segmentLoadsRemaining,
+ @JsonProperty("segmentDropsRemaining") long segmentDropsRemaining,
+ @JsonProperty("bytesRemaining") long bytesRemaining
Review Comment:
```suggestion
@JsonProperty("bytesToLoad") long bytesRemaining
```
##########
server/src/main/java/org/apache/druid/server/DruidInternalDynamicConfigResource.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import com.google.inject.Inject;
+import com.sun.jersey.spi.container.ResourceFilters;
+import org.apache.druid.client.BrokerViewOfCoordinatorConfig;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.apache.druid.server.http.security.ConfigResourceFilter;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@Path("/druid-internal/v1/config")
+public class DruidInternalDynamicConfigResource
Review Comment:
```suggestion
public class BrokerDynamicConfigResource
```
needs a short javadoc too.
##########
server/src/main/java/org/apache/druid/server/coordinator/ServerCloneStatus.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.Objects;
+
+/**
+ * Immutable class which represents the current status of a single clone server.
+ */
+public class ServerCloneStatus
+{
+ private final String sourceServer;
+ private final State state;
+ private final long segmentLoadsRemaining;
+ private final long segmentDropsRemaining;
+ private final long bytesRemaining;
+
+ @JsonCreator
+ public ServerCloneStatus(
+ @JsonProperty("sourceServer") String sourceServer,
+ @JsonProperty("state") State state,
+ @JsonProperty("segmentLoadsRemaining") long segmentLoadsRemaining,
+ @JsonProperty("segmentDropsRemaining") long segmentDropsRemaining,
+ @JsonProperty("bytesRemaining") long bytesRemaining
+ )
+ {
+ this.sourceServer = sourceServer;
+ this.state = state;
+ this.segmentLoadsRemaining = segmentLoadsRemaining;
+ this.segmentDropsRemaining = segmentDropsRemaining;
+ this.bytesRemaining = bytesRemaining;
+ }
+
+ @JsonProperty
+ public String getSourceServer()
+ {
+ return sourceServer;
+ }
+
+ @JsonProperty
+ public long getSegmentLoadsRemaining()
+ {
+ return segmentLoadsRemaining;
+ }
+
+ @JsonProperty
+ public long getSegmentDropsRemaining()
+ {
+ return segmentDropsRemaining;
+ }
+
+ @JsonProperty
+ public long getBytesRemaining()
+ {
+ return bytesRemaining;
+ }
+
+ @JsonProperty
+ public State getState()
+ {
+ return state;
+ }
+
+ public static ServerCloneStatus unknown(String sourceServer)
+ {
+ return new ServerCloneStatus(sourceServer, State.TARGET_SERVER_MISSING, 0, 0, 0);
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ ServerCloneStatus that = (ServerCloneStatus) o;
+ return segmentLoadsRemaining == that.segmentLoadsRemaining
+ && segmentDropsRemaining == that.segmentDropsRemaining
+ && bytesRemaining == that.bytesRemaining
+ && Objects.equals(sourceServer, that.sourceServer)
+ && state == that.state;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Objects.hash(sourceServer, state, segmentLoadsRemaining, segmentDropsRemaining, bytesRemaining);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "CloneStatusMetrics{" +
+ "sourceServer='" + sourceServer + '\'' +
+ ", state=" + state +
+ ", segmentLoadsRemaining=" + segmentLoadsRemaining +
+ ", segmentDropsRemaining=" + segmentDropsRemaining +
+ ", bytesRemaining=" + bytesRemaining +
+ '}';
+ }
+
+ /**
+ * Enum determining the status of the cloning process.
+ */
+ public enum State
+ {
+ /**
+ * The source server is missing from the current cluster view. The clone is continuing to load segments based on the
+ * last seen state of the source cluster.
+ */
+ SOURCE_SERVER_MISSING,
+ /**
+ * The target server is missing from the current cluster view.
+ */
+ TARGET_SERVER_MISSING,
+ /**
+ * Segments are loaded or being loaded. The counts give a better view of the progress.
+ */
+ LOADING
Review Comment:
Maybe we should just call this `IN_PROGRESS`. `LOADING` is a little confusing.
##########
server/src/main/java/org/apache/druid/server/coordinator/ServerCloneStatus.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.Objects;
+
+/**
+ * Immutable class which represents the current status of a single clone server.
+ */
+public class ServerCloneStatus
Review Comment:
Please add a field for targetServer in this class.
##########
docs/api-reference/service-status-api.md:
##########
@@ -658,6 +658,135 @@ Host: http://COORDINATOR_IP:COORDINATOR_PORT
</details>
+
+### Get Historical Cloning Status
+
+Retrieves the current status of Historical cloning from the Coordinator.
+
+#### URL
+
+`GET` `/druid/coordinator/v1/config/cloneStatus`
+
+#### Responses
+
+<Tabs>
+
+<TabItem value="56" label="200 SUCCESS">
+
+
+<br/>
+
+*Successfully retrieved cloning status*
+
+</TabItem>
+</Tabs>
+
+#### Sample request
+
+<Tabs>
+
+<TabItem value="58" label="cURL">
+
+
+```shell
+curl "http://COORDINATOR_IP:COORDINATOR_PORT/druid/coordinator/v1/config/cloneStatus"
+```
+
+</TabItem>
+<TabItem value="59" label="HTTP">
+
+
+```http
+GET /druid/coordinator/v1/config/cloneStatus HTTP/1.1
+Host: http://COORDINATOR_IP:COORDINATOR_PORT
+```
+
+</TabItem>
+</Tabs>
+
+#### Sample response
+
+<details>
+ <summary>View the response</summary>
+
+```json
+{
+ "localhost:8083": {
+ "sourceServer": "localhost:8089",
+ "state": "LOADING",
+ "segmentLoadsRemaining": 0,
+ "segmentDropsRemaining": 0,
+ "bytesRemaining": 0
+ }
+}
+```
+
+</details>
+
+### Get Broker dynamic configuration view
+
+Retrieves the list of Brokers which have an up-to-date view of Coordinator dynamic configuration.
+
+#### URL
+
+`GET` `/druid/coordinator/v1/config/syncedBrokers`
+
+#### Responses
+
+<Tabs>
+
+<TabItem value="56" label="200 SUCCESS">
+
+
+<br/>
+
+*Successfully retrieved Broker Configuration view*
+
+</TabItem>
+</Tabs>
+
+#### Sample request
+
+<Tabs>
+
+<TabItem value="58" label="cURL">
+
+
+```shell
+curl "http://COORDINATOR_IP:COORDINATOR_PORT/druid/coordinator/v1/config/syncedBrokers"
+```
+
+</TabItem>
+<TabItem value="59" label="HTTP">
+
+
+```http
+GET /druid/coordinator/v1/config/syncedBrokers HTTP/1.1
+Host: http://COORDINATOR_IP:COORDINATOR_PORT
+```
+
+</TabItem>
+</Tabs>
+
+#### Sample response
+
+<details>
+ <summary>View the response</summary>
+
+```json
+{
+ "inSyncBrokers": [
+ {
+ "host": "localhost",
+ "port": 8082,
+ "syncTimeInMs": 1745298963900
Review Comment:
```suggestion
"lastSyncTime": 1745298963900
```
##########
processing/src/main/java/org/apache/druid/query/CloneQueryMode.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.query;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import org.apache.druid.error.InvalidInput;
+
+/**
+ * Enum used in the query context to determine if clone queries should be used by native queries.
+ */
+public enum CloneQueryMode
+{
+ /**
+ * For each ongoing cloning, do not query the source server that is being cloned. Other servers which are not
+ * participating in any cloning will still be queried.
+ */
+ CLONES_PREFERRED("clonesPreferred"),
+ /**
+ * Consider both clones and their source servers for querying.
+ */
+ INCLUDE("includeClones"),
+ /**
+ * Do not query clone servers.
+ */
+ EXCLUDE("excludeClones");
Review Comment:
```suggestion
EXCLUDE_CLONES("excludeClones");
```
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorDynamicConfigSyncer.java:
##########
@@ -0,0 +1,191 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import org.apache.druid.client.broker.BrokerClient;
+import org.apache.druid.client.broker.BrokerClientImpl;
+import org.apache.druid.discovery.DiscoveryDruidNode;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.StandardRetryPolicy;
+import org.apache.druid.server.DruidNode;
+import org.apache.druid.server.coordinator.CoordinatorConfigManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.annotation.Nullable;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+/**
+ * Updates all brokers with the latest coordinator dynamic config.
+ */
+public class CoordinatorDynamicConfigSyncer
Review Comment:
Please add some javadocs to the methods.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2062625466
##########
server/src/main/java/org/apache/druid/client/CachingClusteredClient.java:
##########
@@ -126,11 +128,13 @@ public class CachingClusteredClient implements QuerySegmentWalker
private final ForkJoinPool pool;
private final QueryScheduler scheduler;
private final ServiceEmitter emitter;
+ private final BrokerViewOfCoordinatorConfig brokerViewOfCoordinatorConfig;
@Inject
public CachingClusteredClient(
QueryRunnerFactoryConglomerate conglomerate,
TimelineServerView serverView,
+ BrokerViewOfCoordinatorConfig brokerViewOfCoordinatorConfig,
Review Comment:
Thanks for this suggestion, I missed this earlier as `BrokerViewOfCoordinatorConfig` was being used to create the filters. This cleaned up a lot of the code.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052057743
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.client;
+
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @Inject
+ public CoordinatorDynamicConfigView(CoordinatorClient coordinatorClient)
+ {
+ this.coordinatorClient = coordinatorClient;
+ }
+
+ private final AtomicReference<CoordinatorDynamicConfig> config = new AtomicReference<>();
+
+ public CoordinatorDynamicConfig getConfig()
+ {
+ return config.get();
+ }
+
+ public Set<String> getTargetCloneServers()
+ {
+ CoordinatorDynamicConfig coordinatorDynamicConfig = config.get();
+ return coordinatorDynamicConfig.getCloneServers().keySet();
Review Comment:
Yes, this should be immutable.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052106580
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
Review Comment:
Once this class becomes an implementation of the interface `HistoricalFilter`, then we could actually keep pre-computed lists since we would never need to expose them for the purposes of filtration. We would then be able to put stuff in a synchronized block in a more-consistent manner.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2039275089
##########
server/src/main/java/org/apache/druid/client/selector/ServerSelector.java:
##########
@@ -122,12 +122,17 @@
}
public List<DruidServerMetadata> getCandidates(final int numCandidates)
+ {
+ return getCandidates(numCandidates, HistoricalFilter.IDENTITIY_FILTER);
+ }
+
+ public List<DruidServerMetadata> getCandidates(final int numCandidates, HistoricalFilter filter)
{
List<DruidServerMetadata> candidates;
synchronized (this) {
if (numCandidates > 0) {
candidates = new ArrayList<>(numCandidates);
- strategy.pick(historicalServers, segment.get(), numCandidates)
+ strategy.pick(filter.apply(historicalServers), segment.get(), numCandidates)
Review Comment:
There's also one other thing, we also require filtering on `getAllServers()` in ServerSelector, which does not rely on `TierSelectorStrategy.pick()`, so we would need to have passed `HistoricalFilter` and query to this function anyway, as one of the callers of `getAllServers()`
Another thing, we do not always have access to query context in `AbstractTierSelectorStrategy`, the query parameter is nullable and is not always supplied. The default implementation is to pass null.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2051945181
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorDynamicConfigSyncer.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import org.apache.druid.discovery.DiscoveryDruidNode;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHandler;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHolder;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.RequestBuilder;
+import org.apache.druid.rpc.ServiceClient;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.StandardRetryPolicy;
+import org.apache.druid.server.coordinator.CoordinatorConfigManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.jboss.netty.handler.codec.http.HttpMethod;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+
+import java.net.URL;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+/**
+ * Updates all brokers with the latest coordinator dynamic config.
+ */
+public class CoordinatorDynamicConfigSyncer
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigSyncer.class);
+
+ private final CoordinatorConfigManager configManager;
+ private final ObjectMapper jsonMapper;
+ private final DruidNodeDiscoveryProvider druidNodeDiscovery;
+
+ private final AtomicReference<CoordinatorDynamicConfig> lastKnownConfig = new AtomicReference<>();
+ private final ServiceClientFactory clientFactory;
+ private final ExecutorService exec;
+ private final Set<String> inSyncBrokers;
+
+ @Inject
+ public CoordinatorDynamicConfigSyncer(
+ @EscalatedGlobal final ServiceClientFactory clientFactory,
+ final CoordinatorConfigManager configManager,
+ @Json final ObjectMapper jsonMapper,
+ final DruidNodeDiscoveryProvider druidNodeDiscoveryProvider
+ )
+ {
+ this.clientFactory = clientFactory;
+ this.configManager = configManager;
+ this.jsonMapper = jsonMapper;
+ this.druidNodeDiscovery = druidNodeDiscoveryProvider;
+ this.exec = Execs.singleThreaded("DynamicConfigSyncer-%d");
+ this.inSyncBrokers = ConcurrentHashMap.newKeySet();
+ }
+
+ public void broadcastConfigToBrokers()
+ {
+ invalidateInSyncBrokersIfNeeded();
+ for (ServiceLocation broker : getKnownBrokers()) {
+ exec.submit(() -> pushConfigToBroker(broker));
+ }
+ }
+
+ public synchronized Set<String> getInSyncBrokers()
+ {
+ return Set.copyOf(inSyncBrokers);
+ }
+
+ private void pushConfigToBroker(ServiceLocation brokerLocation)
+ {
+ final ServiceClient brokerClient = clientFactory.makeClient(
+ NodeRole.BROKER.getJsonName(),
+ new FixedServiceLocator(brokerLocation),
+ StandardRetryPolicy.builder().maxAttempts(6).build()
+ );
+
+ try {
+ CoordinatorDynamicConfig currentDynamicConfig = configManager.getCurrentDynamicConfig();
+ final RequestBuilder requestBuilder =
+ new RequestBuilder(HttpMethod.POST, "/druid-internal/v1/dynamicConfiguration/coordinatorDynamicConfig")
+ .jsonContent(jsonMapper, currentDynamicConfig);
+
+ final BytesFullResponseHolder responseHolder = brokerClient.request(requestBuilder, new BytesFullResponseHandler());
+ final HttpResponseStatus status = responseHolder.getStatus();
+ if (status.equals(HttpResponseStatus.OK)) {
+ addToInSyncBrokers(currentDynamicConfig, brokerLocation);
+ } else {
+ log.error(
+ "Received status [%s] while posting dynamic configs to broker[%s]",
+ status.getCode(),
+ brokerLocation
+ );
+ }
+ }
+ catch (Exception e) {
+ // Catch and ignore the exception, wait for the next sync.
+ log.error(
+ e,
+ "Exception while syncing dynamic configuration to broker[%s]",
+ brokerLocation
+ );
+ }
+ }
+
+ private Set<ServiceLocation> getKnownBrokers()
+ {
+ return druidNodeDiscovery.getForNodeRole(NodeRole.BROKER)
+ .getAllNodes()
+ .stream()
+ .map(DiscoveryDruidNode::toServiceLocation)
Review Comment:
The `ServiceClientFactory` requires a `ServiceLocator` to create a client for a specific server.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052322075
##########
server/src/main/java/org/apache/druid/client/selector/HistoricalFilter.java:
##########
@@ -0,0 +1,39 @@
+package org.apache.druid.client.selector;
+
+import com.google.common.collect.ImmutableSet;
+import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
+import org.apache.druid.client.QueryableDruidServer;
+
+import java.util.Set;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+
+public class HistoricalFilter implements Function<Int2ObjectRBTreeMap<Set<QueryableDruidServer>>, Int2ObjectRBTreeMap<Set<QueryableDruidServer>>>
Review Comment:
Makes sense! Made this change.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052104015
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
Review Comment:
I am not sure I follow. This class should ideally not have the `getSourceServers` and `getTargetServers` methods at all. The caller can just get the dynamic config and perform any required operation on it.
Having separate methods for `getConfig`, `getSource` and `getTarget` makes it more error prone.
A caller may make calls to these methods in subsequent lines and still get back inconsistent results, since another thread updated the config meanwhile.
Let me know if this makes sense.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052094813
##########
server/src/main/java/org/apache/druid/server/coordinator/CoordinatorDynamicConfig.java:
##########
@@ -191,6 +192,30 @@ private Map<Dimension, String> validateDebugDimensions(Map<String, String> debug
return validDebugDimensions;
}
+ public CoordinatorDynamicConfig snapshot()
Review Comment:
Ideally, if the config is immutable, the sets it uses should be immutable too.
So, you can update the constructor to make sure that everything is immutable.
Making a duplicate copy (i.e. without any changes) of an immutable object adds any value.
##########
server/src/main/java/org/apache/druid/server/coordinator/CoordinatorDynamicConfig.java:
##########
@@ -191,6 +192,30 @@ private Map<Dimension, String> validateDebugDimensions(Map<String, String> debug
return validDebugDimensions;
}
+ public CoordinatorDynamicConfig snapshot()
Review Comment:
Ideally, if the config is immutable, the sets it uses should be immutable too.
So, you can update the constructor to make sure that everything is immutable.
Making a duplicate copy (i.e. without any changes) of an immutable object does not add any value.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2038752369
##########
server/src/main/java/org/apache/druid/server/DruidInternalDynamicConfigResource.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * 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;
+
+import com.google.inject.Inject;
+import org.apache.druid.client.DynamicConfigurationManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@Path("/druid-internal/v1/dynamicConfiguration")
+public class DruidInternalDynamicConfigResource
Review Comment:
I considered this, but shouldn't the path ideally be `/druid-internal` since this is supposed to be an internal API?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2041517123
##########
server/src/test/java/org/apache/druid/server/metrics/TestDynamicConfigurationManager.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.metrics;
+
+import com.google.common.collect.ImmutableSet;
+import org.apache.druid.client.DynamicConfigurationManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import java.util.Set;
+
+public class TestDynamicConfigurationManager extends DynamicConfigurationManager
Review Comment:
Removed.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2041517499
##########
processing/src/main/java/org/apache/druid/query/QueryContexts.java:
##########
@@ -149,6 +150,7 @@ public class QueryContexts
public static final boolean DEFAULT_ENABLE_JOIN_FILTER_PUSH_DOWN = true;
public static final boolean DEFAULT_ENABLE_JOIN_FILTER_REWRITE = true;
public static final boolean DEFAULT_ENABLE_JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS = false;
+ public static final boolean DEFAULT_QUERY_UNMANAGED_SERVERS = false;
Review Comment:
Changed.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052104015
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
Review Comment:
We shouldn't need to pre-compute the lists. Do you want to do that for perf reasons?
This class should ideally not have the `getSourceServers` and `getTargetServers` methods at all. The caller can just get the dynamic config and perform any required operation on it.
Having separate methods for `getConfig`, `getSource` and `getTarget` makes it more error prone.
A caller may make calls to these methods in subsequent lines and still get back inconsistent results, as another thread could have updated the config in the mean time.
Let me know if this makes sense.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2051985006
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.client;
+
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @Inject
+ public CoordinatorDynamicConfigView(CoordinatorClient coordinatorClient)
+ {
+ this.coordinatorClient = coordinatorClient;
+ }
+
+ private final AtomicReference<CoordinatorDynamicConfig> config = new AtomicReference<>();
+
+ public CoordinatorDynamicConfig getConfig()
+ {
+ return config.get();
+ }
+
+ public Set<String> getTargetCloneServers()
+ {
+ CoordinatorDynamicConfig coordinatorDynamicConfig = config.get();
+ return coordinatorDynamicConfig.getCloneServers().keySet();
+ }
+
+ public Set<String> getSourceCloneServers()
+ {
+ CoordinatorDynamicConfig coordinatorDynamicConfig = config.get();
+ return new HashSet<>(coordinatorDynamicConfig.getCloneServers().values());
+ }
+
+ public void updateCloneServers(CoordinatorDynamicConfig updatedConfig)
+ {
+ config.set(updatedConfig);
Review Comment:
Changed
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052325019
##########
docs/api-reference/service-status-api.md:
##########
@@ -1334,4 +1334,126 @@ Host: http://BROKER_IP:BROKER_PORT
#### Sample response
-A successful response to this endpoint results in an empty response body.
\ No newline at end of file
+A successful response to this endpoint results in an empty response body.
+
+### Get Historical Cloning Status
+
+Retrieves the current status of Historical cloning.
+
+#### URL
+
+`GET` `/druid/coordinator/v1/cloneStatus`
+
+#### Responses
+
+<Tabs>
+
+<TabItem value="56" label="200 SUCCESS">
+
+
+<br/>
+
+*Successfully retrieved cloning status*
+
+</TabItem>
+</Tabs>
+
+#### Sample request
+
+<Tabs>
+
+<TabItem value="58" label="cURL">
+
+
+```shell
+curl "http://COORDINATOR_IP:COORDINATOR_PORT/druid/coordinator/v1/cloneStatus"
+```
+
+</TabItem>
+<TabItem value="59" label="HTTP">
+
+
+```http
+GET /druid/coordinator/v1/cloneStatus HTTP/1.1
+Host: http://COORDINATOR_IP:COORDINATOR_PORT
+```
+
+</TabItem>
+</Tabs>
+
+#### Sample response
+
+<details>
+ <summary>View the response</summary>
+
+```json
+{
+ "localhost:8083": {
+ "sourceServer": "localhost:8089",
+ "status": "LOADING",
+ "segmentLoadsRemaining": 0,
+ "segmenetsDropsRemaining": 0,
+ "bytesRemaining": 0
+ }
Review Comment:
We would anyway keep the relation as a map, as we need to return the status of a mapping based on the targetServer as a key.
Given this, is having a different object just to be returned from the API required?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2051946897
##########
server/src/main/java/org/apache/druid/server/ClientQuerySegmentWalker.java:
##########
@@ -607,7 +607,7 @@ private <T> QueryRunner<T> decorateClusterRunner(Query<T> query, QueryRunner<T>
* @param parentQueryResourceId Parent Query's Query Resource ID
* @return DataSource populated with the subqueries
*/
- private DataSource generateSubqueryIds(
+ public static DataSource generateSubqueryIds(
Review Comment:
The CachingClusteredClient benchmark was broken as subquery Ids were not present in the queries it was running. Let me annotate it with a "visible for testing" for clarity.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2054336133
##########
server/src/main/java/org/apache/druid/client/BrokerViewOfCoordinatorConfig.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.client.selector.HistoricalFilter;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.query.CloneQueryMode;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class BrokerViewOfCoordinatorConfig implements HistoricalFilter
+{
+ private static final Logger log = new Logger(BrokerViewOfCoordinatorConfig.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
+ @GuardedBy("this")
+ private Set<String> cloneServers;
+ @GuardedBy("this")
+ private Set<String> serversBeingCloned;
+
+ @Inject
+ public BrokerViewOfCoordinatorConfig(CoordinatorClient coordinatorClient)
+ {
+ this.coordinatorClient = coordinatorClient;
+ }
+
+ public synchronized CoordinatorDynamicConfig getDynamicConfiguration()
+ {
+ return config;
+ }
+
+ /**
+ * Update the config view with a new coordinator dynamic config snapshot. Also updates the source and target clone
+ * servers based on the new dynamic configuration.
+ */
+ public synchronized void setDynamicConfig(@NotNull CoordinatorDynamicConfig updatedConfig)
+ {
+ config = updatedConfig;
+ final Map<String, String> cloneServers = config.getCloneServers();
+ this.cloneServers = ImmutableSet.copyOf(cloneServers.keySet());
+ this.serversBeingCloned = ImmutableSet.copyOf(cloneServers.values());
+ }
+
+ @LifecycleStart
+ public void start()
+ {
+ try {
+ log.info("Fetching coordinator dynamic configuration.");
+
+ CoordinatorDynamicConfig coordinatorDynamicConfig = coordinatorClient.getCoordinatorDynamicConfig().get();
+ setDynamicConfig(coordinatorDynamicConfig);
+
+ log.info("Successfully initialized dynamic config: [%s]", coordinatorDynamicConfig);
+ }
+ catch (Exception e) {
+ // If the fetch fails, the broker should not serve queries. Throw the exception and try again on restart.
+ log.error(e, "Failed to initialize coordinator dynamic config");
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public Int2ObjectRBTreeMap<Set<QueryableDruidServer>> getQueryableServers(
+ Int2ObjectRBTreeMap<Set<QueryableDruidServer>> historicalServers,
+ CloneQueryMode mode
+ )
+ {
+ final Set<String> serversToIgnore = getCurrentServersToIgnore(mode);
+
+ if (serversToIgnore.isEmpty()) {
+ return historicalServers;
+ }
+
+ final Int2ObjectRBTreeMap<Set<QueryableDruidServer>> filteredHistoricals = new Int2ObjectRBTreeMap<>();
+ for (int priority : historicalServers.keySet()) {
+ Set<QueryableDruidServer> servers = historicalServers.get(priority);
+ filteredHistoricals.put(priority,
+ servers.stream()
+ .filter(server -> !serversToIgnore.contains(server.getServer().getHost()))
+ .collect(Collectors.toSet())
+ );
+ }
+
+ return filteredHistoricals;
+ }
+
+ private synchronized Set<String> getCurrentServersToIgnore(CloneQueryMode cloneQueryMode)
+ {
+ switch (cloneQueryMode) {
+ case CLONES_PREFERRED:
+ // Remove servers being cloned targets, so that clones are queried.
+ return serversBeingCloned;
Review Comment:
Since we are iterating an immutable map, I guess it should be fine. Bdw, I think these changes are much more performant.
Thanks for this.
##########
server/src/main/java/org/apache/druid/server/http/BrokerSyncStatus.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.druid.rpc.ServiceLocation;
+
+import java.util.Objects;
+
+public class BrokerSyncStatus
+{
+ private final String host;
+ private final int port;
+ private final long syncTime;
+
+ @JsonCreator
+ public BrokerSyncStatus(
+ @JsonProperty("host") String host,
+ @JsonProperty("port") int port,
+ @JsonProperty("syncTime") long syncTime
Review Comment:
```suggestion
@JsonProperty("syncTimeInMs") long syncTimeInMs
```
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2039275089
##########
server/src/main/java/org/apache/druid/client/selector/ServerSelector.java:
##########
@@ -122,12 +122,17 @@
}
public List<DruidServerMetadata> getCandidates(final int numCandidates)
+ {
+ return getCandidates(numCandidates, HistoricalFilter.IDENTITIY_FILTER);
+ }
+
+ public List<DruidServerMetadata> getCandidates(final int numCandidates, HistoricalFilter filter)
{
List<DruidServerMetadata> candidates;
synchronized (this) {
if (numCandidates > 0) {
candidates = new ArrayList<>(numCandidates);
- strategy.pick(historicalServers, segment.get(), numCandidates)
+ strategy.pick(filter.apply(historicalServers), segment.get(), numCandidates)
Review Comment:
There's also one other thing, we also require filtering on `getAllServers()` in ServerSelector, which does not call `TierSelectorStrategy.pick()`. We would need to filter and create an Int2ObjectRBTreeMap anyway. Since one of the places that calls `getAllServers()` is this function, we would need to pass the filter here anyway.
Another thing, we do not always have access to query context in `AbstractTierSelectorStrategy`, the query parameter is nullable and is not always supplied. The default implementation is to pass null.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2040561302
##########
server/src/test/java/org/apache/druid/server/http/CoordinatorDynamicConfigTest.java:
##########
@@ -570,7 +613,8 @@
Set<String> decommissioningNodes,
boolean pauseCoordination,
boolean replicateAfterLoadTimeout,
- Set<String> turboLoadingNodes
+ Set<String> turboLoadingNodes,
+ Map<String, String> cloneServers
Review Comment:
## Useless parameter
The parameter 'cloneServers' is never used.
[Show more details](https://github.com/apache/druid/security/code-scanning/8908)
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2037154705
##########
server/src/main/java/org/apache/druid/client/coordinator/CoordinatorClient.java:
##########
@@ -87,4 +88,8 @@ public interface CoordinatorClient
*/
ListenableFuture<CompactionStatusResponse> getCompactionSnapshots(@Nullable String dataSource);
+ /**
+ * TODO: javadoc
+ */
+ ListenableFuture<CoordinatorDynamicConfig> getCoordinatorConfig();
Review Comment:
```suggestion
ListenableFuture<CoordinatorDynamicConfig> getCoordinatorDynamicConfig();
```
##########
server/src/main/java/org/apache/druid/client/DynamicConfigurationManager.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.client;
+
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class DynamicConfigurationManager
Review Comment:
```suggestion
public class CoordinatorDynamicConfigView
```
##########
server/src/main/java/org/apache/druid/client/CachingClusteredClient.java:
##########
@@ -598,7 +605,18 @@ private SortedMap<DruidServer, List<SegmentDescriptor>> groupSegmentsByServer(Se
{
final SortedMap<DruidServer, List<SegmentDescriptor>> serverSegments = new TreeMap<>();
for (SegmentServerSelector segmentServer : segments) {
- final QueryableDruidServer queryableDruidServer = segmentServer.getServer().pick(query);
+ Supplier<Set<String>> supplier = () -> {
+ boolean queryUnmanagedServers = query.context().getQueryUnmanagedServers();
+ if (queryUnmanagedServers) {
+ // If this is a test query, ignore source servers.
Review Comment:
+1
##########
server/src/main/java/org/apache/druid/client/DynamicConfigurationManager.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.client;
+
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class DynamicConfigurationManager
Review Comment:
Based on the other comment, this class should perhaps implement the `HistoricalFilter` interface.
##########
server/src/test/java/org/apache/druid/server/metrics/TestDynamicConfigurationManager.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.metrics;
+
+import com.google.common.collect.ImmutableSet;
+import org.apache.druid.client.DynamicConfigurationManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import java.util.Set;
+
+public class TestDynamicConfigurationManager extends DynamicConfigurationManager
Review Comment:
I think the concrete implementation `DynamicConfigurationManager` is simple enough to not require a dedicated test implementation.
##########
server/src/main/java/org/apache/druid/server/DruidInternalDynamicConfigResource.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * 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;
+
+import com.google.inject.Inject;
+import org.apache.druid.client.DynamicConfigurationManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@Path("/druid-internal/v1/dynamicConfiguration")
+public class DruidInternalDynamicConfigResource
Review Comment:
I don't think we need a new resource class for this. We can just add the new methods to `BrokerResource`.
##########
processing/src/main/java/org/apache/druid/query/QueryContexts.java:
##########
@@ -149,6 +150,7 @@ public class QueryContexts
public static final boolean DEFAULT_ENABLE_JOIN_FILTER_PUSH_DOWN = true;
public static final boolean DEFAULT_ENABLE_JOIN_FILTER_REWRITE = true;
public static final boolean DEFAULT_ENABLE_JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS = false;
+ public static final boolean DEFAULT_QUERY_UNMANAGED_SERVERS = false;
Review Comment:
Rather than a boolean, I think we should use an enum `QueryCloneMode` with values:
```
ONLY: Query ONLY the clones
INCLUDE: Query the clones and normal servers
EXCLUDE (default): Do not query the clones
```
##########
server/src/main/java/org/apache/druid/client/selector/ServerSelector.java:
##########
@@ -122,12 +122,17 @@
}
public List<DruidServerMetadata> getCandidates(final int numCandidates)
+ {
+ return getCandidates(numCandidates, HistoricalFilter.IDENTITIY_FILTER);
+ }
+
+ public List<DruidServerMetadata> getCandidates(final int numCandidates, HistoricalFilter filter)
{
List<DruidServerMetadata> candidates;
synchronized (this) {
if (numCandidates > 0) {
candidates = new ArrayList<>(numCandidates);
- strategy.pick(historicalServers, segment.get(), numCandidates)
+ strategy.pick(filter.apply(historicalServers), segment.get(), numCandidates)
Review Comment:
Yeah, I suppose we can hook into the `AbstractTierSelectorStrategy` too if we want to avoid creating the maps every time.
Although, this map will always be small (1 or 2 entries) for any given segment, because it is dictated by the replication factor. So, I am not sure if the impact would really be perceptible. But I still wouldn't mind the improvement.
The only con of mixing the `HistoricalFilter` with the `TierSelectorStrategy` is that we lose the separation of concern and it pollutes the logic a little. Each `TierSelectorStrategy` implementation will need to have a `@JacksonInject HistoricalFilter` arg and pass it up to the super class to use in the `pick` implementation.
##########
server/src/main/java/org/apache/druid/client/selector/HistoricalFilter.java:
##########
@@ -0,0 +1,39 @@
+package org.apache.druid.client.selector;
+
+import com.google.common.collect.ImmutableSet;
+import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
+import org.apache.druid.client.QueryableDruidServer;
+
+import java.util.Set;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+
+public class HistoricalFilter implements Function<Int2ObjectRBTreeMap<Set<QueryableDruidServer>>, Int2ObjectRBTreeMap<Set<QueryableDruidServer>>>
Review Comment:
Make `HistoricalFilter` an interface with a method `getQueryableServers`.
The implementation would be the `DynamicConfigManager` class itself.
```java
public Set<QueryableDruidServer> getQueryableServers(Set<QueryableDruidServer> allServers, CloneQueryMode mode) {
// read the coordinator dynamic config here and ignore the servers from allServers as applicable
}
```
##########
server/src/main/java/org/apache/druid/client/CachingClusteredClient.java:
##########
@@ -598,7 +605,18 @@ private SortedMap<DruidServer, List<SegmentDescriptor>> groupSegmentsByServer(Se
{
final SortedMap<DruidServer, List<SegmentDescriptor>> serverSegments = new TreeMap<>();
for (SegmentServerSelector segmentServer : segments) {
- final QueryableDruidServer queryableDruidServer = segmentServer.getServer().pick(query);
+ Supplier<Set<String>> supplier = () -> {
+ boolean queryUnmanagedServers = query.context().getQueryUnmanagedServers();
+ if (queryUnmanagedServers) {
+ // If this is a test query, ignore source servers.
+ return dynamicConfigurationManager.getSourceClusterServers();
+ } else {
+ return dynamicConfigurationManager.getTargetCloneServers();
Review Comment:
I think atomic reference should be faster:
https://stackoverflow.com/a/31578070
That said, for all the cases, the numbers are small enough (in 2-digit nanos) to not really matter.
I think the question becomes more relevant if we are doing some operations inside the lock.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2053352176
##########
docs/api-reference/service-status-api.md:
##########
@@ -1334,4 +1334,126 @@ Host: http://BROKER_IP:BROKER_PORT
#### Sample response
-A successful response to this endpoint results in an empty response body.
\ No newline at end of file
+A successful response to this endpoint results in an empty response body.
+
+### Get Historical Cloning Status
+
+Retrieves the current status of Historical cloning.
+
+#### URL
+
+`GET` `/druid/coordinator/v1/cloneStatus`
+
+#### Responses
+
+<Tabs>
+
+<TabItem value="56" label="200 SUCCESS">
+
+
+<br/>
+
+*Successfully retrieved cloning status*
+
+</TabItem>
+</Tabs>
+
+#### Sample request
+
+<Tabs>
+
+<TabItem value="58" label="cURL">
+
+
+```shell
+curl "http://COORDINATOR_IP:COORDINATOR_PORT/druid/coordinator/v1/cloneStatus"
+```
+
+</TabItem>
+<TabItem value="59" label="HTTP">
+
+
+```http
+GET /druid/coordinator/v1/cloneStatus HTTP/1.1
+Host: http://COORDINATOR_IP:COORDINATOR_PORT
+```
+
+</TabItem>
+</Tabs>
+
+#### Sample response
+
+<details>
+ <summary>View the response</summary>
+
+```json
+{
+ "localhost:8083": {
+ "sourceServer": "localhost:8089",
+ "status": "LOADING",
+ "segmentLoadsRemaining": 0,
+ "segmenetsDropsRemaining": 0,
+ "bytesRemaining": 0
+ }
+}
+```
+
+</details>
+
+### Get Broker dynamic configuration view
+
+Retrieves the list of Brokers which have an up-to-date view of Coordinator dynamic configuration.
+
+#### URL
+
+`GET` `/druid/coordinator/v1/brokerConfigurationStatus`
+
+#### Responses
+
+<Tabs>
+
+<TabItem value="56" label="200 SUCCESS">
+
+
+<br/>
+
+*Successfully retrieved Broker Configuration view*
+
+</TabItem>
+</Tabs>
+
+#### Sample request
+
+<Tabs>
+
+<TabItem value="58" label="cURL">
+
+
+```shell
+curl "http://COORDINATOR_IP:COORDINATOR_PORT/druid/coordinator/v1/brokerConfigurationStatus"
+```
+
+</TabItem>
+<TabItem value="59" label="HTTP">
+
+
+```http
+GET /druid/coordinator/v1/brokerConfigurationStatus HTTP/1.1
+Host: http://COORDINATOR_IP:COORDINATOR_PORT
+```
+
+</TabItem>
+</Tabs>
+
+#### Sample response
+
+<details>
+ <summary>View the response</summary>
+
+```json
+[
+ "localhost:8082"
+]
Review Comment:
updated
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2048632065
##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/dart/controller/DartTableInputSpecSlicer.java:
##########
@@ -162,7 +163,7 @@ public List<InputSlice> sliceDynamic(
*/
int findWorkerForServerSelector(final ServerSelector serverSelector, final int maxNumSlices)
{
- final QueryableDruidServer server = serverSelector.pick(null);
+ final QueryableDruidServer server = serverSelector.pick(null, HistoricalFilter.IDENTITY_FILTER);
Review Comment:
Lets mention in the release notes clearly that the routing filtering will not work for DART.
Also mention that since MSQ does not query historicals, that execution engine is not affected by these changes.
##########
docs/querying/query-context.md:
##########
@@ -66,6 +66,7 @@ See [SQL query context](sql-query-context.md) for other query context parameters
|`debug`| `false` | Flag indicating whether to enable debugging outputs for the query. When set to false, no additional logs will be produced (logs produced will be entirely dependent on your logging level). When set to true, the following addition logs will be produced:<br />- Log the stack trace of the exception (if any) produced by the query |
|`setProcessingThreadNames`|`true`| Whether processing thread names will be set to `queryType_dataSource_intervals` while processing a query. This aids in interpreting thread dumps, and is on by default. Query overhead can be reduced slightly by setting this to `false`. This has a tiny effect in most scenarios, but can be meaningful in high-QPS, low-per-segment-processing-time scenarios. |
|`sqlPlannerBloat`|`1000`|Calcite parameter which controls whether to merge two Project operators when inlining expressions causes complexity to increase. Implemented as a workaround to exception `There are not enough rules to produce a node with desired properties: convention=DRUID, sort=[]` thrown after rejecting the merge of two projects.|
+|`cloneQueryMode`|`EXCLUDE`| Indicates whether clone Historicals should be queried by brokers. Clone servers are created by the `cloneServers` Coordinator dynamic configuration. Possible values are `EXCLUDE`, `INCLUDE` and `ONLY`. `EXCLUDE` means that clone Historicals are not queried by the broker. `ONLY` indicates that when given a choice between the clone Historical and the original Historical which is being cloned, the broker chooses the clones; Historicals which are not involved in the cloning process will still be queried. `INCLUDE` means that broker queries any Historical without regarding clone status. |
Review Comment:
Instead of `ONLY` should it be `CLONE_PREFERRED`.
##########
processing/src/main/java/org/apache/druid/query/CloneQueryMode.java:
##########
@@ -0,0 +1,27 @@
+/*
+ * 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.query;
+
+public enum CloneQueryMode
Review Comment:
Also mention how this mode is set ie via Query context.
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.client;
+
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @Inject
+ public CoordinatorDynamicConfigView(CoordinatorClient coordinatorClient)
+ {
+ this.coordinatorClient = coordinatorClient;
+ }
+
+ private final AtomicReference<CoordinatorDynamicConfig> config = new AtomicReference<>();
+
+ public CoordinatorDynamicConfig getConfig()
+ {
+ return config.get();
+ }
+
+ public Set<String> getTargetCloneServers()
+ {
+ CoordinatorDynamicConfig coordinatorDynamicConfig = config.get();
+ return coordinatorDynamicConfig.getCloneServers().keySet();
Review Comment:
Is this map immutable ?
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.client;
+
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @Inject
+ public CoordinatorDynamicConfigView(CoordinatorClient coordinatorClient)
+ {
+ this.coordinatorClient = coordinatorClient;
+ }
+
+ private final AtomicReference<CoordinatorDynamicConfig> config = new AtomicReference<>();
+
+ public CoordinatorDynamicConfig getConfig()
+ {
+ return config.get();
+ }
+
+ public Set<String> getTargetCloneServers()
+ {
+ CoordinatorDynamicConfig coordinatorDynamicConfig = config.get();
+ return coordinatorDynamicConfig.getCloneServers().keySet();
+ }
+
+ public Set<String> getSourceCloneServers()
+ {
+ CoordinatorDynamicConfig coordinatorDynamicConfig = config.get();
Review Comment:
If you wanna do this via atomic reference, create a snapshot method in the coordinatorDynamicConfig.
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.client;
+
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @Inject
+ public CoordinatorDynamicConfigView(CoordinatorClient coordinatorClient)
+ {
+ this.coordinatorClient = coordinatorClient;
+ }
+
+ private final AtomicReference<CoordinatorDynamicConfig> config = new AtomicReference<>();
+
+ public CoordinatorDynamicConfig getConfig()
+ {
+ return config.get();
+ }
+
+ public Set<String> getTargetCloneServers()
+ {
+ CoordinatorDynamicConfig coordinatorDynamicConfig = config.get();
+ return coordinatorDynamicConfig.getCloneServers().keySet();
+ }
+
+ public Set<String> getSourceCloneServers()
+ {
+ CoordinatorDynamicConfig coordinatorDynamicConfig = config.get();
+ return new HashSet<>(coordinatorDynamicConfig.getCloneServers().values());
+ }
+
+ public void updateCloneServers(CoordinatorDynamicConfig updatedConfig)
Review Comment:
Please add javadocs.
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.client;
+
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @Inject
+ public CoordinatorDynamicConfigView(CoordinatorClient coordinatorClient)
+ {
+ this.coordinatorClient = coordinatorClient;
+ }
+
+ private final AtomicReference<CoordinatorDynamicConfig> config = new AtomicReference<>();
+
+ public CoordinatorDynamicConfig getConfig()
+ {
+ return config.get();
+ }
+
+ public Set<String> getTargetCloneServers()
+ {
+ CoordinatorDynamicConfig coordinatorDynamicConfig = config.get();
+ return coordinatorDynamicConfig.getCloneServers().keySet();
+ }
+
+ public Set<String> getSourceCloneServers()
+ {
+ CoordinatorDynamicConfig coordinatorDynamicConfig = config.get();
+ return new HashSet<>(coordinatorDynamicConfig.getCloneServers().values());
+ }
+
+ public void updateCloneServers(CoordinatorDynamicConfig updatedConfig)
+ {
+ config.set(updatedConfig);
Review Comment:
Whenever we update, can we also maintain an immutable ignore server list here and then just fetch it on query time.
##########
server/src/main/java/org/apache/druid/server/BrokerQueryResource.java:
##########
@@ -89,19 +95,22 @@ public Response getQueryTargets(
InputStream in,
@QueryParam("pretty") String pretty,
@QueryParam("numCandidates") @DefaultValue("-1") int numCandidates,
+ @QueryParam("cloneQueryMode") CloneQueryMode cloneQueryMode,
Review Comment:
Mark @Nullable ?
##########
server/src/main/java/org/apache/druid/server/BrokerQueryResource.java:
##########
@@ -89,19 +95,22 @@ public Response getQueryTargets(
InputStream in,
@QueryParam("pretty") String pretty,
@QueryParam("numCandidates") @DefaultValue("-1") int numCandidates,
+ @QueryParam("cloneQueryMode") CloneQueryMode cloneQueryMode,
@Context final HttpServletRequest req
) throws IOException
{
final ResourceIOReaderWriter ioReaderWriter = createResourceIOReaderWriter(req, pretty != null);
try {
Query<?> query = ioReaderWriter.getRequestMapper().readValue(in, Query.class);
ExecutionVertex ev = ExecutionVertex.of(query);
+ HistoricalFilter historicalFilter = new HistoricalFilter(configView, cloneQueryMode == null ? CloneQueryMode.EXCLUDE : cloneQueryMode);
Review Comment:
```suggestion
HistoricalFilter historicalFilter = new HistoricalFilter(configView, cloneQueryMode == null ? QUERY_CONTEXT.DEFAULT : cloneQueryMode);
```
?
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorDynamicConfigSyncer.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import org.apache.druid.discovery.DiscoveryDruidNode;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHandler;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHolder;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.RequestBuilder;
+import org.apache.druid.rpc.ServiceClient;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.StandardRetryPolicy;
+import org.apache.druid.server.coordinator.CoordinatorConfigManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.jboss.netty.handler.codec.http.HttpMethod;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+
+import java.net.URL;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+/**
+ * Updates all brokers with the latest coordinator dynamic config.
+ */
+public class CoordinatorDynamicConfigSyncer
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigSyncer.class);
+
+ private final CoordinatorConfigManager configManager;
+ private final ObjectMapper jsonMapper;
+ private final DruidNodeDiscoveryProvider druidNodeDiscovery;
+
+ private final AtomicReference<CoordinatorDynamicConfig> lastKnownConfig = new AtomicReference<>();
+ private final ServiceClientFactory clientFactory;
+ private final ExecutorService exec;
+ private final Set<String> inSyncBrokers;
+
+ @Inject
+ public CoordinatorDynamicConfigSyncer(
+ @EscalatedGlobal final ServiceClientFactory clientFactory,
+ final CoordinatorConfigManager configManager,
+ @Json final ObjectMapper jsonMapper,
+ final DruidNodeDiscoveryProvider druidNodeDiscoveryProvider
+ )
+ {
+ this.clientFactory = clientFactory;
+ this.configManager = configManager;
+ this.jsonMapper = jsonMapper;
+ this.druidNodeDiscovery = druidNodeDiscoveryProvider;
+ this.exec = Execs.singleThreaded("DynamicConfigSyncer-%d");
+ this.inSyncBrokers = ConcurrentHashMap.newKeySet();
+ }
+
+ public void broadcastConfigToBrokers()
+ {
+ invalidateInSyncBrokersIfNeeded();
+ for (ServiceLocation broker : getKnownBrokers()) {
+ exec.submit(() -> pushConfigToBroker(broker));
+ }
+ }
+
+ public synchronized Set<String> getInSyncBrokers()
Review Comment:
Why is this synchronized required ?
##########
server/src/main/java/org/apache/druid/server/coordinator/CloneStatusManager.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.druid.server.coordinator.loading.SegmentAction;
+import org.apache.druid.timeline.DataSegment;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class CloneStatusManager
+{
+ private final AtomicReference<Map<String, CloneStatusMetrics>> cloneStatusSnapshot;
+
+ public CloneStatusManager()
+ {
+ this.cloneStatusSnapshot = new AtomicReference<>(ImmutableMap.of());
+ }
+
+ public Map<String, CloneStatusMetrics> getStatusForAllServers()
+ {
+ return cloneStatusSnapshot.get();
+ }
+
+ public CloneStatusMetrics getStatusForServer(String targetServer)
+ {
+ return cloneStatusSnapshot.get().get(targetServer);
+ }
+
+ public void updateStats(Map<String, ServerHolder> historicalMap, Map<String, String> cloneServers)
+ {
+ final Map<String, CloneStatusMetrics> newStatusMap = new HashMap<>();
+
+ for (Map.Entry<String, String> entry : cloneServers.entrySet()) {
+ final String targetServerName = entry.getKey();
+ final ServerHolder targetServer = historicalMap.get(entry.getKey());
+ final String sourceServerName = entry.getValue();
+
+ long segmentLoad = 0L;
+ long bytesLeft = 0L;
+ long segmentDrop = 0L;
+
+ CloneStatusMetrics newStatus;
+ if (targetServer == null) {
+ newStatus = CloneStatusMetrics.unknown(sourceServerName);
+ } else {
+
+ CloneStatusMetrics.Status status;
+ if (!historicalMap.containsKey(sourceServerName)) {
+ status = CloneStatusMetrics.Status.SOURCE_SERVER_MISSING;
+ } else {
+ status = CloneStatusMetrics.Status.LOADING;
+ }
+
+ for (Map.Entry<DataSegment, SegmentAction> queuedSegment : targetServer.getQueuedSegments().entrySet()) {
+ if (queuedSegment.getValue().isLoad()) {
+ segmentLoad += 1;
+ bytesLeft += queuedSegment.getKey().getSize();
+ } else {
+ segmentDrop += 1;
+ }
+ }
+ newStatus = new CloneStatusMetrics(sourceServerName, status, segmentLoad, segmentDrop, bytesLeft);
+ }
+ newStatusMap.put(targetServerName, newStatus);
+ }
+
+ cloneStatusSnapshot.set(newStatusMap);
Review Comment:
this should be converted to an immutable map.
##########
server/src/main/java/org/apache/druid/server/coordinator/CloneStatusMetrics.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.Objects;
+
+public class CloneStatusMetrics
+{
+ private final String sourceServer;
+ private final Status status;
+ private final long segmentLoadsRemaining;
+ private final long segmenetsDropsRemaining;
+ private final long bytesRemaining;
+
+ @JsonCreator
+ public CloneStatusMetrics(
+ @JsonProperty("sourceServer") String sourceServer,
+ @JsonProperty("status") Status status,
+ @JsonProperty("segmentLoadsRemaining") long segmentLoadsRemaining,
+ @JsonProperty("segmentDropsRemaining") long segmenetsDropsRemaining,
+ @JsonProperty("bytesRemaining") long bytesRemaining
+ )
+ {
+ this.sourceServer = sourceServer;
+ this.status = status;
+ this.segmentLoadsRemaining = segmentLoadsRemaining;
+ this.segmenetsDropsRemaining = segmenetsDropsRemaining;
+ this.bytesRemaining = bytesRemaining;
+ }
+
+ @JsonProperty("sourceServer")
+ public String getSourceServer()
+ {
+ return sourceServer;
+ }
+
+ @JsonProperty("segmentLoadsRemaining")
+ public long getSegmentLoadsRemaining()
+ {
+ return segmentLoadsRemaining;
+ }
+
+ @JsonProperty("segmentDropsRemaining")
+ public long getSegmenetsDropsRemaining()
+ {
+ return segmenetsDropsRemaining;
+ }
+
+ @JsonProperty("bytesRemaining")
+ public long getBytesRemaining()
+ {
+ return bytesRemaining;
+ }
+
+ @JsonProperty("status")
+ public Status getStatus()
+ {
+ return status;
+ }
+
+ public static CloneStatusMetrics unknown(String sourceServer)
+ {
+ return new CloneStatusMetrics(sourceServer, Status.TARGET_SERVER_MISSING, 0, 0, 0);
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ CloneStatusMetrics that = (CloneStatusMetrics) o;
+ return segmentLoadsRemaining == that.segmentLoadsRemaining
+ && segmenetsDropsRemaining == that.segmenetsDropsRemaining
+ && bytesRemaining == that.bytesRemaining
+ && Objects.equals(sourceServer, that.sourceServer)
+ && status == that.status;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Objects.hash(sourceServer, status, segmentLoadsRemaining, segmenetsDropsRemaining, bytesRemaining);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "CloneStatusMetrics{" +
+ "sourceServer='" + sourceServer + '\'' +
+ ", status=" + status +
+ ", segmentLoadsRemaining=" + segmentLoadsRemaining +
+ ", segmenetsDropsRemaining=" + segmenetsDropsRemaining +
+ ", bytesRemaining=" + bytesRemaining +
+ '}';
+ }
+
+ public enum Status
+ {
+ SOURCE_SERVER_MISSING,
Review Comment:
Java docs for enums are generally helpful.
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorResource.java:
##########
@@ -158,4 +164,28 @@ public Response getStatusOfDuties()
{
return Response.ok(new CoordinatorDutyStatus(coordinator.getStatusOfDuties())).build();
}
+
+ @GET
+ @Path("/brokerConfigurationStatus")
+ @ResourceFilters(StateResourceFilter.class)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getBrokerStatus()
+ {
+ return Response.ok(coordinatorDynamicConfigSyncer.getInSyncBrokers()).build();
+ }
+
+ @GET
+ @Path("/cloneStatus")
+ @ResourceFilters(StateResourceFilter.class)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getCloneStatus(@QueryParam("targetServer") String targetServer)
Review Comment:
Should this be marked nullable?
##########
processing/src/main/java/org/apache/druid/query/CloneQueryMode.java:
##########
@@ -0,0 +1,27 @@
+/*
+ * 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.query;
+
+public enum CloneQueryMode
+{
+ ONLY,
Review Comment:
Please add java docs to this.
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.client;
+
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class CoordinatorDynamicConfigView
Review Comment:
Could you please add the updation flow of this class as the responsibility of updating this changes from broker startup , to coordinator pushing updates.
##########
server/src/main/java/org/apache/druid/client/selector/HistoricalFilter.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.client.selector;
+
+import com.google.common.collect.ImmutableSet;
+import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
+import org.apache.druid.client.CoordinatorDynamicConfigView;
+import org.apache.druid.client.QueryableDruidServer;
+import org.apache.druid.query.CloneQueryMode;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+
+public class HistoricalFilter implements Function<Int2ObjectRBTreeMap<Set<QueryableDruidServer>>, Int2ObjectRBTreeMap<Set<QueryableDruidServer>>>
+{
+ public static final HistoricalFilter IDENTITY_FILTER = new HistoricalFilter(ImmutableSet::of);
+
+ public HistoricalFilter(Supplier<Set<String>> serversToIgnoreSupplier)
+ {
+ this.serversToIgnoreSupplier = serversToIgnoreSupplier;
+ }
+
+ public HistoricalFilter(CoordinatorDynamicConfigView configView, CloneQueryMode cloneQueryMode)
+ {
+ this.serversToIgnoreSupplier = () -> {
+ final Set<String> serversToIgnore = new HashSet<>();
Review Comment:
Can't we have this precomputed.
Clone servers are a one time thing. We might do that 10 times in 2 hours and then forget about it for a month or so.
The cost of creating these objects on each query seems a lot.
Suppose you have 1000 historicals, this method might not scale ?
##########
server/src/main/java/org/apache/druid/server/DruidInternalDynamicConfigResource.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import com.google.inject.Inject;
+import com.sun.jersey.spi.container.ResourceFilters;
+import org.apache.druid.client.CoordinatorDynamicConfigView;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.apache.druid.server.http.security.ConfigResourceFilter;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@Path("/druid-internal/v1/dynamicConfiguration")
+public class DruidInternalDynamicConfigResource
+{
+ private final CoordinatorDynamicConfigView coordinatorDynamicConfigView;
+
+ @Inject
+ public DruidInternalDynamicConfigResource(CoordinatorDynamicConfigView coordinatorDynamicConfigView)
+ {
+ this.coordinatorDynamicConfigView = coordinatorDynamicConfigView;
+ }
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @ResourceFilters(ConfigResourceFilter.class)
+ @Path("/coordinatorDynamicConfig")
+ public Response getDatasource()
+ {
+ return Response.ok(coordinatorDynamicConfigView.getConfig()).build();
+ }
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @ResourceFilters(ConfigResourceFilter.class)
+ @Path("/coordinatorDynamicConfig")
+ public Response setDatasource(final CoordinatorDynamicConfig dynamicConfig)
Review Comment:
setDynamicConfig?
##########
server/src/main/java/org/apache/druid/server/DruidInternalDynamicConfigResource.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import com.google.inject.Inject;
+import com.sun.jersey.spi.container.ResourceFilters;
+import org.apache.druid.client.CoordinatorDynamicConfigView;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.apache.druid.server.http.security.ConfigResourceFilter;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@Path("/druid-internal/v1/dynamicConfiguration")
+public class DruidInternalDynamicConfigResource
+{
+ private final CoordinatorDynamicConfigView coordinatorDynamicConfigView;
+
+ @Inject
+ public DruidInternalDynamicConfigResource(CoordinatorDynamicConfigView coordinatorDynamicConfigView)
+ {
+ this.coordinatorDynamicConfigView = coordinatorDynamicConfigView;
+ }
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @ResourceFilters(ConfigResourceFilter.class)
+ @Path("/coordinatorDynamicConfig")
+ public Response getDatasource()
Review Comment:
getDynamicConfig() ?
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorDynamicConfigSyncer.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import org.apache.druid.discovery.DiscoveryDruidNode;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHandler;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHolder;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.RequestBuilder;
+import org.apache.druid.rpc.ServiceClient;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.StandardRetryPolicy;
+import org.apache.druid.server.coordinator.CoordinatorConfigManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.jboss.netty.handler.codec.http.HttpMethod;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+
+import java.net.URL;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+/**
+ * Updates all brokers with the latest coordinator dynamic config.
+ */
+public class CoordinatorDynamicConfigSyncer
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigSyncer.class);
+
+ private final CoordinatorConfigManager configManager;
+ private final ObjectMapper jsonMapper;
+ private final DruidNodeDiscoveryProvider druidNodeDiscovery;
+
+ private final AtomicReference<CoordinatorDynamicConfig> lastKnownConfig = new AtomicReference<>();
+ private final ServiceClientFactory clientFactory;
+ private final ExecutorService exec;
+ private final Set<String> inSyncBrokers;
+
+ @Inject
+ public CoordinatorDynamicConfigSyncer(
+ @EscalatedGlobal final ServiceClientFactory clientFactory,
+ final CoordinatorConfigManager configManager,
+ @Json final ObjectMapper jsonMapper,
+ final DruidNodeDiscoveryProvider druidNodeDiscoveryProvider
+ )
+ {
+ this.clientFactory = clientFactory;
+ this.configManager = configManager;
+ this.jsonMapper = jsonMapper;
+ this.druidNodeDiscovery = druidNodeDiscoveryProvider;
+ this.exec = Execs.singleThreaded("DynamicConfigSyncer-%d");
+ this.inSyncBrokers = ConcurrentHashMap.newKeySet();
+ }
+
+ public void broadcastConfigToBrokers()
+ {
+ invalidateInSyncBrokersIfNeeded();
+ for (ServiceLocation broker : getKnownBrokers()) {
+ exec.submit(() -> pushConfigToBroker(broker));
+ }
+ }
+
+ public synchronized Set<String> getInSyncBrokers()
+ {
+ return Set.copyOf(inSyncBrokers);
+ }
+
+ private void pushConfigToBroker(ServiceLocation brokerLocation)
+ {
+ final ServiceClient brokerClient = clientFactory.makeClient(
+ NodeRole.BROKER.getJsonName(),
+ new FixedServiceLocator(brokerLocation),
+ StandardRetryPolicy.builder().maxAttempts(6).build()
+ );
+
+ try {
+ CoordinatorDynamicConfig currentDynamicConfig = configManager.getCurrentDynamicConfig();
+ final RequestBuilder requestBuilder =
+ new RequestBuilder(HttpMethod.POST, "/druid-internal/v1/dynamicConfiguration/coordinatorDynamicConfig")
+ .jsonContent(jsonMapper, currentDynamicConfig);
+
+ final BytesFullResponseHolder responseHolder = brokerClient.request(requestBuilder, new BytesFullResponseHandler());
+ final HttpResponseStatus status = responseHolder.getStatus();
+ if (status.equals(HttpResponseStatus.OK)) {
+ addToInSyncBrokers(currentDynamicConfig, brokerLocation);
+ } else {
+ log.error(
+ "Received status [%s] while posting dynamic configs to broker[%s]",
+ status.getCode(),
+ brokerLocation
+ );
+ }
+ }
+ catch (Exception e) {
+ // Catch and ignore the exception, wait for the next sync.
+ log.error(
+ e,
+ "Exception while syncing dynamic configuration to broker[%s]",
+ brokerLocation
+ );
+ }
+ }
+
+ private Set<ServiceLocation> getKnownBrokers()
+ {
+ return druidNodeDiscovery.getForNodeRole(NodeRole.BROKER)
+ .getAllNodes()
+ .stream()
+ .map(DiscoveryDruidNode::toServiceLocation)
+ .collect(Collectors.toSet());
+ }
+
+ private synchronized void invalidateInSyncBrokersIfNeeded()
+ {
+ final CoordinatorDynamicConfig currentDynamicConfig = configManager.getCurrentDynamicConfig();
+ if (!currentDynamicConfig.equals(lastKnownConfig.get())) {
+ // Config has changed, clear the inSync list.
+ lastKnownConfig.set(currentDynamicConfig);
+ inSyncBrokers.clear();
Review Comment:
Order should be reversed as just good coding practice.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2051933206
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorResource.java:
##########
@@ -158,4 +164,28 @@ public Response getStatusOfDuties()
{
return Response.ok(new CoordinatorDutyStatus(coordinator.getStatusOfDuties())).build();
}
+
+ @GET
+ @Path("/brokerConfigurationStatus")
Review Comment:
This API should be moved `CoordinatorDynamicConfigResource` class, and path should be
```
/druid/coordinator/v1/config/syncedBrokers
```
or something similar
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052127122
##########
server/src/main/java/org/apache/druid/server/coordinator/CloneStatusManager.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.druid.server.coordinator.loading.SegmentAction;
+import org.apache.druid.timeline.DataSegment;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class CloneStatusManager
+{
+ private final AtomicReference<Map<String, CloneStatusMetrics>> cloneStatusSnapshot;
Review Comment:
The API is currently required to return the status of a single server passed as a query parameter. Shouldn't we keep it as a map for that reason?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2051980262
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
+ @GuardedBy("this")
+ private Set<String> sourceCloneServers;
+ @GuardedBy("this")
+ private Set<String> targetCloneServers;
Review Comment:
This was changed based on a comment from Karan: https://github.com/apache/druid/pull/17899#discussion_r2048664410
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052060491
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.client;
+
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @Inject
+ public CoordinatorDynamicConfigView(CoordinatorClient coordinatorClient)
+ {
+ this.coordinatorClient = coordinatorClient;
+ }
+
+ private final AtomicReference<CoordinatorDynamicConfig> config = new AtomicReference<>();
+
+ public CoordinatorDynamicConfig getConfig()
+ {
+ return config.get();
+ }
+
+ public Set<String> getTargetCloneServers()
+ {
+ CoordinatorDynamicConfig coordinatorDynamicConfig = config.get();
+ return coordinatorDynamicConfig.getCloneServers().keySet();
+ }
+
+ public Set<String> getSourceCloneServers()
+ {
+ CoordinatorDynamicConfig coordinatorDynamicConfig = config.get();
Review Comment:
Should not be needed. https://github.com/apache/druid/pull/17899#discussion_r2051914336
##########
server/src/main/java/org/apache/druid/client/selector/HistoricalFilter.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.client.selector;
+
+import com.google.common.collect.ImmutableSet;
+import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
+import org.apache.druid.client.CoordinatorDynamicConfigView;
+import org.apache.druid.client.QueryableDruidServer;
+import org.apache.druid.query.CloneQueryMode;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+
+public class HistoricalFilter implements Function<Int2ObjectRBTreeMap<Set<QueryableDruidServer>>, Int2ObjectRBTreeMap<Set<QueryableDruidServer>>>
+{
+ public static final HistoricalFilter IDENTITY_FILTER = new HistoricalFilter(ImmutableSet::of);
+
+ public HistoricalFilter(Supplier<Set<String>> serversToIgnoreSupplier)
+ {
+ this.serversToIgnoreSupplier = serversToIgnoreSupplier;
+ }
+
+ public HistoricalFilter(CoordinatorDynamicConfigView configView, CloneQueryMode cloneQueryMode)
+ {
+ this.serversToIgnoreSupplier = () -> {
+ final Set<String> serversToIgnore = new HashSet<>();
Review Comment:
Changed.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052065200
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
Review Comment:
We might need the synchronized if we want procomputed lists of source and targets (https://github.com/apache/druid/pull/17899#discussion_r2051908935)
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on PR #17899:
URL: https://github.com/apache/druid/pull/17899#issuecomment-2834372070
Proceeding with the merge as all the requested changes have been made.
@clintropolis , @cryptoe , please feel free to add comments if you feel there is room for further improvement,
that can be taken up in follow up PRs.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2063505364
##########
processing/src/main/java/org/apache/druid/query/QueryContexts.java:
##########
@@ -149,6 +150,7 @@ public class QueryContexts
public static final boolean DEFAULT_ENABLE_JOIN_FILTER_PUSH_DOWN = true;
public static final boolean DEFAULT_ENABLE_JOIN_FILTER_REWRITE = true;
public static final boolean DEFAULT_ENABLE_JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS = false;
+ public static final CloneQueryMode DEFAULT_CLONE_QUERY_MODE = CloneQueryMode.EXCLUDECLONES;
Review Comment:
Yeah, I see your point. The use case doesn't seem all that important, except maybe to ensure that segment remains available even when the source server flickers (but that is already handled by having 2 replicas).
In fact, the `includeClones` mode might actually cause changes in query performance in a non-deterministic manner.
Let's get rid of it for now. We can add it back if there seems to be a real need for it.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2037126140
##########
server/src/main/java/org/apache/druid/server/DruidInternalDynamicConfigResource.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * 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;
+
+import com.google.inject.Inject;
+import org.apache.druid.client.DynamicConfigurationManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@Path("/druid-internal/v1/dynamicConfiguration")
+public class DruidInternalDynamicConfigResource
+{
+ private final DynamicConfigurationManager dynamicConfigurationManager;
+
+ @Inject
+ public DruidInternalDynamicConfigResource(DynamicConfigurationManager dynamicConfigurationManager)
+ {
+ this.dynamicConfigurationManager = dynamicConfigurationManager;
+ }
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/coordinatorDynamicConfig")
+ public Response getDatasource()
+ {
+ return Response.ok(dynamicConfigurationManager.getConfig()).build();
+ }
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Path("/coordinatorDynamicConfig")
+ public Response getDatasource(final CoordinatorDynamicConfig dynamicConfig)
+ {
+ dynamicConfigurationManager.updateCloneServers(dynamicConfig);
+ return Response.ok(dynamicConfigurationManager.getConfig()).build();
Review Comment:
## Cross-site scripting
Cross-site scripting vulnerability due to a [user-provided value](1).
[Show more details](https://github.com/apache/druid/security/code-scanning/8906)
##########
server/src/main/java/org/apache/druid/client/selector/ServerSelector.java:
##########
@@ -122,12 +122,17 @@
}
public List<DruidServerMetadata> getCandidates(final int numCandidates)
+ {
+ return getCandidates(numCandidates, HistoricalFilter.IDENTITIY_FILTER);
+ }
+
+ public List<DruidServerMetadata> getCandidates(final int numCandidates, HistoricalFilter filter)
{
List<DruidServerMetadata> candidates;
synchronized (this) {
if (numCandidates > 0) {
candidates = new ArrayList<>(numCandidates);
- strategy.pick(historicalServers, segment.get(), numCandidates)
+ strategy.pick(filter.apply(historicalServers), segment.get(), numCandidates)
Review Comment:
## Deprecated method or constructor invocation
Invoking [TierSelectorStrategy.pick](1) should be avoided because it has been deprecated.
[Show more details](https://github.com/apache/druid/security/code-scanning/8907)
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2051924745
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorDynamicConfigSyncer.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import org.apache.druid.discovery.DiscoveryDruidNode;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHandler;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHolder;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.RequestBuilder;
+import org.apache.druid.rpc.ServiceClient;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.StandardRetryPolicy;
+import org.apache.druid.server.coordinator.CoordinatorConfigManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.jboss.netty.handler.codec.http.HttpMethod;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+
+import java.net.URL;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+/**
+ * Updates all brokers with the latest coordinator dynamic config.
+ */
+public class CoordinatorDynamicConfigSyncer
Review Comment:
It feels redundant to have both a duty and a dedicated syncer class with its own `exec`.
I would have preferred having the duty, but since we need to trigger the sync whenever the dynamic config is updated, I think let's just have the syncer.
When coordinator becomes leader, schedule a periodic sync on the `exec`.
The periodic sync task just goes through each broker one by one.
When it is not leader anymore, stop the sync.
Emit metrics for:
- sync time of each broker
- total sync time
- number of failed syncs
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052068438
##########
server/src/main/java/org/apache/druid/server/coordinator/CoordinatorDynamicConfig.java:
##########
@@ -191,6 +192,30 @@ private Map<Dimension, String> validateDebugDimensions(Map<String, String> debug
return validDebugDimensions;
}
+ public CoordinatorDynamicConfig snapshot()
Review Comment:
Is editing the sets or maps not a concern even if the config is immutable? Perhaps this should be changed to deepcopy()?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052057743
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.client;
+
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @Inject
+ public CoordinatorDynamicConfigView(CoordinatorClient coordinatorClient)
+ {
+ this.coordinatorClient = coordinatorClient;
+ }
+
+ private final AtomicReference<CoordinatorDynamicConfig> config = new AtomicReference<>();
+
+ public CoordinatorDynamicConfig getConfig()
+ {
+ return config.get();
+ }
+
+ public Set<String> getTargetCloneServers()
+ {
+ CoordinatorDynamicConfig coordinatorDynamicConfig = config.get();
+ return coordinatorDynamicConfig.getCloneServers().keySet();
Review Comment:
Yes, this should be immutable.
https://github.com/apache/druid/pull/17899#discussion_r2051914336
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052061061
##########
server/src/main/java/org/apache/druid/client/selector/HistoricalFilter.java:
##########
@@ -0,0 +1,39 @@
+package org.apache.druid.client.selector;
+
+import com.google.common.collect.ImmutableSet;
+import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
+import org.apache.druid.client.QueryableDruidServer;
+
+import java.util.Set;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+
+public class HistoricalFilter implements Function<Int2ObjectRBTreeMap<Set<QueryableDruidServer>>, Int2ObjectRBTreeMap<Set<QueryableDruidServer>>>
Review Comment:
Oh, using a set is not a requirement, I just wrote it like that for simplicity. Same goes for the enum arg too.
In essence, we should just make `HistoricalFilter` an interface with some filtration method rather than just using a `Function<A, B>` and have the view class be an implementation of `HistoricalFilter`. It would be a cleaner design that is easier to follow and test.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052104015
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
Review Comment:
We shouldn't need to pre-compute the lists. This class should ideally not have the `getSourceServers` and `getTargetServers` methods at all. The caller can just get the dynamic config and perform any required operation on it.
Having separate methods for `getConfig`, `getSource` and `getTarget` makes it more error prone.
A caller may make calls to these methods in subsequent lines and still get back inconsistent results, since another thread updated the config meanwhile.
Let me know if this makes sense.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052227002
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorDynamicConfigSyncer.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import org.apache.druid.discovery.DiscoveryDruidNode;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHandler;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHolder;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.RequestBuilder;
+import org.apache.druid.rpc.ServiceClient;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.StandardRetryPolicy;
+import org.apache.druid.server.coordinator.CoordinatorConfigManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.jboss.netty.handler.codec.http.HttpMethod;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+
+import java.net.URL;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+/**
+ * Updates all brokers with the latest coordinator dynamic config.
+ */
+public class CoordinatorDynamicConfigSyncer
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigSyncer.class);
+
+ private final CoordinatorConfigManager configManager;
+ private final ObjectMapper jsonMapper;
+ private final DruidNodeDiscoveryProvider druidNodeDiscovery;
+
+ private final AtomicReference<CoordinatorDynamicConfig> lastKnownConfig = new AtomicReference<>();
+ private final ServiceClientFactory clientFactory;
+ private final ExecutorService exec;
+ private final Set<String> inSyncBrokers;
+
+ @Inject
+ public CoordinatorDynamicConfigSyncer(
+ @EscalatedGlobal final ServiceClientFactory clientFactory,
+ final CoordinatorConfigManager configManager,
+ @Json final ObjectMapper jsonMapper,
+ final DruidNodeDiscoveryProvider druidNodeDiscoveryProvider
+ )
+ {
+ this.clientFactory = clientFactory;
+ this.configManager = configManager;
+ this.jsonMapper = jsonMapper;
+ this.druidNodeDiscovery = druidNodeDiscoveryProvider;
+ this.exec = Execs.singleThreaded("DynamicConfigSyncer-%d");
+ this.inSyncBrokers = ConcurrentHashMap.newKeySet();
+ }
+
+ public void broadcastConfigToBrokers()
+ {
+ invalidateInSyncBrokersIfNeeded();
+ for (ServiceLocation broker : getKnownBrokers()) {
+ exec.submit(() -> pushConfigToBroker(broker));
+ }
+ }
+
+ public synchronized Set<String> getInSyncBrokers()
Review Comment:
Wouldn't it be needed as these can be updated/invalidated by a different thread?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2062605083
##########
server/src/main/java/org/apache/druid/client/ServerViewUtil.java:
##########
@@ -42,17 +44,21 @@
TimelineServerView serverView,
String datasource,
List<Interval> intervals,
- int numCandidates
+ int numCandidates,
+ HistoricalFilter historicalFilter,
+ CloneQueryMode cloneQueryMode
)
{
- return getTargetLocations(serverView, new TableDataSource(datasource), intervals, numCandidates);
+ return getTargetLocations(serverView, new TableDataSource(datasource), intervals, numCandidates, historicalFilter, cloneQueryMode);
}
public static List<LocatedSegmentDescriptor> getTargetLocations(
TimelineServerView serverView,
TableDataSource datasource,
List<Interval> intervals,
- int numCandidates
+ int numCandidates,
+ HistoricalFilter historicalFilter,
Review Comment:
## Useless parameter
The parameter 'historicalFilter' is never used.
[Show more details](https://github.com/apache/druid/security/code-scanning/8934)
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz merged PR #17899:
URL: https://github.com/apache/druid/pull/17899
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2063202360
##########
processing/src/main/java/org/apache/druid/query/QueryContexts.java:
##########
@@ -149,6 +150,7 @@ public class QueryContexts
public static final boolean DEFAULT_ENABLE_JOIN_FILTER_PUSH_DOWN = true;
public static final boolean DEFAULT_ENABLE_JOIN_FILTER_REWRITE = true;
public static final boolean DEFAULT_ENABLE_JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS = false;
+ public static final CloneQueryMode DEFAULT_CLONE_QUERY_MODE = CloneQueryMode.EXCLUDECLONES;
Review Comment:
The default should be exclude as we do not want clone servers to be queried by default. They might be running different versions of the code etc, which means that by default we do not want normal queries to be aware of these servers. In fact, should INCLUDE be removed? I don't know of a use case for them, other than ensuring that the query hits any possible server if available.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052065200
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
Review Comment:
We might need the synchronized if we want precomputed lists of source and targets (https://github.com/apache/druid/pull/17899#discussion_r2051908935)
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2058725468
##########
server/src/main/java/org/apache/druid/server/http/BrokerSyncStatus.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.druid.rpc.ServiceLocation;
+
+import java.util.Objects;
+
+public class BrokerSyncStatus
+{
+ private final String host;
+ private final int port;
+ private final long syncTimeInMs;
Review Comment:
> Since this represents a timestamp since epoch, it is expected to be in millis (since that is the convention followed in the rest of Druid).
Is there some dev documentation which mentions the above ?
IMHO units are better represented with the variable name.
##########
server/src/main/java/org/apache/druid/server/http/BrokerSyncStatus.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.druid.rpc.ServiceLocation;
+
+import java.util.Objects;
+
+public class BrokerSyncStatus
+{
+ private final String host;
+ private final int port;
+ private final long syncTimeInMs;
Review Comment:
> Since this represents a timestamp since epoch, it is expected to be in millis (since that is the convention followed in the rest of Druid).
Is there some dev documentation which mentions the above ?
IMHO units are better represented with the variable name.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2058725468
##########
server/src/main/java/org/apache/druid/server/http/BrokerSyncStatus.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.druid.rpc.ServiceLocation;
+
+import java.util.Objects;
+
+public class BrokerSyncStatus
+{
+ private final String host;
+ private final int port;
+ private final long syncTimeInMs;
Review Comment:
Is there some documentation which says that ?
IMHO units are better represented with the variable name.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2051950597
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.client;
+
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class CoordinatorDynamicConfigView
Review Comment:
Added a javadoc
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2041632765
##########
server/src/main/java/org/apache/druid/server/coordinator/CloneStatusMetrics.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.Objects;
+
+public class CloneStatusMetrics
Review Comment:
Add a short javadoc
```suggestion
public class ServerCloneStatus
```
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
Review Comment:
Let's use an `AtomicReference` and get rid of all the `synchronized` for simplicity.
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorResource.java:
##########
@@ -158,4 +164,28 @@ public Response getStatusOfDuties()
{
return Response.ok(new CoordinatorDutyStatus(coordinator.getStatusOfDuties())).build();
}
+
+ @GET
+ @Path("/brokerConfigurationStatus")
+ @ResourceFilters(StateResourceFilter.class)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getBrokerStatus()
+ {
+ return Response.ok(coordinatorDynamicConfigSyncer.getInSyncBrokers()).build();
+ }
+
+ @GET
+ @Path("/cloneStatus")
+ @ResourceFilters(StateResourceFilter.class)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getCloneStatus(@QueryParam("targetServer") @Nullable String targetServer)
+ {
+ if (targetServer != null) {
+ CloneStatusMetrics statusForServer = cloneStatusManager.getStatusForServer(targetServer);
+ return Response.ok(ImmutableMap.of(targetServer, statusForServer)).build();
+
Review Comment:
nit: extra line.
##########
server/src/main/java/org/apache/druid/server/coordinator/CloneStatusManager.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.druid.server.coordinator.loading.SegmentAction;
+import org.apache.druid.timeline.DataSegment;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class CloneStatusManager
+{
+ private final AtomicReference<Map<String, CloneStatusMetrics>> cloneStatusSnapshot;
Review Comment:
Rather than a map, this can be a dedicated `CloneStatus` object. See other comments regarding the payload of the clone status API.
##########
server/src/main/java/org/apache/druid/server/coordinator/CloneStatusMetrics.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.Objects;
+
+public class CloneStatusMetrics
+{
+ private final String sourceServer;
+ private final Status status;
+ private final long segmentLoadsRemaining;
+ private final long segmenetsDropsRemaining;
+ private final long bytesRemaining;
+
+ @JsonCreator
+ public CloneStatusMetrics(
+ @JsonProperty("sourceServer") String sourceServer,
+ @JsonProperty("status") Status status,
+ @JsonProperty("segmentLoadsRemaining") long segmentLoadsRemaining,
+ @JsonProperty("segmentDropsRemaining") long segmenetsDropsRemaining,
+ @JsonProperty("bytesRemaining") long bytesRemaining
+ )
+ {
+ this.sourceServer = sourceServer;
+ this.status = status;
+ this.segmentLoadsRemaining = segmentLoadsRemaining;
+ this.segmenetsDropsRemaining = segmenetsDropsRemaining;
+ this.bytesRemaining = bytesRemaining;
+ }
+
+ @JsonProperty("sourceServer")
+ public String getSourceServer()
+ {
+ return sourceServer;
+ }
+
+ @JsonProperty("segmentLoadsRemaining")
+ public long getSegmentLoadsRemaining()
+ {
+ return segmentLoadsRemaining;
+ }
+
+ @JsonProperty("segmentDropsRemaining")
+ public long getSegmenetsDropsRemaining()
+ {
+ return segmenetsDropsRemaining;
+ }
+
+ @JsonProperty("bytesRemaining")
Review Comment:
You need not specify the property names explicitly since the getters already follow the naming convention.
##########
docs/querying/query-context.md:
##########
@@ -66,6 +66,7 @@ See [SQL query context](sql-query-context.md) for other query context parameters
|`debug`| `false` | Flag indicating whether to enable debugging outputs for the query. When set to false, no additional logs will be produced (logs produced will be entirely dependent on your logging level). When set to true, the following addition logs will be produced:<br />- Log the stack trace of the exception (if any) produced by the query |
|`setProcessingThreadNames`|`true`| Whether processing thread names will be set to `queryType_dataSource_intervals` while processing a query. This aids in interpreting thread dumps, and is on by default. Query overhead can be reduced slightly by setting this to `false`. This has a tiny effect in most scenarios, but can be meaningful in high-QPS, low-per-segment-processing-time scenarios. |
|`sqlPlannerBloat`|`1000`|Calcite parameter which controls whether to merge two Project operators when inlining expressions causes complexity to increase. Implemented as a workaround to exception `There are not enough rules to produce a node with desired properties: convention=DRUID, sort=[]` thrown after rejecting the merge of two projects.|
+|`cloneQueryMode`|`EXCLUDE`| Indicates whether clone Historicals should be queried by brokers. Clone servers are created by the `cloneServers` Coordinator dynamic configuration. Possible values are `EXCLUDE`, `INCLUDE` and `CLONE_PREFERRED`. `EXCLUDE` means that clone Historicals are not queried by the broker. `CLONE_PREFERRED` indicates that when given a choice between the clone Historical and the original Historical which is being cloned, the broker chooses the clones; Historicals which are not involved in the cloning process will still be queried. `INCLUDE` means that broker queries any Historical without regarding clone status. This parameter only affects native queries; MSQ does not query Historicals directly, and Dart will not respect this context parameter.|
Review Comment:
Couple of suggestions:
- Druid typically uses camel-casing for config values. See [enum UsageMode](https://github.com/apache/druid/blob/a85a3e58570d2eec62a5be312fb9e7c86fe37be7/server/src/main/java/org/apache/druid/metadata/segment/cache/SegmentMetadataCache.java#L94) for an example usage
- I don't think we want to prefer clones for querying, we will either query them or not, so that the behaviour of queries is more deterministic. Thus, modes should be `excludeClones`, `includeClones` or `onlyClones`.
```suggestion
|`cloneQueryMode`|`excludeClones`| Indicates whether clone Historicals should be queried by brokers. Clone servers are created by the `cloneServers` Coordinator dynamic configuration. Possible values are `excludeClones`, `includeClones` and `onlyClones`. `EXCLUDE` means that clone Historicals are not queried by the broker. `CLONE_PREFERRED` indicates that when given a choice between the clone Historical and the original Historical which is being cloned, the broker chooses the clones; Historicals which are not involved in the cloning process will still be queried. `INCLUDE` means that broker queries any Historical without regarding clone status. This parameter only affects native queries; MSQ does not query Historicals directly, and Dart will not respect this context parameter.|
```
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
+ @GuardedBy("this")
+ private Set<String> sourceCloneServers;
+ @GuardedBy("this")
+ private Set<String> targetCloneServers;
Review Comment:
These should not be separate fields as they are already present inside the dynamic config and can always be read from there.
##########
docs/api-reference/service-status-api.md:
##########
@@ -1334,4 +1334,126 @@ Host: http://BROKER_IP:BROKER_PORT
#### Sample response
-A successful response to this endpoint results in an empty response body.
\ No newline at end of file
+A successful response to this endpoint results in an empty response body.
+
+### Get Historical Cloning Status
+
+Retrieves the current status of Historical cloning.
+
+#### URL
+
+`GET` `/druid/coordinator/v1/cloneStatus`
+
+#### Responses
+
+<Tabs>
+
+<TabItem value="56" label="200 SUCCESS">
+
+
+<br/>
+
+*Successfully retrieved cloning status*
+
+</TabItem>
+</Tabs>
+
+#### Sample request
+
+<Tabs>
+
+<TabItem value="58" label="cURL">
+
+
+```shell
+curl "http://COORDINATOR_IP:COORDINATOR_PORT/druid/coordinator/v1/cloneStatus"
+```
+
+</TabItem>
+<TabItem value="59" label="HTTP">
+
+
+```http
+GET /druid/coordinator/v1/cloneStatus HTTP/1.1
+Host: http://COORDINATOR_IP:COORDINATOR_PORT
+```
+
+</TabItem>
+</Tabs>
+
+#### Sample response
+
+<details>
+ <summary>View the response</summary>
+
+```json
+{
+ "localhost:8083": {
+ "sourceServer": "localhost:8089",
+ "status": "LOADING",
+ "segmentLoadsRemaining": 0,
+ "segmenetsDropsRemaining": 0,
+ "bytesRemaining": 0
+ }
Review Comment:
I think it would be better to have the payload look more like this, i.e. an array of status objects, each of which contains a source, target and other info.
```suggestion
"cloneStatus": [{
"sourceServer": "localhost:8089",
"targetServer": "localhost:8083",
"status": "LOADING",
"segmentLoadsRemaining": 0,
"segmenetsDropsRemaining": 0,
"bytesRemaining": 0
}]
```
##########
server/src/main/java/org/apache/druid/server/BrokerQueryResource.java:
##########
@@ -89,19 +97,22 @@ public Response getQueryTargets(
InputStream in,
@QueryParam("pretty") String pretty,
@QueryParam("numCandidates") @DefaultValue("-1") int numCandidates,
+ @QueryParam("cloneQueryMode") @Nullable CloneQueryMode cloneQueryMode,
@Context final HttpServletRequest req
) throws IOException
{
final ResourceIOReaderWriter ioReaderWriter = createResourceIOReaderWriter(req, pretty != null);
try {
Query<?> query = ioReaderWriter.getRequestMapper().readValue(in, Query.class);
ExecutionVertex ev = ExecutionVertex.of(query);
+ HistoricalFilter historicalFilter = new HistoricalFilter(configView, cloneQueryMode == null ? QueryContexts.DEFAULT_CLONE_QUERY_MODE : cloneQueryMode);
Review Comment:
Use `QueryContexts.getAsEnum()` here.
##########
server/src/main/java/org/apache/druid/server/coordinator/CloneStatusMetrics.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.Objects;
+
+public class CloneStatusMetrics
+{
+ private final String sourceServer;
+ private final Status status;
+ private final long segmentLoadsRemaining;
+ private final long segmenetsDropsRemaining;
+ private final long bytesRemaining;
+
+ @JsonCreator
+ public CloneStatusMetrics(
+ @JsonProperty("sourceServer") String sourceServer,
+ @JsonProperty("status") Status status,
+ @JsonProperty("segmentLoadsRemaining") long segmentLoadsRemaining,
+ @JsonProperty("segmentDropsRemaining") long segmenetsDropsRemaining,
+ @JsonProperty("bytesRemaining") long bytesRemaining
+ )
+ {
+ this.sourceServer = sourceServer;
+ this.status = status;
+ this.segmentLoadsRemaining = segmentLoadsRemaining;
+ this.segmenetsDropsRemaining = segmenetsDropsRemaining;
+ this.bytesRemaining = bytesRemaining;
+ }
+
+ @JsonProperty("sourceServer")
+ public String getSourceServer()
+ {
+ return sourceServer;
+ }
+
+ @JsonProperty("segmentLoadsRemaining")
+ public long getSegmentLoadsRemaining()
+ {
+ return segmentLoadsRemaining;
+ }
+
+ @JsonProperty("segmentDropsRemaining")
+ public long getSegmenetsDropsRemaining()
+ {
+ return segmenetsDropsRemaining;
+ }
+
+ @JsonProperty("bytesRemaining")
+ public long getBytesRemaining()
+ {
+ return bytesRemaining;
+ }
+
+ @JsonProperty("status")
+ public Status getStatus()
+ {
+ return status;
+ }
+
+ public static CloneStatusMetrics unknown(String sourceServer)
+ {
+ return new CloneStatusMetrics(sourceServer, Status.TARGET_SERVER_MISSING, 0, 0, 0);
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ CloneStatusMetrics that = (CloneStatusMetrics) o;
+ return segmentLoadsRemaining == that.segmentLoadsRemaining
+ && segmenetsDropsRemaining == that.segmenetsDropsRemaining
+ && bytesRemaining == that.bytesRemaining
+ && Objects.equals(sourceServer, that.sourceServer)
+ && status == that.status;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Objects.hash(sourceServer, status, segmentLoadsRemaining, segmenetsDropsRemaining, bytesRemaining);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "CloneStatusMetrics{" +
+ "sourceServer='" + sourceServer + '\'' +
+ ", status=" + status +
+ ", segmentLoadsRemaining=" + segmentLoadsRemaining +
+ ", segmenetsDropsRemaining=" + segmenetsDropsRemaining +
+ ", bytesRemaining=" + bytesRemaining +
+ '}';
+ }
+
+ public enum Status
Review Comment:
```suggestion
public enum State
```
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class CoordinatorDynamicConfigView
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigView.class);
+ private final CoordinatorClient coordinatorClient;
+
+ @GuardedBy("this")
+ private CoordinatorDynamicConfig config;
+ @GuardedBy("this")
+ private Set<String> sourceCloneServers;
+ @GuardedBy("this")
+ private Set<String> targetCloneServers;
+
+ @Inject
+ public CoordinatorDynamicConfigView(CoordinatorClient coordinatorClient)
+ {
+ this.coordinatorClient = coordinatorClient;
+ }
+
+ public synchronized CoordinatorDynamicConfig getDynamicConfiguration()
+ {
+ return config;
+ }
+
+ /**
+ * Update the config view with a new coordinator dynamic config snapshot. Also updates the source and target clone
+ * servers based on the new dynamic configuration.
+ */
+ public synchronized void setDynamicConfiguration(@NotNull CoordinatorDynamicConfig updatedConfig)
Review Comment:
```suggestion
public synchronized void setDynamicConfig(@NotNull CoordinatorDynamicConfig updatedConfig)
```
##########
docs/api-reference/service-status-api.md:
##########
@@ -1334,4 +1334,126 @@ Host: http://BROKER_IP:BROKER_PORT
#### Sample response
-A successful response to this endpoint results in an empty response body.
\ No newline at end of file
+A successful response to this endpoint results in an empty response body.
+
+### Get Historical Cloning Status
Review Comment:
This section should be moved under the Coordinator heading.
##########
docs/api-reference/service-status-api.md:
##########
@@ -1334,4 +1334,126 @@ Host: http://BROKER_IP:BROKER_PORT
#### Sample response
-A successful response to this endpoint results in an empty response body.
\ No newline at end of file
+A successful response to this endpoint results in an empty response body.
+
+### Get Historical Cloning Status
+
+Retrieves the current status of Historical cloning.
Review Comment:
```suggestion
Retrieves the current status of Historical cloning from the Coordinator.
```
##########
server/src/main/java/org/apache/druid/server/BrokerQueryResource.java:
##########
@@ -89,19 +97,22 @@ public Response getQueryTargets(
InputStream in,
@QueryParam("pretty") String pretty,
@QueryParam("numCandidates") @DefaultValue("-1") int numCandidates,
+ @QueryParam("cloneQueryMode") @Nullable CloneQueryMode cloneQueryMode,
Review Comment:
Pass in a String rather than an enum here.
##########
server/src/main/java/org/apache/druid/server/coordinator/CoordinatorDynamicConfig.java:
##########
@@ -191,6 +192,30 @@ private Map<Dimension, String> validateDebugDimensions(Map<String, String> debug
return validDebugDimensions;
}
+ public CoordinatorDynamicConfig snapshot()
Review Comment:
Is this meant to create a copy of the config or a snapshot?
Either way, the config itself is immutable, we shouldn't need this method.
##########
server/src/main/java/org/apache/druid/client/CachingClusteredClient.java:
##########
@@ -139,7 +141,8 @@ public CachingClusteredClient(
BrokerParallelMergeConfig parallelMergeConfig,
@Merging ForkJoinPool pool,
QueryScheduler scheduler,
- ServiceEmitter emitter
+ ServiceEmitter emitter,
+ CoordinatorDynamicConfigView coordinatorDynamicConfigView
Review Comment:
Nit: Please move this arg to after or just before `TimelineServerView`.
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorDynamicConfigSyncer.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import org.apache.druid.discovery.DiscoveryDruidNode;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHandler;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHolder;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.RequestBuilder;
+import org.apache.druid.rpc.ServiceClient;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.StandardRetryPolicy;
+import org.apache.druid.server.coordinator.CoordinatorConfigManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.jboss.netty.handler.codec.http.HttpMethod;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+
+import java.net.URL;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+/**
+ * Updates all brokers with the latest coordinator dynamic config.
+ */
+public class CoordinatorDynamicConfigSyncer
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigSyncer.class);
+
+ private final CoordinatorConfigManager configManager;
+ private final ObjectMapper jsonMapper;
+ private final DruidNodeDiscoveryProvider druidNodeDiscovery;
+
+ private final AtomicReference<CoordinatorDynamicConfig> lastKnownConfig = new AtomicReference<>();
+ private final ServiceClientFactory clientFactory;
+ private final ExecutorService exec;
+ private final Set<String> inSyncBrokers;
+
+ @Inject
+ public CoordinatorDynamicConfigSyncer(
+ @EscalatedGlobal final ServiceClientFactory clientFactory,
+ final CoordinatorConfigManager configManager,
+ @Json final ObjectMapper jsonMapper,
+ final DruidNodeDiscoveryProvider druidNodeDiscoveryProvider
+ )
+ {
+ this.clientFactory = clientFactory;
+ this.configManager = configManager;
+ this.jsonMapper = jsonMapper;
+ this.druidNodeDiscovery = druidNodeDiscoveryProvider;
+ this.exec = Execs.singleThreaded("DynamicConfigSyncer-%d");
+ this.inSyncBrokers = ConcurrentHashMap.newKeySet();
+ }
+
+ public void broadcastConfigToBrokers()
+ {
+ invalidateInSyncBrokersIfNeeded();
+ for (ServiceLocation broker : getKnownBrokers()) {
+ exec.submit(() -> pushConfigToBroker(broker));
+ }
+ }
+
+ public synchronized Set<String> getInSyncBrokers()
+ {
+ return Set.copyOf(inSyncBrokers);
+ }
+
+ private void pushConfigToBroker(ServiceLocation brokerLocation)
+ {
+ final ServiceClient brokerClient = clientFactory.makeClient(
+ NodeRole.BROKER.getJsonName(),
+ new FixedServiceLocator(brokerLocation),
+ StandardRetryPolicy.builder().maxAttempts(6).build()
+ );
+
+ try {
+ CoordinatorDynamicConfig currentDynamicConfig = configManager.getCurrentDynamicConfig();
+ final RequestBuilder requestBuilder =
+ new RequestBuilder(HttpMethod.POST, "/druid-internal/v1/dynamicConfiguration/coordinatorDynamicConfig")
+ .jsonContent(jsonMapper, currentDynamicConfig);
+
+ final BytesFullResponseHolder responseHolder = brokerClient.request(requestBuilder, new BytesFullResponseHandler());
+ final HttpResponseStatus status = responseHolder.getStatus();
+ if (status.equals(HttpResponseStatus.OK)) {
+ addToInSyncBrokers(currentDynamicConfig, brokerLocation);
+ } else {
+ log.error(
+ "Received status [%s] while posting dynamic configs to broker[%s]",
+ status.getCode(),
+ brokerLocation
+ );
+ }
+ }
+ catch (Exception e) {
+ // Catch and ignore the exception, wait for the next sync.
+ log.error(
+ e,
+ "Exception while syncing dynamic configuration to broker[%s]",
+ brokerLocation
+ );
+ }
+ }
+
+ private Set<ServiceLocation> getKnownBrokers()
+ {
+ return druidNodeDiscovery.getForNodeRole(NodeRole.BROKER)
+ .getAllNodes()
+ .stream()
+ .map(DiscoveryDruidNode::toServiceLocation)
+ .collect(Collectors.toSet());
+ }
+
+ private synchronized void invalidateInSyncBrokersIfNeeded()
+ {
+ final CoordinatorDynamicConfig currentDynamicConfig = configManager.getCurrentDynamicConfig();
+ if (!currentDynamicConfig.equals(lastKnownConfig.get())) {
+ // Config has changed, clear the inSync list.
+ inSyncBrokers.clear();
+ lastKnownConfig.set(currentDynamicConfig);
+ }
+ }
+
+ private synchronized void addToInSyncBrokers(CoordinatorDynamicConfig config, ServiceLocation broker)
Review Comment:
```suggestion
private synchronized void markBrokerAsSynced(CoordinatorDynamicConfig config, ServiceLocation broker)
```
##########
server/src/main/java/org/apache/druid/server/coordinator/duty/BrokerDynamicConfigSync.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * 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.server.coordinator.DruidCoordinatorRuntimeParams;
+import org.apache.druid.server.http.CoordinatorDynamicConfigSyncer;
+
+/**
+ * Duty to periodically broadcast the coordinator dynamic configuration to all brokers.
+ */
+public class BrokerDynamicConfigSync implements CoordinatorDuty
Review Comment:
```suggestion
public class SendDynamicConfigToBrokers implements CoordinatorDuty
```
##########
server/src/test/java/org/apache/druid/client/TestCoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.client;
+
+import java.util.Set;
+
+public class TestCoordinatorDynamicConfigView extends CoordinatorDynamicConfigView
Review Comment:
Do not have this test implementation since the super class is fairly simple itself. Use a test coordinator client instead.
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorDynamicConfigSyncer.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import org.apache.druid.discovery.DiscoveryDruidNode;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHandler;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHolder;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.RequestBuilder;
+import org.apache.druid.rpc.ServiceClient;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.StandardRetryPolicy;
+import org.apache.druid.server.coordinator.CoordinatorConfigManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.jboss.netty.handler.codec.http.HttpMethod;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+
+import java.net.URL;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+/**
+ * Updates all brokers with the latest coordinator dynamic config.
+ */
+public class CoordinatorDynamicConfigSyncer
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigSyncer.class);
+
+ private final CoordinatorConfigManager configManager;
+ private final ObjectMapper jsonMapper;
+ private final DruidNodeDiscoveryProvider druidNodeDiscovery;
+
+ private final AtomicReference<CoordinatorDynamicConfig> lastKnownConfig = new AtomicReference<>();
+ private final ServiceClientFactory clientFactory;
+ private final ExecutorService exec;
+ private final Set<String> inSyncBrokers;
+
+ @Inject
+ public CoordinatorDynamicConfigSyncer(
+ @EscalatedGlobal final ServiceClientFactory clientFactory,
+ final CoordinatorConfigManager configManager,
+ @Json final ObjectMapper jsonMapper,
+ final DruidNodeDiscoveryProvider druidNodeDiscoveryProvider
+ )
+ {
+ this.clientFactory = clientFactory;
+ this.configManager = configManager;
+ this.jsonMapper = jsonMapper;
+ this.druidNodeDiscovery = druidNodeDiscoveryProvider;
+ this.exec = Execs.singleThreaded("DynamicConfigSyncer-%d");
+ this.inSyncBrokers = ConcurrentHashMap.newKeySet();
+ }
+
+ public void broadcastConfigToBrokers()
+ {
+ invalidateInSyncBrokersIfNeeded();
+ for (ServiceLocation broker : getKnownBrokers()) {
+ exec.submit(() -> pushConfigToBroker(broker));
Review Comment:
I don't think there is much point in submitting a separate runnable for each broker, since the underlying exec is single threaded. Might as well just do everything in one task.
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorDynamicConfigSyncer.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import org.apache.druid.discovery.DiscoveryDruidNode;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHandler;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHolder;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.RequestBuilder;
+import org.apache.druid.rpc.ServiceClient;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.StandardRetryPolicy;
+import org.apache.druid.server.coordinator.CoordinatorConfigManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.jboss.netty.handler.codec.http.HttpMethod;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+
+import java.net.URL;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+/**
+ * Updates all brokers with the latest coordinator dynamic config.
+ */
+public class CoordinatorDynamicConfigSyncer
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigSyncer.class);
+
+ private final CoordinatorConfigManager configManager;
+ private final ObjectMapper jsonMapper;
+ private final DruidNodeDiscoveryProvider druidNodeDiscovery;
+
+ private final AtomicReference<CoordinatorDynamicConfig> lastKnownConfig = new AtomicReference<>();
+ private final ServiceClientFactory clientFactory;
+ private final ExecutorService exec;
+ private final Set<String> inSyncBrokers;
+
+ @Inject
+ public CoordinatorDynamicConfigSyncer(
+ @EscalatedGlobal final ServiceClientFactory clientFactory,
+ final CoordinatorConfigManager configManager,
+ @Json final ObjectMapper jsonMapper,
+ final DruidNodeDiscoveryProvider druidNodeDiscoveryProvider
+ )
+ {
+ this.clientFactory = clientFactory;
+ this.configManager = configManager;
+ this.jsonMapper = jsonMapper;
+ this.druidNodeDiscovery = druidNodeDiscoveryProvider;
+ this.exec = Execs.singleThreaded("DynamicConfigSyncer-%d");
+ this.inSyncBrokers = ConcurrentHashMap.newKeySet();
+ }
+
+ public void broadcastConfigToBrokers()
+ {
+ invalidateInSyncBrokersIfNeeded();
+ for (ServiceLocation broker : getKnownBrokers()) {
+ exec.submit(() -> pushConfigToBroker(broker));
+ }
+ }
+
+ public synchronized Set<String> getInSyncBrokers()
+ {
+ return Set.copyOf(inSyncBrokers);
+ }
+
+ private void pushConfigToBroker(ServiceLocation brokerLocation)
+ {
+ final ServiceClient brokerClient = clientFactory.makeClient(
+ NodeRole.BROKER.getJsonName(),
+ new FixedServiceLocator(brokerLocation),
+ StandardRetryPolicy.builder().maxAttempts(6).build()
+ );
+
+ try {
+ CoordinatorDynamicConfig currentDynamicConfig = configManager.getCurrentDynamicConfig();
+ final RequestBuilder requestBuilder =
+ new RequestBuilder(HttpMethod.POST, "/druid-internal/v1/dynamicConfiguration/coordinatorDynamicConfig")
+ .jsonContent(jsonMapper, currentDynamicConfig);
+
+ final BytesFullResponseHolder responseHolder = brokerClient.request(requestBuilder, new BytesFullResponseHandler());
+ final HttpResponseStatus status = responseHolder.getStatus();
+ if (status.equals(HttpResponseStatus.OK)) {
+ addToInSyncBrokers(currentDynamicConfig, brokerLocation);
+ } else {
+ log.error(
+ "Received status [%s] while posting dynamic configs to broker[%s]",
+ status.getCode(),
+ brokerLocation
+ );
+ }
+ }
+ catch (Exception e) {
+ // Catch and ignore the exception, wait for the next sync.
+ log.error(
+ e,
+ "Exception while syncing dynamic configuration to broker[%s]",
+ brokerLocation
+ );
+ }
+ }
+
+ private Set<ServiceLocation> getKnownBrokers()
+ {
+ return druidNodeDiscovery.getForNodeRole(NodeRole.BROKER)
+ .getAllNodes()
+ .stream()
+ .map(DiscoveryDruidNode::toServiceLocation)
Review Comment:
Nit: How does using a `ServiceLocation` help? Is it so that we can use the `toURL()` method?
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorResource.java:
##########
@@ -43,11 +45,15 @@
public class CoordinatorResource
{
private final DruidCoordinator coordinator;
+ private final CloneStatusManager cloneStatusManager;
+ private final CoordinatorDynamicConfigSyncer coordinatorDynamicConfigSyncer;
@Inject
- public CoordinatorResource(DruidCoordinator coordinator)
+ public CoordinatorResource(DruidCoordinator coordinator, CloneStatusManager cloneStatusManager, CoordinatorDynamicConfigSyncer coordinatorDynamicConfigSyncer)
Review Comment:
Please put arguments in separate lines.
##########
server/src/main/java/org/apache/druid/discovery/DiscoveryDruidNode.java:
##########
@@ -200,6 +201,21 @@ public <T extends DruidService> T getService(String key, Class<T> clazz)
return null;
}
+ public ServiceLocation toServiceLocation()
Review Comment:
I don't think this is a common use case (yet). This method should live in the syncer class where this is actually used.
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorDynamicConfigSyncer.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import org.apache.druid.discovery.DiscoveryDruidNode;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHandler;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHolder;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.RequestBuilder;
+import org.apache.druid.rpc.ServiceClient;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.StandardRetryPolicy;
+import org.apache.druid.server.coordinator.CoordinatorConfigManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.jboss.netty.handler.codec.http.HttpMethod;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+
+import java.net.URL;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+/**
+ * Updates all brokers with the latest coordinator dynamic config.
+ */
+public class CoordinatorDynamicConfigSyncer
Review Comment:
It feels redundant to have both a duty and a dedicated syncer class with its own `exec`.
I would have preferred having the duty, but since we need to trigger the sync whenever the dynamic config is updated, I think let's just have the syncer.
When coordinator becomes leader, schedule a period sync on the `exec`. The periodic sync task just goes through each broker one by one.
When it is not leader anymore, stop the sync.
Emit metrics for:
- sync time of each broker
- total sync time
- number of failed syncs
##########
server/src/main/java/org/apache/druid/client/CoordinatorDynamicConfigView.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.client;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import com.google.inject.Inject;
+import org.apache.druid.client.coordinator.CoordinatorClient;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.DruidInternalDynamicConfigResource;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Broker view of the coordinator dynamic configuration, and its derived values such as target and source clone servers.
+ * This class is registered as a managed lifecycle to fetch the coordinator dynamic configuration on startup. Further
+ * updates are handled through {@link DruidInternalDynamicConfigResource}.
+ */
+public class CoordinatorDynamicConfigView
Review Comment:
```suggestion
public class BrokerViewOfCoordinatorConfig
```
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorDynamicConfigSyncer.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import org.apache.druid.discovery.DiscoveryDruidNode;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHandler;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHolder;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.RequestBuilder;
+import org.apache.druid.rpc.ServiceClient;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.StandardRetryPolicy;
+import org.apache.druid.server.coordinator.CoordinatorConfigManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.jboss.netty.handler.codec.http.HttpMethod;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+
+import java.net.URL;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+/**
+ * Updates all brokers with the latest coordinator dynamic config.
+ */
+public class CoordinatorDynamicConfigSyncer
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigSyncer.class);
+
+ private final CoordinatorConfigManager configManager;
+ private final ObjectMapper jsonMapper;
+ private final DruidNodeDiscoveryProvider druidNodeDiscovery;
+
+ private final AtomicReference<CoordinatorDynamicConfig> lastKnownConfig = new AtomicReference<>();
+ private final ServiceClientFactory clientFactory;
+ private final ExecutorService exec;
+ private final Set<String> inSyncBrokers;
+
+ @Inject
+ public CoordinatorDynamicConfigSyncer(
+ @EscalatedGlobal final ServiceClientFactory clientFactory,
Review Comment:
We should try to use the `BrokerClient` instead. We might need to add a new method there.
##########
server/src/main/java/org/apache/druid/server/ClientInfoResource.java:
##########
@@ -86,14 +89,16 @@ public class ClientInfoResource
private SegmentMetadataQueryConfig segmentMetadataQueryConfig;
private final AuthConfig authConfig;
private final AuthorizerMapper authorizerMapper;
+ private final CoordinatorDynamicConfigView configView;
@Inject
public ClientInfoResource(
FilteredServerInventoryView serverInventoryView,
TimelineServerView timelineServerView,
SegmentMetadataQueryConfig segmentMetadataQueryConfig,
AuthConfig authConfig,
- AuthorizerMapper authorizerMapper
+ AuthorizerMapper authorizerMapper,
+ CoordinatorDynamicConfigView configView
Review Comment:
Move this to after `TimelineServerView` arg.
##########
server/src/main/java/org/apache/druid/server/coordinator/DruidCoordinator.java:
##########
@@ -559,7 +567,8 @@ private List<CoordinatorDuty> makeHistoricalManagementDuties()
new MarkOvershadowedSegmentsAsUnused(deleteSegments),
new MarkEternityTombstonesAsUnused(deleteSegments),
new BalanceSegments(config.getCoordinatorPeriod()),
- new CloneHistoricals(loadQueueManager),
+ new CloneHistoricals(loadQueueManager, cloneStatusManager),
+ new BrokerDynamicConfigSync(coordinatorDynamicConfigSyncer),
Review Comment:
Put this duty in a separate duty group to avoid affecting the other critical historical management duties.
Or better yet, let's just get rid of the duty. See the other comments.
##########
server/src/main/java/org/apache/druid/server/ClientQuerySegmentWalker.java:
##########
@@ -607,7 +607,7 @@ private <T> QueryRunner<T> decorateClusterRunner(Query<T> query, QueryRunner<T>
* @param parentQueryResourceId Parent Query's Query Resource ID
* @return DataSource populated with the subqueries
*/
- private DataSource generateSubqueryIds(
+ public static DataSource generateSubqueryIds(
Review Comment:
Why public?
##########
server/src/main/java/org/apache/druid/server/coordinator/CloneStatusManager.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.druid.server.coordinator.loading.SegmentAction;
+import org.apache.druid.timeline.DataSegment;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class CloneStatusManager
+{
+ private final AtomicReference<Map<String, CloneStatusMetrics>> cloneStatusSnapshot;
+
+ public CloneStatusManager()
+ {
+ this.cloneStatusSnapshot = new AtomicReference<>(ImmutableMap.of());
Review Comment:
```suggestion
this.cloneStatusSnapshot = new AtomicReference<>(Map.of());
```
##########
server/src/main/java/org/apache/druid/server/DruidInternalDynamicConfigResource.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import com.google.inject.Inject;
+import com.sun.jersey.spi.container.ResourceFilters;
+import org.apache.druid.client.CoordinatorDynamicConfigView;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.apache.druid.server.http.security.ConfigResourceFilter;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@Path("/druid-internal/v1/dynamicConfiguration")
+public class DruidInternalDynamicConfigResource
+{
+ private final CoordinatorDynamicConfigView coordinatorDynamicConfigView;
+
+ @Inject
+ public DruidInternalDynamicConfigResource(CoordinatorDynamicConfigView coordinatorDynamicConfigView)
+ {
+ this.coordinatorDynamicConfigView = coordinatorDynamicConfigView;
+ }
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @ResourceFilters(ConfigResourceFilter.class)
+ @Path("/coordinatorDynamicConfig")
+ public Response getDynamicConfig()
+ {
+ return Response.ok(coordinatorDynamicConfigView.getDynamicConfiguration()).build();
+ }
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @ResourceFilters(ConfigResourceFilter.class)
+ @Path("/coordinatorDynamicConfig")
+ public Response setDynamicConfig(final CoordinatorDynamicConfig dynamicConfig)
+ {
+ coordinatorDynamicConfigView.setDynamicConfiguration(dynamicConfig);
+ return Response.ok("OK").build();
Review Comment:
Nicer to include a proper JSON response, even if it is just `{"success": true}`.
```suggestion
return Response.ok("OK").build();
```
##########
server/src/main/java/org/apache/druid/server/ClientInfoResource.java:
##########
@@ -300,6 +306,7 @@ public Iterable<LocatedSegmentDescriptor> getQueryTargets(
@PathParam("dataSourceName") String datasource,
@QueryParam("intervals") String intervals,
@QueryParam("numCandidates") @DefaultValue("-1") int numCandidates,
+ @QueryParam("cloneQueryMode") CloneQueryMode cloneQueryMode,
Review Comment:
Use String param and `QueryContexts.getAsEnum()`, same as suggested in the other resource class.
##########
server/src/main/java/org/apache/druid/server/DruidInternalDynamicConfigResource.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import com.google.inject.Inject;
+import com.sun.jersey.spi.container.ResourceFilters;
+import org.apache.druid.client.CoordinatorDynamicConfigView;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.apache.druid.server.http.security.ConfigResourceFilter;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@Path("/druid-internal/v1/dynamicConfiguration")
Review Comment:
```suggestion
@Path("/druid-internal/v1/config")
```
##########
server/src/main/java/org/apache/druid/server/DruidInternalDynamicConfigResource.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import com.google.inject.Inject;
+import com.sun.jersey.spi.container.ResourceFilters;
+import org.apache.druid.client.CoordinatorDynamicConfigView;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.apache.druid.server.http.security.ConfigResourceFilter;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@Path("/druid-internal/v1/dynamicConfiguration")
+public class DruidInternalDynamicConfigResource
+{
+ private final CoordinatorDynamicConfigView coordinatorDynamicConfigView;
+
+ @Inject
+ public DruidInternalDynamicConfigResource(CoordinatorDynamicConfigView coordinatorDynamicConfigView)
+ {
+ this.coordinatorDynamicConfigView = coordinatorDynamicConfigView;
+ }
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @ResourceFilters(ConfigResourceFilter.class)
+ @Path("/coordinatorDynamicConfig")
+ public Response getDynamicConfig()
+ {
+ return Response.ok(coordinatorDynamicConfigView.getDynamicConfiguration()).build();
+ }
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @ResourceFilters(ConfigResourceFilter.class)
+ @Path("/coordinatorDynamicConfig")
Review Comment:
```suggestion
@Path("/coordinator")
```
##########
server/src/main/java/org/apache/druid/server/coordinator/CloneStatusManager.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.druid.server.coordinator.loading.SegmentAction;
+import org.apache.druid.timeline.DataSegment;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class CloneStatusManager
+{
+ private final AtomicReference<Map<String, CloneStatusMetrics>> cloneStatusSnapshot;
+
+ public CloneStatusManager()
+ {
+ this.cloneStatusSnapshot = new AtomicReference<>(ImmutableMap.of());
+ }
+
+ public Map<String, CloneStatusMetrics> getStatusForAllServers()
+ {
+ return cloneStatusSnapshot.get();
+ }
+
+ public CloneStatusMetrics getStatusForServer(String targetServer)
Review Comment:
mark this method as nullable.
##########
docs/api-reference/service-status-api.md:
##########
@@ -1334,4 +1334,126 @@ Host: http://BROKER_IP:BROKER_PORT
#### Sample response
-A successful response to this endpoint results in an empty response body.
\ No newline at end of file
+A successful response to this endpoint results in an empty response body.
+
+### Get Historical Cloning Status
+
+Retrieves the current status of Historical cloning.
+
+#### URL
+
+`GET` `/druid/coordinator/v1/cloneStatus`
+
+#### Responses
+
+<Tabs>
+
+<TabItem value="56" label="200 SUCCESS">
+
+
+<br/>
+
+*Successfully retrieved cloning status*
+
+</TabItem>
+</Tabs>
+
+#### Sample request
+
+<Tabs>
+
+<TabItem value="58" label="cURL">
+
+
+```shell
+curl "http://COORDINATOR_IP:COORDINATOR_PORT/druid/coordinator/v1/cloneStatus"
+```
+
+</TabItem>
+<TabItem value="59" label="HTTP">
+
+
+```http
+GET /druid/coordinator/v1/cloneStatus HTTP/1.1
+Host: http://COORDINATOR_IP:COORDINATOR_PORT
+```
+
+</TabItem>
+</Tabs>
+
+#### Sample response
+
+<details>
+ <summary>View the response</summary>
+
+```json
+{
+ "localhost:8083": {
+ "sourceServer": "localhost:8089",
+ "status": "LOADING",
+ "segmentLoadsRemaining": 0,
+ "segmenetsDropsRemaining": 0,
+ "bytesRemaining": 0
+ }
+}
+```
+
+</details>
+
+### Get Broker dynamic configuration view
+
+Retrieves the list of Brokers which have an up-to-date view of Coordinator dynamic configuration.
+
+#### URL
+
+`GET` `/druid/coordinator/v1/brokerConfigurationStatus`
+
+#### Responses
+
+<Tabs>
+
+<TabItem value="56" label="200 SUCCESS">
+
+
+<br/>
+
+*Successfully retrieved Broker Configuration view*
+
+</TabItem>
+</Tabs>
+
+#### Sample request
+
+<Tabs>
+
+<TabItem value="58" label="cURL">
+
+
+```shell
+curl "http://COORDINATOR_IP:COORDINATOR_PORT/druid/coordinator/v1/brokerConfigurationStatus"
+```
+
+</TabItem>
+<TabItem value="59" label="HTTP">
+
+
+```http
+GET /druid/coordinator/v1/brokerConfigurationStatus HTTP/1.1
+Host: http://COORDINATOR_IP:COORDINATOR_PORT
+```
+
+</TabItem>
+</Tabs>
+
+#### Sample response
+
+<details>
+ <summary>View the response</summary>
+
+```json
+[
+ "localhost:8082"
+]
Review Comment:
Include more info in the response, and avoid returning a JSON array. Return a JSON object instead.
A JSON object lends itself better to be extended easily in the future.
```
"syncedBrokers": [
{"host": "broker1", "lastSyncTime": 123456789},
{"host": "broker2", "lastSyncTime": 123456789}
]
```
##########
server/src/main/java/org/apache/druid/server/DruidInternalDynamicConfigResource.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import com.google.inject.Inject;
+import com.sun.jersey.spi.container.ResourceFilters;
+import org.apache.druid.client.CoordinatorDynamicConfigView;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.apache.druid.server.http.security.ConfigResourceFilter;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@Path("/druid-internal/v1/dynamicConfiguration")
+public class DruidInternalDynamicConfigResource
+{
+ private final CoordinatorDynamicConfigView coordinatorDynamicConfigView;
+
+ @Inject
+ public DruidInternalDynamicConfigResource(CoordinatorDynamicConfigView coordinatorDynamicConfigView)
+ {
+ this.coordinatorDynamicConfigView = coordinatorDynamicConfigView;
+ }
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @ResourceFilters(ConfigResourceFilter.class)
+ @Path("/coordinatorDynamicConfig")
Review Comment:
```suggestion
@Path("/coordinator")
```
##########
server/src/main/java/org/apache/druid/server/coordinator/CloneStatusManager.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.druid.server.coordinator.loading.SegmentAction;
+import org.apache.druid.timeline.DataSegment;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class CloneStatusManager
Review Comment:
Please add short javadocs for the class and the methods.
##########
server/src/main/java/org/apache/druid/server/DruidInternalDynamicConfigResource.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * 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;
+
+import com.google.inject.Inject;
+import org.apache.druid.client.DynamicConfigurationManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@Path("/druid-internal/v1/dynamicConfiguration")
+public class DruidInternalDynamicConfigResource
Review Comment:
Sure, that's fair.
##########
server/src/main/java/org/apache/druid/server/coordinator/CloneStatusManager.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.druid.server.coordinator.loading.SegmentAction;
+import org.apache.druid.timeline.DataSegment;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class CloneStatusManager
+{
+ private final AtomicReference<Map<String, CloneStatusMetrics>> cloneStatusSnapshot;
+
+ public CloneStatusManager()
+ {
+ this.cloneStatusSnapshot = new AtomicReference<>(ImmutableMap.of());
+ }
+
+ public Map<String, CloneStatusMetrics> getStatusForAllServers()
+ {
+ return cloneStatusSnapshot.get();
+ }
+
+ public CloneStatusMetrics getStatusForServer(String targetServer)
+ {
+ return cloneStatusSnapshot.get().get(targetServer);
+ }
+
+ public void updateStats(Map<String, ServerHolder> historicalMap, Map<String, String> cloneServers)
+ {
+ final Map<String, CloneStatusMetrics> newStatusMap = new HashMap<>();
+
+ for (Map.Entry<String, String> entry : cloneServers.entrySet()) {
+ final String targetServerName = entry.getKey();
+ final ServerHolder targetServer = historicalMap.get(entry.getKey());
+ final String sourceServerName = entry.getValue();
+
+ long segmentLoad = 0L;
+ long bytesLeft = 0L;
+ long segmentDrop = 0L;
+
+ CloneStatusMetrics newStatus;
+ if (targetServer == null) {
+ newStatus = CloneStatusMetrics.unknown(sourceServerName);
+ } else {
+
+ CloneStatusMetrics.Status status;
+ if (!historicalMap.containsKey(sourceServerName)) {
+ status = CloneStatusMetrics.Status.SOURCE_SERVER_MISSING;
+ } else {
+ status = CloneStatusMetrics.Status.LOADING;
+ }
+
+ for (Map.Entry<DataSegment, SegmentAction> queuedSegment : targetServer.getQueuedSegments().entrySet()) {
+ if (queuedSegment.getValue().isLoad()) {
+ segmentLoad += 1;
+ bytesLeft += queuedSegment.getKey().getSize();
+ } else {
+ segmentDrop += 1;
+ }
+ }
+ newStatus = new CloneStatusMetrics(sourceServerName, status, segmentLoad, segmentDrop, bytesLeft);
+ }
+ newStatusMap.put(targetServerName, newStatus);
+ }
+
+ cloneStatusSnapshot.set(ImmutableMap.copyOf(newStatusMap));
Review Comment:
Let's move all of this logic into the duty and just send the final status objects to this class.
##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/dart/controller/DartTableInputSpecSlicer.java:
##########
@@ -162,7 +163,7 @@ public List<InputSlice> sliceDynamic(
*/
int findWorkerForServerSelector(final ServerSelector serverSelector, final int maxNumSlices)
{
- final QueryableDruidServer server = serverSelector.pick(null);
+ final QueryableDruidServer server = serverSelector.pick(null, HistoricalFilter.IDENTITY_FILTER);
Review Comment:
+1
##########
server/src/main/java/org/apache/druid/client/selector/HistoricalFilter.java:
##########
@@ -0,0 +1,39 @@
+package org.apache.druid.client.selector;
+
+import com.google.common.collect.ImmutableSet;
+import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
+import org.apache.druid.client.QueryableDruidServer;
+
+import java.util.Set;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+
+public class HistoricalFilter implements Function<Int2ObjectRBTreeMap<Set<QueryableDruidServer>>, Int2ObjectRBTreeMap<Set<QueryableDruidServer>>>
Review Comment:
This still needs to be addressed.
##########
server/src/main/java/org/apache/druid/server/coordinator/CloneStatusManager.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.druid.server.coordinator.loading.SegmentAction;
+import org.apache.druid.timeline.DataSegment;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class CloneStatusManager
+{
+ private final AtomicReference<Map<String, CloneStatusMetrics>> cloneStatusSnapshot;
+
+ public CloneStatusManager()
+ {
+ this.cloneStatusSnapshot = new AtomicReference<>(ImmutableMap.of());
+ }
+
+ public Map<String, CloneStatusMetrics> getStatusForAllServers()
+ {
+ return cloneStatusSnapshot.get();
+ }
+
+ public CloneStatusMetrics getStatusForServer(String targetServer)
+ {
+ return cloneStatusSnapshot.get().get(targetServer);
+ }
+
+ public void updateStats(Map<String, ServerHolder> historicalMap, Map<String, String> cloneServers)
Review Comment:
```suggestion
public void updateStatus(Map<String, ServerHolder> historicalMap, Map<String, String> cloneServers)
```
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2051912653
##########
server/src/main/java/org/apache/druid/server/BrokerQueryResource.java:
##########
@@ -89,19 +97,22 @@ public Response getQueryTargets(
InputStream in,
@QueryParam("pretty") String pretty,
@QueryParam("numCandidates") @DefaultValue("-1") int numCandidates,
+ @QueryParam("cloneQueryMode") @Nullable CloneQueryMode cloneQueryMode,
@Context final HttpServletRequest req
) throws IOException
{
final ResourceIOReaderWriter ioReaderWriter = createResourceIOReaderWriter(req, pretty != null);
try {
Query<?> query = ioReaderWriter.getRequestMapper().readValue(in, Query.class);
ExecutionVertex ev = ExecutionVertex.of(query);
+ HistoricalFilter historicalFilter = new HistoricalFilter(configView, cloneQueryMode == null ? QueryContexts.DEFAULT_CLONE_QUERY_MODE : cloneQueryMode);
Review Comment:
Use `QueryContexts.getAsEnum()` here to get the enum from the String (once the arg is updated).
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052100450
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorDynamicConfigSyncer.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.http;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import org.apache.druid.discovery.DiscoveryDruidNode;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHandler;
+import org.apache.druid.java.util.http.client.response.BytesFullResponseHolder;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.RequestBuilder;
+import org.apache.druid.rpc.ServiceClient;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.StandardRetryPolicy;
+import org.apache.druid.server.coordinator.CoordinatorConfigManager;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.jboss.netty.handler.codec.http.HttpMethod;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+
+import java.net.URL;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
+/**
+ * Updates all brokers with the latest coordinator dynamic config.
+ */
+public class CoordinatorDynamicConfigSyncer
+{
+ private static final Logger log = new Logger(CoordinatorDynamicConfigSyncer.class);
+
+ private final CoordinatorConfigManager configManager;
+ private final ObjectMapper jsonMapper;
+ private final DruidNodeDiscoveryProvider druidNodeDiscovery;
+
+ private final AtomicReference<CoordinatorDynamicConfig> lastKnownConfig = new AtomicReference<>();
+ private final ServiceClientFactory clientFactory;
+ private final ExecutorService exec;
+ private final Set<String> inSyncBrokers;
+
+ @Inject
+ public CoordinatorDynamicConfigSyncer(
+ @EscalatedGlobal final ServiceClientFactory clientFactory,
Review Comment:
Yes, that's correct. We would still use the `ServiceClientFactory` but instead of building a `ServiceClient` in the `pushConfigToBroker` method, we would construct a `BrokerClient` so that some of the boilerplate code can be removed from this class.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Add changes to prevent Broker from querying cloned Historicals (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17899:
URL: https://github.com/apache/druid/pull/17899#discussion_r2052094813
##########
server/src/main/java/org/apache/druid/server/coordinator/CoordinatorDynamicConfig.java:
##########
@@ -191,6 +192,30 @@ private Map<Dimension, String> validateDebugDimensions(Map<String, String> debug
return validDebugDimensions;
}
+ public CoordinatorDynamicConfig snapshot()
Review Comment:
Ideally, if the config is immutable, the sets it uses should be immutable too.
So, you can update the constructor to make sure that everything is immutable (but that doesn't really feel necessary to me at this point either).
Making a duplicate copy (i.e. without any changes) of an immutable object does not add any value.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org