use of org.apache.ignite.internal.processors.cache.version.GridCacheVersionEx in project ignite by apache.
the class IgniteUtils method readVersion.
/**
* @param arr Array.
* @param off Offset.
* @param verEx If {@code true} reads {@link GridCacheVersionEx} instance.
* @return Version.
*/
public static GridCacheVersion readVersion(byte[] arr, long off, boolean verEx) {
int topVer = GridUnsafe.getInt(arr, off);
off += 4;
int nodeOrderDrId = GridUnsafe.getInt(arr, off);
off += 4;
long order = GridUnsafe.getLong(arr, off);
off += 8;
GridCacheVersion ver = new GridCacheVersion(topVer, nodeOrderDrId, order);
if (verEx) {
topVer = GridUnsafe.getInt(arr, off);
off += 4;
nodeOrderDrId = GridUnsafe.getInt(arr, off);
off += 4;
order = GridUnsafe.getLong(arr, off);
ver = new GridCacheVersionEx(topVer, nodeOrderDrId, order, ver);
}
return ver;
}
use of org.apache.ignite.internal.processors.cache.version.GridCacheVersionEx in project ignite by apache.
the class IgniteUtils method readVersion.
/**
* @param ptr Offheap address.
* @param verEx If {@code true} reads {@link GridCacheVersionEx} instance.
* @return Version.
*/
public static GridCacheVersion readVersion(long ptr, boolean verEx) {
GridCacheVersion ver = new GridCacheVersion(GridUnsafe.getInt(ptr), GridUnsafe.getInt(ptr + 4), GridUnsafe.getLong(ptr + 8));
if (verEx) {
ptr += 16;
ver = new GridCacheVersionEx(GridUnsafe.getInt(ptr), GridUnsafe.getInt(ptr + 4), GridUnsafe.getLong(ptr + 8), ver);
}
return ver;
}
use of org.apache.ignite.internal.processors.cache.version.GridCacheVersionEx in project ignite by apache.
the class GridCacheVersionSelfTest method testMarshalling.
/**
* Test versions marshalling.
*
* @throws Exception If failed.
*/
public void testMarshalling() throws Exception {
GridCacheVersion ver = version(1, 1);
GridCacheVersionEx verEx = new GridCacheVersionEx(2, 2, 0, ver);
Marshaller marsh = createStandaloneBinaryMarshaller();
byte[] verBytes = marsh.marshal(ver);
byte[] verExBytes = marsh.marshal(verEx);
GridCacheVersion verNew = marsh.unmarshal(verBytes, Thread.currentThread().getContextClassLoader());
GridCacheVersionEx verExNew = marsh.unmarshal(verExBytes, Thread.currentThread().getContextClassLoader());
assert ver.equals(verNew);
assert verEx.equals(verExNew);
}
use of org.apache.ignite.internal.processors.cache.version.GridCacheVersionEx in project ignite by apache.
the class GridDhtAtomicCache method updateSingle.
/**
* Updates locked entries one-by-one.
*
* @param nearNode Originating node.
* @param hasNear {@code True} if originating node has near cache.
* @param req Update request.
* @param res Update response.
* @param locked Locked entries.
* @param ver Assigned update version.
* @param dhtFut Optional DHT future.
* @param replicate Whether DR is enabled for that cache.
* @param taskName Task name.
* @param expiry Expiry policy.
* @param sndPrevVal If {@code true} sends previous value to backups.
* @return Return value.
* @throws GridCacheEntryRemovedException Should be never thrown.
*/
private UpdateSingleResult updateSingle(ClusterNode nearNode, boolean hasNear, GridNearAtomicAbstractUpdateRequest req, GridNearAtomicUpdateResponse res, List<GridDhtCacheEntry> locked, GridCacheVersion ver, @Nullable GridDhtAtomicAbstractUpdateFuture dhtFut, boolean replicate, String taskName, @Nullable IgniteCacheExpiryPolicy expiry, boolean sndPrevVal) throws GridCacheEntryRemovedException {
GridCacheReturn retVal = null;
Collection<IgniteBiTuple<GridDhtCacheEntry, GridCacheVersion>> deleted = null;
AffinityTopologyVersion topVer = req.topologyVersion();
boolean checkReaders = hasNear || ctx.discovery().hasNearCache(ctx.cacheId(), topVer);
boolean intercept = ctx.config().getInterceptor() != null;
AffinityAssignment affAssignment = ctx.affinity().assignment(topVer);
// Avoid iterator creation.
for (int i = 0; i < req.size(); i++) {
KeyCacheObject k = req.key(i);
GridCacheOperation op = req.operation();
// No GridCacheEntryRemovedException can be thrown.
try {
GridDhtCacheEntry entry = locked.get(i);
GridCacheVersion newConflictVer = req.conflictVersion(i);
long newConflictTtl = req.conflictTtl(i);
long newConflictExpireTime = req.conflictExpireTime(i);
assert !(newConflictVer instanceof GridCacheVersionEx) : newConflictVer;
Object writeVal = op == TRANSFORM ? req.entryProcessor(i) : req.writeValue(i);
Collection<UUID> readers = null;
Collection<UUID> filteredReaders = null;
if (checkReaders) {
readers = entry.readers();
filteredReaders = F.view(entry.readers(), F.notEqualTo(nearNode.id()));
}
GridCacheUpdateAtomicResult updRes = entry.innerUpdate(ver, nearNode.id(), locNodeId, op, writeVal, req.invokeArguments(), writeThrough() && !req.skipStore(), !req.skipStore(), sndPrevVal || req.returnValue(), req.keepBinary(), expiry, /*event*/
true, /*metrics*/
true, /*primary*/
true, /*verCheck*/
false, topVer, req.filter(), replicate ? DR_PRIMARY : DR_NONE, newConflictTtl, newConflictExpireTime, newConflictVer, /*conflictResolve*/
true, intercept, req.subjectId(), taskName, /*prevVal*/
null, /*updateCntr*/
null, dhtFut);
if (dhtFut != null) {
if (updRes.sendToDht()) {
// Send to backups even in case of remove-remove scenarios.
GridCacheVersionConflictContext<?, ?> conflictCtx = updRes.conflictResolveResult();
if (conflictCtx == null)
newConflictVer = null;
else if (conflictCtx.isMerge())
// Conflict version is discarded in case of merge.
newConflictVer = null;
EntryProcessor<Object, Object, Object> entryProcessor = null;
dhtFut.addWriteEntry(affAssignment, entry, updRes.newValue(), entryProcessor, updRes.newTtl(), updRes.conflictExpireTime(), newConflictVer, sndPrevVal, updRes.oldValue(), updRes.updateCounter());
if (!F.isEmpty(filteredReaders))
dhtFut.addNearWriteEntries(filteredReaders, entry, updRes.newValue(), entryProcessor, updRes.newTtl(), updRes.conflictExpireTime());
} else {
if (log.isDebugEnabled())
log.debug("Entry did not pass the filter or conflict resolution (will skip write) " + "[entry=" + entry + ", filter=" + Arrays.toString(req.filter()) + ']');
}
}
if (hasNear) {
if (updRes.sendToDht()) {
if (!ctx.affinity().partitionBelongs(nearNode, entry.partition(), topVer)) {
// If put the same value as in request then do not need to send it back.
if (op == TRANSFORM || writeVal != updRes.newValue()) {
res.addNearValue(i, updRes.newValue(), updRes.newTtl(), updRes.conflictExpireTime());
} else
res.addNearTtl(i, updRes.newTtl(), updRes.conflictExpireTime());
if (updRes.newValue() != null) {
IgniteInternalFuture<Boolean> f = entry.addReader(nearNode.id(), req.messageId(), topVer);
assert f == null : f;
}
} else if (// Reader became primary or backup.
F.contains(readers, nearNode.id()))
entry.removeReader(nearNode.id(), req.messageId());
else
res.addSkippedIndex(i);
} else
res.addSkippedIndex(i);
}
if (updRes.removeVersion() != null) {
if (deleted == null)
deleted = new ArrayList<>(req.size());
deleted.add(F.t(entry, updRes.removeVersion()));
}
if (op == TRANSFORM) {
assert !req.returnValue();
IgniteBiTuple<Object, Exception> compRes = updRes.computedResult();
if (compRes != null && (compRes.get1() != null || compRes.get2() != null)) {
if (retVal == null)
retVal = new GridCacheReturn(nearNode.isLocal());
retVal.addEntryProcessResult(ctx, k, null, compRes.get1(), compRes.get2(), req.keepBinary());
}
} else {
// Create only once.
if (retVal == null) {
CacheObject ret = updRes.oldValue();
retVal = new GridCacheReturn(ctx, nearNode.isLocal(), req.keepBinary(), req.returnValue() ? ret : null, updRes.success());
}
}
} catch (IgniteCheckedException e) {
res.addFailedKey(k, e);
}
}
return new UpdateSingleResult(retVal, deleted, dhtFut);
}
use of org.apache.ignite.internal.processors.cache.version.GridCacheVersionEx in project ignite by apache.
the class IgniteUtils method writeVersion.
/**
* @param arr Array.
* @param off Offset.
* @param ver Version.
* @return Offset.
*/
public static long writeVersion(byte[] arr, long off, GridCacheVersion ver) {
boolean verEx = ver instanceof GridCacheVersionEx;
GridUnsafe.putBoolean(arr, off++, verEx);
if (verEx) {
GridCacheVersion drVer = ver.conflictVersion();
assert drVer != null;
GridUnsafe.putInt(arr, off, drVer.topologyVersion());
off += 4;
GridUnsafe.putInt(arr, off, drVer.nodeOrderAndDrIdRaw());
off += 4;
GridUnsafe.putLong(arr, off, drVer.order());
off += 8;
}
GridUnsafe.putInt(arr, off, ver.topologyVersion());
off += 4;
GridUnsafe.putInt(arr, off, ver.nodeOrderAndDrIdRaw());
off += 4;
GridUnsafe.putLong(arr, off, ver.order());
off += 8;
return off;
}
Aggregations