Search in sources :

Example 1 with IgniteIrreparableConsistencyViolationException

use of org.apache.ignite.internal.processors.cache.distributed.near.consistency.IgniteIrreparableConsistencyViolationException in project ignite by apache.

the class AbstractReadRepairTest method checkEvent.

/**
 */
protected void checkEvent(ReadRepairData data, IgniteIrreparableConsistencyViolationException e) {
    Map<Object, Map<ClusterNode, CacheConsistencyViolationEvent.EntryInfo>> evtEntries = new HashMap<>();
    Map<Object, Object> evtFixed = new HashMap<>();
    Map<Integer, InconsistentMapping> inconsistent = data.data.entrySet().stream().filter(entry -> !entry.getValue().consistent).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    while (!evtEntries.keySet().equals(inconsistent.keySet())) {
        if (!evtDeq.isEmpty()) {
            CacheConsistencyViolationEvent evt = evtDeq.remove();
            assertEquals(atomicityMode() == TRANSACTIONAL ? data.strategy : ReadRepairStrategy.CHECK_ONLY, evt.getStrategy());
            // Optimistic and read committed transactions produce per key fixes.
            evtEntries.putAll(evt.getEntries());
            evtFixed.putAll(evt.getFixedEntries());
        }
    }
    for (Map.Entry<Integer, InconsistentMapping> mapping : inconsistent.entrySet()) {
        Integer key = mapping.getKey();
        Integer fixed = mapping.getValue().fixed;
        Integer primary = mapping.getValue().primary;
        boolean repairable = mapping.getValue().repairable;
        if (!repairable)
            assertNotNull(e);
        if (e == null) {
            assertTrue(repairable);
            assertTrue(evtFixed.containsKey(key));
            assertEquals(fixed, evtFixed.get(key));
        } else // Repairable but not repaired (because of irreparable entry at the same tx) entries.
        if (e.irreparableKeys().contains(key) || (e.repairableKeys() != null && e.repairableKeys().contains(key)))
            assertFalse(evtFixed.containsKey(key));
        Map<ClusterNode, CacheConsistencyViolationEvent.EntryInfo> evtEntryInfos = evtEntries.get(key);
        if (evtEntryInfos != null)
            for (Map.Entry<ClusterNode, CacheConsistencyViolationEvent.EntryInfo> evtEntryInfo : evtEntryInfos.entrySet()) {
                ClusterNode node = evtEntryInfo.getKey();
                CacheConsistencyViolationEvent.EntryInfo info = evtEntryInfo.getValue();
                if (info.isCorrect())
                    assertEquals(fixed, info.getValue());
                if (info.isPrimary()) {
                    assertEquals(primary, info.getValue());
                    assertEquals(node, primaryNode(key, DEFAULT_CACHE_NAME).cluster().localNode());
                }
            }
    }
    int expectedFixedCnt = inconsistent.size() - (e != null ? (e.repairableKeys() != null ? e.repairableKeys().size() : 0) + e.irreparableKeys().size() : 0);
    assertEquals(expectedFixedCnt, evtFixed.size());
    assertTrue(evtDeq.isEmpty());
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) Map(java.util.Map) PARTITIONED(org.apache.ignite.cache.CacheMode.PARTITIONED) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) EventType(org.apache.ignite.events.EventType) Collection(java.util.Collection) Event(org.apache.ignite.events.Event) ReadRepairStrategy(org.apache.ignite.cache.ReadRepairStrategy) Collectors(java.util.stream.Collectors) IgniteCache(org.apache.ignite.IgniteCache) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CU(org.apache.ignite.internal.util.typedef.internal.CU) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) ClusterState(org.apache.ignite.cluster.ClusterState) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) IgniteIrreparableConsistencyViolationException(org.apache.ignite.internal.processors.cache.distributed.near.consistency.IgniteIrreparableConsistencyViolationException) GridDrType(org.apache.ignite.internal.processors.dr.GridDrType) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IgniteEvents(org.apache.ignite.IgniteEvents) G(org.apache.ignite.internal.util.typedef.G) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) Ignite(org.apache.ignite.Ignite) CacheConsistencyViolationEvent(org.apache.ignite.events.CacheConsistencyViolationEvent) CacheObjectImpl(org.apache.ignite.internal.processors.cache.CacheObjectImpl) FULL_SYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) T2(org.apache.ignite.internal.util.typedef.T2) REPLICATED(org.apache.ignite.cache.CacheMode.REPLICATED) Consumer(java.util.function.Consumer) GridCacheVersionManager(org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager) TreeMap(java.util.TreeMap) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) ATOMIC(org.apache.ignite.cache.CacheAtomicityMode.ATOMIC) EVT_CONSISTENCY_VIOLATION(org.apache.ignite.events.EventType.EVT_CONSISTENCY_VIOLATION) Comparator(java.util.Comparator) Collections(java.util.Collections) CacheMode(org.apache.ignite.cache.CacheMode) ClusterNode(org.apache.ignite.cluster.ClusterNode) HashMap(java.util.HashMap) CacheConsistencyViolationEvent(org.apache.ignite.events.CacheConsistencyViolationEvent) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ConcurrentLinkedDeque (java.util.concurrent.ConcurrentLinkedDeque)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 Ignite (org.apache.ignite.Ignite)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteEvents (org.apache.ignite.IgniteEvents)1 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)1 ATOMIC (org.apache.ignite.cache.CacheAtomicityMode.ATOMIC)1 TRANSACTIONAL (org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL)1 CacheMode (org.apache.ignite.cache.CacheMode)1 PARTITIONED (org.apache.ignite.cache.CacheMode.PARTITIONED)1