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

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


The following commit(s) were added to refs/heads/master by this push:
     new ea4769b049 HDDS-10210. Ensure atomic update in 
StateContext#updateCommandStatus (#6091)
ea4769b049 is described below

commit ea4769b04928dbf190fdab07be0790d40b90216e
Author: Ivan Andika <[email protected]>
AuthorDate: Fri Jan 26 19:15:14 2024 +0800

    HDDS-10210. Ensure atomic update in StateContext#updateCommandStatus (#6091)
---
 .../container/common/statemachine/StateContext.java     | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git 
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/StateContext.java
 
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/StateContext.java
index 13f7ad6150..6bbf8e4794 100644
--- 
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/StateContext.java
+++ 
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/StateContext.java
@@ -893,18 +893,21 @@ public class StateContext {
   }
 
   /**
-   * Updates status of a pending status command.
+   * Updates the command status of a pending command.
    * @param cmdId       command id
    * @param cmdStatusUpdater Consumer to update command status.
-   * @return true if command status updated successfully else false.
+   * @return true if command status updated successfully else if the command
+   * associated with the command id does not exist in the context.
    */
   public boolean updateCommandStatus(Long cmdId,
       Consumer<CommandStatus> cmdStatusUpdater) {
-    if (cmdStatusMap.containsKey(cmdId)) {
-      cmdStatusUpdater.accept(cmdStatusMap.get(cmdId));
-      return true;
-    }
-    return false;
+    CommandStatus updatedCommandStatus = cmdStatusMap.computeIfPresent(cmdId,
+        (key, value) -> {
+          cmdStatusUpdater.accept(value);
+          return value;
+        }
+    );
+    return updatedCommandStatus != null;
   }
 
   public void configureHeartbeatFrequency() {


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

Reply via email to