You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "jakubmatyszewski (via GitHub)" <gi...@apache.org> on 2024/09/17 09:33:34 UTC

[PR] Overlord incremental select worker strategy (druid)

jakubmatyszewski opened a new pull request, #14934:
URL: https://github.com/apache/druid/pull/14934

   ### Description
   
   I was trying to use existing `fillCapacity` select worker strategy in an effort to implement MiddleManager autoscaling, but since MM instances that I use are created by k8s statefulsets it wasn't consistent enough. Proposed strategy fills capacity based on worker's hostname, with assumption that host is k8s FQDN - eg. `druid-middlemanager-0.druid-middlemanager.druid-test.svc.cluster.local:8091`.
   
   Similar problem was discussed in https://github.com/apache/druid/issues/8801.
   I'm not sure if this feature is desirable and this is my first java admission, so I'll take every bit of critique here. I can add tests if it will appear that this feature might be useful and we want to add it to codebase.
   
   ##### Key changed/added classes in this PR
    * `FillIncrementallyWorkerSelectStrategy`
    * `FillIncrementallyWithAffinityWorkerSelectStrategy`
    * `FillIncrementallyWithCategorySpecWorkerSelectStrategy`
   
   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.
   - [x] 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] Overlord incremental select worker strategy (druid)

Posted by "github-code-scanning[bot] (via GitHub)" <gi...@apache.org>.
github-code-scanning[bot] commented on code in PR #14934:
URL: https://github.com/apache/druid/pull/14934#discussion_r1311470783


##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/setup/FillIncrementallyWorkerSelectStrategy.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.indexing.overlord.setup;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.collect.ImmutableMap;
+import org.apache.druid.indexing.common.task.Task;
+import org.apache.druid.indexing.overlord.ImmutableWorkerInfo;
+import org.apache.druid.indexing.overlord.config.WorkerTaskRunnerConfig;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+public class FillIncrementallyWorkerSelectStrategy implements WorkerSelectStrategy
+{
+  private final AffinityConfig affinityConfig;
+
+  @JsonCreator
+  public FillIncrementallyWorkerSelectStrategy(
+      @JsonProperty("affinityConfig") AffinityConfig affinityConfig
+  )
+  {
+    this.affinityConfig = affinityConfig;
+  }
+
+  @JsonProperty
+  public AffinityConfig getAffinityConfig()
+  {
+    return affinityConfig;
+  }
+
+  @Override
+  public ImmutableWorkerInfo findWorkerForTask(
+      final WorkerTaskRunnerConfig config,
+      final ImmutableMap<String, ImmutableWorkerInfo> zkWorkers,
+      final Task task
+  )
+  {
+    return WorkerSelectUtils.selectWorker(
+        task,
+        zkWorkers,
+        config,
+        affinityConfig,
+        FillIncrementallyWorkerSelectStrategy::selectFromEligibleWorkers
+    );
+  }
+
+  static ImmutableWorkerInfo selectFromEligibleWorkers(final Map<String, ImmutableWorkerInfo> eligibleWorkers)
+  {
+    List<ImmutableWorkerInfo> sortedWorkers = eligibleWorkers.values()
+        .stream()
+        .sorted(
+          Comparator.comparing(
+            worker -> {
+              String host = worker.getWorker().getHost();
+              int hostNumber = extractHostNumber(host);
+              return hostNumber;
+            }
+          )
+        ).collect(Collectors.toList());
+
+    ImmutableWorkerInfo selectedWorker = null;
+
+    for (ImmutableWorkerInfo worker : sortedWorkers) {
+      if (worker.getAvailableCapacity() > 0) {
+        selectedWorker = worker;
+        break;
+      }
+    }
+
+    return selectedWorker;
+  }
+
+  private static int extractHostNumber(String host)
+  {
+    // Assumes the host format is based on k8s statefulset FQDN - "druid-middlemanager-<numeral>.druid-middlemanager..."
+    String[] parts = host.split("\\.");
+    String numeralPart = parts[0].substring(parts[0].lastIndexOf("-") + 1);
+    return Integer.parseInt(numeralPart);

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more details](https://github.com/apache/druid/security/code-scanning/5754)



-- 
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] Overlord incremental select worker strategy (druid)

Posted by "AmatyaAvadhanula (via GitHub)" <gi...@apache.org>.
AmatyaAvadhanula commented on PR #14934:
URL: https://github.com/apache/druid/pull/14934#issuecomment-2355043330

   @jakubmatyszewski, thank you for your contribution! Are you interested in reviving this PR?


-- 
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] Overlord incremental select worker strategy (druid)

