cchung100m commented on code in PR #8990:
URL: https://github.com/apache/ozone/pull/8990#discussion_r2594464783
##########
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:
Hi @adoroszlai
We might encounter race condition issue if we modified this.replicaMap
directly:
> T result = update.apply(this.replicaMap);
this.replicas = Collections.unmodifiableSet(new
HashSet<>(this.replicaMap.values()));
--
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]