You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uniffle.apache.org by ro...@apache.org on 2023/03/10 07:12:39 UTC

[incubator-uniffle] branch master updated: [MINOR] fix: Add method `close` for ApplicationManager (#704)

This is an automated email from the ASF dual-hosted git repository.

roryqi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-uniffle.git


The following commit(s) were added to refs/heads/master by this push:
     new 40725078 [MINOR] fix: Add  method `close` for ApplicationManager (#704)
40725078 is described below

commit 4072507836f2758cb59fa1a38813d2ed8843bba4
Author: roryqi <ro...@apache.org>
AuthorDate: Fri Mar 10 15:12:34 2023 +0800

    [MINOR] fix: Add  method `close` for ApplicationManager (#704)
    
    ### What changes were proposed in this pull request?
    Add  method `close` for ApplicationManager
    
    ### Why are the changes needed?
    Clean resources while testing. It will improve the stability of our test.
    
    ### Does this PR introduce _any_ user-facing change?
    No.
    
    ### How was this patch tested?
    GA passed
---
 .../apache/uniffle/coordinator/ApplicationManager.java  | 17 ++++++++++++++---
 .../apache/uniffle/coordinator/CoordinatorServer.java   |  3 +++
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/coordinator/src/main/java/org/apache/uniffle/coordinator/ApplicationManager.java b/coordinator/src/main/java/org/apache/uniffle/coordinator/ApplicationManager.java
index 193a28ee..b5e3f740 100644
--- a/coordinator/src/main/java/org/apache/uniffle/coordinator/ApplicationManager.java
+++ b/coordinator/src/main/java/org/apache/uniffle/coordinator/ApplicationManager.java
@@ -17,6 +17,7 @@
 
 package org.apache.uniffle.coordinator;
 
+import java.io.Closeable;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Arrays;
@@ -46,7 +47,7 @@ import org.apache.uniffle.coordinator.strategy.storage.RankValue;
 import org.apache.uniffle.coordinator.strategy.storage.SelectStorageStrategy;
 import org.apache.uniffle.coordinator.util.CoordinatorUtils;
 
-public class ApplicationManager {
+public class ApplicationManager implements Closeable {
 
   private static final Logger LOG = LoggerFactory.getLogger(ApplicationManager.class);
   // TODO: Add anomaly detection for other storage
@@ -62,6 +63,7 @@ public class ApplicationManager {
   private final Map<String, String> remoteStorageToHost = Maps.newConcurrentMap();
   private final Map<String, RemoteStorageInfo> availableRemoteStorageInfo;
   private final ScheduledExecutorService detectStorageScheduler;
+  private final ScheduledExecutorService checkAppScheduler;
   private Map<String, Map<String, Long>> currentUserAndApp = Maps.newConcurrentMap();
   private Map<String, String> appIdToUser = Maps.newConcurrentMap();
   private QuotaManager quotaManager;
@@ -93,9 +95,9 @@ public class ApplicationManager {
       }
     }
     // the thread for checking application status
-    ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(
+    checkAppScheduler = Executors.newSingleThreadScheduledExecutor(
         ThreadUtils.getThreadFactory("ApplicationManager-%d"));
-    scheduledExecutorService.scheduleAtFixedRate(
+    checkAppScheduler.scheduleAtFixedRate(
         this::statusCheck, expired / 2, expired / 2, TimeUnit.MILLISECONDS);
     // the thread for checking if the storage is normal
     detectStorageScheduler = Executors.newSingleThreadScheduledExecutor(
@@ -350,6 +352,15 @@ public class ApplicationManager {
     return REMOTE_PATH_SCHEMA;
   }
 
+  public void close() {
+    if (detectStorageScheduler != null) {
+      detectStorageScheduler.shutdownNow();
+    }
+    if (checkAppScheduler != null) {
+      checkAppScheduler.shutdownNow();
+    }
+  }
+
   public enum StrategyName {
     APP_BALANCE,
     IO_SAMPLE
diff --git a/coordinator/src/main/java/org/apache/uniffle/coordinator/CoordinatorServer.java b/coordinator/src/main/java/org/apache/uniffle/coordinator/CoordinatorServer.java
index a016df6a..0ac8f246 100644
--- a/coordinator/src/main/java/org/apache/uniffle/coordinator/CoordinatorServer.java
+++ b/coordinator/src/main/java/org/apache/uniffle/coordinator/CoordinatorServer.java
@@ -120,6 +120,9 @@ public class CoordinatorServer extends ReconfigurableBase {
     if (jettyServer != null) {
       jettyServer.stop();
     }
+    if (applicationManager != null) {
+      applicationManager.close();
+    }
     if (clusterManager != null) {
       clusterManager.close();
     }