You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2022/06/14 14:58:45 UTC

[GitHub] [ozone] adoroszlai commented on a diff in pull request #3482: HDDS-6829. Limit the no of inflight replication tasks in SCM.

adoroszlai commented on code in PR #3482:
URL: https://github.com/apache/ozone/pull/3482#discussion_r896936558


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/LegacyReplicationManager.java:
##########
@@ -102,6 +105,111 @@ public class LegacyReplicationManager {
   public static final Logger LOG =
       LoggerFactory.getLogger(LegacyReplicationManager.class);
 
+  static class InflightMap {
+    private final Map<ContainerID, List<InflightAction>> map
+        = new ConcurrentHashMap<>();
+    private final InflightType type;
+    private final int sizeLimit;
+    private final AtomicInteger inflightCount = new AtomicInteger();
+
+    InflightMap(InflightType type, int sizeLimit) {
+      this.type = type;
+      this.sizeLimit = sizeLimit > 0 ? sizeLimit : Integer.MAX_VALUE;
+    }
+
+    boolean isReplication() {
+      return type == InflightType.REPLICATION;
+    }
+
+    private List<InflightAction> get(ContainerID id) {
+      return map.get(id);
+    }
+
+    boolean containsKey(ContainerID id) {
+      return map.containsKey(id);
+    }
+
+    int inflightActionCount(ContainerID id) {
+      return Optional.ofNullable(map.get(id)).map(List::size).orElse(0);
+    }
+
+    int containerCount() {
+      return map.size();
+    }
+
+    boolean isFull() {
+      return inflightCount.get() >= sizeLimit;
+    }
+
+    void clear() {
+      map.clear();
+    }
+
+    void iterate(ContainerID id, Function<InflightAction, Boolean> processor) {
+      for (; ;) {
+        final List<InflightAction> actions = get(id);
+        if (actions == null) {
+          return;
+        }
+        synchronized (actions) {
+          if (get(id) != actions) {
+            continue; //actions is changed, retry
+          }
+          for (Iterator<InflightAction> i = actions.iterator(); i.hasNext();) {
+            final Boolean remove = processor.apply(i.next());
+            if (remove == Boolean.TRUE) {

Review Comment:
   > The windbags failure does not seem related to this.
   
   `M B RC: Suspicious comparison of Boolean references in org.apache.hadoop.hdds.scm.container.replication.LegacyReplicationManager$InflightMap.iterate(ContainerID, Function)  At LegacyReplicationManager.java:[line 160]`
   
   I think it is related, assuming windbags == findbugs. :)
   
   Maybe I'm missing something, but can we use `Predicate<InflightAction>` instead of `Function<InflightAction, Boolean>`?



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org