use of org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi in project ignite by apache.
the class ClusterCachesInfo method validateNoNewCachesWithNewFormat.
/**
* Validates that joining node doesn't have newly configured caches
* in case when there is no cluster-wide support of SPLITTED_CACHE_CONFIGURATIONS.
*
* If validation is failed that caches will be destroyed cluster-wide and node joining process will be failed.
*
* @param clusterWideCacheData Cluster wide cache data.
*/
public void validateNoNewCachesWithNewFormat(CacheNodeCommonDiscoveryData clusterWideCacheData) {
IgniteDiscoverySpi spi = (IgniteDiscoverySpi) ctx.discovery().getInjectedDiscoverySpi();
boolean allowSplitCacheConfigurations = spi.allNodesSupport(IgniteFeatures.SPLITTED_CACHE_CONFIGURATIONS);
if (!allowSplitCacheConfigurations) {
List<String> cachesToDestroy = new ArrayList<>();
for (DynamicCacheDescriptor cacheDescriptor : registeredCaches().values()) {
CacheData clusterCacheData = clusterWideCacheData.caches().get(cacheDescriptor.cacheName());
// Node spawned new cache.
if (clusterCacheData.receivedFrom().equals(cacheDescriptor.receivedFrom()))
cachesToDestroy.add(cacheDescriptor.cacheName());
}
if (!cachesToDestroy.isEmpty()) {
ctx.cache().dynamicDestroyCaches(cachesToDestroy, false);
throw new IllegalStateException("Node can't join to cluster in compatibility mode with newly configured caches: " + cachesToDestroy);
}
}
}
use of org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi in project ignite by apache.
the class IgniteClientReconnectFailoverAbstractTest method reconnectFailover.
/**
* @param c Test closure.
* @throws Exception If failed.
*/
protected final void reconnectFailover(final Callable<Void> c) throws Exception {
final Ignite client = grid(serverCount());
assertTrue(client.cluster().localNode().isClient());
Ignite srv = ignite(0);
IgniteDiscoverySpi srvSpi = spi0(srv);
final AtomicBoolean stop = new AtomicBoolean(false);
final IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
try {
int iter = 0;
while (!stop.get()) {
try {
c.call();
} catch (CacheException e) {
checkAndWait(e);
} catch (IgniteClientDisconnectedException e) {
checkAndWait(e);
}
if (++iter % 100 == 0)
log.info("Iteration: " + iter);
if (barrier != null)
barrier.await();
}
return null;
} catch (Throwable e) {
log.error("Unexpected error in operation thread: " + e, e);
stop.set(true);
throw e;
}
}
}, THREADS, "test-operation-thread");
final AtomicReference<CountDownLatch> disconnected = new AtomicReference<>();
final AtomicReference<CountDownLatch> reconnected = new AtomicReference<>();
IgnitePredicate<Event> p = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
info("Reconnected: " + evt);
CountDownLatch latch = reconnected.get();
assertNotNull(latch);
assertEquals(1, latch.getCount());
latch.countDown();
} else if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED) {
info("Disconnected: " + evt);
CountDownLatch latch = disconnected.get();
assertNotNull(latch);
assertEquals(1, latch.getCount());
latch.countDown();
}
return true;
}
};
client.events().localListen(p, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED);
try {
long stopTime = System.currentTimeMillis() + TEST_TIME;
String err = null;
while (System.currentTimeMillis() < stopTime && !fut.isDone()) {
U.sleep(500);
CountDownLatch disconnectLatch = new CountDownLatch(1);
CountDownLatch reconnectLatch = new CountDownLatch(1);
disconnected.set(disconnectLatch);
reconnected.set(reconnectLatch);
UUID nodeId = client.cluster().localNode().id();
log.info("Fail client: " + nodeId);
srvSpi.failNode(nodeId, null);
if (!disconnectLatch.await(10_000, MILLISECONDS)) {
err = "Failed to wait for disconnect";
break;
}
if (!reconnectLatch.await(10_000, MILLISECONDS)) {
err = "Failed to wait for reconnect";
break;
}
barrier = new CyclicBarrier(THREADS + 1, new Runnable() {
@Override
public void run() {
barrier = null;
}
});
try {
barrier.await(10, SECONDS);
} catch (TimeoutException ignored) {
err = "Operations hang or fail with unexpected error.";
break;
}
}
if (err != null) {
log.error("Test error: " + err);
U.dumpThreads(log);
CyclicBarrier barrier0 = barrier;
if (barrier0 != null) {
barrier = null;
barrier0.reset();
}
stop.set(true);
fut.get();
fail(err);
}
stop.set(true);
fut.get();
} finally {
client.events().stopLocalListen(p);
stop.set(true);
}
}
use of org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi in project ignite by apache.
the class IgniteClientReconnectApiExceptionTest method doTestIgniteOperationOnDisconnect.
/**
* @param client Client.
* @param ops Operations closures.
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
private void doTestIgniteOperationOnDisconnect(Ignite client, final List<T2<Callable, C1<Object, Boolean>>> ops) throws Exception {
assertNotNull(client.cache(DEFAULT_CACHE_NAME));
final IgniteDiscoverySpi clientSpi = spi0(client);
Ignite srv = clientRouter(client);
DiscoverySpi srvSpi = spi0(srv);
final CountDownLatch disconnectLatch = new CountDownLatch(1);
final CountDownLatch reconnectLatch = new CountDownLatch(1);
log.info("Block reconnect.");
DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener();
clientSpi.setInternalListener(lsnr);
lsnr.startBlockJoin();
final List<IgniteInternalFuture> futs = new ArrayList<>();
client.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED) {
info("Disconnected: " + evt);
assertEquals(1, reconnectLatch.getCount());
for (T2<Callable, C1<Object, Boolean>> op : ops) futs.add(GridTestUtils.runAsync(op.get1()));
disconnectLatch.countDown();
} else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
info("Reconnected: " + evt);
reconnectLatch.countDown();
}
return true;
}
}, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED);
try {
log.info("Fail client.");
srvSpi.failNode(client.cluster().localNode().id(), null);
waitReconnectEvent(disconnectLatch);
assertEquals(ops.size(), futs.size());
for (IgniteInternalFuture<?> fut : futs) assertNotDone(fut);
U.sleep(2000);
for (IgniteInternalFuture<?> fut : futs) assertNotDone(fut);
log.info("Allow reconnect.");
lsnr.stopBlockJoin();
waitReconnectEvent(reconnectLatch);
// Check operation after reconnect working.
for (int i = 0; i < futs.size(); i++) {
final int i0 = i;
try {
final Object futRes = futs.get(i0).get(2, SECONDS);
assertTrue(GridTestUtils.runAsync(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return ops.get(i0).get2().apply(futRes);
}
}).get(2, SECONDS));
} catch (IgniteFutureTimeoutCheckedException e) {
e.printStackTrace();
fail("Operation timeout. Iteration: " + i + ".");
}
}
} finally {
lsnr.stopBlockJoin();
for (IgniteInternalFuture fut : futs) fut.cancel();
stopAllGrids();
}
}
use of org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi in project ignite by apache.
the class IgniteClientReconnectAbstractTest method reconnectClientNodes.
/**
* Reconnect client node.
*
* @param log Logger.
* @param clients Clients.
* @param srv Server.
* @param disconnectedC Closure which will be run when client node disconnected.
* @throws Exception If failed.
*/
protected static void reconnectClientNodes(final IgniteLogger log, List<Ignite> clients, Ignite srv, @Nullable Runnable disconnectedC) throws Exception {
final IgniteDiscoverySpi srvSpi = spi0(srv);
final CountDownLatch disconnectLatch = new CountDownLatch(clients.size());
final CountDownLatch reconnectLatch = new CountDownLatch(clients.size());
log.info("Block reconnect.");
List<DiscoverySpiTestListener> blockLsnrs = new ArrayList<>();
for (Ignite client : clients) {
DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener();
lsnr.startBlockJoin();
blockLsnrs.add(lsnr);
spi0(client).setInternalListener(lsnr);
}
IgnitePredicate<Event> p = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED) {
log.info("Disconnected: " + evt);
disconnectLatch.countDown();
} else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
log.info("Reconnected: " + evt);
reconnectLatch.countDown();
}
return true;
}
};
try {
for (Ignite client : clients) client.events().localListen(p, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED);
for (Ignite client : clients) srvSpi.failNode(client.cluster().localNode().id(), null);
waitReconnectEvent(log, disconnectLatch);
if (disconnectedC != null)
disconnectedC.run();
log.info("Allow reconnect.");
for (DiscoverySpiTestListener blockLsnr : blockLsnrs) blockLsnr.stopBlockJoin();
waitReconnectEvent(log, reconnectLatch);
for (Ignite client : clients) client.events().stopLocalListen(p);
} finally {
for (DiscoverySpiTestListener blockLsnr : blockLsnrs) blockLsnr.stopBlockJoin();
}
}
use of org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi in project ignite by apache.
the class CacheLateAffinityAssignmentTest method testDelayAssignmentCacheDestroyCreate.
/**
* Wait for rebalance, cache is destroyed and created again.
*
* @throws Exception If failed.
*/
@Test
public void testDelayAssignmentCacheDestroyCreate() throws Exception {
Ignite ignite0 = startServer(0, 1);
CacheConfiguration ccfg = cacheConfiguration();
ccfg.setName(CACHE_NAME2);
ignite0.createCache(ccfg);
DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener();
((IgniteDiscoverySpi) ignite0.configuration().getDiscoverySpi()).setInternalListener(lsnr);
TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite0.configuration().getCommunicationSpi();
blockSupplySend(spi, CACHE_NAME2);
lsnr.blockCustomEvent(CacheAffinityChangeMessage.class);
startServer(1, 2);
startGrid(3);
checkAffinity(3, topVer(3, 0), false);
spi.stopBlock();
lsnr.waitCustomEvent();
ignite0.destroyCache(CACHE_NAME2);
ccfg = cacheConfiguration();
ccfg.setName(CACHE_NAME2);
ccfg.setAffinity(affinityFunction(10));
ignite0.createCache(ccfg);
lsnr.stopBlockCustomEvents();
checkAffinity(3, topVer(3, 1), false);
checkAffinity(3, topVer(3, 2), false);
idealAff.get(2L).remove(CU.cacheId(CACHE_NAME2));
calculateAffinity(3);
checkAffinity(3, topVer(3, 3), true);
}
Aggregations