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

   ## What changes were proposed in this pull request?
   
   `DatanodeDBProfile` may leak `ManagedColumnFamilyOptions` and its related 
objects:
   
   ```
   [Finalizer] WARN  managed.ManagedRocksObjectUtils 
(ManagedRocksObjectUtils.java:assertClosed(54)) - ManagedLRUCache is not closed 
properly
   [Finalizer] WARN  managed.ManagedRocksObjectUtils 
(ManagedRocksObjectUtils.java:assertClosed(54)) - ManagedBloomFilter is not 
closed properly
   [Finalizer] WARN  managed.ManagedRocksObjectUtils 
(ManagedRocksObjectUtils.java:assertClosed(54)) - ManagedColumnFamilyOptions is 
not closed properly
   ```
   
   `AtomicReference#updateAndGet` requires the update function to be free of 
side-effects, since it is applied in a loop and may be executed multiple times 
until `compareAndSet` succeeds.  However, `op -> op != null ? op : 
createColumnFamilyOptions(config))` has side-effect: the creation of a 
`ManagedColumnFamilyOptions`.  The objects created in unsuccessful attempts are 
leaked.
   
   `op != null ? op : ...` indicates we only want to replace `null` value, any 
non-`null` value already set is OK.  So `updateAndGet` can be replaced with a 
single `compareAndSet(null, ...)`.  If `non-null` value is found during set, 
the new instance needs to be closed.  Once a non-`null` value is set, it is 
never replaced, so we can return it early to avoid unnecessary object creation.
   
   https://issues.apache.org/jira/browse/HDDS-8476
   
   ## How was this patch tested?
   
   Added debug log in `DatanodeDBProfile` to show `ManagedColumnFamilyOptions` 
instances being created and returned.  Verified that the test does not fail due 
to leaks even if two instances of `ManagedColumnFamilyOptions` were created in 
`getColumnFamilyOptions` -- one was used later for each call, the other was 
closed properly right after creation.
   
   CI:
   https://github.com/adoroszlai/hadoop-ozone/actions/runs/5011701073


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