adoroszlai commented on code in PR #8990:
URL: https://github.com/apache/ozone/pull/8990#discussion_r2593397621
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/states/ContainerEntry.java:
##########
@@ -42,14 +44,22 @@ public ContainerInfo getInfo() {
}
public Set<ContainerReplica> getReplicas() {
- return new HashSet<>(replicas.values());
+ return replicas;
}
public ContainerReplica put(ContainerReplica r) {
- return replicas.put(r.getDatanodeDetails().getID(), r);
+ return copyAndUpdate(map -> map.put(r.getDatanodeDetails().getID(), r));
}
public ContainerReplica removeReplica(DatanodeID datanodeID) {
- return replicas.remove(datanodeID);
+ return copyAndUpdate(map -> map.remove(datanodeID));
+ }
+
+ private <T> T copyAndUpdate(java.util.function.Function<Map<DatanodeID,
ContainerReplica>, T> update) {
+ Map<DatanodeID, ContainerReplica> map = new HashMap<>(this.replicaMap);
+ T result = update.apply(map);
+ this.replicaMap = map;
+ this.replicas = Collections.unmodifiableSet(new HashSet<>(map.values()));
Review Comment:
With `new HashSet<>(map.values())` we can keep the same `replicaMap`, no
need to re-create for each update.
--
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]