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


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/LegacyReplicationManager.java:
##########
@@ -102,6 +104,98 @@ public class LegacyReplicationManager {
   public static final Logger LOG =
       LoggerFactory.getLogger(LegacyReplicationManager.class);
 
+  enum Inflight {REPLICATION, DELETION}
+
+  static class InflightMap {
+    private final Map<ContainerID, List<InflightAction>> map
+        = new ConcurrentHashMap<>();
+    private final Inflight type;
+    private final int actionSizeLimit;
+
+    InflightMap(Inflight type, int actionSizeLimit) {
+      this.type = type;
+      this.actionSizeLimit = actionSizeLimit;
+    }
+
+    boolean isReplication() {
+      return type == Inflight.REPLICATION;
+    }
+
+    private List<InflightAction> get(ContainerID id) {
+      return map.get(id);
+    }
+
+    boolean containsKey(ContainerID id) {
+      return map.containsKey(id);
+    }
+
+    int size(ContainerID id) {
+      return Optional.ofNullable(map.get(id)).map(List::size).orElse(0);
+    }
+
+    int size() {
+      return map.size();
+    }
+
+    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 removed, retry
+          }
+          for (Iterator<InflightAction> i = actions.iterator(); i.hasNext(); ) 
{
+            final Boolean remove = processor.apply(i.next());
+            if (remove == Boolean.TRUE) {
+              i.remove();
+            }
+          }
+          map.computeIfPresent(id, (k, v) -> v == actions && v.isEmpty() ? 
null : v);
+        }
+      }
+    }
+
+    boolean add(ContainerID id, InflightAction a) {
+      for(;;) {
+        final List<InflightAction> actions = map.computeIfAbsent(id,
+            key -> new LinkedList<>());
+        synchronized (actions) {
+          if (get(id) != actions) {
+            continue; //actions is removed, retry
+          }
+          if (actions.size() >= actionSizeLimit) {

Review Comment:
   I also wonder if we would be better checking the size in 
`handleUnderReplicatedContainer()` and skipping it before doing all the work to 
find a new target etc. If there is no capacity to schedule a replica, they we 
,ay as well skip the work too.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to