smengcl commented on code in PR #4567:
URL: https://github.com/apache/ozone/pull/4567#discussion_r1244630006
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotCache.java:
##########
@@ -224,29 +225,33 @@ public ReferenceCounted<IOmMetadataReader, SnapshotCache>
get(String key,
* @param key snapshot table key
*/
public void release(String key) {
- ReferenceCounted<IOmMetadataReader, SnapshotCache> rcOmSnapshot =
- dbMap.get(key);
- Preconditions.checkNotNull(rcOmSnapshot,
- "Key '" + key + "' does not exist in cache");
-
- if (rcOmSnapshot.decrementRefCount() == 0L) {
- synchronized (pendingEvictionList) {
- // Eligible to be closed, add it to the list.
- pendingEvictionList.add(rcOmSnapshot);
- // The cache size might have already exceed the soft limit
- // Thus triggering cleanup() to check and evict if applicable
- cleanup();
+ dbMap.compute(key, (k, v) -> {
+ if (v == null) {
+ throw new IllegalArgumentException(
+ "Key '" + key + "' does not exist in cache");
}
- }
+
+ if (v.decrementRefCount() == 0L) {
+ synchronized (pendingEvictionList) {
+ // Eligible to be closed, add it to the list.
+ pendingEvictionList.add(v);
+ // The cache size might have already exceed the soft limit
+ // Thus triggering cleanup() to check and evict if applicable
+ cleanup();
+ }
+ }
+
+ return v;
Review Comment:
Since the ref counting is still done inside dbMap's monitor lock, the
previously mentioned issue
[here](https://github.com/apache/ozone/pull/4567#discussion_r1232881842) and
[here](https://github.com/apache/ozone/pull/4567#discussion_r1232883122) should
not revive.
And `cleanup()` is now wrapped inside `synchronized`.
--
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]