use of org.apache.ignite.internal.tx.message.TxFinishRequest in project ignite-3 by apache.
the class TxManagerImpl method finishRemote.
/**
* {@inheritDoc}
*/
@Override
public CompletableFuture<Void> finishRemote(NetworkAddress addr, Timestamp ts, boolean commit, Set<String> groups) {
assert groups != null && !groups.isEmpty();
TxFinishRequest req = FACTORY.txFinishRequest().timestamp(ts).groups(groups).commit(commit).build();
CompletableFuture<NetworkMessage> fut = clusterService.messagingService().invoke(addr, req, TIMEOUT);
// Submit response to a dedicated pool to avoid deadlocks. TODO: IGNITE-15389
return fut.thenApplyAsync(resp -> ((TxFinishResponse) resp).errorMessage()).thenCompose(msg -> msg == null ? completedFuture(null) : failedFuture(new TransactionException(msg)));
}
use of org.apache.ignite.internal.tx.message.TxFinishRequest 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;
}
});
}
}
use of org.apache.ignite.internal.tx.message.TxFinishRequest in project ignite-3 by apache.
the class MessagingServiceTestUtils method mockMessagingService.
/**
* Prepares messaging service mock.
*
* @param txManager Transaction manager.
* @return Messaging service mock.
*/
public static MessagingService mockMessagingService(TxManager txManager) {
MessagingService messagingService = Mockito.mock(MessagingService.class, RETURNS_DEEP_STUBS);
doAnswer(invocationClose -> {
assert invocationClose.getArgument(1) instanceof TxFinishRequest;
TxFinishRequest txFinishRequest = invocationClose.getArgument(1);
if (txFinishRequest.commit()) {
txManager.commitAsync(txFinishRequest.timestamp()).get();
} else {
txManager.rollbackAsync(txFinishRequest.timestamp()).get();
}
return CompletableFuture.completedFuture(mock(TxFinishResponse.class));
}).when(messagingService).invoke(any(NetworkAddress.class), any(TxFinishRequest.class), anyLong());
return messagingService;
}
Aggregations