Ivan, We don't need the "close" method in the proposed approach, because it's enough having "commit(Async)" and "rollback(Async)" to finish a transaction. Semantically "close" is the same as "rollback".
If you are using "runInTransaction" API, you can't forget to call "close", it will be done automatically (rollback will be called at the end of a transaction closure). For async API it's required semantically to call commit or rollback. As for utility methods, I would keep tx API as small as possible for now. Anyway, these methods can be added later, if the need arises. ср, 14 июл. 2021 г. в 10:13, Ivan Daschinsky <ivanda...@gmail.com>: > Alexey, and is there any analogue to close() of transaction? When you start > transaction, you should somehow to close it, if you don't catch exception > or forget to commit. > > I suggest to add method closeAsync() to Transaction, so user can call it in > handle or whenComplete, i.e. > > So code will looks like > > CacheApi cache = CacheApi.getCache("testCache"); > > Transactions > .beginTransaction() > .thenCompose(tx -> { > CacheApi txCache = cache.withTx(tx); > CompletableFuture<Void> result = txCache.getAsync("key") > .thenCompose(val -> { > if (val == "test") { > return txCache.putAsync("key", "test1"); > } > else > return CompletableFuture.completedFuture(null); > }) > .thenCompose(v -> tx.commitAsync()) > .handle((v, ex) -> null); > return result.thenCompose(v -> tx.closeAsync()); > }); > > I also suggests to add method something like this > > static CompletableFuture<Void> inTxAsync(Function<Transaction, > CompletableFuture<Void>> action) { > return Transactions > .beginTransaction() > .thenCompose(tx -> { > CompletableFuture<Object> result = action.apply(tx) > .handle((v, ex) -> null); > return result.thenCompose(v -> tx.closeAsync()); > }); > } > > Async api is not very readable, but this method can help user write code, > this is rewritten first example: > > Transactions.inTxAsync(tx -> { > CacheApi txCache = cache.withTx(tx); > return txCache.getAsync("key") > .thenCompose(val -> { > if (val == "test") { > return txCache.putAsync("key", "test1"); > } > else > return CompletableFuture.completedFuture(null); > }) > .thenCompose(v -> tx.commitAsync()); > }); > > ср, 14 июл. 2021 г. в 10:03, Alexei Scherbakov < > alexey.scherbak...@gmail.com > >: > > > Andrey, > > > > I suggest you look at the PR [1], if you haven't. > > > > A transaction [2] > > Transactions facade [3] > > Examples [4] > > > > [1] https://github.com/apache/ignite-3/pull/214/files > > [2] > > > > > https://github.com/apache/ignite-3/blob/d2122ce8c15de020e121f53509bd5a097aac9cf2/modules/api/src/main/java/org/apache/ignite/tx/Transaction.java > > [3] > > > > > https://github.com/apache/ignite-3/blob/d2122ce8c15de020e121f53509bd5a097aac9cf2/modules/api/src/main/java/org/apache/ignite/tx/IgniteTransactions.java > > [4] > > > > > https://github.com/apache/ignite-3/blob/d2122ce8c15de020e121f53509bd5a097aac9cf2/modules/table/src/test/java/org/apache/ignite/internal/table/TxTest.java > > > > > > вт, 13 июл. 2021 г. в 19:41, Andrey Gura <ag...@apache.org>: > > > > > Alexey, > > > > > > could you please describe Transaction interface? > > > > > > Also it would be great to have a couple examples of using the proposed > > API. > > > > > > On Tue, Jul 13, 2021 at 4:43 PM Alexei Scherbakov > > > <alexey.scherbak...@gmail.com> wrote: > > > > > > > > Folks, > > > > > > > > I've prepared a PR implementing my vision of public transactions API. > > > > > > > > API is very simple and similar to Ignite 2, but has some differences. > > > > > > > > More details can be found here [1] > > > > > > > > Share your thoughts. > > > > > > > > [1] https://issues.apache.org/jira/browse/IGNITE-15086 > > > > > > > > -- > > > > > > > > Best regards, > > > > Alexei Scherbakov > > > > > > > > > -- > > > > Best regards, > > Alexei Scherbakov > > > > > -- > Sincerely yours, Ivan Daschinskiy > -- Best regards, Alexei Scherbakov