use of org.apache.ignite.internal.processors.cache.IgniteInternalCache in project ignite by apache.
the class GridCommandHandlerConsistencyTest method fillCache.
/**
*/
private void fillCache(String name, Ignite filtered, boolean incVal) throws Exception {
for (Ignite node : G.allGrids()) {
if (node.equals(filtered))
continue;
while (// Waiting for cache internals to init.
((IgniteEx) node).cachex(name) == null) U.sleep(1);
}
GridCacheVersionManager mgr = ((GridCacheAdapter) (grid(1)).cachex(name).cache()).context().shared().versions();
for (int key = 0; key < PARTITIONS; key++) {
List<Ignite> nodes = new ArrayList<>();
nodes.add(primaryNode(key, name));
nodes.addAll(backupNodes(key, name));
Collections.shuffle(nodes);
int val = key;
Object obj;
for (Ignite node : nodes) {
IgniteInternalCache cache = ((IgniteEx) node).cachex(name);
GridCacheAdapter adapter = ((GridCacheAdapter) cache.cache());
GridCacheEntryEx entry = adapter.entryEx(key);
val = incVal ? ++val : val;
if (binaryCache()) {
BinaryObjectBuilder builder = node.binary().builder("org.apache.ignite.TestValue");
builder.setField("val", val);
obj = builder.build();
} else
obj = val;
boolean init = entry.initialValue(// Incremental or same value.
new CacheObjectImpl(obj, null), // Incremental version.
mgr.next(entry.context().kernalContext().discovery().topologyVersion()), 0, 0, false, AffinityTopologyVersion.NONE, GridDrType.DR_NONE, false, false);
assertTrue("iterableKey " + key + " already inited", init);
}
}
}
use of org.apache.ignite.internal.processors.cache.IgniteInternalCache in project ignite by apache.
the class GridCacheSetAbstractSelfTest method assertSetResourcesCleared.
/**
* Checks internal set maps are cleared.
*/
private void assertSetResourcesCleared() {
assertSetIteratorsCleared();
for (int i = 0; i < gridCount(); i++) {
IgniteKernal grid = (IgniteKernal) grid(i);
for (IgniteInternalCache cache : grid.cachesx(null)) {
CacheDataStructuresManager dsMgr = cache.context().dataStructures();
Map map = GridTestUtils.getFieldValue(dsMgr, "setsMap");
assertEquals("Set not removed [grid=" + i + ", map=" + map + ']', 0, map.size());
}
}
}
use of org.apache.ignite.internal.processors.cache.IgniteInternalCache in project ignite by apache.
the class IgnitePdsCacheAssignmentNodeRestartsTest method checkAffinity.
/**
* @throws Exception If failed.
*/
private void checkAffinity() throws Exception {
List<Ignite> nodes = G.allGrids();
ClusterNode crdNode = null;
for (Ignite node : nodes) {
ClusterNode locNode = node.cluster().localNode();
if (crdNode == null || locNode.order() < crdNode.order())
crdNode = locNode;
}
AffinityTopologyVersion topVer = ((IgniteKernal) grid(crdNode)).context().cache().context().exchange().readyAffinityVersion();
Map<String, List<List<ClusterNode>>> affMap = new HashMap<>();
for (Ignite node : nodes) {
IgniteKernal node0 = (IgniteKernal) node;
for (IgniteInternalCache cache : node0.context().cache().caches()) {
List<List<ClusterNode>> aff = affMap.get(cache.name());
List<List<ClusterNode>> aff0 = cache.context().affinity().assignments(topVer);
if (aff != null)
assertEquals(aff, aff0);
else
affMap.put(cache.name(), aff0);
}
}
}
use of org.apache.ignite.internal.processors.cache.IgniteInternalCache in project ignite by apache.
the class AbstractReadRepairTest method setDifferentValuesForSameKey.
/**
*/
private InconsistentMapping setDifferentValuesForSameKey(int key, boolean misses, boolean nulls, ReadRepairStrategy strategy) throws Exception {
List<Ignite> nodes = new ArrayList<>();
Map<Ignite, T2<Integer, GridCacheVersion>> mapping = new HashMap<>();
Ignite primary = primaryNode(key, DEFAULT_CACHE_NAME);
ThreadLocalRandom rnd = ThreadLocalRandom.current();
if (rnd.nextBoolean()) {
// Reversed order.
nodes.addAll(backupNodes(key, DEFAULT_CACHE_NAME));
nodes.add(primary);
} else {
nodes.add(primary);
nodes.addAll(backupNodes(key, DEFAULT_CACHE_NAME));
}
if (// Random order.
rnd.nextBoolean())
Collections.shuffle(nodes);
IgniteInternalCache<Integer, Integer> internalCache = (grid(1)).cachex(DEFAULT_CACHE_NAME);
GridCacheVersionManager mgr = ((GridCacheAdapter) internalCache.cache()).context().shared().versions();
int incVal = 0;
Integer primVal = null;
Collection<T2<Integer, GridCacheVersion>> vals = new ArrayList<>();
if (misses) {
List<Ignite> keeped = nodes.subList(0, rnd.nextInt(1, nodes.size()));
nodes.stream().filter(node -> !keeped.contains(node)).forEach(node -> {
T2<Integer, GridCacheVersion> nullT2 = new T2<>(null, null);
vals.add(nullT2);
mapping.put(node, nullT2);
});
// Recording nulls (missed values).
nodes = keeped;
}
boolean rmvd = false;
boolean incVer = rnd.nextBoolean();
GridCacheVersion ver = null;
for (Ignite node : nodes) {
IgniteInternalCache<Integer, Integer> cache = ((IgniteEx) node).cachex(DEFAULT_CACHE_NAME);
GridCacheAdapter<Integer, Integer> adapter = (GridCacheAdapter) cache.cache();
GridCacheEntryEx entry = adapter.entryEx(key);
if (ver == null || incVer)
// Incremental version.
ver = mgr.next(entry.context().kernalContext().discovery().topologyVersion());
boolean rmv = nulls && (!rmvd || rnd.nextBoolean());
Integer val = rmv ? null : rnd.nextBoolean() ? /*increment or same as previously*/
++incVal : incVal;
T2<Integer, GridCacheVersion> valVer = new T2<>(val, val != null ? ver : null);
vals.add(valVer);
mapping.put(node, valVer);
GridKernalContext kctx = ((IgniteEx) node).context();
// Incremental value.
byte[] bytes = kctx.cacheObjects().marshal(entry.context().cacheObjectContext(), rmv ? -1 : val);
try {
kctx.cache().context().database().checkpointReadLock();
boolean init = entry.initialValue(new CacheObjectImpl(null, bytes), ver, 0, 0, false, AffinityTopologyVersion.NONE, GridDrType.DR_NONE, false, false);
if (rmv) {
if (cache.configuration().getAtomicityMode() == ATOMIC)
entry.innerUpdate(ver, ((IgniteEx) node).localNode().id(), ((IgniteEx) node).localNode().id(), GridCacheOperation.DELETE, null, null, false, false, false, false, null, false, false, false, false, AffinityTopologyVersion.NONE, null, GridDrType.DR_NONE, 0, 0, null, false, false, null, null, null, null, false);
else
entry.innerRemove(null, ((IgniteEx) node).localNode().id(), ((IgniteEx) node).localNode().id(), false, false, false, false, false, null, AffinityTopologyVersion.NONE, CU.empty0(), GridDrType.DR_NONE, null, null, null, 1L);
rmvd = true;
assertFalse(entry.hasValue());
} else
assertTrue(entry.hasValue());
assertTrue("iterableKey " + key + " already inited", init);
if (node.equals(primary))
primVal = val;
} finally {
((IgniteEx) node).context().cache().context().database().checkpointReadUnlock();
}
}
assertEquals(vals.size(), mapping.size());
assertEquals(vals.size(), internalCache.configuration().getCacheMode() == REPLICATED ? serverNodesCount() : backupsCount() + 1);
if (!misses && !nulls)
// Primary value set.
assertTrue(primVal != null);
Integer fixed;
boolean consistent;
boolean repairable;
if (vals.stream().distinct().count() == 1) {
// Consistent value.
consistent = true;
repairable = true;
fixed = vals.iterator().next().getKey();
} else {
consistent = false;
// Currently, Atomic caches can not be repaired.
repairable = atomicityMode() != ATOMIC;
switch(strategy) {
case LWW:
if (misses || rmvd || !incVer) {
repairable = false;
// Should never be returned.
fixed = Integer.MIN_VALUE;
} else
fixed = incVal;
break;
case PRIMARY:
fixed = primVal;
break;
case RELATIVE_MAJORITY:
// Should never be returned.
fixed = Integer.MIN_VALUE;
Map<T2<Integer, GridCacheVersion>, Integer> counts = new HashMap<>();
for (T2<Integer, GridCacheVersion> val : vals) {
counts.putIfAbsent(val, 0);
counts.compute(val, (k, v) -> v + 1);
}
int[] sorted = counts.values().stream().sorted(Comparator.reverseOrder()).mapToInt(v -> v).toArray();
int max = sorted[0];
if (sorted.length > 1 && sorted[1] == max)
repairable = false;
if (repairable)
for (Map.Entry<T2<Integer, GridCacheVersion>, Integer> count : counts.entrySet()) if (count.getValue().equals(max)) {
fixed = count.getKey().getKey();
break;
}
break;
case REMOVE:
fixed = null;
break;
case CHECK_ONLY:
repairable = false;
// Should never be returned.
fixed = Integer.MIN_VALUE;
break;
default:
throw new UnsupportedOperationException(strategy.toString());
}
}
return new InconsistentMapping(mapping, primVal, fixed, repairable, consistent);
}
use of org.apache.ignite.internal.processors.cache.IgniteInternalCache in project ignite by apache.
the class IgnitePdsCorruptedStoreTest method testCacheMetaCorruption.
/**
* Test node invalidation when cache meta is corrupted.
*/
@Test
public void testCacheMetaCorruption() throws Exception {
IgniteEx ignite = startGrid(0);
ignite.cluster().active(true);
IgniteInternalCache cache = ignite.cachex(CACHE_NAME1);
cache.put(1, 1);
int partId = cache.affinity().partition(1);
int grpId = cache.context().group().groupId();
corruptTreeRoot(ignite, (PageMemoryEx) cache.context().dataRegion().pageMemory(), grpId, partId);
ignite.cluster().active(false);
stopGrid(0);
try {
startGrid(0);
ignite.cluster().active(true);
cache.put(1, 1);
} catch (Exception e) {
// No-op.
}
waitFailure(StorageException.class);
}
Aggregations