You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2020/05/28 02:11:15 UTC

[GitHub] [druid] gianm commented on a change in pull request #9603: Add new round robin strategy for loading segments.

gianm commented on a change in pull request #9603:
URL: https://github.com/apache/druid/pull/9603#discussion_r431543156



##########
File path: server/src/main/java/org/apache/druid/server/coordinator/DruidCoordinatorRuntimeParams.java
##########
@@ -56,11 +64,50 @@
     return segmentsSet;
   }
 
+  /**
+   * Creates a {@link Set} by choosing used segments from each datasource in a round robin fashion.
+   * The order of segments picked for a datasource is dependent on the iteration order of
+   * {@link ImmutableDruidDataSource#getSegments()}. So if it is desired to have newer segments
+   * be picked up before the older ones, the {@link Collection} returned by {@link ImmutableDruidDataSource#getSegments()}
+   * needs to be setup accordingly.
+   */
+  private static Set<DataSegment> createUsedSegmentSetInRoundRobinFashion(Map<String, ImmutableDruidDataSource> dataSourcesWithAllUsedSegments)

Review comment:
       It would be nice to have some symmetry between this method and `createUsedSegmentsSet`. Maybe they could both accept a DataSourcesSnapshot and both return a Set. Unifying them under a LoadSegmentStrategy interface as suggested by another comment might be a good way to do that.
   
   What do you think?

##########
File path: server/src/main/java/org/apache/druid/client/ImmutableDruidDataSource.java
##########
@@ -53,7 +53,10 @@ public ImmutableDruidDataSource(String name, Map<String, String> properties, Map
   {
     this.name = Preconditions.checkNotNull(name);
     this.properties = ImmutableMap.copyOf(properties);
-    this.idToSegments = ImmutableSortedMap.copyOf(idToSegments);
+    // By setting the order to reverse, for a datasource, newer segments will be ordered before older ones.

Review comment:
       Why is this being done, though?
   
   The comment should ideally mention it.

##########
File path: server/src/main/java/org/apache/druid/server/coordinator/DruidCoordinator.java
##########
@@ -667,17 +667,21 @@ public void run()
         // Do coordinator stuff.
         DataSourcesSnapshot dataSourcesSnapshot = segmentsMetadataManager.getSnapshotOfDataSourcesWithAllUsedSegments();
 
-        DruidCoordinatorRuntimeParams params =
-            DruidCoordinatorRuntimeParams
-                .newBuilder()
-                .withDatabaseRuleManager(metadataRuleManager)
-                .withStartTimeNanos(startTimeNanos)
-                .withSnapshotOfDataSourcesWithAllUsedSegments(dataSourcesSnapshot)
-                .withDynamicConfigs(getDynamicConfigs())
-                .withCompactionConfig(getCompactionConfig())
-                .withEmitter(emitter)
-                .withBalancerStrategy(balancerStrategy)
-                .build();
+        boolean useRoundRobinSegmentLoad = config.getLoadSegmentStrategy().equalsIgnoreCase("roundRobin");

Review comment:
       I know that `druid.coordinator.loadqueuepeon.type` is done this way, but it's not great, because it doesn't validate inputs. If a user typos something or puts in in invalid value then they will silently get the `newFirst` behavior. Could you please improve this, in one of the following ways? (Either one is ok by me.)
   
   1. Check that the strategy is either `roundRobin` or `newFirst`, and if it's neither, then throw an IllegalArgumentException. It'd be good to do that in its own method and include a unit test for it. It could even be a method the `DruidCoordinatorConfig` class. You could potentially introduce a LoadSegmentStrategy interface, with two implementations, and add a `config.makeLoadSegmentStrategy()` method that creates the right one.
   
   2. Do the JsonConfigProvider method that is more common in Druid. (The config-magic approach used by DruidCoordinatorConfig is a bit unconventional). To do this: (1) introduce a LoadSegmentStrategy interface with Jackson deserialization info (like below), then bind it in CliCoordinator with JsonConfigProvider.
   
   If you're doing (2), the LoadSegmentStrategy interface would look something like this:
   
   ```java
   @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "strategy")
   @JsonSubTypes(value = {
           @JsonSubTypes.Type(name = "newFirst", value = NewFirstLoadSegmentStrategy.class),
           @JsonSubTypes.Type(name = "roundRobin", value = RoundRobinLoadSegmentStrategy.class)
   })
   public interface LoadSegmentStrategy
   {
     /**
       * Some appropriate docs about the method contract.
       */
     Set<DataSegment> getUsedSegments(DataSourceSnapshot snapshot);
   }
   ```
   
   The binding in CliCoordinator would look like:
   
   ```java
   JsonConfigProvider.bindWithDefault(
     binder,
     "druid.coordinator.load.segment",
     LoadSegmentStrategy.class,
     NewFirstLoadSegmentStrategy.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.

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