chihsuan commented on code in PR #11376:
URL: https://github.com/apache/ozone/pull/11376#discussion_r4173915612
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshot.java:
##########
@@ -343,21 +351,21 @@ public UUID getSnapshotID() {
@Override
public void close() throws IOException {
- // Close DB
- omMetadataManager.getStore().close();
+ try {
+ // Close DB
+ omMetadataManager.getStore().close();
+ } finally {
+ // Closed properly: stop tracking so the leak reporter does not fire at
GC.
+ leakTracker.close();
+ }
}
- @Override
- protected void finalize() throws Throwable {
- // Verify that the DB handle has been closed, log warning otherwise
- // https://softwareengineering.stackexchange.com/a/288724
- if (!omMetadataManager.getStore().isClosed()) {
- LOG.warn("{} is not closed properly. snapshotName: {}",
- // Print hash code for debugging
- omMetadataManager.getStore().toString(),
- snapshotName);
- }
- super.finalize();
+ /**
+ * @return a leak reporter that captures only the store's hashcode and the
snapshot name,
+ * never the {@link OmSnapshot} itself.
+ */
+ static Runnable newLeakReporter(String storeHashCode, String snapshotName) {
+ return () -> LOG.warn("{} is not closed properly. snapshotName: {}",
storeHashCode, snapshotName);
Review Comment:
nit: Since the tests no longer call it, I think it can be private now. The
parameter name could also be clearer, see the suggestion.
```suggestion
/**
* @return a leak reporter that captures only the store description and
the snapshot name,
* never the {@link OmSnapshot} itself.
*/
private static Runnable newLeakReporter(String storeDescription, String
snapshotName) {
return () -> LOG.warn("{} is not closed properly. snapshotName: {}",
storeDescription, snapshotName);
```
##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshotLeakDetection.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.UUID;
+import org.apache.hadoop.hdds.utils.db.DBStore;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
+import org.apache.ozone.test.GenericTestUtils.LogCapturer;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test {@link OmSnapshot}'s leak detection: the snapshot registers with a
shared LeakDetector
+ * and warns if it is garbage collected while its underlying store is still
open.
Review Comment:
nit: This description is outdated. The store state is no longer checked, so
it now warns whenever `close()` was not called.
```suggestion
* Test {@link OmSnapshot}'s leak detection: the snapshot registers with a
shared LeakDetector
* and warns if it is garbage collected without being closed.
```
--
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]