use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.
the class GridCacheMapEntry method peek.
/**
* {@inheritDoc}
*/
@Nullable
@Override
public CacheObject peek(@Nullable IgniteCacheExpiryPolicy plc) throws GridCacheEntryRemovedException, IgniteCheckedException {
IgniteInternalTx tx = cctx.tm().localTx();
AffinityTopologyVersion topVer = tx != null ? tx.topologyVersion() : cctx.affinity().affinityTopologyVersion();
return peek(true, false, topVer, plc);
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.
the class GridNearTxFinishFuture method finishOnePhase.
/**
* @param commit Commit flag.
*/
private void finishOnePhase(boolean commit) {
assert Thread.holdsLock(this);
if (finishOnePhaseCalled)
return;
finishOnePhaseCalled = true;
GridDistributedTxMapping locMapping = mappings.localMapping();
if (locMapping != null) {
// No need to send messages as transaction was already committed on remote node.
// Finish local mapping only as we need send commit message to backups.
IgniteInternalFuture<IgniteInternalTx> fut = cctx.tm().txHandler().finishColocatedLocal(commit, tx);
// Add new future.
if (fut != null)
add(fut);
}
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.
the class GridNearTxFinishFuture method finish.
/**
* @param miniId Mini future ID.
* @param m Mapping.
* @param commit Commit flag.
*/
private void finish(int miniId, GridDistributedTxMapping m, boolean commit) {
ClusterNode n = m.primary();
assert !m.empty() : m;
CacheWriteSynchronizationMode syncMode = tx.syncMode();
if (m.explicitLock())
syncMode = FULL_SYNC;
// Version to be added in completed versions on primary node.
GridCacheVersion completedVer = !commit && tx.timeout() > 0 ? tx.xidVersion() : null;
GridNearTxFinishRequest req = new GridNearTxFinishRequest(futId, tx.xidVersion(), tx.threadId(), commit, tx.isInvalidate(), tx.system(), tx.ioPolicy(), syncMode, m.explicitLock(), tx.storeEnabled(), tx.topologyVersion(), // Reuse 'baseVersion' to do not add new fields in message.
completedVer, null, null, tx.size(), tx.subjectId(), tx.taskNameHash(), tx.activeCachesDeploymentEnabled());
// If this is the primary node for the keys.
if (n.isLocal()) {
req.miniId(miniId);
IgniteInternalFuture<IgniteInternalTx> fut = cctx.tm().txHandler().finish(n.id(), tx, req);
// Add new future.
if (fut != null && syncMode == FULL_SYNC)
add(fut);
} else {
FinishMiniFuture fut = new FinishMiniFuture(miniId, m);
req.miniId(fut.futureId());
// Append new future.
add(fut);
if (tx.pessimistic())
cctx.tm().beforeFinishRemote(n.id(), tx.threadId());
try {
cctx.io().send(n, req, tx.ioPolicy());
if (msgLog.isDebugEnabled()) {
msgLog.debug("Near finish fut, sent request [" + "txId=" + tx.nearXidVersion() + ", node=" + n.id() + ']');
}
boolean wait = syncMode != FULL_ASYNC;
// If we don't wait for result, then mark future as done.
if (!wait)
fut.onDone();
} catch (ClusterTopologyCheckedException ignored) {
// Remove previous mapping.
mappings.remove(m.primary().id());
fut.onNodeLeft(n.id(), false);
} catch (IgniteCheckedException e) {
if (msgLog.isDebugEnabled()) {
msgLog.debug("Near finish fut, failed to send request [" + "txId=" + tx.nearXidVersion() + ", node=" + n.id() + ", err=" + e + ']');
}
// Fail the whole thing.
fut.onDone(e);
}
}
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.
the class GridNearLockFuture method map.
/**
* Basically, future mapping consists from two parts. First, we must determine the topology version this future
* will map on. Locking is performed within a user transaction, we must continue to map keys on the same
* topology version as it started. If topology version is undefined, we get current topology future and wait
* until it completes so the topology is ready to use.
* <p/>
* During the second part we map keys to primary nodes using topology snapshot we obtained during the first
* part. Note that if primary node leaves grid, the future will fail and transaction will be rolled back.
*/
void map() {
if (tx != null && tx.trackTimeout()) {
if (!tx.removeTimeoutHandler()) {
tx.finishFuture().listen(new IgniteInClosure<IgniteInternalFuture<IgniteInternalTx>>() {
@Override
public void apply(IgniteInternalFuture<IgniteInternalTx> fut) {
IgniteTxTimeoutCheckedException err = new IgniteTxTimeoutCheckedException("Failed to " + "acquire lock, transaction was rolled back on timeout [timeout=" + tx.timeout() + ", tx=" + tx + ']');
onError(err);
onComplete(false, false, false);
}
});
return;
}
}
if (timeout > 0) {
timeoutObj = new LockTimeoutObject();
cctx.time().addTimeoutObject(timeoutObj);
}
boolean added = cctx.mvcc().addFuture(this);
assert added : this;
// Obtain the topology version to use.
long threadId = Thread.currentThread().getId();
AffinityTopologyVersion topVer = cctx.mvcc().lastExplicitLockTopologyVersion(threadId);
// If there is another system transaction in progress, use it's topology version to prevent deadlock.
if (topVer == null && tx != null && tx.system())
topVer = cctx.tm().lockedTopologyVersion(threadId, tx);
if (topVer != null && tx != null)
tx.topologyVersion(topVer);
if (topVer == null && tx != null)
topVer = tx.topologyVersionSnapshot();
if (topVer != null) {
for (GridDhtTopologyFuture fut : cctx.shared().exchange().exchangeFutures()) {
if (fut.exchangeDone() && fut.topologyVersion().equals(topVer)) {
Throwable err = fut.validateCache(cctx, recovery, read, null, keys);
if (err != null) {
onDone(err);
return;
}
break;
}
}
// Continue mapping on the same topology version as it was before.
if (this.topVer == null)
this.topVer = topVer;
map(keys, false, true);
markInitialized();
return;
}
// Must get topology snapshot and map on that version.
mapOnTopology(false);
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.
the class GridCacheStoreManagerAdapter method loadFromStore.
/**
* Loads data from persistent store.
*
* @param tx Cache transaction.
* @param key Cache key.
* @param convert Convert flag.
* @return Loaded value, possibly <tt>null</tt>.
* @throws IgniteCheckedException If data loading failed.
*/
@Nullable
private Object loadFromStore(@Nullable IgniteInternalTx tx, KeyCacheObject key, boolean convert) throws IgniteCheckedException {
if (store != null) {
if (key.internal())
// Never load internal keys from store as they are never persisted.
return null;
Object storeKey = cctx.unwrapBinaryIfNeeded(key, !convertBinary());
if (log.isDebugEnabled())
log.debug(S.toString("Loading value from store for key", "key", storeKey, true));
sessionInit0(tx, StoreOperation.READ, false);
boolean threwEx = true;
Object val = null;
try {
val = singleThreadGate.load(storeKey);
threwEx = false;
} catch (ClassCastException e) {
handleClassCastException(e);
} catch (CacheLoaderException e) {
throw new IgniteCheckedException(e);
} catch (Exception e) {
throw new IgniteCheckedException(new CacheLoaderException(e));
} finally {
IgniteInternalTx tx0 = tx;
if (tx0 != null && (tx0.dht() && tx0.local()))
tx0 = null;
sessionEnd0(tx0, threwEx);
}
if (log.isDebugEnabled())
log.debug(S.toString("Loaded value from store", "key", key, true, "val", val, true));
if (convert) {
val = convert(val);
return val;
} else
return val;
}
return null;
}
Aggregations