use of org.apache.ignite.internal.util.typedef.G in project ignite by apache.
the class ZookeeperDiscoverySplitBrainTest method testSimpleSplitBrain.
/**
* A simple split-brain test, where cluster spliited on 2 parts of server nodes (2 and 3).
* There is also client which sees both parts of splitted cluster.
*
* Result cluster should be: 3 server nodes + 1 client.
*
* @throws Exception If failed.
*/
@Test
public void testSimpleSplitBrain() throws Exception {
failCommSpi = true;
startGridsMultiThreaded(5);
startClientGridsMultiThreaded(5, 3);
awaitPartitionMapExchange();
List<ClusterNode> all = G.allGrids().stream().map(g -> g.cluster().localNode()).collect(Collectors.toList());
List<ClusterNode> part1 = all.subList(0, 3);
List<ClusterNode> part2 = all.subList(3, all.size());
ConnectionsFailureMatrix matrix = ConnectionsFailureMatrix.buildFrom(part1, part2);
ClusterNode lastClient = startGrid(8).cluster().localNode();
awaitPartitionMapExchange();
// Make last client connected to other nodes.
for (ClusterNode node : all) {
if (node.id().equals(lastClient.id()))
continue;
matrix.addConnection(lastClient, node);
matrix.addConnection(node, lastClient);
}
PeerToPeerCommunicationFailureSpi.fail(matrix);
waitForTopology(4);
}
use of org.apache.ignite.internal.util.typedef.G in project ignite by apache.
the class IgniteLogicalRecoveryWithParamsTest method testPartiallyCommitedTx.
/**
* Tests concurrent tx with node stop and further recovery.
*/
private void testPartiallyCommitedTx() throws Exception {
final String cacheName = "recovery";
int itmsCount = 30_000;
AtomicBoolean failFileIO = new AtomicBoolean();
List<Integer> keys;
CacheConfiguration<Integer, Integer> cfg = new CacheConfiguration<Integer, Integer>(cacheName).setCacheMode(CacheMode.PARTITIONED).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC).setBackups(backups).setAffinity(new RendezvousAffinityFunction(false, 32));
try {
final IgniteEx srv = (IgniteEx) startGridsMultiThreaded(numSrvNodes);
G.allGrids().forEach(n -> setWalIOFactory(n, failFileIO));
IgniteEx clnt = startClientGrid("client");
TestRecordingCommunicationSpi nearComm = TestRecordingCommunicationSpi.spi(clnt);
srv.cluster().state(ClusterState.ACTIVE);
final IgniteCache cache = clnt.getOrCreateCache(cfg);
final CountDownLatch commitStart = new CountDownLatch(1);
forceCheckpoint();
nearComm.blockMessages((node, msg) -> msg instanceof GridNearTxPrepareRequest);
if (singleNodeTx)
keys = primaryKeys(srv.cache(cacheName), itmsCount, 0);
else
keys = IntStream.range(0, itmsCount).boxed().collect(Collectors.toList());
Thread t = new Thread(() -> {
try (Transaction tx = clnt.transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
keys.forEach(k -> cache.put(k, k));
commitStart.countDown();
tx.commit();
}
});
t.start();
commitStart.await();
nearComm.waitForBlocked();
nearComm.stopBlock();
assertTrue(waitForWalUpdates(G.allGrids().stream().filter(g -> !g.configuration().isClientMode()).collect(Collectors.toList())));
} finally {
failFileIO.set(true);
stopAllGrids(true);
assertTrue(G.allGrids().isEmpty());
}
final IgniteEx srv = (IgniteEx) startGridsMultiThreaded(numSrvNodes);
srv.cluster().state(ClusterState.ACTIVE);
IgniteCache<Integer, Integer> cache = srv.cache(cacheName);
int cSize = cache.size();
boolean pr = cache.get(keys.get(0)) == null;
for (int i : keys) {
Object res = cache.get(i);
if (pr != (res == null))
assertEquals("ethalon=" + pr + ", current=" + res + ", key=" + i, pr, res == null);
}
assert (cSize == itmsCount || cSize == 0) : "unexpected cache size: " + cSize;
}
use of org.apache.ignite.internal.util.typedef.G in project ignite by apache.
the class IgniteSnapshotRemoteRequestTest method testSnapshotRemoteRequestEachOther.
/**
* @throws Exception If fails.
*/
@Test
public void testSnapshotRemoteRequestEachOther() throws Exception {
IgniteEx ignite = startGridsWithCache(2, CACHE_KEYS_RANGE, valueBuilder(), dfltCacheCfg);
ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get(TIMEOUT);
IgniteSnapshotManager mgr0 = snp(ignite);
IgniteSnapshotManager mgr1 = snp(grid(1));
UUID node0 = grid(0).localNode().id();
UUID node1 = grid(1).localNode().id();
Map<Integer, Set<Integer>> fromNode1 = owningParts(ignite, CU.cacheId(DEFAULT_CACHE_NAME), node1);
Map<Integer, Set<Integer>> fromNode0 = owningParts(grid(1), CU.cacheId(DEFAULT_CACHE_NAME), node0);
G.allGrids().forEach(g -> TestRecordingCommunicationSpi.spi(g).blockMessages((n, msg) -> msg instanceof SnapshotFilesRequestMessage));
CountDownLatch latch = new CountDownLatch(fromNode1.values().stream().mapToInt(Set::size).sum() + fromNode0.values().stream().mapToInt(Set::size).sum());
// Snapshot must be taken on node1 and transmitted to node0.
IgniteInternalFuture<?> futFrom1To0 = mgr0.requestRemoteSnapshotFiles(node1, SNAPSHOT_NAME, fromNode1, () -> false, defaultPartitionConsumer(fromNode1, latch));
IgniteInternalFuture<?> futFrom0To1 = mgr1.requestRemoteSnapshotFiles(node0, SNAPSHOT_NAME, fromNode0, () -> false, defaultPartitionConsumer(fromNode0, latch));
G.allGrids().forEach(g -> TestRecordingCommunicationSpi.spi(g).stopBlock());
latch.await(TIMEOUT, TimeUnit.MILLISECONDS);
futFrom0To1.get(TIMEOUT);
futFrom1To0.get(TIMEOUT);
}
use of org.apache.ignite.internal.util.typedef.G in project ignite by apache.
the class IgniteClusterSnapshotSelfTest method testSnapshotPrimaryBackupsTheSame.
/**
* @throws Exception If fails.
*/
@Test
public void testSnapshotPrimaryBackupsTheSame() throws Exception {
int grids = 3;
AtomicInteger cacheKey = new AtomicInteger();
IgniteEx ignite = startGridsWithCache(grids, dfltCacheCfg, CACHE_KEYS_RANGE);
IgniteInternalFuture<Long> atLoadFut = GridTestUtils.runMultiThreadedAsync(() -> {
while (!Thread.currentThread().isInterrupted()) {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
int gId = rnd.nextInt(grids);
IgniteCache<Integer, Integer> txCache = grid(gId).getOrCreateCache(dfltCacheCfg.getName());
try (Transaction tx = grid(gId).transactions().txStart()) {
txCache.put(cacheKey.incrementAndGet(), 0);
txCache.put(cacheKey.incrementAndGet(), 1);
tx.commit();
}
}
}, 5, "tx-cache-put-");
IgniteInternalFuture<Long> txLoadFut = GridTestUtils.runMultiThreadedAsync(() -> {
while (!Thread.currentThread().isInterrupted()) {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
IgniteCache<Integer, Integer> atomicCache = grid(rnd.nextInt(grids)).getOrCreateCache(atomicCcfg);
atomicCache.put(cacheKey.incrementAndGet(), 0);
}
}, 5, "atomic-cache-put-");
try {
IgniteFuture<Void> fut = ignite.snapshot().createSnapshot(SNAPSHOT_NAME);
fut.get();
} finally {
txLoadFut.cancel();
atLoadFut.cancel();
}
stopAllGrids();
IgniteEx snpIg0 = startGridsFromSnapshot(grids, cfg -> resolveSnapshotWorkDirectory(cfg).getAbsolutePath(), SNAPSHOT_NAME, false);
// Block whole rebalancing.
for (Ignite g : G.allGrids()) TestRecordingCommunicationSpi.spi(g).blockMessages((node, msg) -> msg instanceof GridDhtPartitionDemandMessage);
snpIg0.cluster().state(ACTIVE);
assertFalse("Primary and backup in snapshot must have the same counters. Rebalance must not happen.", GridTestUtils.waitForCondition(() -> {
boolean hasMsgs = false;
for (Ignite g : G.allGrids()) hasMsgs |= TestRecordingCommunicationSpi.spi(g).hasBlockedMessages();
return hasMsgs;
}, REBALANCE_AWAIT_TIME));
TestRecordingCommunicationSpi.stopBlockAll();
assertPartitionsSame(idleVerify(snpIg0, dfltCacheCfg.getName(), atomicCcfg.getName()));
}
use of org.apache.ignite.internal.util.typedef.G in project ignite by apache.
the class RunningQueriesTest method assertNoRunningQueries.
/**
* Check all nodes except passed as parameter on no any running queries.
*
* @param excludeNodes Nodes which will be excluded from check.
*/
private void assertNoRunningQueries(IgniteEx... excludeNodes) {
Set<UUID> excludeIds = Stream.of(excludeNodes).map((ignite) -> ignite.localNode().id()).collect(Collectors.toSet());
for (Ignite g : G.allGrids()) {
IgniteEx node = (IgniteEx) g;
if (!excludeIds.contains(node.localNode().id())) {
Collection<GridRunningQueryInfo> runningQueries = node.context().query().runningQueries(-1);
Assert.assertEquals(0, runningQueries.size());
}
}
}
Aggregations