Search in sources :

Example 1 with CacheConsistencyViolationEvent

use of org.apache.ignite.events.CacheConsistencyViolationEvent 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)

Example 2 with CacheConsistencyViolationEvent

use of org.apache.ignite.events.CacheConsistencyViolationEvent in project ignite by apache.

the class AbstractReadRepairTest method beforeTestsStarted.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTestsStarted() throws Exception {
    super.beforeTestsStarted();
    if (persistenceEnabled())
        cleanPersistenceDir();
    // Server nodes.
    Ignite ignite = startGrids(serverNodesCount());
    // Client node 1.
    startClientGrid(G.allGrids().size() + 1);
    // Client node 2.
    startClientGrid(G.allGrids().size() + 1);
    final IgniteEvents evts = ignite.events();
    evts.remoteListen(null, (IgnitePredicate<Event>) e -> {
        assert e instanceof CacheConsistencyViolationEvent;
        evtDeq.add((CacheConsistencyViolationEvent) e);
        return true;
    }, EVT_CONSISTENCY_VIOLATION);
    if (persistenceEnabled())
        ignite.cluster().state(ClusterState.ACTIVE);
    ignite.getOrCreateCache(cacheConfiguration());
    awaitPartitionMapExchange();
}
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) CacheConsistencyViolationEvent(org.apache.ignite.events.CacheConsistencyViolationEvent) IgniteEvents(org.apache.ignite.IgniteEvents) Event(org.apache.ignite.events.Event) CacheConsistencyViolationEvent(org.apache.ignite.events.CacheConsistencyViolationEvent) Ignite(org.apache.ignite.Ignite)

Example 3 with CacheConsistencyViolationEvent

use of org.apache.ignite.events.CacheConsistencyViolationEvent in project ignite by apache.

the class GridNearReadRepairAbstractFuture method recordConsistencyViolation.

/**
 * @param fixedEntries Fixed map.
 */
protected final void recordConsistencyViolation(Collection<KeyCacheObject> inconsistentKeys, Map<KeyCacheObject, EntryGetResult> fixedEntries, ReadRepairStrategy strategy) {
    GridEventStorageManager evtMgr = ctx.gridEvents();
    if (!evtMgr.isRecordable(EVT_CONSISTENCY_VIOLATION))
        return;
    Map<Object, Map<ClusterNode, CacheConsistencyViolationEvent.EntryInfo>> entries = new HashMap<>();
    for (Map.Entry<ClusterNode, GridPartitionedGetFuture<KeyCacheObject, EntryGetResult>> pair : futs.entrySet()) {
        ClusterNode node = pair.getKey();
        GridPartitionedGetFuture<KeyCacheObject, EntryGetResult> fut = pair.getValue();
        for (KeyCacheObject key : fut.keys()) {
            if (inconsistentKeys.contains(key)) {
                Map<ClusterNode, CacheConsistencyViolationEvent.EntryInfo> map = entries.computeIfAbsent(ctx.unwrapBinaryIfNeeded(key, !deserializeBinary, false, null), k -> new HashMap<>());
                EntryGetResult res = fut.result().get(key);
                CacheEntryVersion ver = res != null ? res.version() : null;
                Object val = res != null ? ctx.unwrapBinaryIfNeeded(res.value(), !deserializeBinary, false, null) : null;
                boolean primary = primaries.get(key).equals(fut.affNode());
                boolean correct = fixedEntries != null && ((fixedEntries.get(key) != null && fixedEntries.get(key).equals(res)) || (fixedEntries.get(key) == null && res == null));
                map.put(node, new EventEntryInfo(val, ver, primary, correct));
            }
        }
    }
    Map<Object, Object> fixed;
    if (fixedEntries == null)
        fixed = Collections.emptyMap();
    else {
        fixed = new HashMap<>();
        for (Map.Entry<KeyCacheObject, EntryGetResult> entry : fixedEntries.entrySet()) {
            Object key = ctx.unwrapBinaryIfNeeded(entry.getKey(), !deserializeBinary, false, null);
            Object val = entry.getValue() != null ? ctx.unwrapBinaryIfNeeded(entry.getValue().value(), !deserializeBinary, false, null) : null;
            fixed.put(key, val);
        }
    }
    evtMgr.record(new CacheConsistencyViolationEvent(ctx.name(), ctx.discovery().localNode(), "Consistency violation was " + (fixed == null ? "NOT " : "") + "fixed.", entries, fixed, strategy));
}
Also used : GridEventStorageManager(org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridPartitionedGetFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedGetFuture) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CacheEntryVersion(org.apache.ignite.cache.CacheEntryVersion) CacheConsistencyViolationEvent(org.apache.ignite.events.CacheConsistencyViolationEvent) EntryGetResult(org.apache.ignite.internal.processors.cache.EntryGetResult) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Aggregations

HashMap (java.util.HashMap)3 Map (java.util.Map)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 CacheConsistencyViolationEvent (org.apache.ignite.events.CacheConsistencyViolationEvent)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 ConcurrentLinkedDeque (java.util.concurrent.ConcurrentLinkedDeque)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 Consumer (java.util.function.Consumer)2 Collectors (java.util.stream.Collectors)2 Ignite (org.apache.ignite.Ignite)2 IgniteCache (org.apache.ignite.IgniteCache)2 IgniteEvents (org.apache.ignite.IgniteEvents)2 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)2 ATOMIC (org.apache.ignite.cache.CacheAtomicityMode.ATOMIC)2 TRANSACTIONAL (org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL)2