Search in sources :

Example 1 with TxFinishResponseBuilder

use of org.apache.ignite.internal.tx.message.TxFinishResponseBuilder in project ignite-3 by apache.

the class TxManagerImpl method onReceived.

/**
 * {@inheritDoc}
 */
@Override
public void onReceived(NetworkMessage message, NetworkAddress senderAddr, @Nullable Long correlationId) {
    // Support raft and transactions interop.
    if (message instanceof TxFinishRequest) {
        TxFinishRequest req = (TxFinishRequest) message;
        Set<String> groups = req.groups();
        CompletableFuture[] futs = new CompletableFuture[groups.size()];
        int i = 0;
        // Finish a tx for enlisted groups.
        for (String grp : groups) {
            futs[i++] = finish(grp, req.timestamp(), req.commit());
        }
        CompletableFuture.allOf(futs).thenCompose(ignored -> req.commit() ? commitAsync(req.timestamp()) : rollbackAsync(req.timestamp())).handle(new BiFunction<Void, Throwable, Void>() {

            @Override
            public Void apply(Void ignored, Throwable err) {
                TxFinishResponseBuilder resp = FACTORY.txFinishResponse();
                if (err != null) {
                    resp.errorMessage(err.getMessage());
                }
                clusterService.messagingService().respond(senderAddr, resp.build(), correlationId);
                return null;
            }
        });
    }
}
Also used : TransactionException(org.apache.ignite.tx.TransactionException) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) BiFunction(java.util.function.BiFunction) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) IgniteStringFormatter.format(org.apache.ignite.lang.IgniteStringFormatter.format) TxFinishRequest(org.apache.ignite.internal.tx.message.TxFinishRequest) ByteBuffer(java.nio.ByteBuffer) TxState(org.apache.ignite.internal.tx.TxState) Map(java.util.Map) TxMessageGroup(org.apache.ignite.internal.tx.message.TxMessageGroup) InternalTransaction(org.apache.ignite.internal.tx.InternalTransaction) NetworkMessageHandler(org.apache.ignite.network.NetworkMessageHandler) TxFinishResponse(org.apache.ignite.internal.tx.message.TxFinishResponse) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) NetworkMessage(org.apache.ignite.network.NetworkMessage) Timestamp(org.apache.ignite.internal.tx.Timestamp) TxManager(org.apache.ignite.internal.tx.TxManager) TxFinishResponseBuilder(org.apache.ignite.internal.tx.message.TxFinishResponseBuilder) NetworkAddress(org.apache.ignite.network.NetworkAddress) Objects(java.util.Objects) TestOnly(org.jetbrains.annotations.TestOnly) CompletableFuture.failedFuture(java.util.concurrent.CompletableFuture.failedFuture) Nullable(org.jetbrains.annotations.Nullable) LockException(org.apache.ignite.internal.tx.LockException) LockManager(org.apache.ignite.internal.tx.LockManager) TxMessagesFactory(org.apache.ignite.internal.tx.message.TxMessagesFactory) ClusterService(org.apache.ignite.network.ClusterService) IgniteUuid(org.apache.ignite.lang.IgniteUuid) TxFinishRequest(org.apache.ignite.internal.tx.message.TxFinishRequest) CompletableFuture(java.util.concurrent.CompletableFuture) TxFinishResponseBuilder(org.apache.ignite.internal.tx.message.TxFinishResponseBuilder)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 CompletableFuture.failedFuture (java.util.concurrent.CompletableFuture.failedFuture)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 BiFunction (java.util.function.BiFunction)1 InternalTransaction (org.apache.ignite.internal.tx.InternalTransaction)1 LockException (org.apache.ignite.internal.tx.LockException)1 LockManager (org.apache.ignite.internal.tx.LockManager)1 Timestamp (org.apache.ignite.internal.tx.Timestamp)1 TxManager (org.apache.ignite.internal.tx.TxManager)1 TxState (org.apache.ignite.internal.tx.TxState)1 TxFinishRequest (org.apache.ignite.internal.tx.message.TxFinishRequest)1 TxFinishResponse (org.apache.ignite.internal.tx.message.TxFinishResponse)1 TxFinishResponseBuilder (org.apache.ignite.internal.tx.message.TxFinishResponseBuilder)1 TxMessageGroup (org.apache.ignite.internal.tx.message.TxMessageGroup)1