szetszwo commented on PR #5947:
URL: https://github.com/apache/ozone/pull/5947#issuecomment-1883350547
> ... otherwise, it will wait in while loop to check and set. ...
You are right. We should check inside the while loop.
```java
@Override
public void close() {
// wait till all access to rocks db is process to avoid crash while close
while (!counter.compareAndSet(0, Long.MIN_VALUE)) {
if (counter.get() < 0) {
return;
}
try {
Thread.currentThread().sleep(1);
} catch (InterruptedException e) {
close(columnFamilies, db, descriptors, writeOptions, dbOptions);
Thread.currentThread().interrupt();
return;
}
}
// Wait for all background work to be cancelled first. e.g. RDB
compaction
db.get().cancelAllBackgroundWork(true);
// Then close all attached listeners
dbOptions.listeners().forEach(listener -> listener.close());
if (columnFamilies != null) {
columnFamilies.values().stream().forEach(f -> f.markClosed());
}
// close when counter is 0, no more operation
close(columnFamilies, db, descriptors, writeOptions, dbOptions);
}
```
> To avoid lock contention, ...
`counter` is `AtomicLong`. Where is the lock?
--
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]