You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@amoro.apache.org by cz...@apache.org on 2024/09/19 02:01:09 UTC

(amoro) branch master updated: [Amoro-3196]: Fix scheduling hungry issue (#3203)

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

czy006 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/amoro.git


The following commit(s) were added to refs/heads/master by this push:
     new 5027abe21 [Amoro-3196]: Fix scheduling hungry issue (#3203)
5027abe21 is described below

commit 5027abe21b43dc263be096e7dd879e37c5a74beb
Author: majin1102 <ma...@gmail.com>
AuthorDate: Thu Sep 19 10:01:05 2024 +0800

    [Amoro-3196]: Fix scheduling hungry issue (#3203)
    
    * Amoro-3196: Fix scheduling hungry issue
    
    * Apply spotless
    
    ---------
    
    Co-authored-by: majin.nathan <ma...@bytedance.com>
---
 .../amoro/server/optimizing/SchedulingPolicy.java  | 24 ++++++++++------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/amoro-ams/src/main/java/org/apache/amoro/server/optimizing/SchedulingPolicy.java b/amoro-ams/src/main/java/org/apache/amoro/server/optimizing/SchedulingPolicy.java
index 72dfdce76..c62a188b6 100644
--- a/amoro-ams/src/main/java/org/apache/amoro/server/optimizing/SchedulingPolicy.java
+++ b/amoro-ams/src/main/java/org/apache/amoro/server/optimizing/SchedulingPolicy.java
@@ -41,7 +41,6 @@ public class SchedulingPolicy {
 
   private final Map<ServerTableIdentifier, TableRuntime> tableRuntimeMap = new HashMap<>();
   private volatile String policyName;
-  private Comparator<TableRuntime> tableSorter;
   private final Lock tableLock = new ReentrantLock();
 
   public SchedulingPolicy(ResourceGroup group) {
@@ -55,17 +54,6 @@ public class SchedulingPolicy {
           Optional.ofNullable(optimizerGroup.getProperties())
               .orElseGet(Maps::newHashMap)
               .getOrDefault(SCHEDULING_POLICY_PROPERTY_NAME, QUOTA);
-      if (policyName.equalsIgnoreCase(QUOTA)) {
-        if (tableSorter == null || !(tableSorter instanceof QuotaOccupySorter)) {
-          tableSorter = new QuotaOccupySorter();
-        }
-      } else if (policyName.equalsIgnoreCase(BALANCED)) {
-        if (tableSorter == null || !(tableSorter instanceof BalancedSorter)) {
-          tableSorter = new BalancedSorter();
-        }
-      } else {
-        throw new IllegalArgumentException("Illegal scheduling policy: " + policyName);
-      }
     } finally {
       tableLock.unlock();
     }
@@ -81,13 +69,23 @@ public class SchedulingPolicy {
       fillSkipSet(skipSet);
       return tableRuntimeMap.values().stream()
           .filter(tableRuntime -> !skipSet.contains(tableRuntime.getTableIdentifier()))
-          .min(tableSorter)
+          .min(createSorterByPolicy())
           .orElse(null);
     } finally {
       tableLock.unlock();
     }
   }
 
+  private Comparator<TableRuntime> createSorterByPolicy() {
+    if (policyName.equalsIgnoreCase(QUOTA)) {
+      return new QuotaOccupySorter();
+    } else if (policyName.equalsIgnoreCase(BALANCED)) {
+      return new BalancedSorter();
+    } else {
+      throw new IllegalArgumentException("Illegal scheduling policy: " + policyName);
+    }
+  }
+
   public TableRuntime getTableRuntime(ServerTableIdentifier tableIdentifier) {
     tableLock.lock();
     try {