use of org.apache.ignite.internal.processors.cache.version.GridCacheVersion in project ignite by apache.
the class GridCacheMapEntry method evictInternal.
/**
* {@inheritDoc}
*/
@Override
public boolean evictInternal(GridCacheVersion obsoleteVer, @Nullable CacheEntryPredicate[] filter, boolean evictOffheap) throws IgniteCheckedException {
boolean marked = false;
try {
if (F.isEmptyOrNulls(filter)) {
lockEntry();
try {
if (evictionDisabled()) {
assert !obsolete();
return false;
}
if (obsoleteVersionExtras() != null)
return true;
// TODO IGNITE-5286: need keep removed entries in heap map, otherwise removes can be lost.
if (cctx.deferredDelete() && deletedUnlocked())
return false;
if (!hasReaders() && markObsolete0(obsoleteVer, false, null)) {
// Nullify value after swap.
value(null);
if (evictOffheap)
removeValue();
marked = true;
return true;
}
} finally {
unlockEntry();
}
} else {
// For optimistic check.
while (true) {
GridCacheVersion v;
lockEntry();
try {
v = ver;
} finally {
unlockEntry();
}
if (!cctx.isAll(/*version needed for sync evicts*/
this, filter))
return false;
lockEntry();
try {
if (evictionDisabled()) {
assert !obsolete();
return false;
}
if (obsoleteVersionExtras() != null)
return true;
if (!v.equals(ver))
// Version has changed since entry passed the filter. Do it again.
continue;
// TODO IGNITE-5286: need keep removed entries in heap map, otherwise removes can be lost.
if (cctx.deferredDelete() && deletedUnlocked())
return false;
if (!hasReaders() && markObsolete0(obsoleteVer, false, null)) {
// Nullify value after swap.
value(null);
if (evictOffheap)
removeValue();
marked = true;
return true;
} else
return false;
} finally {
unlockEntry();
}
}
}
} catch (GridCacheEntryRemovedException ignore) {
if (log.isDebugEnabled())
log.debug("Got removed entry when evicting (will simply return): " + this);
return true;
} finally {
if (marked)
onMarkedObsolete();
}
return false;
}
use of org.apache.ignite.internal.processors.cache.version.GridCacheVersion in project ignite by apache.
the class GridCacheMapEntry method innerReload.
/**
* {@inheritDoc}
*/
@SuppressWarnings({ "TooBroadScope" })
@Nullable
@Override
public final CacheObject innerReload() throws IgniteCheckedException, GridCacheEntryRemovedException {
CU.checkStore(cctx);
GridCacheVersion startVer;
boolean wasNew;
lockEntry();
try {
checkObsolete();
// Cache version for optimistic check.
startVer = ver;
wasNew = isNew();
} finally {
unlockEntry();
}
String taskName = cctx.kernalContext().job().currentTaskName();
// Check before load.
CacheObject ret = cctx.toCacheObject(readThrough(null, key, true, taskName));
boolean touch = false;
try {
ensureFreeSpace();
lockEntry();
try {
long ttl = ttlExtras();
// Generate new version.
GridCacheVersion nextVer = cctx.versions().nextForLoad(ver);
// If entry was loaded during read step.
if (wasNew && !isNew())
// Map size was updated on entry creation.
return ret;
// If version matched, set value.
if (startVer.equals(ver)) {
long expTime = CU.toExpireTime(ttl);
// Detach value before index update.
ret = cctx.kernalContext().cacheObjects().prepareForCache(ret, cctx);
// Update indexes.
if (ret != null) {
storeValue(ret, expTime, nextVer);
if (cctx.deferredDelete() && !isInternal() && !detached() && deletedUnlocked())
deletedUnlocked(false);
} else {
if (cctx.mvccEnabled())
cctx.offheap().mvccRemoveAll(this);
else
removeValue();
if (cctx.deferredDelete() && !isInternal() && !detached() && !deletedUnlocked())
deletedUnlocked(true);
}
update(ret, expTime, ttl, nextVer, true);
touch = true;
// If value was set - return, otherwise try again.
return ret;
}
} finally {
unlockEntry();
}
touch = true;
return ret;
} finally {
if (touch)
touch();
}
}
use of org.apache.ignite.internal.processors.cache.version.GridCacheVersion in project ignite by apache.
the class GridCacheMapEntry method markObsoleteIfEmpty.
/**
* {@inheritDoc}
*/
@Override
public boolean markObsoleteIfEmpty(@Nullable GridCacheVersion obsoleteVer) throws IgniteCheckedException {
boolean obsolete = false;
boolean deferred = false;
GridCacheVersion ver0 = null;
lockEntry();
try {
if (obsoleteVersionExtras() != null)
return false;
if (hasValueUnlocked()) {
long expireTime = expireTimeExtras();
if (expireTime > 0 && (expireTime < U.currentTimeMillis())) {
if (obsoleteVer == null)
obsoleteVer = nextVersion();
if (onExpired(this.val, obsoleteVer)) {
if (cctx.deferredDelete()) {
deferred = true;
ver0 = ver;
} else
obsolete = true;
}
}
} else {
if (cctx.deferredDelete() && !isStartVersion() && !detached()) {
if (!deletedUnlocked()) {
update(null, 0L, 0L, ver, true);
deletedUnlocked(true);
deferred = true;
ver0 = ver;
}
} else {
if (obsoleteVer == null)
obsoleteVer = nextVersion();
obsolete = markObsolete0(obsoleteVer, true, null);
}
}
} finally {
unlockEntry();
if (obsolete)
onMarkedObsolete();
if (deferred)
cctx.onDeferredDelete(this, ver0);
}
return obsolete;
}
use of org.apache.ignite.internal.processors.cache.version.GridCacheVersion in project ignite by apache.
the class GridCacheTtlManager method expire.
/**
* Processes specified amount of expired entries.
*
* @param amount Limit of processed entries by single call, {@code -1} for no limit.
* @return {@code True} if unprocessed expired entries remains.
*/
public boolean expire(int amount) {
// TTL manager is not initialized or eagerTtl disabled for cache.
if (!eagerTtlEnabled)
return false;
assert cctx != null;
long now = U.currentTimeMillis();
try {
if (pendingEntries != null) {
GridNearCacheAdapter nearCache = cctx.near();
GridCacheVersion obsoleteVer = null;
int limit = (-1 != amount) ? amount : pendingEntries.sizex();
for (int cnt = limit; cnt > 0; cnt--) {
EntryWrapper e = pendingEntries.firstx();
if (e == null || e.expireTime > now)
// All expired entries are processed.
break;
if (pendingEntries.remove(e)) {
if (obsoleteVer == null)
obsoleteVer = cctx.cache().nextVersion();
GridNearCacheEntry nearEntry = nearCache.peekExx(e.key);
if (nearEntry != null)
expireC.apply(nearEntry, obsoleteVer);
}
}
}
if (!cctx.affinityNode())
return false;
if (!hasPendingEntries || nextCleanTime > U.currentTimeMillis())
return false;
boolean more = cctx.offheap().expire(dhtCtx, expireC, amount);
if (more)
return true;
// There is nothing to clean, so the next clean up can be postponed.
nextCleanTime = U.currentTimeMillis() + unwindThrottlingTimeout;
if (amount != -1 && pendingEntries != null) {
EntryWrapper e = pendingEntries.firstx();
return e != null && e.expireTime <= now;
}
} catch (GridDhtInvalidPartitionException e) {
if (log.isDebugEnabled())
log.debug("Partition became invalid during rebalancing (will ignore): " + e.partition());
return false;
} catch (IgniteCheckedException e) {
U.error(log, "Failed to process entry expiration: " + e, e);
} catch (IgniteException e) {
if (e.hasCause(NodeStoppingException.class)) {
if (log.isDebugEnabled())
log.debug("Failed to expire because node is stopped: " + e);
} else
throw e;
}
return false;
}
use of org.apache.ignite.internal.processors.cache.version.GridCacheVersion in project ignite by apache.
the class GridCacheMvccManager method addFuture.
/**
* /**
* Adds future.
*
* @param fut Future.
* @return {@code True} if added.
*/
@SuppressWarnings({ "SynchronizationOnLocalVariableOrMethodParameter" })
public boolean addFuture(final GridCacheVersionedFuture<?> fut) {
if (fut.isDone()) {
fut.markNotTrackable();
return true;
}
if (!fut.trackable())
return true;
while (true) {
Collection<GridCacheVersionedFuture<?>> old = verFuts.get(fut.version());
if (old == null) {
Collection<GridCacheVersionedFuture<?>> col = new HashSet<GridCacheVersionedFuture<?>>(U.capacity(1), 0.75f) {
{
// Make sure that we add future to queue before
// adding queue to the map of futures.
add(fut);
}
@Override
public int hashCode() {
return System.identityHashCode(this);
}
@Override
public boolean equals(Object obj) {
return obj == this;
}
};
old = verFuts.putIfAbsent(fut.version(), col);
}
if (old != null) {
boolean empty, dup = false;
synchronized (old) {
empty = old.isEmpty();
if (!empty)
dup = !old.add(fut);
}
// Future is being removed, so we force-remove here and try again.
if (empty) {
if (verFuts.remove(fut.version(), old)) {
if (log.isDebugEnabled())
log.debug("Removed future list from futures map for lock version: " + fut.version());
}
continue;
}
if (dup) {
if (log.isDebugEnabled())
log.debug("Found duplicate future in futures map (will not add): " + fut);
return false;
}
}
// Handle version mappings.
if (fut instanceof GridCacheMappedVersion) {
GridCacheVersion from = ((GridCacheMappedVersion) fut).mappedVersion();
if (from != null)
mapVersion(from, fut.version());
}
if (log.isDebugEnabled())
log.debug("Added future to future map: " + fut);
break;
}
// Just in case if future was completed before it was added.
if (fut.isDone())
removeVersionedFuture(fut);
else
onFutureAdded(fut);
return true;
}
Aggregations