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 DataPageIO method getRowSize.
/**
* @param row Row.
* @param withCacheId If {@code true} adds cache ID size.
* @return Entry size on page.
* @throws IgniteCheckedException If failed.
*/
public static int getRowSize(CacheDataRow row, boolean withCacheId) throws IgniteCheckedException {
KeyCacheObject key = row.key();
CacheObject val = row.value();
int keyLen = key.valueBytesLength(null);
int valLen = val.valueBytesLength(null);
return keyLen + valLen + CacheVersionIO.size(row.version(), false) + 8 + (withCacheId ? 4 : 0);
}
use of org.apache.ignite.internal.processors.cache.CacheObject in project ignite by apache.
the class GridNearCacheEntry method removeLock.
/**
* Unlocks local lock.
*
* @return Removed candidate, or <tt>null</tt> if thread still holds the lock.
*/
@Nullable
@Override
public GridCacheMvccCandidate removeLock() {
CacheLockCandidates prev = null;
CacheLockCandidates owner = null;
CacheObject val;
UUID locId = cctx.nodeId();
GridCacheMvccCandidate cand = null;
lockEntry();
try {
GridCacheMvcc mvcc = mvccExtras();
if (mvcc != null) {
prev = mvcc.allOwners();
boolean emptyBefore = mvcc.isEmpty();
cand = mvcc.localCandidate(locId, Thread.currentThread().getId());
assert cand == null || cand.nearLocal();
if (cand != null && cand.owner()) {
// If a reentry, then release reentry. Otherwise, remove lock.
GridCacheMvccCandidate reentry = cand.unenter();
if (reentry != null) {
assert reentry.reentry();
return reentry;
}
mvcc.remove(cand.version());
owner = mvcc.allOwners();
} else
return null;
boolean emptyAfter = mvcc.isEmpty();
checkCallbacks(emptyBefore, emptyAfter);
if (emptyAfter)
mvccExtras(null);
}
val = this.val;
} finally {
unlockEntry();
}
assert cand != null;
assert owner != prev;
if (log.isDebugEnabled())
log.debug("Released local candidate from entry [owner=" + owner + ", prev=" + prev + ", entry=" + this + ']');
cctx.mvcc().removeExplicitLock(cand);
checkThreadChain(cand);
// This call must be outside of synchronization.
checkOwnerChanged(prev, owner, val);
return cand;
}
use of org.apache.ignite.internal.processors.cache.CacheObject in project ignite by apache.
the class GridLocalAtomicCache method getAllInternal.
/**
* Entry point to all public API get methods.
*
* @param keys Keys to remove.
* @param storeEnabled Store enabled flag.
* @param taskName Task name.
* @param deserializeBinary Deserialize binary .
* @param skipVals Skip value flag.
* @param needVer Need version.
* @return Key-value map.
* @throws IgniteCheckedException If failed.
*/
@SuppressWarnings("ConstantConditions")
private Map<K, V> getAllInternal(@Nullable Collection<? extends K> keys, boolean storeEnabled, String taskName, boolean deserializeBinary, boolean skipVals, boolean needVer) throws IgniteCheckedException {
ctx.checkSecurity(SecurityPermission.CACHE_READ);
if (F.isEmpty(keys))
return Collections.emptyMap();
CacheOperationContext opCtx = ctx.operationContextPerCall();
UUID subjId = ctx.subjectIdPerCall(null, opCtx);
Map<K, V> vals = U.newHashMap(keys.size());
if (keyCheck)
validateCacheKeys(keys);
final IgniteCacheExpiryPolicy expiry = expiryPolicy(opCtx != null ? opCtx.expiry() : null);
boolean success = true;
boolean readNoEntry = ctx.readNoEntry(expiry, false);
final boolean evt = !skipVals;
for (K key : keys) {
if (key == null)
throw new NullPointerException("Null key.");
KeyCacheObject cacheKey = ctx.toCacheKeyObject(key);
boolean skipEntry = readNoEntry;
if (readNoEntry) {
CacheDataRow row = ctx.offheap().read(ctx, cacheKey);
if (row != null) {
long expireTime = row.expireTime();
if (expireTime == 0 || expireTime > U.currentTimeMillis()) {
ctx.addResult(vals, cacheKey, row.value(), skipVals, false, deserializeBinary, true, null, row.version(), 0, 0, needVer);
if (ctx.statisticsEnabled() && !skipVals)
metrics0().onRead(true);
if (evt) {
ctx.events().readEvent(cacheKey, null, row.value(), subjId, taskName, !deserializeBinary);
}
} else
skipEntry = false;
} else
success = false;
}
if (!skipEntry) {
GridCacheEntryEx entry = null;
while (true) {
try {
entry = entryEx(cacheKey);
if (entry != null) {
CacheObject v;
if (needVer) {
EntryGetResult res = entry.innerGetVersioned(null, null, /*update-metrics*/
false, /*event*/
evt, subjId, null, taskName, expiry, !deserializeBinary, null);
if (res != null) {
ctx.addResult(vals, cacheKey, res, skipVals, false, deserializeBinary, true, needVer);
} else
success = false;
} else {
v = entry.innerGet(null, null, /*read-through*/
false, /*update-metrics*/
true, /*event*/
evt, subjId, null, taskName, expiry, !deserializeBinary);
if (v != null) {
ctx.addResult(vals, cacheKey, v, skipVals, false, deserializeBinary, true, null, 0, 0);
} else
success = false;
}
}
// While.
break;
} catch (GridCacheEntryRemovedException ignored) {
// No-op, retry.
} finally {
if (entry != null)
ctx.evicts().touch(entry, ctx.affinity().affinityTopologyVersion());
}
if (!success && storeEnabled)
break;
}
}
if (!success) {
if (!storeEnabled && ctx.statisticsEnabled() && !skipVals)
metrics0().onRead(false);
}
}
if (success || !storeEnabled)
return vals;
return getAllAsync(keys, null, opCtx == null || !opCtx.skipStore(), false, subjId, taskName, deserializeBinary, opCtx != null && opCtx.recovery(), /*force primary*/
false, expiry, skipVals, needVer).get();
}
use of org.apache.ignite.internal.processors.cache.CacheObject in project ignite by apache.
the class GridCacheQueryManager method store.
/**
* Writes key-value pair to index.
*
* @param key Key.
* @param partId Partition.
* @param prevVal Previous value.
* @param prevVer Previous version.
* @param val Value.
* @param ver Cache entry version.
* @param expirationTime Expiration time or 0 if never expires.
* @param link Link.
* @throws IgniteCheckedException In case of error.
*/
public void store(KeyCacheObject key, int partId, @Nullable CacheObject prevVal, @Nullable GridCacheVersion prevVer, CacheObject val, GridCacheVersion ver, long expirationTime, long link) throws IgniteCheckedException {
assert key != null;
assert val != null;
assert enabled();
if (key instanceof GridCacheInternal)
// No-op.
return;
if (!enterBusy())
throw new NodeStoppingException("Operation has been cancelled (node is stopping).");
try {
if (isIndexingSpiEnabled()) {
CacheObjectContext coctx = cctx.cacheObjectContext();
Object key0 = unwrapIfNeeded(key, coctx);
Object val0 = unwrapIfNeeded(val, coctx);
cctx.kernalContext().indexing().store(cacheName, key0, val0, expirationTime);
}
if (qryProcEnabled)
qryProc.store(cacheName, key, partId, prevVal, prevVer, val, ver, expirationTime, link);
} finally {
invalidateResultCache();
leaveBusy();
}
}
Aggregations