use of org.apache.ignite.internal.processors.cache.distributed.TestCacheNodeExcludingFilter in project ignite by apache.
the class ZookeeperDiscoveryCommunicationFailureTest method testCommunicationFailureResolve_CachesInfo1.
/**
* @throws Exception If failed.
*/
@Test
public void testCommunicationFailureResolve_CachesInfo1() throws Exception {
testCommSpi = true;
sesTimeout = 5000;
final CacheInfoCommunicationFailureResolver rslvr = new CacheInfoCommunicationFailureResolver();
commFailureRslvr = new IgniteOutClosure<CommunicationFailureResolver>() {
@Override
public CommunicationFailureResolver apply() {
return rslvr;
}
};
startGrids(2);
awaitPartitionMapExchange();
Map<String, T3<Integer, Integer, Integer>> expCaches = new HashMap<>();
expCaches.put(DEFAULT_CACHE_NAME, new T3<>(RendezvousAffinityFunction.DFLT_PARTITION_COUNT, 0, 1));
checkResolverCachesInfo(ignite(0), expCaches);
List<CacheConfiguration> caches = new ArrayList<>();
CacheConfiguration c1 = new CacheConfiguration("c1");
c1.setBackups(1);
c1.setAffinity(new RendezvousAffinityFunction(false, 64));
caches.add(c1);
CacheConfiguration c2 = new CacheConfiguration("c2");
c2.setBackups(2);
c2.setAffinity(new RendezvousAffinityFunction(false, 128));
caches.add(c2);
CacheConfiguration c3 = new CacheConfiguration("c3");
c3.setCacheMode(CacheMode.REPLICATED);
c3.setAffinity(new RendezvousAffinityFunction(false, 256));
caches.add(c3);
ignite(0).createCaches(caches);
expCaches.put("c1", new T3<>(64, 1, 2));
expCaches.put("c2", new T3<>(128, 2, 2));
expCaches.put("c3", new T3<>(256, 1, 2));
checkResolverCachesInfo(ignite(0), expCaches);
startGrid(2);
startGrid(3);
awaitPartitionMapExchange();
expCaches.put("c2", new T3<>(128, 2, 3));
expCaches.put("c3", new T3<>(256, 1, 4));
checkResolverCachesInfo(ignite(0), expCaches);
CacheConfiguration<Object, Object> c4 = new CacheConfiguration<>("c4");
c4.setCacheMode(CacheMode.PARTITIONED);
c4.setBackups(0);
c4.setAffinity(new RendezvousAffinityFunction(false, 256));
c4.setNodeFilter(new TestCacheNodeExcludingFilter(getTestIgniteInstanceName(0), getTestIgniteInstanceName(1)));
ignite(2).createCache(c4);
expCaches.put("c4", new T3<>(256, 0, 1));
checkResolverCachesInfo(ignite(0), expCaches);
// Stop current coordinator, check new coordinator will initialize required caches information.
stopGrid(0);
awaitPartitionMapExchange();
expCaches.put("c3", new T3<>(256, 1, 3));
checkResolverCachesInfo(ignite(1), expCaches);
startGrid(0);
expCaches.put("c3", new T3<>(256, 1, 4));
checkResolverCachesInfo(ignite(1), expCaches);
stopGrid(1);
expCaches.put("c3", new T3<>(256, 1, 3));
checkResolverCachesInfo(ignite(3), expCaches);
}
use of org.apache.ignite.internal.processors.cache.distributed.TestCacheNodeExcludingFilter in project ignite by apache.
the class CacheMvccTransactionsTest method testGetVersionRequestFailover.
/**
* @throws Exception If failed.
*/
@Test
public void testGetVersionRequestFailover() throws Exception {
final int NODES = 5;
testSpi = true;
startGridsMultiThreaded(NODES - 1);
client = true;
Ignite client = startGrid(NODES - 1);
final List<String> cacheNames = new ArrayList<>();
final Map<Integer, Integer> vals = new HashMap<>();
for (int i = 0; i < 100; i++) vals.put(i, i);
for (CacheConfiguration ccfg : cacheConfigurations()) {
ccfg.setName("cache-" + cacheNames.size());
ccfg.setNodeFilter(new TestCacheNodeExcludingFilter(getTestIgniteInstanceName(0)));
cacheNames.add(ccfg.getName());
IgniteCache cache = client.createCache(ccfg);
try (Transaction tx = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
writeAllByMode(cache, vals, PUT, INTEGER_CODEC);
tx.commit();
}
}
final AtomicInteger nodeIdx = new AtomicInteger(1);
final AtomicBoolean done = new AtomicBoolean();
try {
IgniteInternalFuture getFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
Ignite node = ignite(nodeIdx.getAndIncrement());
int cnt = 0;
while (!done.get()) {
for (String cacheName : cacheNames) {
// TODO IGNITE-6754 add SQL and SCAN support.
Map<Integer, Integer> res = readAllByMode(node.cache(cacheName), vals.keySet(), GET, INTEGER_CODEC);
assertEquals(vals, res);
}
cnt++;
}
log.info("Finished [node=" + node.name() + ", cnt=" + cnt + ']');
return null;
}
}, NODES - 1, "get-thread");
doSleep(1000);
TestRecordingCommunicationSpi crdSpi = TestRecordingCommunicationSpi.spi(ignite(0));
crdSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
return msg instanceof MvccSnapshotResponse;
}
});
crdSpi.waitForBlocked();
stopGrid(0);
doSleep(1000);
done.set(true);
getFut.get();
} finally {
done.set(true);
}
}
use of org.apache.ignite.internal.processors.cache.distributed.TestCacheNodeExcludingFilter in project ignite by apache.
the class CacheMvccAbstractBasicCoordinatorFailoverTest method readInProgressCoordinatorFailsSimple.
/**
* @param fromClient {@code True} if read from client node, otherwise from server node.
* @param crdChangeCnt Number of coordinator changes.
* @param readInTx {@code True} to read inside transaction.
* @param cfgC Cache configuration closure.
* @param readMode Read mode.
* @param writeMode Write mode.
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
private void readInProgressCoordinatorFailsSimple(boolean fromClient, int crdChangeCnt, final boolean readInTx, @Nullable IgniteInClosure<CacheConfiguration> cfgC, ReadMode readMode, WriteMode writeMode) throws Exception {
info("readInProgressCoordinatorFailsSimple [fromClient=" + fromClient + ", crdChangeCnt=" + crdChangeCnt + ", readInTx=" + readInTx + ']');
testSpi = true;
client = false;
final int SRVS = 3;
final int COORDS = crdChangeCnt + 1;
startGrids(SRVS + COORDS);
client = true;
assertTrue(startGrid(SRVS + COORDS).configuration().isClientMode());
final Ignite getNode = fromClient ? ignite(SRVS + COORDS) : ignite(COORDS);
String[] excludeNodes = new String[COORDS];
for (int i = 0; i < COORDS; i++) excludeNodes[i] = testNodeName(i);
CacheConfiguration ccfg = cacheConfiguration(cacheMode(), FULL_SYNC, 0, DFLT_PARTITION_COUNT).setNodeFilter(new TestCacheNodeExcludingFilter(excludeNodes));
if (cfgC != null)
cfgC.apply(ccfg);
final IgniteCache cache = getNode.createCache(ccfg);
final Set<Integer> keys = new TreeSet<>();
List<Integer> keys1 = primaryKeys(jcache(COORDS), 10);
List<Integer> keys2 = primaryKeys(jcache(COORDS + 1), 10);
keys.addAll(keys1);
keys.addAll(keys2);
Map<Integer, Integer> vals = new LinkedHashMap();
for (Integer key : keys) vals.put(key, -1);
try (Transaction tx = getNode.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
writeAllByMode(cache, vals, writeMode, INTEGER_CODEC);
tx.commit();
}
final TestRecordingCommunicationSpi getNodeSpi = TestRecordingCommunicationSpi.spi(getNode);
getNodeSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
String msgClsName = msg.getClass().getSimpleName();
return msgClsName.matches("GridNearGetRequest|GridH2QueryRequest|GridCacheQueryRequest");
}
});
IgniteInternalFuture getFut = GridTestUtils.runAsync(new Callable() {
@Override
public Object call() throws Exception {
Map<Integer, Integer> res = null;
if (readInTx) {
try (Transaction tx = getNode.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
res = readAllByMode(cache, keys, readMode, INTEGER_CODEC);
tx.rollback();
} catch (Exception e) {
handleTxException(e);
}
} else
res = readAllByMode(cache, keys, readMode, INTEGER_CODEC);
assertTrue((res != null || readInTx) || (res != null && 20 == res.size()));
if (res != null) {
Integer val = null;
for (Integer val0 : res.values()) {
assertNotNull(val0);
if (val == null)
val = val0;
else
assertEquals("res=" + res, val, val0);
}
}
return null;
}
}, "get-thread");
getNodeSpi.waitForBlocked();
for (int i = 0; i < crdChangeCnt; i++) stopGrid(i);
for (int i = 0; i < 10; i++) {
vals = new LinkedHashMap();
for (Integer key : keys) vals.put(key, i);
while (true) {
try (Transaction tx = getNode.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
writeAllByMode(cache, vals, writeMode, INTEGER_CODEC);
tx.commit();
break;
} catch (Exception e) {
handleTxException(e);
}
}
}
getNodeSpi.stopBlock(true);
getFut.get();
for (Ignite node : G.allGrids()) checkActiveQueriesCleanup(node);
}
use of org.apache.ignite.internal.processors.cache.distributed.TestCacheNodeExcludingFilter in project ignite by apache.
the class CacheMvccAbstractBasicCoordinatorFailoverTest method checkCoordinatorChangeActiveQueryClientFails_Simple.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
protected void checkCoordinatorChangeActiveQueryClientFails_Simple(@Nullable IgniteInClosure<CacheConfiguration> cfgC, ReadMode readMode, WriteMode writeMode) throws Exception {
testSpi = true;
client = false;
final int SRVS = 3;
final int COORDS = 1;
startGrids(SRVS + COORDS);
client = true;
Ignite client = startGrid(SRVS + COORDS);
CacheConfiguration ccfg = cacheConfiguration(cacheMode(), FULL_SYNC, 0, DFLT_PARTITION_COUNT).setNodeFilter(new TestCacheNodeExcludingFilter(testNodeName(0)));
if (cfgC != null)
cfgC.apply(ccfg);
final IgniteCache cache = client.createCache(ccfg);
final Map<Integer, Integer> vals = new LinkedHashMap<>();
for (int i = 0; i < 100; i++) vals.put(i, i);
try (Transaction tx = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
writeAllByMode(cache, vals, writeMode, INTEGER_CODEC);
tx.commit();
}
final TestRecordingCommunicationSpi clientSpi = TestRecordingCommunicationSpi.spi(client);
clientSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
String msgClsName = msg.getClass().getSimpleName();
return msgClsName.matches("GridNearGetRequest|GridH2QueryRequest|GridCacheQueryRequest");
}
});
IgniteInternalFuture getFut = GridTestUtils.runAsync(new Callable() {
@Override
public Object call() throws Exception {
Map res = readAllByMode(cache, vals.keySet(), readMode, INTEGER_CODEC);
assertEquals(vals, res);
return null;
}
}, "get-thread");
clientSpi.waitForBlocked();
stopGrid(0);
clientSpi.stopBlock(true);
getFut.get();
for (Ignite node : G.allGrids()) checkActiveQueriesCleanup(node);
}
use of org.apache.ignite.internal.processors.cache.distributed.TestCacheNodeExcludingFilter in project ignite by apache.
the class CacheMvccAbstractBasicCoordinatorFailoverTest method readInProgressCoordinatorFails.
/**
* @param readDelay {@code True} if delays get requests.
* @param readInTx {@code True} to read inside transaction.
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
protected void readInProgressCoordinatorFails(boolean readDelay, final boolean readInTx, final TransactionConcurrency concurrency, final TransactionIsolation isolation, ReadMode readMode, WriteMode writeMode, @Nullable IgniteInClosure<CacheConfiguration> cfgC) throws Exception {
final int COORD_NODES = 5;
final int SRV_NODES = 4;
if (readDelay)
testSpi = true;
startGrids(COORD_NODES);
startGridsMultiThreaded(COORD_NODES, SRV_NODES);
client = true;
Ignite client = startGrid(COORD_NODES + SRV_NODES);
final List<String> cacheNames = new ArrayList<>();
final int KEYS = 100;
final Map<Integer, Integer> vals = new LinkedHashMap<>();
for (int i = 0; i < KEYS; i++) vals.put(i, 0);
String[] exclude = new String[COORD_NODES];
for (int i = 0; i < COORD_NODES; i++) exclude[i] = testNodeName(i);
for (CacheConfiguration ccfg : cacheConfigurations()) {
ccfg.setName("cache-" + cacheNames.size());
if (cfgC != null)
cfgC.apply(ccfg);
// First server nodes are 'dedicated' coordinators.
ccfg.setNodeFilter(new TestCacheNodeExcludingFilter(exclude));
cacheNames.add(ccfg.getName());
IgniteCache cache = client.createCache(ccfg);
boolean updated = false;
while (!updated) {
try (Transaction tx = client.transactions().txStart(concurrency, isolation)) {
tx.timeout(TX_TIMEOUT);
writeAllByMode(cache, vals, writeMode, INTEGER_CODEC);
tx.commit();
updated = true;
} catch (Exception e) {
handleTxException(e);
}
}
}
if (readDelay) {
for (int i = COORD_NODES; i < COORD_NODES + SRV_NODES + 1; i++) {
TestRecordingCommunicationSpi.spi(ignite(i)).closure(new IgniteBiInClosure<ClusterNode, Message>() {
@Override
public void apply(ClusterNode node, Message msg) {
if (msg instanceof GridNearGetRequest)
doSleep(ThreadLocalRandom.current().nextLong(50) + 1);
}
});
}
}
final AtomicBoolean done = new AtomicBoolean();
try {
final AtomicInteger readNodeIdx = new AtomicInteger(0);
IgniteInternalFuture getFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
Ignite node = ignite(COORD_NODES + (readNodeIdx.getAndIncrement() % (SRV_NODES + 1)));
int cnt = 0;
while (!done.get() && !Thread.currentThread().isInterrupted()) {
for (String cacheName : cacheNames) {
IgniteCache cache = node.cache(cacheName);
Map<Integer, Integer> res = null;
if (readInTx) {
try (Transaction tx = node.transactions().txStart(concurrency, isolation)) {
tx.timeout(TX_TIMEOUT);
res = readAllByMode(cache, vals.keySet(), readMode, INTEGER_CODEC);
tx.commit();
} catch (Exception e) {
// TODO Remove catch clause when IGNITE-8841 implemented.
handleTxException(e);
}
} else
res = readAllByMode(cache, vals.keySet(), readMode, INTEGER_CODEC);
if (readInTx) {
// TODO IGNITE-8841
assertTrue("res.size=" + (res == null ? 0 : res.size()) + ", res=" + res, res == null || vals.size() == res.size());
} else {
assertEquals(vals.size(), res.size());
Integer val0 = null;
for (Integer val : res.values()) {
if (val0 == null)
val0 = val;
else
assertEquals(val0, val);
}
}
}
cnt++;
}
log.info("Finished [node=" + node.name() + ", readCnt=" + cnt + ']');
return null;
} catch (Throwable e) {
error("Unexpected error: " + e, e);
throw e;
}
}
}, ((SRV_NODES + 1) + 1) * 2, "get-thread");
IgniteInternalFuture putFut1 = GridTestUtils.runAsync(new Callable() {
@Override
public Void call() throws Exception {
Ignite node = ignite(COORD_NODES);
List<IgniteCache> caches = new ArrayList<>();
for (String cacheName : cacheNames) caches.add(node.cache(cacheName));
Integer val = 1;
while (!done.get()) {
Map<Integer, Integer> vals = new LinkedHashMap<>();
for (int i = 0; i < KEYS; i++) vals.put(i, val);
for (IgniteCache cache : caches) {
try {
try (Transaction tx = node.transactions().txStart(concurrency, isolation)) {
tx.timeout(TX_TIMEOUT);
writeAllByMode(cache, vals, writeMode, INTEGER_CODEC);
tx.commit();
}
} catch (Exception e) {
handleTxException(e);
}
}
val++;
}
return null;
}
}, "putAll-thread");
IgniteInternalFuture putFut2 = GridTestUtils.runAsync(new Callable() {
@Override
public Void call() throws Exception {
Ignite node = ignite(COORD_NODES);
IgniteCache cache = node.cache(cacheNames.get(0));
Integer val = 0;
while (!done.get()) {
try {
try (Transaction tx = node.transactions().txStart(concurrency, isolation)) {
tx.timeout(TX_TIMEOUT);
writeByMode(cache, Integer.MAX_VALUE, val, writeMode, INTEGER_CODEC);
tx.commit();
}
} catch (Exception e) {
handleTxException(e);
}
val++;
}
return null;
}
}, "put-thread");
for (int i = 0; i < COORD_NODES && !getFut.isDone(); i++) {
U.sleep(3000);
stopGrid(i);
awaitPartitionMapExchange();
}
done.set(true);
getFut.get();
putFut1.get();
putFut2.get();
for (Ignite node : G.allGrids()) checkActiveQueriesCleanup(node);
} finally {
done.set(true);
}
}
Aggregations