use of org.apache.ignite.internal.processors.cache.GridCacheContext in project ignite by apache.
the class GridNearOptimisticSerializableTxPrepareFuture method onOwnerChanged.
/** {@inheritDoc} */
@Override
public boolean onOwnerChanged(GridCacheEntryEx entry, GridCacheMvccCandidate owner) {
if (log.isDebugEnabled())
log.debug("Transaction future received owner changed callback: " + entry);
if ((entry.context().isNear() || entry.context().isLocal()) && owner != null) {
IgniteTxEntry txEntry = tx.entry(entry.txKey());
if (txEntry != null) {
if (entry.context().isLocal()) {
GridCacheVersion serReadVer = txEntry.entryReadVersion();
if (serReadVer != null) {
GridCacheContext ctx = entry.context();
while (true) {
try {
if (!entry.checkSerializableReadVersion(serReadVer)) {
Object key = entry.key().value(ctx.cacheObjectContext(), false);
IgniteTxOptimisticCheckedException err0 = new IgniteTxOptimisticCheckedException(S.toString("Failed to prepare transaction, read/write conflict", "key", key, true, "cache", ctx.name(), false));
ERR_UPD.compareAndSet(this, null, err0);
}
break;
} catch (GridCacheEntryRemovedException ignored) {
entry = ctx.cache().entryEx(entry.key(), tx.topologyVersion());
txEntry.cached(entry);
}
}
}
}
if (keyLockFut != null)
keyLockFut.onKeyLocked(entry.txKey());
return true;
}
}
return false;
}
use of org.apache.ignite.internal.processors.cache.GridCacheContext in project ignite by apache.
the class GridNearTxLocal method readyNearLock.
/**
* @param txEntry TX entry.
* @param dhtVer DHT version.
* @param pendingVers Pending versions.
* @param committedVers Committed versions.
* @param rolledbackVers Rolled back versions.
*/
private void readyNearLock(IgniteTxEntry txEntry, GridCacheVersion dhtVer, Collection<GridCacheVersion> pendingVers, Collection<GridCacheVersion> committedVers, Collection<GridCacheVersion> rolledbackVers) {
while (true) {
GridCacheContext cacheCtx = txEntry.cached().context();
assert cacheCtx.isNear();
GridDistributedCacheEntry entry = (GridDistributedCacheEntry) txEntry.cached();
try {
// Handle explicit locks.
GridCacheVersion explicit = txEntry.explicitVersion();
if (explicit == null) {
entry.readyNearLock(xidVer, dhtVer, committedVers, rolledbackVers, pendingVers);
}
break;
} catch (GridCacheEntryRemovedException ignored) {
assert entry.obsoleteVersion() != null;
if (log.isDebugEnabled())
log.debug("Replacing obsolete entry in remote transaction [entry=" + entry + ", tx=" + this + ']');
// Replace the entry.
txEntry.cached(txEntry.context().cache().entryEx(txEntry.key(), topologyVersion()));
}
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheContext in project ignite by apache.
the class GridLocalCacheEntry method checkThreadChain.
/** {@inheritDoc} */
@Override
protected void checkThreadChain(GridCacheMvccCandidate owner) {
assert !Thread.holdsLock(this);
assert owner != null;
assert owner.owner() || owner.used() : "Neither owner or used flags are set on ready local candidate: " + owner;
if (owner.next() != null) {
for (GridCacheMvccCandidate cand = owner.next(); cand != null; cand = cand.next()) {
assert cand.local();
// Allow next lock in the thread to proceed.
if (!cand.used()) {
GridCacheContext cctx0 = cand.parent().context();
GridLocalCacheEntry e = (GridLocalCacheEntry) cctx0.cache().peekEx(cand.parent().key());
// so we check for null.
if (e != null)
e.recheck();
break;
}
}
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheContext in project ignite by apache.
the class GridNearPessimisticTxPrepareFuture method preparePessimistic.
/**
*
*/
private void preparePessimistic() {
Map<UUID, GridDistributedTxMapping> mappings = new HashMap<>();
AffinityTopologyVersion topVer = tx.topologyVersion();
GridDhtTxMapping txMapping = new GridDhtTxMapping();
boolean hasNearCache = false;
for (IgniteTxEntry txEntry : tx.allEntries()) {
txEntry.clearEntryReadVersion();
GridCacheContext cacheCtx = txEntry.context();
if (cacheCtx.isNear())
hasNearCache = true;
List<ClusterNode> nodes;
if (!cacheCtx.isLocal()) {
GridDhtPartitionTopology top = cacheCtx.topology();
nodes = top.nodes(cacheCtx.affinity().partition(txEntry.key()), topVer);
} else
nodes = cacheCtx.affinity().nodesByKey(txEntry.key(), topVer);
assert !nodes.isEmpty();
ClusterNode primary = nodes.get(0);
GridDistributedTxMapping nodeMapping = mappings.get(primary.id());
if (nodeMapping == null)
mappings.put(primary.id(), nodeMapping = new GridDistributedTxMapping(primary));
txEntry.nodeId(primary.id());
nodeMapping.add(txEntry);
txMapping.addMapping(nodes);
}
tx.transactionNodes(txMapping.transactionNodes());
if (!hasNearCache)
checkOnePhase(txMapping);
long timeout = tx.remainingTime();
if (timeout == -1) {
onDone(new IgniteTxTimeoutCheckedException("Transaction timed out and was rolled back: " + tx));
return;
}
int miniId = 0;
Map<UUID, Collection<UUID>> txNodes = txMapping.transactionNodes();
for (final GridDistributedTxMapping m : mappings.values()) {
final ClusterNode primary = m.primary();
if (primary.isLocal()) {
if (m.hasNearCacheEntries() && m.hasColocatedCacheEntries()) {
GridNearTxPrepareRequest nearReq = createRequest(txMapping.transactionNodes(), m, timeout, m.nearEntriesReads(), m.nearEntriesWrites());
prepareLocal(nearReq, m, ++miniId, true);
GridNearTxPrepareRequest colocatedReq = createRequest(txNodes, m, timeout, m.colocatedEntriesReads(), m.colocatedEntriesWrites());
prepareLocal(colocatedReq, m, ++miniId, false);
} else {
GridNearTxPrepareRequest req = createRequest(txNodes, m, timeout, m.reads(), m.writes());
prepareLocal(req, m, ++miniId, m.hasNearCacheEntries());
}
} else {
GridNearTxPrepareRequest req = createRequest(txNodes, m, timeout, m.reads(), m.writes());
final MiniFuture fut = new MiniFuture(m, ++miniId);
req.miniId(fut.futureId());
add(fut);
try {
cctx.io().send(primary, req, tx.ioPolicy());
if (msgLog.isDebugEnabled()) {
msgLog.debug("Near pessimistic prepare, sent request [txId=" + tx.nearXidVersion() + ", node=" + primary.id() + ']');
}
} catch (ClusterTopologyCheckedException e) {
e.retryReadyFuture(cctx.nextAffinityReadyFuture(topVer));
fut.onNodeLeft(e);
} catch (IgniteCheckedException e) {
if (msgLog.isDebugEnabled()) {
msgLog.debug("Near pessimistic prepare, failed send request [txId=" + tx.nearXidVersion() + ", node=" + primary.id() + ", err=" + e + ']');
}
fut.onError(e);
break;
}
}
}
markInitialized();
}
use of org.apache.ignite.internal.processors.cache.GridCacheContext in project ignite by apache.
the class GridNearSingleGetRequest method prepareMarshal.
/** {@inheritDoc} */
@Override
public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException {
super.prepareMarshal(ctx);
assert key != null;
GridCacheContext cctx = ctx.cacheContext(cacheId);
prepareMarshalCacheObject(key, cctx);
}
Aggregations