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 2022/10/28 21:30:45 UTC

[GitHub] [druid] a2l007 commented on a diff in pull request #13269: Add a OverlordHelper that cleans up durable storage objects in MSQ

a2l007 commented on code in PR #13269:
URL: https://github.com/apache/druid/pull/13269#discussion_r1008503684


##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/indexing/DurableStorageCleaner.java:
##########
@@ -0,0 +1,106 @@
+/*
+ * 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.msq.indexing;
+
+import com.google.common.collect.Sets;
+import com.google.inject.Inject;
+import org.apache.druid.indexing.overlord.TaskRunner;
+import org.apache.druid.indexing.overlord.TaskRunnerWorkItem;
+import org.apache.druid.indexing.overlord.helpers.OverlordHelper;
+import org.apache.druid.java.util.common.concurrent.ScheduledExecutors;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.msq.shuffle.DurableStorageOutputChannelFactory;
+import org.apache.druid.storage.StorageConnector;
+import org.joda.time.Duration;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.stream.Collectors;
+
+/**
+ * This method polls the durable storage for any stray directories, i.e. the ones that donot have a controller task
+ * associated with it and cleans them periodically.
+ * This ensures that the tasks which that have exited abruptly or have failed to clean up the durable storage themselves
+ * donot pollute it with worker outputs and temporary files. See {@link DurableStorageCleanerConfig} for the configs.
+ */
+public class DurableStorageCleaner implements OverlordHelper
+{
+
+  private static final Logger LOG = new Logger(DurableStorageCleaner.class);
+
+  private final DurableStorageCleanerConfig config;
+  private final StorageConnector storageConnector;
+  private final TaskRunner taskRunner;
+
+  @Inject
+  public DurableStorageCleaner(
+      final DurableStorageCleanerConfig config,
+      final StorageConnector storageConnector,
+      final TaskRunner taskRunner
+  )
+  {
+    this.config = config;
+    this.storageConnector = storageConnector;
+    this.taskRunner = taskRunner;
+  }
+
+  @Override
+  public boolean isEnabled()
+  {
+    return config.isEnabled();
+  }
+
+  @Override
+  public void schedule(ScheduledExecutorService exec)
+  {
+    LOG.info("Starting the DurableStorageCleaner with the config [%s]", config);
+
+    ScheduledExecutors.scheduleWithFixedDelay(
+        exec,
+        Duration.standardSeconds(config.getInitialDelaySeconds()),
+        Duration.standardSeconds(config.getDelaySeconds()),
+        () -> {
+          try {
+            Set<String> allDirectories = new HashSet<>(storageConnector.ls(""));
+            Set<String> runningTaskIds = taskRunner.getRunningTasks()
+                                                   .stream()
+                                                   .map(TaskRunnerWorkItem::getTaskId)
+                                                   .map(DurableStorageOutputChannelFactory::getControllerDirectory)
+                                                   .collect(Collectors.toSet());
+            Set<String> unknownDirectories = Sets.difference(allDirectories, runningTaskIds);
+            LOG.info(
+                "Following directories donot have a corresponding MSQ task associated with it:\n%s\nThese will get cleaned up.",
+                unknownDirectories
+            );
+            for (String unknownDirectory : unknownDirectories) {
+              LOG.info("");

Review Comment:
   Can we log the directory name here?



##########
core/src/main/java/org/apache/druid/storage/StorageConnector.java:
##########
@@ -104,4 +105,6 @@
    * @throws IOException
    */
   void deleteRecursively(String path) throws IOException;
+
+  List<String> ls(String dirName) throws IOException;

Review Comment:
   Can we make the method name more readable, `listFiles` maybe? Javadocs and unit tests would be useful for this method as well.



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