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());
}
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();
}
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));
}
Aggregations