You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/11/01 09:02:12 UTC

[GitHub] [ignite-3] rpuch opened a new pull request, #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

rpuch opened a new pull request, #1291:
URL: https://github.com/apache/ignite-3/pull/1291

   https://issues.apache.org/jira/browse/IGNITE-18032


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] SammyVimes commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
SammyVimes commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1012147972


##########
modules/transactions/src/test/java/org/apache/ignite/internal/tx/storage/state/TxStateStorageAbstractTest.java:
##########
@@ -150,10 +167,14 @@ public void testCas() throws Exception {
 
     @Test
     public void testScan() throws Exception {
-        try (TxStateTableStorage tableStorage = createStorage()) {
-            TxStateStorage storage0 = tableStorage.getOrCreateTxStateStorage(0);
-            TxStateStorage storage1 = tableStorage.getOrCreateTxStateStorage(1);
-            TxStateStorage storage2 = tableStorage.getOrCreateTxStateStorage(2);
+        try (
+                var storageHolder0 = new AutoCloser<>(tableStorage.getOrCreateTxStateStorage(0), TxStateStorage::close);

Review Comment:
   It's hard to tell, but I think `try-with-resources` is used for the clarity of the code, not for security (because you have to close resources either way). And with AutoCloser we have to write more code with no profit. It's all my opinion of course



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1011737467


##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/MetaStorageManager.java:
##########
@@ -227,7 +227,7 @@ public void stop() throws Exception {
             IgniteUtils.closeAll(

Review Comment:
   Why? It closes all `Closeables` given to it. Those are not `Runnable`s.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1012539556


##########
modules/raft/src/test/java/org/apache/ignite/raft/jraft/storage/impl/BaseLogStorageTest.java:
##########
@@ -16,6 +16,12 @@
  */
 package org.apache.ignite.raft.jraft.storage.impl;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;

Review Comment:
   Oh, thanks, good catch. I had no idea JRaft code has a different order of imports.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1013028487


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/raft/RocksDbClusterStateStorage.java:
##########
@@ -209,10 +209,10 @@ public void destroy() {
     }
 
     @Override
-    public void close() throws Exception {
+    public void close() {
         IgniteUtils.shutdownAndAwaitTermination(snapshotExecutor, 10, TimeUnit.SECONDS);
 
-        IgniteUtils.closeAll(options, db);
+        RocksUtils.closeAll(options, db);

Review Comment:
   The idea of this method is to have ability to close RocksDB references in such a way that no `throws` needs to be declared on the `closeAll()` (because `AbstractNativeReference`, which implements `AutoCloseable`, does not declare any `throws`). On the other hand, a method that accepts `AutoCloseable`s (like `IgniteUtils.closeAll()`) or `ManualCloseable` (that you imagined) would have to declare `throws Exception` which is what I tried to avoid for RocksDB resources. Hence this method.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1011730982


##########
modules/core/src/main/java/org/apache/ignite/internal/ManuallyCloseable.java:
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.ignite.internal;
+
+/**
+ * Represents something that must be eventually closed. It is different from {@link AutoCloseable} which is for being
+ * used in try-with-resources; IDEs treat any usage of an AutoCloseable outside of a try-with-resources block as a suspicious
+ * and issue a warning, so it becomes a drag to work with code that uses AutoCloseable for classes which instances
+ * are used with patterns different from the try-with-resources pattern.
+ *
+ * <p>The main reason of this interface appearance was the desire to mark 'must-be-eventually-closed' types so that
+ * we don't forget closing their instances.
+ *
+ * <p>Subinterfaces and classes implementing this interface should declare a narrower {@code throws} declaration (either
+ * having concrete subclasses of {@link Exception} or declaring no exceptions at all).
+ */
+public interface ManuallyCloseable {

Review Comment:
   We don't need `ManuallyStartable` because you cannot forget about starting a component (you will see an error instantly when trying to use an unstarted component).



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1012539301


##########
modules/transactions/src/test/java/org/apache/ignite/internal/tx/storage/state/TxStateStorageAbstractTest.java:
##########
@@ -150,10 +167,14 @@ public void testCas() throws Exception {
 
     @Test
     public void testScan() throws Exception {
-        try (TxStateTableStorage tableStorage = createStorage()) {
-            TxStateStorage storage0 = tableStorage.getOrCreateTxStateStorage(0);
-            TxStateStorage storage1 = tableStorage.getOrCreateTxStateStorage(1);
-            TxStateStorage storage2 = tableStorage.getOrCreateTxStateStorage(2);
+        try (
+                var storageHolder0 = new AutoCloser<>(tableStorage.getOrCreateTxStateStorage(0), TxStateStorage::close);

Review Comment:
   `try-with-resources` provides some safeness guarantees, you cannot forget to close a resource used with `try-with-resources`, but you can if you don't use this idiom.
   
   On the other hand, in tests it's not that critical to leak a resource, so I removed `try-with-resources` altogether.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1013041611


##########
modules/core/src/main/java/org/apache/ignite/internal/close/AutoCloser.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.ignite.internal.close;
+
+/**
+ * A utility that allows to use something that is not an {@link AutoCloseable} in try-with-resources blocks.
+ *
+ * @param <T> Type of the resource.
+ * @param <X> Exception that can be thrown by the closer during closing. This type parameter is needed to make sure
+ *     that {@link AutoCloser#close()} throws declaration is as narrow as possible.
+ */
+@SuppressWarnings("CheckedExceptionClass")
+public class AutoCloser<T, X extends Exception> implements AutoCloseable {

Review Comment:
   Removed the stuff



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1013030298


##########
modules/metastorage-server/src/main/java/org/apache/ignite/internal/metastorage/server/raft/MetaStorageListener.java:
##########
@@ -418,7 +418,7 @@ public boolean onSnapshotLoad(Path path) {
     public void onShutdown() {
         try {
             storage.close();
-        } catch (Exception e) {
+        } catch (RuntimeException e) {

Review Comment:
   Before, we were handling ANYTHING. Now we handle a lot less; but the idea to catch `RuntimeException` was to keep the old behavior.
   
   Should I remove the try/catch altogether?



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1011732342


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/raft/ClusterStateStorage.java:
##########
@@ -104,6 +105,12 @@ public interface ClusterStateStorage extends AutoCloseable {
      */
     void restoreSnapshot(Path snapshotPath);
 
+    /**
+     * Closes this storage.
+     */
+    @Override
+    void close();

Review Comment:
   On `ManuallyCloseable`, it is declared to throw `Exception`. This one does not declare anything, so re-declaring it here has value.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1011746145


##########
modules/transactions/src/test/java/org/apache/ignite/internal/tx/storage/state/TxStateStorageAbstractTest.java:
##########
@@ -150,10 +167,14 @@ public void testCas() throws Exception {
 
     @Test
     public void testScan() throws Exception {
-        try (TxStateTableStorage tableStorage = createStorage()) {
-            TxStateStorage storage0 = tableStorage.getOrCreateTxStateStorage(0);
-            TxStateStorage storage1 = tableStorage.getOrCreateTxStateStorage(1);
-            TxStateStorage storage2 = tableStorage.getOrCreateTxStateStorage(2);
+        try (
+                var storageHolder0 = new AutoCloser<>(tableStorage.getOrCreateTxStateStorage(0), TxStateStorage::close);

Review Comment:
   On the other hand, the code with try-with-resources is safer, it closes the storage.
   
   Do you think it's not important in tests and should be replaced with simply calling `close()` in the end?



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1011735610


##########
modules/core/src/main/java/org/apache/ignite/internal/close/ManuallyCloseable.java:
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.ignite.internal.close;
+
+/**
+ * Represents something that must be eventually closed. It is different from {@link AutoCloseable} which is for being
+ * used in try-with-resources; IDEs treat any usage of an AutoCloseable outside of a try-with-resources block as a suspicious
+ * and issue a warning, so it becomes a drag to work with code that uses AutoCloseable for classes which instances
+ * are used with patterns different from the try-with-resources pattern.
+ *
+ * <p>The main reason of this interface appearance was the desire to mark 'must-be-eventually-closed' types so that
+ * we don't forget closing their instances.

Review Comment:
   Only as an 'annotation'. If you are unsure about whether you must close something, you might inspect its interfaces. If it is a `ManuallyCloseable`, then you must close it.
   
   Actually, I'm not sure this is actually needed, this was suggested by @sanpwc
   Sasha, could you please step in? Do we actually need it?



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] sanpwc commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
sanpwc commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1012699888


##########
modules/core/src/main/java/org/apache/ignite/internal/close/ManuallyCloseable.java:
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.ignite.internal.close;
+
+/**
+ * Represents something that must be eventually closed. It is different from {@link AutoCloseable} which is for being
+ * used in try-with-resources; IDEs treat any usage of an AutoCloseable outside of a try-with-resources block as a suspicious
+ * and issue a warning, so it becomes a drag to work with code that uses AutoCloseable for classes which instances
+ * are used with patterns different from the try-with-resources pattern.
+ *
+ * <p>The main reason of this interface appearance was the desire to mark 'must-be-eventually-closed' types so that
+ * we don't forget closing their instances.

Review Comment:
   `implements AutoClosable` is a 
   - Highly visible and commonly known marker of a fact that it's necessary to close given resource.
   - Helper that explicitly denotes the method to be called in order to cleanup the resource is _close_ .
   Meaning that it's simple to check whether the class is AutoClosable and to call close method on it. Otherwise it'll be necessary to go through the class in order to find stop(), close(), destroy() or other similar methods, ask class owner whether given resource should be closed and all other messy stuff. AutoClosable as a marker interface makes life easier.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] SammyVimes commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
SammyVimes commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1012050838


##########
modules/raft/src/test/java/org/apache/ignite/raft/jraft/storage/impl/BaseLogStorageTest.java:
##########
@@ -16,6 +16,12 @@
  */
 package org.apache.ignite.raft.jraft.storage.impl;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;

Review Comment:
   I mean, we are trying to change as little as we can in jraft sources and this looks like an accidental import reformat



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1011743140


##########
modules/rocksdb-common/build.gradle:
##########
@@ -23,6 +23,10 @@ dependencies {
     implementation project(':ignite-core')
     implementation libs.jetbrains.annotations
     api libs.rocksdb.jni
+
+    testImplementation libs.hamcrest.core
+    testImplementation libs.hamcrest.core

Review Comment:
   I added only 2 dependencies in build.gradle because other 2 dependencies seem to be already there. They are added by
   
   ```
   apply from: "$rootDir/buildscripts/java-junit5.gradle"
   ```
   
   probably. At least, the project compiles (including tests) via Gradle.
   
   I removed the duplicate, thanks



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] sanpwc commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
sanpwc commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1013017537


##########
modules/metastorage-server/src/main/java/org/apache/ignite/internal/metastorage/server/raft/MetaStorageListener.java:
##########
@@ -418,7 +418,7 @@ public boolean onSnapshotLoad(Path path) {
     public void onShutdown() {
         try {
             storage.close();
-        } catch (Exception e) {
+        } catch (RuntimeException e) {

Review Comment:
   Well, that's actually very confusing. Almost no one will handle RuntimeException.



##########
modules/core/src/main/java/org/apache/ignite/internal/close/AutoCloser.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.ignite.internal.close;
+
+/**
+ * A utility that allows to use something that is not an {@link AutoCloseable} in try-with-resources blocks.
+ *
+ * @param <T> Type of the resource.
+ * @param <X> Exception that can be thrown by the closer during closing. This type parameter is needed to make sure
+ *     that {@link AutoCloser#close()} throws declaration is as narrow as possible.
+ */
+@SuppressWarnings("CheckedExceptionClass")
+public class AutoCloser<T, X extends Exception> implements AutoCloseable {

Review Comment:
   Well, to be honest all that stuff seems as an over design to me. 



##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/raft/RocksDbClusterStateStorage.java:
##########
@@ -209,10 +209,10 @@ public void destroy() {
     }
 
     @Override
-    public void close() throws Exception {
+    public void close() {
         IgniteUtils.shutdownAndAwaitTermination(snapshotExecutor, 10, TimeUnit.SECONDS);
 
-        IgniteUtils.closeAll(options, db);
+        RocksUtils.closeAll(options, db);

Review Comment:
   Why it's RocksUtils? I'd expect closeAll(ManuallyClosable) in IgniteUtils.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] tkalkirill commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
tkalkirill commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1010456737


##########
modules/core/src/main/java/org/apache/ignite/internal/ManuallyCloseable.java:
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.ignite.internal;
+
+/**
+ * Represents something that must be eventually closed. It is different from {@link AutoCloseable} which is for being
+ * used in try-with-resources; IDEs treat any usage of an AutoCloseable outside of a try-with-resources block as a suspicious
+ * and issue a warning, so it becomes a drag to work with code that uses AutoCloseable for classes which instances
+ * are used with patterns different from the try-with-resources pattern.
+ *
+ * <p>The main reason of this interface appearance was the desire to mark 'must-be-eventually-closed' types so that
+ * we don't forget closing their instances.
+ *
+ * <p>Subinterfaces and classes implementing this interface should declare a narrower {@code throws} declaration (either
+ * having concrete subclasses of {@link Exception} or declaring no exceptions at all).
+ */
+public interface ManuallyCloseable {

Review Comment:
   Do I understand correctly that this interface is similar to a marker one? It seems to me that there is no need for it.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1010481936


##########
modules/core/src/main/java/org/apache/ignite/internal/ManuallyCloseable.java:
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.ignite.internal;
+
+/**
+ * Represents something that must be eventually closed. It is different from {@link AutoCloseable} which is for being
+ * used in try-with-resources; IDEs treat any usage of an AutoCloseable outside of a try-with-resources block as a suspicious
+ * and issue a warning, so it becomes a drag to work with code that uses AutoCloseable for classes which instances
+ * are used with patterns different from the try-with-resources pattern.
+ *
+ * <p>The main reason of this interface appearance was the desire to mark 'must-be-eventually-closed' types so that
+ * we don't forget closing their instances.
+ *
+ * <p>Subinterfaces and classes implementing this interface should declare a narrower {@code throws} declaration (either
+ * having concrete subclasses of {@link Exception} or declaring no exceptions at all).
+ */
+public interface ManuallyCloseable {

Review Comment:
   @sanpwc pointed out that `AutoCloseable` provides us with a hint that 'this particular instance needs to be eventually closed'. As we want to remove `AutoCloseable` from long-lived objects, it seems nice to have a weaker replacement. This is not too dramatic, it's like a marker or a comment, you are right, but it costs us almost nothing to declare it on a type where we already want to have `close()` method.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1011737467


##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/MetaStorageManager.java:
##########
@@ -227,7 +227,7 @@ public void stop() throws Exception {
             IgniteUtils.closeAll(

Review Comment:
   Why? It closes all `Closeables` given to it. Those are ot `Runnable`s.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1011736062


##########
modules/metastorage-server/src/main/java/org/apache/ignite/internal/metastorage/server/persistence/RocksDbKeyValueStorage.java:
##########
@@ -226,10 +227,10 @@ private void destroyRocksDb() throws RocksDBException {
 
     /** {@inheritDoc} */
     @Override
-    public void close() throws Exception {
+    public void close() {
         IgniteUtils.shutdownAndAwaitTermination(snapshotExecutor, 10, TimeUnit.SECONDS);
 
-        IgniteUtils.closeAll(db, options);
+        RocksUtils.closeAll(db, options);

Review Comment:
   It can throw a `RuntimeException`, but not a checked one



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1011738791


##########
modules/raft/src/test/java/org/apache/ignite/raft/jraft/storage/impl/BaseLogStorageTest.java:
##########
@@ -16,6 +16,12 @@
  */
 package org.apache.ignite.raft.jraft.storage.impl;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;

Review Comment:
   Why not?



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] rpuch commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
rpuch commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1013030298


##########
modules/metastorage-server/src/main/java/org/apache/ignite/internal/metastorage/server/raft/MetaStorageListener.java:
##########
@@ -418,7 +418,7 @@ public boolean onSnapshotLoad(Path path) {
     public void onShutdown() {
         try {
             storage.close();
-        } catch (Exception e) {
+        } catch (RuntimeException e) {

Review Comment:
   Before, we were handling ANYTHING. Now we handle a lot less. Should I remove the try/catch altogether?



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] SammyVimes merged pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
SammyVimes merged PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] tkalkirill commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
tkalkirill commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1011392496


##########
modules/core/src/main/java/org/apache/ignite/internal/ManuallyCloseable.java:
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.ignite.internal;
+
+/**
+ * Represents something that must be eventually closed. It is different from {@link AutoCloseable} which is for being
+ * used in try-with-resources; IDEs treat any usage of an AutoCloseable outside of a try-with-resources block as a suspicious
+ * and issue a warning, so it becomes a drag to work with code that uses AutoCloseable for classes which instances
+ * are used with patterns different from the try-with-resources pattern.
+ *
+ * <p>The main reason of this interface appearance was the desire to mark 'must-be-eventually-closed' types so that
+ * we don't forget closing their instances.
+ *
+ * <p>Subinterfaces and classes implementing this interface should declare a narrower {@code throws} declaration (either
+ * having concrete subclasses of {@link Exception} or declaring no exceptions at all).
+ */
+public interface ManuallyCloseable {

Review Comment:
   Another argument against such an interface: why there is an **ManuallyCloseable** and no **ManuallyStartable** and others like them. They will introduce redundancy into development.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite-3] SammyVimes commented on a diff in pull request #1291: IGNITE-18032 Do not implement AutoCloseable on classes instances of which are not meant to be used in try-with-resources

Posted by GitBox <gi...@apache.org>.
SammyVimes commented on code in PR #1291:
URL: https://github.com/apache/ignite-3/pull/1291#discussion_r1011563801


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/raft/ClusterStateStorage.java:
##########
@@ -104,6 +105,12 @@ public interface ClusterStateStorage extends AutoCloseable {
      */
     void restoreSnapshot(Path snapshotPath);
 
+    /**
+     * Closes this storage.
+     */
+    @Override
+    void close();

Review Comment:
   Isn't close inherited from the interface?



##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/MetaStorageManager.java:
##########
@@ -227,7 +227,7 @@ public void stop() throws Exception {
             IgniteUtils.closeAll(

Review Comment:
   probably this should be called `runAll` then



##########
modules/metastorage-server/src/main/java/org/apache/ignite/internal/metastorage/server/persistence/RocksDbKeyValueStorage.java:
##########
@@ -226,10 +227,10 @@ private void destroyRocksDb() throws RocksDBException {
 
     /** {@inheritDoc} */
     @Override
-    public void close() throws Exception {
+    public void close() {
         IgniteUtils.shutdownAndAwaitTermination(snapshotExecutor, 10, TimeUnit.SECONDS);
 
-        IgniteUtils.closeAll(db, options);
+        RocksUtils.closeAll(db, options);

Review Comment:
   Can't it throw an exception actually?



##########
modules/raft/src/test/java/org/apache/ignite/raft/jraft/storage/impl/BaseLogStorageTest.java:
##########
@@ -16,6 +16,12 @@
  */
 package org.apache.ignite.raft.jraft.storage.impl;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;

Review Comment:
   Are you sure that imports should be here in jraft?



##########
modules/transactions/src/test/java/org/apache/ignite/internal/tx/storage/state/TxStateStorageAbstractTest.java:
##########
@@ -150,10 +167,14 @@ public void testCas() throws Exception {
 
     @Test
     public void testScan() throws Exception {
-        try (TxStateTableStorage tableStorage = createStorage()) {
-            TxStateStorage storage0 = tableStorage.getOrCreateTxStateStorage(0);
-            TxStateStorage storage1 = tableStorage.getOrCreateTxStateStorage(1);
-            TxStateStorage storage2 = tableStorage.getOrCreateTxStateStorage(2);
+        try (
+                var storageHolder0 = new AutoCloser<>(tableStorage.getOrCreateTxStateStorage(0), TxStateStorage::close);

Review Comment:
   Funny thing, you actually write more code than there were or even would be if there was no `AutoCloser`:
   
   ```
   var storageHolder0 = tableStorage.getOrCreateTxStateStorage(0); 
   storageHolder0.close();
   ```
   
   And that's without calling `.value()` on all this holders...



##########
modules/core/src/main/java/org/apache/ignite/internal/close/ManuallyCloseable.java:
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.ignite.internal.close;
+
+/**
+ * Represents something that must be eventually closed. It is different from {@link AutoCloseable} which is for being
+ * used in try-with-resources; IDEs treat any usage of an AutoCloseable outside of a try-with-resources block as a suspicious
+ * and issue a warning, so it becomes a drag to work with code that uses AutoCloseable for classes which instances
+ * are used with patterns different from the try-with-resources pattern.
+ *
+ * <p>The main reason of this interface appearance was the desire to mark 'must-be-eventually-closed' types so that
+ * we don't forget closing their instances.

Review Comment:
   How does it help developers not to forget closing?



##########
modules/rocksdb-common/build.gradle:
##########
@@ -23,6 +23,10 @@ dependencies {
     implementation project(':ignite-core')
     implementation libs.jetbrains.annotations
     api libs.rocksdb.jni
+
+    testImplementation libs.hamcrest.core
+    testImplementation libs.hamcrest.core

Review Comment:
   this line is the same as above + in pom.xml you've added 4 dependencies and here only 2 (or 3 with the duplicate)



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org