Ivan Andika created HDDS-10210:
----------------------------------
Summary: Ensure atomic update in StateContext#updateCommandStatus
Key: HDDS-10210
URL: https://issues.apache.org/jira/browse/HDDS-10210
Project: Apache Ozone
Issue Type: Improvement
Components: DN, Ozone Datanode
Affects Versions: 1.4.0
Reporter: Ivan Andika
Assignee: Ivan Andika
The cmdStatusMap in StateContext is a ConcurrentHashMap
Currently the update logic for command status is as follows:
{code:java}
public boolean updateCommandStatus(Long cmdId,
Consumer<CommandStatus> cmdStatusUpdater) {
if (cmdStatusMap.containsKey(cmdId)) {
cmdStatusUpdater.accept(cmdStatusMap.get(cmdId));
return true;
}
return false;
} {code}
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. This might
trigger race condition.
We should use atomic operation like computeIfPresent.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]