ivandika3 opened a new pull request, #6091:
URL: https://github.com/apache/ozone/pull/6091

   ## What changes were proposed in this pull request?
   
   While tracing the block deletion logic, I found a possible problem regarding 
command status update logic.
   
   The cmdStatusMap in StateContext is a ConcurrentHashMap
   
   Currently the update logic for command status is as follows:
   
   ```java
   public boolean updateCommandStatus(Long cmdId,
       Consumer<CommandStatus> cmdStatusUpdater) {
     if (cmdStatusMap.containsKey(cmdId)) {
       cmdStatusUpdater.accept(cmdStatusMap.get(cmdId));
       return true;
     }
     return false;
   }
   ```
   
   It does not seem correct. Although the get containsKey and get is protected 
by the ConcurrentHashMap, the CommandStatus retrieved is mutated directly using 
the cmdStatusUpdater and not protected by the ConcurrentHashMap (Please correct 
me if I'm mistaken). This might trigger race condition.
   
   We should use atomic operation like computeIfPresent.
   
   Note: The cmdStatusMap is also exposed to public (getCommandStatusMap) which 
might not be a good idea since we cannot guarantee correct usage of the map. We 
might need to encapsulate it properly inside StateContext.
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-10210
   
   ## How was this patch tested?
   
   Existing tests.
   
   Clean CI: https://github.com/ivandika3/ozone/actions/runs/7650123708
   


-- 
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