Posted by "abhishekagarwal87 (via GitHub)" <gi...@apache.org>.
abhishekagarwal87 commented on PR #14934:
URL: https://github.com/apache/druid/pull/14934#issuecomment-1708100356

   thank you for your contribution. can you elaborate a bit on following 
   > but since MM instances that I use are created by k8s statefulsets it wasn't consistent enough.
   
   what is not consistent? 


-- 
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] Overlord incremental select worker strategy (druid)

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #14934:
URL: https://github.com/apache/druid/pull/14934#issuecomment-2480865309

   This pull request has been marked as stale due to 60 days of inactivity.
   It will be closed in 4 weeks if no further activity occurs. If you think
   that's incorrect or this pull request should instead be reviewed, please simply
   write any comment. Even if closed, you can still revive the PR at any time or
   discuss it on the dev@druid.apache.org list.
   Thank you for your contributions.


-- 
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] Overlord incremental select worker strategy (druid)

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #14934: Overlord incremental select worker strategy
URL: https://github.com/apache/druid/pull/14934


-- 
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] Overlord incremental select worker strategy (druid)

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #14934:
URL: https://github.com/apache/druid/pull/14934#issuecomment-2028506916

   This pull request/issue has been closed due to lack of activity. If you think that
   is incorrect, or the pull request requires review, you can revive the PR at any time.


-- 
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] Overlord incremental select worker strategy (druid)

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #14934: Overlord incremental select worker strategy
URL: https://github.com/apache/druid/pull/14934


-- 
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] Overlord incremental select worker strategy (druid)

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #14934:
URL: https://github.com/apache/druid/pull/14934#issuecomment-1974951697

   This pull request has been marked as stale due to 60 days of inactivity.
   It will be closed in 4 weeks if no further activity occurs. If you think
   that's incorrect or this pull request should instead be reviewed, please simply
   write any comment. Even if closed, you can still revive the PR at any time or
   discuss it on the dev@druid.apache.org list.
   Thank you for your contributions.


-- 
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] Overlord incremental select worker strategy (druid)

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #14934:
URL: https://github.com/apache/druid/pull/14934#issuecomment-2543388058

   This pull request/issue has been closed due to lack of activity. If you think that
   is incorrect, or the pull request requires review, you can revive the PR at any time.


-- 
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] Overlord incremental select worker strategy (druid)

Posted by "jakubmatyszewski (via GitHub)" <gi...@apache.org>.
jakubmatyszewski commented on PR #14934:
URL: https://github.com/apache/druid/pull/14934#issuecomment-1708132309

   > thank you for your contribution. can you elaborate a bit on following
   > 
   > > but since MM instances that I use are created by k8s statefulsets it wasn't consistent enough.
   > 
   > what is not consistent?
   
   For statefulset to scale down we need to take into consideration that:
   > When Pods are being deleted, they are terminated in reverse order, from {N-1..0}.
   
   But with existing `fillCapacity` overlord strategy it doesn't care on what host ordinal index it accumulates tasks - it **just** checks which middlemanager instance has highest `currCapacityUsed` value. So in scenarios when there are multiple middlemanagers with same amount of `currCapacityUsed` it seems like this strategy picks middlemanagers at random.


-- 
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