smengcl commented on code in PR #5934:
URL: https://github.com/apache/ozone/pull/5934#discussion_r1443904354
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotCache.java:
##########
@@ -304,30 +305,28 @@ private void cleanupInternal() {
OmSnapshot omSnapshot = (OmSnapshot) rcOmSnapshot.get();
LOG.debug("Evicting OmSnapshot instance {} with table key {}",
rcOmSnapshot, omSnapshot.getSnapshotTableKey());
- // Sanity check
- Preconditions.checkState(rcOmSnapshot.getTotalRefCount() == 0L,
- "Illegal state: OmSnapshot reference count non-zero ("
- + rcOmSnapshot.getTotalRefCount() + ") but shows up in the "
- + "clean up list");
Review Comment:
~~Why do we remove this check here?~~ Let's put the check at
https://github.com/apache/ozone/pull/5934/files#r1443904694 instead.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotCache.java:
##########
@@ -304,30 +305,28 @@ private void cleanupInternal() {
OmSnapshot omSnapshot = (OmSnapshot) rcOmSnapshot.get();
LOG.debug("Evicting OmSnapshot instance {} with table key {}",
rcOmSnapshot, omSnapshot.getSnapshotTableKey());
- // Sanity check
- Preconditions.checkState(rcOmSnapshot.getTotalRefCount() == 0L,
- "Illegal state: OmSnapshot reference count non-zero ("
- + rcOmSnapshot.getTotalRefCount() + ") but shows up in the "
- + "clean up list");
final String key = omSnapshot.getSnapshotTableKey();
- final ReferenceCounted<IOmMetadataReader, SnapshotCache> result =
- dbMap.remove(key);
- // Sanity check
- Preconditions.checkState(rcOmSnapshot == result,
- "Cache map entry removal failure. The cache is in an inconsistent "
- + "state. Expected OmSnapshot instance: " + rcOmSnapshot
- + ", actual: " + result + " for key: " + key);
-
- pendingEvictionList.remove(result);
-
- // Close the instance, which also closes its DB handle.
- try {
- ((OmSnapshot) rcOmSnapshot.get()).close();
- } catch (IOException ex) {
- throw new IllegalStateException("Error while closing snapshot DB", ex);
- }
+ dbMap.computeIfPresent(key, (k, v) -> {
+ // Sanity check
+ Preconditions.checkState(rcOmSnapshot == v,
+ "Cache map entry removal failure. The cache is in an inconsistent "
+ + "state. Expected OmSnapshot instance: " + rcOmSnapshot
+ + ", actual: " + v + " for key: " + key);
+
+ // Close the instance, which also closes its DB handle.
+ if (rcOmSnapshot.getTotalRefCount() == 0L) {
+ try {
+ ((OmSnapshot) rcOmSnapshot.get()).close();
+ } catch (IOException ex) {
+ throw new IllegalStateException("Error while closing snapshot DB",
ex);
+ }
+ return null;
+ }
Review Comment:
This can be put here as an alternative to
https://github.com/apache/ozone/pull/5934/files#r1443904354 ?
```suggestion
} else {
// throw here?
}
```
--
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]