use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.
the class GridCacheMapEntry method updateIndex.
/**
* {@inheritDoc}
*/
@Override
public void updateIndex(SchemaIndexCacheVisitorClosure clo) throws IgniteCheckedException, GridCacheEntryRemovedException {
lockEntry();
try {
if (isInternal())
return;
checkObsolete();
CacheDataRow row = cctx.offheap().read(this);
if (row != null)
clo.apply(row);
} finally {
unlockEntry();
}
}
use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.
the class GridCacheMapEntry method initialValue.
/**
* {@inheritDoc}
*/
@Override
public boolean initialValue(CacheObject val, GridCacheVersion ver, MvccVersion mvccVer, MvccVersion newMvccVer, byte mvccTxState, byte newMvccTxState, long ttl, long expireTime, boolean preload, AffinityTopologyVersion topVer, GridDrType drType, boolean fromStore, boolean primary, CacheDataRow row) throws IgniteCheckedException, GridCacheEntryRemovedException {
assert !primary || !(preload || fromStore);
ensureFreeSpace();
boolean deferred = false;
boolean obsolete = false;
GridCacheVersion oldVer = null;
lockListenerReadLock();
lockEntry();
try {
checkObsolete();
boolean walEnabled = !cctx.isNear() && cctx.group().persistenceEnabled() && cctx.group().walEnabled();
long expTime = expireTime < 0 ? CU.toExpireTime(ttl) : expireTime;
val = cctx.kernalContext().cacheObjects().prepareForCache(val, cctx);
final boolean unswapped = ((flags & IS_UNSWAPPED_MASK) != 0);
boolean update;
IgnitePredicate<CacheDataRow> p = new IgnitePredicate<CacheDataRow>() {
@Override
public boolean apply(@Nullable CacheDataRow row) {
boolean update0;
GridCacheVersion currentVer = row != null ? row.version() : GridCacheMapEntry.this.ver;
boolean isStartVer = cctx.shared().versions().isStartVersion(currentVer);
if (cctx.group().persistenceEnabled()) {
if (!isStartVer) {
if (cctx.atomic())
update0 = ATOMIC_VER_COMPARATOR.compare(currentVer, ver) < 0;
else
update0 = currentVer.compareTo(ver) < 0;
} else
update0 = true;
} else
update0 = isStartVer;
update0 |= (!preload && deletedUnlocked());
return update0;
}
};
if (unswapped) {
update = p.apply(null);
if (update) {
// If entry is already unswapped and we are modifying it, we must run deletion callbacks for old value.
long oldExpTime = expireTimeUnlocked();
if (oldExpTime > 0 && oldExpTime < U.currentTimeMillis()) {
if (onExpired(this.val, null)) {
if (cctx.deferredDelete()) {
deferred = true;
oldVer = this.ver;
} else if (val == null)
obsolete = true;
}
}
if (cctx.mvccEnabled()) {
assert !preload;
cctx.offheap().mvccInitialValue(this, val, ver, expTime, mvccVer, newMvccVer);
} else
storeValue(val, expTime, ver, null, row);
}
} else {
if (cctx.mvccEnabled()) {
// cannot identify whether the entry is exist on the fly
unswap(false);
if (update = p.apply(null)) {
// If entry is already unswapped and we are modifying it, we must run deletion callbacks for old value.
long oldExpTime = expireTimeUnlocked();
long delta = (oldExpTime == 0 ? 0 : oldExpTime - U.currentTimeMillis());
if (delta < 0) {
if (onExpired(this.val, null)) {
if (cctx.deferredDelete()) {
deferred = true;
oldVer = this.ver;
} else if (val == null)
obsolete = true;
}
}
assert !preload;
cctx.offheap().mvccInitialValue(this, val, ver, expTime, mvccVer, newMvccVer);
}
} else
// Optimization to access storage only once.
update = storeValue(val, expTime, ver, p, row);
}
if (update) {
update(val, expTime, ttl, ver, true);
boolean skipQryNtf = false;
if (val == null) {
skipQryNtf = true;
if (cctx.deferredDelete() && !deletedUnlocked() && !isInternal())
deletedUnlocked(true);
} else if (deletedUnlocked())
deletedUnlocked(false);
long updateCntr = 0;
if (!preload)
updateCntr = nextPartitionCounter(topVer, true, true, null);
if (walEnabled) {
if (cctx.mvccEnabled()) {
cctx.shared().wal().log(new MvccDataRecord(new MvccDataEntry(cctx.cacheId(), key, val, val == null ? DELETE : GridCacheOperation.CREATE, null, ver, expireTime, partition(), updateCntr, mvccVer == null ? MvccUtils.INITIAL_VERSION : mvccVer)));
} else {
cctx.shared().wal().log(new DataRecord(new DataEntry(cctx.cacheId(), key, val, val == null ? DELETE : GridCacheOperation.CREATE, null, ver, expireTime, partition(), updateCntr, DataEntry.flags(primary, preload, fromStore))));
}
}
drReplicate(drType, val, ver, topVer);
if (!skipQryNtf) {
cctx.continuousQueries().onEntryUpdated(key, val, null, this.isInternal() || !this.context().userCache(), this.partition(), true, preload, updateCntr, null, topVer);
}
updatePlatformCache(val, topVer);
onUpdateFinished(updateCntr);
if (!fromStore && cctx.store().isLocal()) {
if (val != null)
cctx.store().put(null, key, val, ver);
}
return true;
}
return false;
} finally {
unlockEntry();
unlockListenerReadLock();
if (obsolete) {
onMarkedObsolete();
cctx.cache().removeEntry(this);
}
if (deferred) {
assert oldVer != null;
cctx.onDeferredDelete(this, oldVer);
}
}
}
use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.
the class IgniteCacheOffheapManagerImpl method iterator.
/**
* @param cacheId Cache ID.
* @param dataIt Data store iterator.
* @param mvccSnapshot Mvcc snapshot.
* @param dataPageScanEnabled Flag to enable data page scan.
* @return Rows iterator
*/
private GridCloseableIterator<CacheDataRow> iterator(int cacheId, Iterator<CacheDataStore> dataIt, MvccSnapshot mvccSnapshot, Boolean dataPageScanEnabled) {
return new GridCloseableIteratorAdapter<CacheDataRow>() {
/**
*/
private GridCursor<? extends CacheDataRow> cur;
/**
*/
private int curPart;
/**
*/
private CacheDataRow next;
@Override
protected CacheDataRow onNext() {
CacheDataRow res = next;
next = null;
return res;
}
@Override
protected boolean onHasNext() throws IgniteCheckedException {
if (next != null)
return true;
while (true) {
try {
if (cur == null) {
if (dataIt.hasNext()) {
CacheDataStore ds = dataIt.next();
curPart = ds.partId();
// Data page scan is disabled by default for scan queries.
// TODO https://issues.apache.org/jira/browse/IGNITE-11998
CacheDataTree.setDataPageScanEnabled(false);
try {
if (mvccSnapshot == null)
cur = cacheId == CU.UNDEFINED_CACHE_ID ? ds.cursor() : ds.cursor(cacheId);
else {
cur = cacheId == CU.UNDEFINED_CACHE_ID ? ds.cursor(mvccSnapshot) : ds.cursor(cacheId, mvccSnapshot);
}
} finally {
CacheDataTree.setDataPageScanEnabled(false);
}
} else
break;
}
if (cur.next()) {
next = cur.get();
next.key().partition(curPart);
break;
} else
cur = null;
} catch (IgniteCheckedException ex) {
throw new IgniteCheckedException("Failed to get next data row due to underlying cursor " + "invalidation", ex);
}
}
return next != null;
}
};
}
use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.
the class IgniteCacheOffheapManagerImpl method read.
/**
* {@inheritDoc}
*/
@Nullable
@Override
public CacheDataRow read(GridCacheContext cctx, KeyCacheObject key) throws IgniteCheckedException {
CacheDataStore dataStore = dataStore(cctx, key);
CacheDataRow row = dataStore != null ? dataStore.find(cctx, key) : null;
assert row == null || row.value() != null : row;
return row;
}
use of org.apache.ignite.internal.processors.cache.persistence.CacheDataRow in project ignite by apache.
the class IgniteCacheOffheapManagerImpl method clearCache.
/**
* Clears offheap entries.
*
* @param readers {@code True} to clear readers.
*/
@Override
public void clearCache(GridCacheContext cctx, boolean readers) {
GridCacheVersion obsoleteVer = null;
try (GridCloseableIterator<CacheDataRow> it = grp.isLocal() ? iterator(cctx.cacheId(), cacheDataStores().iterator(), null, null) : evictionSafeIterator(cctx.cacheId(), cacheDataStores().iterator())) {
while (it.hasNext()) {
cctx.shared().database().checkpointReadLock();
try {
KeyCacheObject key = it.next().key();
try {
if (obsoleteVer == null)
obsoleteVer = cctx.cache().nextVersion();
GridCacheEntryEx entry = cctx.cache().entryEx(key);
entry.clear(obsoleteVer, readers);
} catch (GridDhtInvalidPartitionException ignore) {
// Ignore.
} catch (IgniteCheckedException e) {
U.error(log, "Failed to clear cache entry: " + key, e);
}
} finally {
cctx.shared().database().checkpointReadUnlock();
}
}
} catch (IgniteCheckedException e) {
U.error(log, "Failed to close iterator", e);
}
}
Aggregations