Skip to content

Commit

Permalink
GG-11133 TTL should be tracked in off-heap page structures
Browse files Browse the repository at this point in the history
  • Loading branch information
tledkov-gridgain committed Jun 16, 2016
1 parent 4ec0fed commit 226a448
Show file tree
Hide file tree
Showing 14 changed files with 543 additions and 215 deletions.
Expand Up @@ -324,9 +324,9 @@ public GridCacheContext(
this.qryMgr = add(qryMgr); this.qryMgr = add(qryMgr);
this.contQryMgr = add(contQryMgr); this.contQryMgr = add(contQryMgr);
this.dataStructuresMgr = add(dataStructuresMgr); this.dataStructuresMgr = add(dataStructuresMgr);
this.ttlMgr = add(ttlMgr);
this.drMgr = add(drMgr); this.drMgr = add(drMgr);
this.offheapMgr = add(offheapMgr); this.offheapMgr = add(offheapMgr);
this.ttlMgr = add(ttlMgr);
this.rslvrMgr = add(rslvrMgr); this.rslvrMgr = add(rslvrMgr);
this.pluginMgr = add(pluginMgr); this.pluginMgr = add(pluginMgr);
this.affMgr = add(affMgr); this.affMgr = add(affMgr);
Expand Down
Expand Up @@ -125,7 +125,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme


/** Key. */ /** Key. */
@GridToStringInclude @GridToStringInclude
protected final KeyCacheObject key; protected KeyCacheObject key;


/** Value. */ /** Value. */
@GridToStringInclude @GridToStringInclude
Expand Down Expand Up @@ -157,6 +157,11 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
@GridToStringInclude @GridToStringInclude
protected byte flags; protected byte flags;


/** Offheap link. */
@GridToStringInclude
private long link;


/** /**
* @param cctx Cache context. * @param cctx Cache context.
* @param key Cache key. * @param key Cache key.
Expand Down Expand Up @@ -395,24 +400,57 @@ protected GridDhtLocalPartition localPartition() {
*/ */
@Nullable protected CacheObject unswap(boolean needVal, boolean checkExpire) @Nullable protected CacheObject unswap(boolean needVal, boolean checkExpire)
throws IgniteCheckedException, GridCacheEntryRemovedException { throws IgniteCheckedException, GridCacheEntryRemovedException {

boolean obsolete = false;
boolean deferred = false;
GridCacheVersion ver0 = null;

synchronized (this) { synchronized (this) {
checkObsolete(); checkObsolete();


if (isStartVersion() && ((flags & IS_UNSWAPPED_MASK) == 0)) { if (isStartVersion() && ((flags & IS_UNSWAPPED_MASK) == 0)) {
IgniteBiTuple<CacheObject, GridCacheVersion> read = cctx.offheap().read(this); IgniteCacheOffheapManager.CacheObjectEntry read = cctx.offheap().read(this);


flags |= IS_UNSWAPPED_MASK; flags |= IS_UNSWAPPED_MASK;


if (read != null) { if (read != null) {
CacheObject val = read.get1(); CacheObject val = read.getValue();
link = read.getLink();


update(val, 0, 0, read.get2(), false); update(val, read.getExpireTime(), 0, read.getVersion(), false);


return val; long delta = checkExpire ?
(read.getExpireTime() == 0 ? 0 : read.getExpireTime() - U.currentTimeMillis())
: 0;

if (delta >= 0)
return val;
else {
if (onExpired(this.val, null)) {
if (cctx.deferredDelete()) {
deferred = true;
ver0 = ver;
}
else
obsolete = true;
}
}
} }
} }
} }


if (obsolete) {
onMarkedObsolete();

cctx.cache().removeEntry(this);
}

if (deferred) {
assert ver0 != null;

cctx.onDeferredDelete(this, ver0);
}

return null; return null;
} }


Expand Down Expand Up @@ -2800,6 +2838,15 @@ int hash() {
return hash; return hash;
} }


/**
* Gets offheap link.
*
* @return Offheap link.
*/
long link() {
return link;
}

/** {@inheritDoc} */ /** {@inheritDoc} */
@Nullable @Override public CacheObject peek( @Nullable @Override public CacheObject peek(
boolean heap, boolean heap,
Expand Down Expand Up @@ -3289,8 +3336,8 @@ private GridCacheVersion nextVersion() {
synchronized (this) { synchronized (this) {
checkObsolete(); checkObsolete();


if (isStartVersion()) // Always unswap entry due to the fact that TTL entries are stored at offheap memory
unswap(true, false); unswap(true, false);


long expireTime = expireTimeExtras(); long expireTime = expireTimeExtras();


Expand Down Expand Up @@ -3503,7 +3550,7 @@ protected void storeValue(@Nullable CacheObject val,
assert Thread.holdsLock(this); assert Thread.holdsLock(this);
assert val != null : "null values in update for key: " + key; assert val != null : "null values in update for key: " + key;


cctx.offheap().update(key, val, ver, expireTime, partition(), localPartition()); link = cctx.offheap().update(key, val, ver, expireTime, partition(), localPartition());
} }


/** /**
Expand Down Expand Up @@ -3572,10 +3619,10 @@ private CacheObject saveOldValueUnlocked(boolean qryOnly) throws IgniteCheckedEx
CacheObject val = this.val; CacheObject val = this.val;


if (val == null && isStartVersion()) { if (val == null && isStartVersion()) {
IgniteBiTuple<CacheObject, GridCacheVersion> t = detached() || isNear() ? null : cctx.offheap().read(this); IgniteCacheOffheapManager.CacheObjectEntry t = detached() || isNear() ? null : cctx.offheap().read(this);


if (t != null) if (t != null)
val = t.get1(); val = t.getValue();
} }


return val; return val;
Expand Down Expand Up @@ -4005,7 +4052,7 @@ public long expireTimeExtras() {
protected void ttlAndExpireTimeExtras(long ttl, long expireTime) { protected void ttlAndExpireTimeExtras(long ttl, long expireTime) {
assert ttl != CU.TTL_NOT_CHANGED && ttl != CU.TTL_ZERO; assert ttl != CU.TTL_NOT_CHANGED && ttl != CU.TTL_ZERO;


extras = (extras != null) ? extras.ttlAndExpireTime(ttl, expireTime) : ttl != CU.TTL_ETERNAL ? extras = (extras != null) ? extras.ttlAndExpireTime(ttl, expireTime) : expireTime != CU.EXPIRE_TIME_ETERNAL ?
new GridCacheTtlEntryExtras(ttl, expireTime) : null; new GridCacheTtlEntryExtras(ttl, expireTime) : null;
} }


Expand Down

0 comments on commit 226a448

Please sign in to comment.