use of org.apache.ignite.internal.processors.cache.CacheObjectImpl in project ignite by apache.
the class IgniteCacheContinuousQueryImmutableEntryTest method testCacheContinuousQueryEntrySerialization.
/**
*/
@Test
public void testCacheContinuousQueryEntrySerialization() {
CacheContinuousQueryEntry e0 = new CacheContinuousQueryEntry(1, EventType.UPDATED, new KeyCacheObjectImpl(1, new byte[] { 0, 0, 0, 1 }, 1), new CacheObjectImpl(2, new byte[] { 0, 0, 0, 2 }), new CacheObjectImpl(2, new byte[] { 0, 0, 0, 3 }), true, 1, 1L, new AffinityTopologyVersion(1L), (byte) 0);
e0.markFiltered();
ByteBuffer buf = ByteBuffer.allocate(4096);
DirectMessageWriter writer = new DirectMessageWriter((byte) 1);
// Skip write class header.
writer.onHeaderWritten();
e0.writeTo(buf, writer);
CacheContinuousQueryEntry e1 = new CacheContinuousQueryEntry();
IgniteMessageFactoryImpl msgFactory = new IgniteMessageFactoryImpl(new MessageFactory[] { new GridIoMessageFactory() });
e1.readFrom(ByteBuffer.wrap(buf.array()), new DirectMessageReader(msgFactory, (byte) 1));
assertEquals(e0.cacheId(), e1.cacheId());
assertEquals(e0.eventType(), e1.eventType());
assertEquals(e0.isFiltered(), e1.isFiltered());
assertEquals(e0.isBackup(), e1.isBackup());
assertEquals(e0.isKeepBinary(), e1.isKeepBinary());
assertEquals(e0.partition(), e1.partition());
assertEquals(e0.updateCounter(), e1.updateCounter());
// Key and value shouldn't be serialized in case an event is filtered.
assertNull(e1.key());
assertNotNull(e0.key());
assertNull(e1.oldValue());
assertNotNull(e0.oldValue());
assertNull(e1.value());
assertNotNull(e0.value());
}
use of org.apache.ignite.internal.processors.cache.CacheObjectImpl 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.CacheObjectImpl in project ignite by apache.
the class CdcCacheVersionTest method addConflictData.
/**
*/
private void addConflictData(IgniteEx cli, IgniteCache<Integer, User> cache, int from, int to, TransactionConcurrency concurrency, TransactionIsolation isolation) {
try {
IgniteInternalCache<Integer, User> intCache = cli.cachex(cache.getName());
Map<KeyCacheObject, GridCacheDrInfo> drMap = new HashMap<>();
for (int i = from; i < to; i++) {
KeyCacheObject key = new KeyCacheObjectImpl(i, null, intCache.affinity().partition(i));
CacheObject val = new CacheObjectImpl(createUser(i), null);
val.prepareMarshal(intCache.context().cacheObjectContext());
drMap.put(key, new GridCacheDrInfo(val, new GridCacheVersion(1, i, 1, OTHER_CLUSTER_ID)));
}
if (concurrency != null) {
try (Transaction tx = cli.transactions().txStart(concurrency, isolation)) {
intCache.putAllConflict(drMap);
tx.commit();
}
} else
intCache.putAllConflict(drMap);
} catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
}
use of org.apache.ignite.internal.processors.cache.CacheObjectImpl in project ignite by apache.
the class IgniteWalConverterSensitiveDataTest method withSensitiveData.
/**
* Creating {@link WALRecord} instances with sensitive data.
*
* @return {@link WALRecord} instances with sensitive data.
*/
private Collection<WALRecord> withSensitiveData() {
List<WALRecord> walRecords = new ArrayList<>();
int cacheId = CU.cacheId(DEFAULT_CACHE_NAME);
DataEntry dataEntry = new DataEntry(cacheId, new KeyCacheObjectImpl(SENSITIVE_DATA_VALUE_PREFIX, null, 0), new CacheObjectImpl(SENSITIVE_DATA_VALUE_PREFIX, null), GridCacheOperation.CREATE, new GridCacheVersion(), new GridCacheVersion(), 0, 0, 0, DataEntry.EMPTY_FLAGS);
byte[] sensitiveDataBytes = SENSITIVE_DATA_VALUE_PREFIX.getBytes(StandardCharsets.UTF_8);
walRecords.add(new DataRecord(dataEntry));
walRecords.add(new MetastoreDataRecord(SENSITIVE_DATA_VALUE_PREFIX, sensitiveDataBytes));
return walRecords;
}
Aggregations