Search in sources :

Example 1 with CacheEntryVersion

use of org.apache.ignite.cache.CacheEntryVersion 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)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CacheEntryVersion (org.apache.ignite.cache.CacheEntryVersion)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 CacheConsistencyViolationEvent (org.apache.ignite.events.CacheConsistencyViolationEvent)1 GridEventStorageManager (org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager)1 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)1 EntryGetResult (org.apache.ignite.internal.processors.cache.EntryGetResult)1 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)1 GridPartitionedGetFuture (org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedGetFuture)1