use of org.apache.ignite.internal.pagemem.wal.record.MvccDataEntry in project ignite by apache.
the class GridCacheMapEntry method mvccUpdateRowsWithPreloadInfo.
/**
* {@inheritDoc}
*/
@Override
public GridCacheUpdateTxResult mvccUpdateRowsWithPreloadInfo(IgniteInternalTx tx, UUID affNodeId, AffinityTopologyVersion topVer, List<GridCacheEntryInfo> entries, GridCacheOperation op, MvccSnapshot mvccVer, IgniteUuid futId, int batchNum) throws IgniteCheckedException, GridCacheEntryRemovedException {
assert mvccVer != null && MvccUtils.mvccVersionIsValid(mvccVer.coordinatorVersion(), mvccVer.counter(), mvccVer.operationCounter());
assert !F.isEmpty(entries);
WALPointer logPtr = null;
ensureFreeSpace();
CacheObject val = null;
CacheObject oldVal = null;
lockEntry();
try {
checkObsolete();
boolean walEnabled = cctx.group().persistenceEnabled() && cctx.group().walEnabled();
List<DataEntry> walEntries = walEnabled ? new ArrayList<>(entries.size() + 1) : Collections.EMPTY_LIST;
// or via rebalance.
for (int i = 0; i < entries.size(); i++) {
GridCacheMvccEntryInfo info = (GridCacheMvccEntryInfo) entries.get(i);
assert info.mvccTxState() == TxState.COMMITTED || MvccUtils.compare(info, mvccVer.coordinatorVersion(), mvccVer.counter()) == 0;
assert info.newMvccTxState() == TxState.COMMITTED || MvccUtils.compareNewVersion(info, mvccVer.coordinatorVersion(), mvccVer.counter()) == 0 || info.newMvccCoordinatorVersion() == MvccUtils.MVCC_CRD_COUNTER_NA;
boolean added = cctx.offheap().mvccUpdateRowWithPreloadInfo(this, info.value(), info.version(), info.expireTime(), info.mvccVersion(), info.newMvccVersion(), info.mvccTxState(), info.newMvccTxState());
if (walEnabled)
walEntries.add(toMvccDataEntry(info, tx));
if (oldVal == null && MvccUtils.compare(info.mvccVersion(), mvccVer.coordinatorVersion(), mvccVer.counter()) != 0 && MvccUtils.compareNewVersion(info, mvccVer.coordinatorVersion(), mvccVer.counter()) == 0)
// Old means a value before current transaction.
oldVal = info.value();
if (!added)
break;
}
GridCacheMvccEntryInfo last = (GridCacheMvccEntryInfo) entries.get(0);
if (walEnabled)
Collections.reverse(walEntries);
if (op == DELETE) {
assert MvccUtils.compareNewVersion(last, mvccVer) == 0;
if (walEnabled)
walEntries.add(new MvccDataEntry(cctx.cacheId(), key, null, DELETE, tx.nearXidVersion(), last.version(), last.expireTime(), key.partition(), 0, last.mvccVersion()));
} else {
assert last.newMvccCoordinatorVersion() == MvccUtils.MVCC_CRD_COUNTER_NA;
assert MvccUtils.compare(last, mvccVer) == 0;
val = last.value();
}
if (walEnabled)
logPtr = cctx.shared().wal().log(new MvccDataRecord(walEntries));
} finally {
if (lockedByCurrentThread()) {
unlockEntry();
cctx.evicts().touch(this);
}
}
GridCacheUpdateTxResult res = new GridCacheUpdateTxResult(true, logPtr);
res.newValue(val);
res.oldValue(oldVal);
return res;
}
use of org.apache.ignite.internal.pagemem.wal.record.MvccDataEntry in project ignite by apache.
the class GridCacheDatabaseSharedManager method applyUpdate.
/**
* @param cacheCtx Cache context to apply an update.
* @param dataEntry Data entry to apply.
* @throws IgniteCheckedException If failed to restore.
*/
private void applyUpdate(GridCacheContext<?, ?> cacheCtx, DataEntry dataEntry) throws IgniteCheckedException {
assert cacheCtx.offheap() instanceof GridCacheOffheapManager;
int partId = dataEntry.partitionId();
if (partId == -1)
partId = cacheCtx.affinity().partition(dataEntry.key());
GridDhtLocalPartition locPart = cacheCtx.isLocal() ? null : cacheCtx.topology().forceCreatePartition(partId);
switch(dataEntry.op()) {
case CREATE:
case UPDATE:
if (dataEntry instanceof MvccDataEntry) {
cacheCtx.offheap().mvccApplyUpdate(cacheCtx, dataEntry.key(), dataEntry.value(), dataEntry.writeVersion(), dataEntry.expireTime(), locPart, ((MvccDataEntry) dataEntry).mvccVer());
} else {
cacheCtx.offheap().update(cacheCtx, dataEntry.key(), dataEntry.value(), dataEntry.writeVersion(), dataEntry.expireTime(), locPart, null);
}
if (dataEntry.partitionCounter() != 0)
cacheCtx.offheap().dataStore(locPart).updateInitialCounter(dataEntry.partitionCounter() - 1, 1);
break;
case DELETE:
if (dataEntry instanceof MvccDataEntry) {
cacheCtx.offheap().mvccApplyUpdate(cacheCtx, dataEntry.key(), null, dataEntry.writeVersion(), 0L, locPart, ((MvccDataEntry) dataEntry).mvccVer());
} else
cacheCtx.offheap().remove(cacheCtx, dataEntry.key(), partId, locPart);
if (dataEntry.partitionCounter() != 0)
cacheCtx.offheap().dataStore(locPart).updateInitialCounter(dataEntry.partitionCounter() - 1, 1);
break;
case READ:
// do nothing
break;
default:
throw new IgniteCheckedException("Invalid operation for WAL entry update: " + dataEntry.op());
}
}
Aggregations