use of org.apache.ignite.internal.processors.cache.CacheObject in project ignite by apache.
the class GridCacheAffinityImpl method affinityKey.
/** {@inheritDoc} */
@Override
public Object affinityKey(K key) {
A.notNull(key, "key");
if (key instanceof CacheObject && !(key instanceof BinaryObject)) {
CacheObjectContext ctx = cctx.cacheObjectContext();
if (ctx == null)
throw new IgniteException(FAILED_TO_FIND_CACHE_ERR_MSG + cctx.name());
key = ((CacheObject) key).value(ctx, false);
}
CacheConfiguration ccfg = cctx.config();
if (ccfg == null)
throw new IgniteException(FAILED_TO_FIND_CACHE_ERR_MSG + cctx.name());
return ccfg.getAffinityMapper().affinityKey(key);
}
use of org.apache.ignite.internal.processors.cache.CacheObject in project ignite by apache.
the class GridDistributedCacheEntry method doneRemote.
/**
*
* @param lockVer Done version.
* @param baseVer Base version.
* @param pendingVers Pending versions that are less than lock version.
* @param committedVers Completed versions for reordering.
* @param rolledbackVers Rolled back versions for reordering.
* @param sysInvalidate Flag indicating if this entry is done from invalidated transaction (in case of tx
* salvage). In this case all locks before salvaged lock will marked as used and corresponding
* transactions will be invalidated.
* @throws GridCacheEntryRemovedException If entry has been removed.
*/
public void doneRemote(GridCacheVersion lockVer, GridCacheVersion baseVer, @Nullable Collection<GridCacheVersion> pendingVers, Collection<GridCacheVersion> committedVers, Collection<GridCacheVersion> rolledbackVers, boolean sysInvalidate) throws GridCacheEntryRemovedException {
CacheLockCandidates prev = null;
CacheLockCandidates owner = null;
CacheObject val;
synchronized (this) {
checkObsolete();
GridCacheMvcc mvcc = mvccExtras();
if (mvcc != null) {
prev = mvcc.allOwners();
boolean emptyBefore = mvcc.isEmpty();
// Order completed versions.
if (!F.isEmpty(committedVers) || !F.isEmpty(rolledbackVers)) {
mvcc.orderCompleted(lockVer, committedVers, rolledbackVers);
if (!baseVer.equals(lockVer))
mvcc.orderCompleted(baseVer, committedVers, rolledbackVers);
}
if (sysInvalidate && baseVer != null)
mvcc.salvageRemote(baseVer);
owner = mvcc.doneRemote(lockVer, maskNull(pendingVers), maskNull(committedVers), maskNull(rolledbackVers));
boolean emptyAfter = mvcc.isEmpty();
checkCallbacks(emptyBefore, emptyAfter);
if (emptyAfter)
mvccExtras(null);
}
val = this.val;
}
// This call must be made outside of synchronization.
checkOwnerChanged(prev, owner, val);
}
use of org.apache.ignite.internal.processors.cache.CacheObject in project ignite by apache.
the class GridDistributedCacheEntry method recheck.
/**
* Rechecks if lock should be reassigned.
*/
public void recheck() {
CacheLockCandidates prev = null;
CacheLockCandidates owner = null;
CacheObject val;
synchronized (this) {
GridCacheMvcc mvcc = mvccExtras();
if (mvcc != null) {
prev = mvcc.allOwners();
boolean emptyBefore = mvcc.isEmpty();
owner = mvcc.recheck();
boolean emptyAfter = mvcc.isEmpty();
checkCallbacks(emptyBefore, emptyAfter);
if (emptyAfter)
mvccExtras(null);
}
val = this.val;
}
// This call must be made outside of synchronization.
checkOwnerChanged(prev, owner, val);
}
use of org.apache.ignite.internal.processors.cache.CacheObject in project ignite by apache.
the class DataPageIO method writeFragment.
/**
* Try to write fragment data.
*
* @param rowOff Offset in row data bytes.
* @param payloadSize Data length that should be written in this fragment.
* @param type Type of the part of entry.
* @return Actually written data.
* @throws IgniteCheckedException If fail.
*/
private int writeFragment(final CacheDataRow row, final ByteBuffer buf, final int rowOff, final int payloadSize, final EntryPart type, final int keySize, final int valSize) throws IgniteCheckedException {
if (payloadSize == 0)
return 0;
final int prevLen;
final int curLen;
int cacheIdSize = row.cacheId() == 0 ? 0 : 4;
switch(type) {
case CACHE_ID:
prevLen = 0;
curLen = cacheIdSize;
break;
case KEY:
prevLen = cacheIdSize;
curLen = cacheIdSize + keySize;
break;
case EXPIRE_TIME:
prevLen = cacheIdSize + keySize;
curLen = cacheIdSize + keySize + 8;
break;
case VALUE:
prevLen = cacheIdSize + keySize + 8;
curLen = cacheIdSize + keySize + valSize + 8;
break;
case VERSION:
prevLen = cacheIdSize + keySize + valSize + 8;
curLen = cacheIdSize + keySize + valSize + CacheVersionIO.size(row.version(), false) + 8;
break;
default:
throw new IllegalArgumentException("Unknown entry part type: " + type);
}
if (curLen <= rowOff)
return 0;
final int len = Math.min(curLen - rowOff, payloadSize);
if (type == EntryPart.EXPIRE_TIME)
writeExpireTimeFragment(buf, row.expireTime(), rowOff, len, prevLen);
else if (type == EntryPart.CACHE_ID)
writeCacheIdFragment(buf, row.cacheId(), rowOff, len, prevLen);
else if (type != EntryPart.VERSION) {
// Write key or value.
final CacheObject co = type == EntryPart.KEY ? row.key() : row.value();
co.putValue(buf, rowOff - prevLen, len);
} else
writeVersionFragment(buf, row.version(), rowOff, len, prevLen);
return len;
}
use of org.apache.ignite.internal.processors.cache.CacheObject in project ignite by apache.
the class GridDhtTransactionalCacheAdapter method createLockReply.
/**
* @param nearNode Near node.
* @param entries Entries.
* @param req Lock request.
* @param tx Transaction.
* @param mappedVer Mapped version.
* @param err Error.
* @return Response.
*/
private GridNearLockResponse createLockReply(ClusterNode nearNode, List<GridCacheEntryEx> entries, GridNearLockRequest req, @Nullable GridDhtTxLocalAdapter tx, GridCacheVersion mappedVer, Throwable err) {
assert mappedVer != null;
assert tx == null || tx.xidVersion().equals(mappedVer);
try {
// Send reply back to originating near node.
GridNearLockResponse res = new GridNearLockResponse(ctx.cacheId(), req.version(), req.futureId(), req.miniId(), tx != null && tx.onePhaseCommit(), entries.size(), err, null, ctx.deploymentEnabled());
if (err == null) {
res.pending(localDhtPendingVersions(entries, mappedVer));
// We have to add completed versions for cases when nearLocal and remote transactions
// execute concurrently.
IgnitePair<Collection<GridCacheVersion>> versPair = ctx.tm().versions(req.version());
res.completedVersions(versPair.get1(), versPair.get2());
int i = 0;
for (ListIterator<GridCacheEntryEx> it = entries.listIterator(); it.hasNext(); ) {
GridCacheEntryEx e = it.next();
assert e != null;
while (true) {
try {
// Don't return anything for invalid partitions.
if (tx == null || !tx.isRollbackOnly()) {
GridCacheVersion dhtVer = req.dhtVersion(i);
GridCacheVersion ver = e.version();
boolean ret = req.returnValue(i) || dhtVer == null || !dhtVer.equals(ver);
CacheObject val = null;
if (ret)
val = e.innerGet(null, tx, /*read-through*/
false, /*update-metrics*/
true, /*event notification*/
req.returnValue(i), CU.subjectId(tx, ctx.shared()), null, tx != null ? tx.resolveTaskName() : null, null, req.keepBinary());
assert e.lockedBy(mappedVer) || (ctx.mvcc().isRemoved(e.context(), mappedVer) && req.timeout() > 0) : "Entry does not own lock for tx [locNodeId=" + ctx.localNodeId() + ", entry=" + e + ", mappedVer=" + mappedVer + ", ver=" + ver + ", tx=" + tx + ", req=" + req + ", err=" + err + ']';
boolean filterPassed = false;
if (tx != null && tx.onePhaseCommit()) {
IgniteTxEntry writeEntry = tx.entry(ctx.txKey(e.key()));
assert writeEntry != null : "Missing tx entry for locked cache entry: " + e;
filterPassed = writeEntry.filtersPassed();
}
if (ret && val == null)
val = e.valueBytes(null);
// We include values into response since they are required for local
// calls and won't be serialized. We are also including DHT version.
res.addValueBytes(ret ? val : null, filterPassed, ver, mappedVer);
} else {
// We include values into response since they are required for local
// calls and won't be serialized. We are also including DHT version.
res.addValueBytes(null, false, e.version(), mappedVer);
}
break;
} catch (GridCacheEntryRemovedException ignore) {
if (log.isDebugEnabled())
log.debug("Got removed entry when sending reply to DHT lock request " + "(will retry): " + e);
e = entryExx(e.key());
it.set(e);
}
}
i++;
}
}
return res;
} catch (IgniteCheckedException e) {
U.error(log, "Failed to get value for lock reply message for node [node=" + U.toShortString(nearNode) + ", req=" + req + ']', e);
return new GridNearLockResponse(ctx.cacheId(), req.version(), req.futureId(), req.miniId(), false, entries.size(), e, null, ctx.deploymentEnabled());
}
}
Aggregations