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 2021/05/10 19:27:51 UTC

[GitHub] [druid] clintropolis commented on a change in pull request #11144: Make sure updating coordinator config is protected against race condition

clintropolis commented on a change in pull request #11144:
URL: https://github.com/apache/druid/pull/11144#discussion_r629623614



##########
File path: core/src/main/java/org/apache/druid/common/config/ConfigManager.java
##########
@@ -168,64 +171,99 @@ private void poll()
     return holder.getReference();
   }
 
-
   public <T> SetResult set(final String key, final ConfigSerde<T> serde, final T obj)
   {
-    if (obj == null || !started) {
-      if (obj == null) {
-        return SetResult.fail(new IllegalAccessException("input obj is null"));
+    return set(key, serde, null, obj);
+  }
+
+  public <T> SetResult set(final String key, final ConfigSerde<T> serde, @Nullable final T oldObject, final T newObject)
+  {
+    if (newObject == null || !started) {
+      if (newObject == null) {
+        return SetResult.fail(new IllegalAccessException("input obj is null"), false);

Review comment:
       super nitpick: i know this isn't new or your fault, but "obj" doesn't seem to need to be shortened

##########
File path: server/src/main/java/org/apache/druid/server/http/CoordinatorCompactionConfigsResource.java
##########
@@ -162,27 +165,68 @@ public Response deleteCompactionConfig(
       @Context HttpServletRequest req
   )
   {
-    final CoordinatorCompactionConfig current = CoordinatorCompactionConfig.current(manager);
-    final Map<String, DataSourceCompactionConfig> configs = current
-        .getCompactionConfigs()
-        .stream()
-        .collect(Collectors.toMap(DataSourceCompactionConfig::getDataSource, Function.identity()));
+    Callable<SetResult> callable = () -> {
+      final CoordinatorCompactionConfig current = CoordinatorCompactionConfig.current(manager);
+      final Map<String, DataSourceCompactionConfig> configs = current
+          .getCompactionConfigs()
+          .stream()
+          .collect(Collectors.toMap(DataSourceCompactionConfig::getDataSource, Function.identity()));
+
+      final DataSourceCompactionConfig config = configs.remove(dataSource);
+      if (config == null) {
+        return SetResult.fail(new NoSuchElementException("datasource not found"), false);
+      }
+
+      return manager.set(
+          CoordinatorCompactionConfig.CONFIG_KEY,
+          // Do database insert without swap if the current config is empty as this means the config may be null in the database
+          CoordinatorCompactionConfig.empty().equals(current) ? null : current,
+          CoordinatorCompactionConfig.from(current, ImmutableList.copyOf(configs.values())),
+          new AuditInfo(author, comment, req.getRemoteAddr())
+      );
+    };
+    return updateConfigHelper(callable);
+  }
 
-    final DataSourceCompactionConfig config = configs.remove(dataSource);
-    if (config == null) {
-      return Response.status(Response.Status.NOT_FOUND).build();
+  @VisibleForTesting
+  Response updateConfigHelper(Callable<SetResult> updateMethod)
+  {
+    int attemps = 0;
+    SetResult setResult = null;
+    try {
+      while (attemps < UPDATE_NUM_RETRY) {
+        setResult = updateMethod.call();
+        if (setResult.isOk() || !setResult.isRetryable()) {
+          break;
+        }
+        attemps++;
+        updateRetryDelay();
+      }
+    }

Review comment:
       Does RetryUtils not suitable for some 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.

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