use of org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot in project ignite by apache.
the class GridCacheAdapter method localEntries.
/**
* {@inheritDoc}
*/
@Override
public final Iterable<Cache.Entry<K, V>> localEntries(CachePeekMode[] peekModes) throws IgniteCheckedException {
assert peekModes != null;
ctx.checkSecurity(SecurityPermission.CACHE_READ);
PeekModes modes = parsePeekModes(peekModes, false);
Collection<Iterator<Cache.Entry<K, V>>> its = new ArrayList<>();
final boolean keepBinary = ctx.keepBinary();
if (ctx.isLocal()) {
modes.primary = true;
modes.backup = true;
}
if (modes.offheap) {
if (modes.heap && modes.near && ctx.isNear())
its.add(ctx.near().nearEntries().iterator());
if (modes.primary || modes.backup) {
AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
IgniteCacheOffheapManager offheapMgr = ctx.isNear() ? ctx.near().dht().context().offheap() : ctx.offheap();
MvccSnapshot mvccSnapshot = ctx.mvccEnabled() ? MvccUtils.MVCC_MAX_SNAPSHOT : null;
its.add(offheapMgr.cacheEntriesIterator(ctx, modes.primary, modes.backup, topVer, ctx.keepBinary(), mvccSnapshot, null));
}
} else if (modes.heap) {
if (ctx.mvccEnabled())
return F.emptyIterator();
if (modes.near && ctx.isNear())
its.add(ctx.near().nearEntries().iterator());
if (modes.primary || modes.backup) {
GridDhtCacheAdapter<K, V> cache = ctx.isNear() ? ctx.near().dht() : ctx.dht();
its.add(cache.localEntriesIterator(modes.primary, modes.backup, keepBinary));
}
}
final Iterator<Cache.Entry<K, V>> it = F.flatIterators(its);
return new Iterable<Cache.Entry<K, V>>() {
@Override
public Iterator<Cache.Entry<K, V>> iterator() {
return it;
}
@Override
public String toString() {
return "CacheLocalEntries []";
}
};
}
use of org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot in project ignite by apache.
the class GridDhtColocatedCache method getAllAsync.
/**
* {@inheritDoc}
*/
@Override
public IgniteInternalFuture<Map<K, V>> getAllAsync(@Nullable final Collection<? extends K> keys, boolean forcePrimary, boolean skipTx, String taskName, final boolean deserializeBinary, final boolean recovery, final ReadRepairStrategy readRepairStrategy, final boolean skipVals, final boolean needVer) {
ctx.checkSecurity(SecurityPermission.CACHE_READ);
if (F.isEmpty(keys))
return new GridFinishedFuture<>(Collections.<K, V>emptyMap());
warnIfUnordered(keys, BulkOperation.GET);
GridNearTxLocal tx = checkCurrentTx();
final CacheOperationContext opCtx = ctx.operationContextPerCall();
if (!ctx.mvccEnabled() && tx != null && !tx.implicit() && !skipTx) {
return asyncOp(tx, new AsyncOp<Map<K, V>>(keys) {
/**
* {@inheritDoc}
*/
@Override
public IgniteInternalFuture<Map<K, V>> op(GridNearTxLocal tx, AffinityTopologyVersion readyTopVer) {
return tx.getAllAsync(ctx, readyTopVer, ctx.cacheKeysView(keys), deserializeBinary, skipVals, false, opCtx != null && opCtx.skipStore(), recovery, readRepairStrategy, needVer);
}
}, opCtx, /*retry*/
false);
}
MvccSnapshot mvccSnapshot = null;
MvccQueryTracker mvccTracker = null;
if (ctx.mvccEnabled()) {
try {
if (tx != null)
mvccSnapshot = MvccUtils.requestSnapshot(tx);
else {
mvccTracker = MvccUtils.mvccTracker(ctx, null);
mvccSnapshot = mvccTracker.snapshot();
}
assert mvccSnapshot != null;
} catch (IgniteCheckedException ex) {
return new GridFinishedFuture<>(ex);
}
}
AffinityTopologyVersion topVer;
if (tx != null)
topVer = tx.topologyVersion();
else if (mvccTracker != null)
topVer = mvccTracker.topologyVersion();
else
topVer = ctx.affinity().affinityTopologyVersion();
if (readRepairStrategy != null) {
return new GridNearReadRepairCheckOnlyFuture(ctx, ctx.cacheKeysView(keys), readRepairStrategy, opCtx == null || !opCtx.skipStore(), taskName, deserializeBinary, recovery, skipVals ? null : expiryPolicy(opCtx != null ? opCtx.expiry() : null), skipVals, needVer, false, tx).multi();
}
IgniteInternalFuture<Map<K, V>> fut = loadAsync(ctx.cacheKeysView(keys), opCtx == null || !opCtx.skipStore(), forcePrimary, topVer, taskName, deserializeBinary, recovery, skipVals ? null : expiryPolicy(opCtx != null ? opCtx.expiry() : null), skipVals, needVer, false, null, mvccSnapshot);
if (mvccTracker != null) {
final MvccQueryTracker mvccTracker0 = mvccTracker;
fut.listen(new CI1<IgniteInternalFuture<Map<K, V>>>() {
/**
* {@inheritDoc}
*/
@Override
public void apply(IgniteInternalFuture<Map<K, V>> future) {
if (future.isDone())
mvccTracker0.onDone();
}
});
}
return fut;
}
use of org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot in project ignite by apache.
the class InlineIndexImpl method filterClosure.
/**
*/
private InlineTreeFilterClosure filterClosure(IndexQueryContext qryCtx) {
if (qryCtx == null)
return null;
IndexingQueryCacheFilter cacheFilter = qryCtx.cacheFilter() == null ? null : qryCtx.cacheFilter().forCache(cctx.cache().name());
MvccSnapshot v = qryCtx.mvccSnapshot();
assert !cctx.mvccEnabled() || v != null;
if (cacheFilter == null && v == null)
return null;
return new InlineTreeFilterClosure(cacheFilter, qryCtx.rowFilter(), v, cctx, cctx.kernalContext().config().getGridLogger());
}
use of org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot in project ignite by apache.
the class GridDhtTxFinishFuture method finish.
/**
* @param commit Commit flag.
* @param dhtMap DHT map.
* @param nearMap Near map.
* @return {@code True} in case there is at least one synchronous {@code MiniFuture} to wait for.
*/
private boolean finish(boolean commit, Map<UUID, GridDistributedTxMapping> dhtMap, Map<UUID, GridDistributedTxMapping> nearMap) {
if (tx.onePhaseCommit())
return false;
assert !commit || !tx.txState().mvccEnabled() || tx.mvccSnapshot() != null || F.isEmpty(tx.writeEntries());
boolean sync = tx.syncMode() == FULL_SYNC;
if (tx.explicitLock() || tx.queryEnlisted())
sync = true;
boolean res = false;
int miniId = 0;
// Do not need process active transactions on backups.
MvccSnapshot mvccSnapshot = tx.mvccSnapshot();
if (mvccSnapshot != null)
mvccSnapshot = mvccSnapshot.withoutActiveTransactions();
// Create mini futures.
for (GridDistributedTxMapping dhtMapping : dhtMap.values()) {
ClusterNode n = dhtMapping.primary();
assert !n.isLocal();
GridDistributedTxMapping nearMapping = nearMap.get(n.id());
if (!dhtMapping.queryUpdate() && dhtMapping.empty() && nearMapping != null && nearMapping.empty())
// Nothing to send.
continue;
MiniFuture fut = new MiniFuture(++miniId, dhtMapping, nearMapping);
// Append new future.
add(fut);
GridDhtTxFinishRequest req = new GridDhtTxFinishRequest(tx.nearNodeId(), futId, fut.futureId(), tx.topologyVersion(), tx.xidVersion(), tx.commitVersion(), tx.threadId(), tx.isolation(), commit, tx.isInvalidate(), tx.system(), tx.ioPolicy(), tx.isSystemInvalidate(), sync || !commit ? FULL_SYNC : tx.syncMode(), tx.completedBase(), tx.committedVersions(), tx.rolledbackVersions(), tx.pendingVersions(), tx.size(), tx.taskNameHash(), tx.activeCachesDeploymentEnabled(), null, false, false, mvccSnapshot, commit ? null : cctx.tm().txHandler().filterUpdateCountersForBackupNode(tx, n));
req.writeVersion(tx.writeVersion() != null ? tx.writeVersion() : tx.xidVersion());
try {
if (isNull(cctx.discovery().getAlive(n.id()))) {
log.error("Unable to send message (node left topology): " + n);
fut.onNodeLeft(new ClusterTopologyCheckedException("Node left grid while sending message to: " + n.id()));
} else {
cctx.io().send(n, req, tx.ioPolicy());
if (msgLog.isDebugEnabled()) {
msgLog.debug("DHT finish fut, sent request dht [txId=" + tx.nearXidVersion() + ", dhtTxId=" + tx.xidVersion() + ", node=" + n.id() + ']');
}
if (sync || !commit)
// Force sync mode for rollback to prevent an issue with concurrent recovery.
res = true;
else
fut.onDone();
}
} catch (IgniteCheckedException e) {
// Fail the whole thing.
if (e instanceof ClusterTopologyCheckedException)
fut.onNodeLeft((ClusterTopologyCheckedException) e);
else {
if (msgLog.isDebugEnabled()) {
msgLog.debug("DHT finish fut, failed to send request dht [txId=" + tx.nearXidVersion() + ", dhtTxId=" + tx.xidVersion() + ", node=" + n.id() + ", err=" + e + ']');
}
fut.onResult(e);
}
}
}
for (GridDistributedTxMapping nearMapping : nearMap.values()) {
if (!dhtMap.containsKey(nearMapping.primary().id())) {
if (nearMapping.empty())
// Nothing to send.
continue;
MiniFuture fut = new MiniFuture(++miniId, null, nearMapping);
// Append new future.
add(fut);
GridDhtTxFinishRequest req = new GridDhtTxFinishRequest(tx.nearNodeId(), futId, fut.futureId(), tx.topologyVersion(), tx.xidVersion(), tx.commitVersion(), tx.threadId(), tx.isolation(), commit, tx.isInvalidate(), tx.system(), tx.ioPolicy(), tx.isSystemInvalidate(), sync ? FULL_SYNC : tx.syncMode(), tx.completedBase(), tx.committedVersions(), tx.rolledbackVersions(), tx.pendingVersions(), tx.size(), tx.taskNameHash(), tx.activeCachesDeploymentEnabled(), false, false, mvccSnapshot, null);
req.writeVersion(tx.writeVersion());
try {
cctx.io().send(nearMapping.primary(), req, tx.ioPolicy());
if (msgLog.isDebugEnabled()) {
msgLog.debug("DHT finish fut, sent request near [txId=" + tx.nearXidVersion() + ", dhtTxId=" + tx.xidVersion() + ", node=" + nearMapping.primary().id() + ']');
}
if (sync)
res = true;
else
fut.onDone();
} catch (IgniteCheckedException e) {
// Fail the whole thing.
if (e instanceof ClusterTopologyCheckedException)
fut.onNodeLeft((ClusterTopologyCheckedException) e);
else {
if (msgLog.isDebugEnabled()) {
msgLog.debug("DHT finish fut, failed to send request near [txId=" + tx.nearXidVersion() + ", dhtTxId=" + tx.xidVersion() + ", node=" + nearMapping.primary().id() + ", err=" + e + ']');
}
fut.onResult(e);
}
}
}
}
return res;
}
use of org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot in project ignite by apache.
the class GridDhtTransactionalCacheAdapter method processDhtTxQueryEnlistRequest.
/**
* @param primary Primary node.
* @param req Message.
* @param first Flag if this is a first request in current operation.
*/
private void processDhtTxQueryEnlistRequest(UUID primary, GridDhtTxQueryEnlistRequest req, boolean first) {
try {
assert req.version() != null && req.op() != null;
GridDhtTxRemote tx = ctx.tm().tx(req.version());
if (tx == null) {
if (!first)
throw new IgniteCheckedException("Can not find a transaction for version [version=" + req.version() + ']');
GridDhtTxQueryFirstEnlistRequest req0 = (GridDhtTxQueryFirstEnlistRequest) req;
tx = new GridDhtTxRemote(ctx.shared(), req0.nearNodeId(), req0.dhtFutureId(), primary, req0.nearXidVersion(), req0.topologyVersion(), req0.version(), null, ctx.systemTx(), ctx.ioPolicy(), PESSIMISTIC, REPEATABLE_READ, false, req0.timeout(), -1, securitySubjectId(ctx), req0.taskNameHash(), false, null);
tx.mvccSnapshot(new MvccSnapshotWithoutTxs(req0.coordinatorVersion(), req0.counter(), MVCC_OP_COUNTER_NA, req0.cleanupVersion()));
tx = ctx.tm().onCreated(null, tx);
if (tx == null || !ctx.tm().onStarted(tx)) {
throw new IgniteTxRollbackCheckedException("Failed to update backup " + "(transaction has been completed): " + req0.version());
}
}
assert tx != null;
MvccSnapshot s0 = tx.mvccSnapshot();
MvccSnapshot snapshot = new MvccSnapshotWithoutTxs(s0.coordinatorVersion(), s0.counter(), req.operationCounter(), s0.cleanupVersion());
ctx.tm().txHandler().mvccEnlistBatch(tx, ctx, req.op(), req.keys(), req.values(), snapshot, req.dhtFutureId(), req.batchId());
GridDhtTxQueryEnlistResponse res = new GridDhtTxQueryEnlistResponse(req.cacheId(), req.dhtFutureId(), req.batchId(), null);
try {
ctx.io().send(primary, res, ctx.ioPolicy());
} catch (IgniteCheckedException ioEx) {
U.error(log, "Failed to send DHT enlist reply to primary node [node: " + primary + ", req=" + req + ']', ioEx);
}
} catch (Throwable e) {
GridDhtTxQueryEnlistResponse res = new GridDhtTxQueryEnlistResponse(ctx.cacheId(), req.dhtFutureId(), req.batchId(), e);
try {
ctx.io().send(primary, res, ctx.ioPolicy());
} catch (IgniteCheckedException ioEx) {
U.error(log, "Failed to send DHT enlist reply to primary node " + "[node: " + primary + ", req=" + req + ']', ioEx);
}
if (e instanceof Error)
throw (Error) e;
}
}
Aggregations