siddhantsangwan opened a new pull request, #4643: URL: https://github.com/apache/ozone/pull/4643
## What changes were proposed in this pull request? Problem: Container Balancer gets a reference to a Container's `ContainerInfo` from `ContainerManager` in several places throughout the balancer package. We need to investigate if there are possible race conditions with other parts of SCM changing the replicas of a container etc. In the investigation it was found that in most places, the `ContainerInfo` object's `usedBytes` field is being read through the getter `ContainerInfo#getUsedBytes`. `usedBytes` is written in `AbstractContainerReportHandler#updateContainerUsedAndKeys` when a container report is processed. Since `usedBytes` is a long primitive type and reads/writes to a long are not atomic, there's a race condition between the balancer thread reading this value and the report handling thread writing to it. This PR proposes making `usedBytes` volatile because reads/writes to a volatile long are atomic - https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.7. This should solve the race condition. `AbstractFindTargetGreedy` passes a `ContainerInfo` to `PlacementPolicyValidateProxy#validateContainerPlacement`. This method reads the replication type and replication factor from `ContainerInfo`. These values should stay constant, so synchronization is not required here. I don't think locking on `ContainerInfo` is required in the balancer package except in `MoveManager` where it's already present. ## What is the link to the Apache JIRA https://issues.apache.org/jira/browse/HDDS-8347 ## How was this patch tested? Ran existing tests. -- 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]
