use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.
the class PartitionCommandListenerTest method before.
/**
* Initializes a table listener before tests.
*/
@BeforeEach
public void before() {
ClusterService clusterService = Mockito.mock(ClusterService.class, RETURNS_DEEP_STUBS);
NetworkAddress addr = new NetworkAddress("127.0.0.1", 5003);
Mockito.when(clusterService.topologyService().localMember().address()).thenReturn(addr);
commandListener = new PartitionListener(UUID.randomUUID(), new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), new TxManagerImpl(clusterService, new HeapLockManager())));
}
use of org.apache.ignite.network.NetworkAddress in project ignite-3 by apache.
the class TransactionImpl method finish.
/**
* Finishes a transaction.
*
* @param commit {@code true} to commit, false to rollback.
* @return The future.
*/
private CompletableFuture<Void> finish(boolean commit) {
Map<NetworkAddress, Set<String>> tmp = new HashMap<>();
// Group by common leader addresses.
for (RaftGroupService svc : enlisted) {
NetworkAddress addr = svc.leader().address();
tmp.computeIfAbsent(addr, k -> new HashSet<>()).add(svc.groupId());
}
CompletableFuture[] futs = new CompletableFuture[tmp.size() + 1];
int i = 0;
for (Map.Entry<NetworkAddress, Set<String>> entry : tmp.entrySet()) {
boolean local = address.equals(entry.getKey());
futs[i++] = txManager.finishRemote(entry.getKey(), timestamp, commit, entry.getValue());
LOG.debug("finish [addr={}, commit={}, ts={}, local={}, groupIds={}", address, commit, timestamp, local, entry.getValue());
}
// Handle coordinator's tx.
futs[i] = tmp.containsKey(address) ? CompletableFuture.completedFuture(null) : commit ? txManager.commitAsync(timestamp) : txManager.rollbackAsync(timestamp);
return CompletableFuture.allOf(futs);
}
use of org.apache.ignite.network.NetworkAddress 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.network.NetworkAddress 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.network.NetworkAddress in project ignite-3 by apache.
the class ItClusterServiceTest method testShutdown.
@Test
void testShutdown(TestInfo testInfo) {
var addr = new NetworkAddress("localhost", 10000);
ClusterService service = clusterService(testInfo, addr.port(), new StaticNodeFinder(List.of(addr)), new TestScaleCubeClusterServiceFactory());
service.start();
service.stop();
assertThat(service.isStopped(), is(true));
ExecutionException e = assertThrows(ExecutionException.class, () -> service.messagingService().send(mock(ClusterNode.class), mock(NetworkMessage.class)).get(5, TimeUnit.SECONDS));
assertThat(e.getCause(), isA(NodeStoppingException.class));
}
Aggregations