use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionsStateValidator in project ignite by apache.
the class GridCachePartitionsStateValidatorSelfTest method testPartitionCacheSizesValidation.
/**
* Test partition cache sizes validation.
*/
@Test
public void testPartitionCacheSizesValidation() {
UUID remoteNode = UUID.randomUUID();
UUID ignoreNode = UUID.randomUUID();
// For partitions 0 and 2 we have inconsistent update counters.
Map<Integer, T2<Long, Long>> updateCountersMap = new HashMap<>();
updateCountersMap.put(0, new T2<>(2L, 2L));
updateCountersMap.put(1, new T2<>(2L, 2L));
updateCountersMap.put(2, new T2<>(5L, 5L));
// For partitions 0 and 2 we have inconsistent cache sizes.
Map<Integer, Long> cacheSizesMap = new HashMap<>();
cacheSizesMap.put(0, 2L);
cacheSizesMap.put(1, 2L);
cacheSizesMap.put(2, 2L);
// Form single messages map.
Map<UUID, GridDhtPartitionsSingleMessage> messages = new HashMap<>();
messages.put(remoteNode, from(updateCountersMap, cacheSizesMap));
messages.put(ignoreNode, from(updateCountersMap, cacheSizesMap));
GridDhtPartitionsStateValidator validator = new GridDhtPartitionsStateValidator(cctxMock);
// (partId, (nodeId, cacheSize))
Map<Integer, Map<UUID, Long>> result = validator.validatePartitionsSizes(topologyMock, messages, Sets.newHashSet(ignoreNode));
// Check that validation result contains all necessary information.
Assert.assertEquals(2, result.size());
Assert.assertTrue(result.containsKey(0));
Assert.assertTrue(result.containsKey(2));
Assert.assertTrue(result.get(0).get(localNodeId) == 1L);
Assert.assertTrue(result.get(0).get(remoteNode) == 2L);
Assert.assertTrue(result.get(2).get(localNodeId) == 3L);
Assert.assertTrue(result.get(2).get(remoteNode) == 2L);
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionsStateValidator in project ignite by apache.
the class GridCachePartitionsStateValidationTest method testPartitionCountersConsistencyOnExchange.
/**
* Test that all nodes send correct {@link GridDhtPartitionsSingleMessage} with consistent update counters.
*
* @throws Exception If failed.
*/
@Test
public void testPartitionCountersConsistencyOnExchange() throws Exception {
// Reopen https://issues.apache.org/jira/browse/IGNITE-10766 if starts failing with forced MVCC
IgniteEx ignite = startGrids(4);
ignite.cluster().active(true);
awaitPartitionMapExchange();
final String atomicCacheName = "atomic-cache";
final String txCacheName = "tx-cache";
Ignite client = startClientGrid(4);
IgniteCache atomicCache = client.getOrCreateCache(new CacheConfiguration<>(atomicCacheName).setAtomicityMode(CacheAtomicityMode.ATOMIC).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC).setBackups(2).setAffinity(new RendezvousAffinityFunction(false, 32)));
IgniteCache txCache = client.getOrCreateCache(new CacheConfiguration<>(txCacheName).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC).setBackups(2).setAffinity(new RendezvousAffinityFunction(false, 32)));
for (int it = 0; it < 10; it++) {
SingleMessageInterceptorCommunicationSpi spi = (SingleMessageInterceptorCommunicationSpi) ignite.configuration().getCommunicationSpi();
spi.clear();
// Stop load future.
final AtomicBoolean stop = new AtomicBoolean();
// Run atomic load.
IgniteInternalFuture atomicLoadFuture = GridTestUtils.runMultiThreadedAsync(() -> {
int k = 0;
while (!stop.get()) {
k++;
try {
atomicCache.put(k, k);
} catch (Exception ignored) {
}
}
}, 1, "atomic-load");
// Run tx load.
IgniteInternalFuture txLoadFuture = GridTestUtils.runMultiThreadedAsync(() -> {
final int txOps = 5;
while (!stop.get()) {
List<Integer> randomKeys = Stream.generate(() -> ThreadLocalRandom.current().nextInt(5)).limit(txOps).sorted().collect(Collectors.toList());
try (Transaction tx = ignite.transactions().txStart(OPTIMISTIC, READ_COMMITTED)) {
for (Integer key : randomKeys) txCache.put(key, key);
tx.commit();
} catch (Exception ignored) {
}
}
}, 4, "tx-load");
// Wait for some data.
Thread.sleep(1000);
// Prevent sending full message.
spi.blockFullMessage();
// Trigger exchange.
IgniteInternalFuture nodeStopFuture = GridTestUtils.runAsync(() -> stopGrid(3));
try {
spi.waitUntilAllSingleMessagesAreSent();
List<GridDhtPartitionsSingleMessage> interceptedMessages = spi.getMessages();
// Associate each message with existing node UUID.
Map<UUID, GridDhtPartitionsSingleMessage> messagesMap = new HashMap<>();
for (int i = 0; i < interceptedMessages.size(); i++) messagesMap.put(grid(i + 1).context().localNodeId(), interceptedMessages.get(i));
GridDhtPartitionsStateValidator validator = new GridDhtPartitionsStateValidator(ignite.context().cache().context());
// Validate partition update counters. If counters are not consistent, exception will be thrown.
validator.validatePartitionsUpdateCounters(ignite.cachex(atomicCacheName).context().topology(), messagesMap, Collections.emptySet());
validator.validatePartitionsUpdateCounters(ignite.cachex(txCacheName).context().topology(), messagesMap, Collections.emptySet());
} finally {
// Stop load and resume exchange.
spi.unblockFullMessage();
stop.set(true);
atomicLoadFuture.get();
txLoadFuture.get();
nodeStopFuture.get();
}
// Return grid to initial state.
startGrid(3);
awaitPartitionMapExchange();
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionsStateValidator in project ignite by apache.
the class GridCachePartitionsStateValidatorSelfTest method testPartitionCountersValidation.
/**
* Test partition update counters validation.
*/
@Test
public void testPartitionCountersValidation() {
UUID remoteNode = UUID.randomUUID();
UUID ignoreNode = UUID.randomUUID();
// For partitions 0 and 2 we have inconsistent update counters.
Map<Integer, T2<Long, Long>> updateCountersMap = new HashMap<>();
updateCountersMap.put(0, new T2<>(2L, 2L));
updateCountersMap.put(1, new T2<>(2L, 2L));
updateCountersMap.put(2, new T2<>(5L, 5L));
// For partitions 0 and 2 we have inconsistent cache sizes.
Map<Integer, Long> cacheSizesMap = new HashMap<>();
cacheSizesMap.put(0, 2L);
cacheSizesMap.put(1, 2L);
cacheSizesMap.put(2, 2L);
// Form single messages map.
Map<UUID, GridDhtPartitionsSingleMessage> messages = new HashMap<>();
messages.put(remoteNode, from(updateCountersMap, cacheSizesMap));
messages.put(ignoreNode, from(updateCountersMap, cacheSizesMap));
GridDhtPartitionsStateValidator validator = new GridDhtPartitionsStateValidator(cctxMock);
// (partId, (nodeId, updateCounter))
Map<Integer, Map<UUID, Long>> result = validator.validatePartitionsUpdateCounters(topologyMock, messages, Sets.newHashSet(ignoreNode));
// Check that validation result contains all necessary information.
Assert.assertEquals(2, result.size());
Assert.assertTrue(result.containsKey(0));
Assert.assertTrue(result.containsKey(2));
Assert.assertTrue(result.get(0).get(localNodeId) == 1L);
Assert.assertTrue(result.get(0).get(remoteNode) == 2L);
Assert.assertTrue(result.get(2).get(localNodeId) == 3L);
Assert.assertTrue(result.get(2).get(remoteNode) == 5L);
}
Aggregations