use of org.apache.ignite.internal.processors.cache.distributed.GridCacheMappedVersion in project ignite by apache.
the class GridCacheMvccManager method addFuture.
/**
* /**
* Adds future.
*
* @param fut Future.
* @return {@code True} if added.
*/
@SuppressWarnings({ "SynchronizationOnLocalVariableOrMethodParameter" })
public boolean addFuture(final GridCacheVersionedFuture<?> fut) {
if (fut.isDone()) {
fut.markNotTrackable();
return true;
}
if (!fut.trackable())
return true;
while (true) {
Collection<GridCacheVersionedFuture<?>> old = verFuts.get(fut.version());
if (old == null) {
Collection<GridCacheVersionedFuture<?>> col = new HashSet<GridCacheVersionedFuture<?>>(U.capacity(1), 0.75f) {
{
// Make sure that we add future to queue before
// adding queue to the map of futures.
add(fut);
}
@Override
public int hashCode() {
return System.identityHashCode(this);
}
@Override
public boolean equals(Object obj) {
return obj == this;
}
};
old = verFuts.putIfAbsent(fut.version(), col);
}
if (old != null) {
boolean empty, dup = false;
synchronized (old) {
empty = old.isEmpty();
if (!empty)
dup = !old.add(fut);
}
// Future is being removed, so we force-remove here and try again.
if (empty) {
if (verFuts.remove(fut.version(), old)) {
if (log.isDebugEnabled())
log.debug("Removed future list from futures map for lock version: " + fut.version());
}
continue;
}
if (dup) {
if (log.isDebugEnabled())
log.debug("Found duplicate future in futures map (will not add): " + fut);
return false;
}
}
// Handle version mappings.
if (fut instanceof GridCacheMappedVersion) {
GridCacheVersion from = ((GridCacheMappedVersion) fut).mappedVersion();
if (from != null)
mapVersion(from, fut.version());
}
if (log.isDebugEnabled())
log.debug("Added future to future map: " + fut);
break;
}
// Just in case if future was completed before it was added.
if (fut.isDone())
removeVersionedFuture(fut);
else
onFutureAdded(fut);
return true;
}
use of org.apache.ignite.internal.processors.cache.distributed.GridCacheMappedVersion in project ignite by apache.
the class GridCacheMvccManager method addFuture.
/**
/**
* Adds future.
*
* @param fut Future.
* @return {@code True} if added.
*/
@SuppressWarnings({ "SynchronizationOnLocalVariableOrMethodParameter" })
public boolean addFuture(final GridCacheMvccFuture<?> fut) {
if (fut.isDone()) {
fut.markNotTrackable();
return true;
}
if (!fut.trackable())
return true;
while (true) {
Collection<GridCacheMvccFuture<?>> old = mvccFuts.get(fut.version());
if (old == null) {
Collection<GridCacheMvccFuture<?>> col = new HashSet<GridCacheMvccFuture<?>>(U.capacity(1), 0.75f) {
{
// Make sure that we add future to queue before
// adding queue to the map of futures.
add(fut);
}
@Override
public int hashCode() {
return System.identityHashCode(this);
}
@Override
public boolean equals(Object obj) {
return obj == this;
}
};
old = mvccFuts.putIfAbsent(fut.version(), col);
}
if (old != null) {
boolean empty, dup = false;
synchronized (old) {
empty = old.isEmpty();
if (!empty)
dup = !old.add(fut);
}
// Future is being removed, so we force-remove here and try again.
if (empty) {
if (mvccFuts.remove(fut.version(), old)) {
if (log.isDebugEnabled())
log.debug("Removed future list from futures map for lock version: " + fut.version());
}
continue;
}
if (dup) {
if (log.isDebugEnabled())
log.debug("Found duplicate future in futures map (will not add): " + fut);
return false;
}
}
// Handle version mappings.
if (fut instanceof GridCacheMappedVersion) {
GridCacheVersion from = ((GridCacheMappedVersion) fut).mappedVersion();
if (from != null)
mapVersion(from, fut.version());
}
if (log.isDebugEnabled())
log.debug("Added future to future map: " + fut);
break;
}
// Just in case if future was completed before it was added.
if (fut.isDone())
removeMvccFuture(fut);
else
onFutureAdded(fut);
return true;
}
use of org.apache.ignite.internal.processors.cache.distributed.GridCacheMappedVersion in project ignite by apache.
the class IgniteTxManager method uncommitTx.
/**
* Tries to minimize damage from partially-committed transaction.
*
* @param tx Tx to uncommit.
*/
void uncommitTx(IgniteInternalTx tx) {
assert tx != null;
if (log.isDebugEnabled())
log.debug("Uncommiting from TM: " + tx);
ConcurrentMap<GridCacheVersion, IgniteInternalTx> txIdMap = transactionMap(tx);
if (txIdMap.remove(tx.xidVersion(), tx)) {
// 1. Unlock write resources.
unlockMultiple(tx, tx.writeEntries());
// 2. Unlock read resources if required.
if (unlockReadEntries(tx))
unlockMultiple(tx, tx.readEntries());
// 3. Notify evictions.
notifyEvictions(tx);
// 4. Remove from per-thread storage.
clearThreadMap(tx);
// 5. Unregister explicit locks.
if (!tx.alternateVersions().isEmpty()) {
for (GridCacheVersion ver : tx.alternateVersions()) idMap.remove(ver);
}
// 6. Remove Near-2-DHT mappings.
if (tx instanceof GridCacheMappedVersion)
mappedVers.remove(((GridCacheMappedVersion) tx).mappedVersion());
// 7. Clear context.
resetContext();
if (log.isDebugEnabled())
log.debug("Uncommitted from TM: " + tx);
} else if (log.isDebugEnabled())
log.debug("Did not uncommit from TM (was already committed or rolled back): " + tx);
}
use of org.apache.ignite.internal.processors.cache.distributed.GridCacheMappedVersion in project ignite by apache.
the class IgniteTxManager method commitTx.
/**
* Commits a transaction.
*
* @param tx Transaction to commit.
* @throws IgniteCheckedException If failed.
*/
public void commitTx(IgniteInternalTx tx) throws IgniteCheckedException {
assert tx != null;
assert tx.state() == COMMITTING : "Invalid transaction state for commit from tm [state=" + tx.state() + ", expected=COMMITTING, tx=" + tx + ']';
if (log.isDebugEnabled())
log.debug("Committing from TM [locNodeId=" + cctx.localNodeId() + ", tx=" + tx + ']');
/*
* Note that write phase is handled by transaction adapter itself,
* so we don't do it here.
*/
Object committed0 = completedVersHashMap.get(tx.xidVersion());
Boolean committed = committed0 != null && !committed0.equals(Boolean.FALSE);
// 1. Make sure that committed version has been recorded.
if (!(committed || tx.writeSet().isEmpty() || tx.isSystemInvalidate())) {
uncommitTx(tx);
tx.errorWhenCommitting();
throw new IgniteCheckedException("Missing commit version (consider increasing " + IGNITE_MAX_COMPLETED_TX_COUNT + " system property) [ver=" + tx.xidVersion() + ", committed0=" + committed0 + ", tx=" + tx.getClass().getSimpleName() + ']');
}
ConcurrentMap<GridCacheVersion, IgniteInternalTx> txIdMap = transactionMap(tx);
if (txIdMap.remove(tx.xidVersion(), tx)) {
// 2. Must process completed entries before unlocking!
processCompletedEntries(tx);
if (tx instanceof GridDhtTxLocal) {
GridDhtTxLocal dhtTxLoc = (GridDhtTxLocal) tx;
collectPendingVersions(dhtTxLoc);
}
// 3. Unlock write resources.
unlockMultiple(tx, tx.writeEntries());
// 4. Unlock read resources if required.
if (unlockReadEntries(tx))
unlockMultiple(tx, tx.readEntries());
// 5. Notify evictions.
notifyEvictions(tx);
// 6. Remove obsolete entries from cache.
removeObsolete(tx);
// 7. Remove from per-thread storage.
clearThreadMap(tx);
// 8. Unregister explicit locks.
if (!tx.alternateVersions().isEmpty()) {
for (GridCacheVersion ver : tx.alternateVersions()) idMap.remove(ver);
}
// 9. Remove Near-2-DHT mappings.
if (tx instanceof GridCacheMappedVersion) {
GridCacheVersion mapped = ((GridCacheMappedVersion) tx).mappedVersion();
if (mapped != null)
mappedVers.remove(mapped);
}
// 10. Clear context.
resetContext();
// 11. Update metrics.
if (!tx.dht() && tx.local()) {
if (!tx.system())
cctx.txMetrics().onTxCommit();
writeStatistics(tx, true);
tx.txState().onTxEnd(cctx, tx, true);
}
if (slowTxWarnTimeout > 0 && tx.local() && U.currentTimeMillis() - tx.startTime() > slowTxWarnTimeout)
U.warn(log, "Slow transaction detected [tx=" + tx + ", slowTxWarnTimeout=" + slowTxWarnTimeout + ']');
if (log.isDebugEnabled())
log.debug("Committed from TM [locNodeId=" + cctx.localNodeId() + ", tx=" + tx + ']');
} else if (log.isDebugEnabled())
log.debug("Did not commit from TM (was already committed): " + tx);
}
use of org.apache.ignite.internal.processors.cache.distributed.GridCacheMappedVersion in project ignite by apache.
the class IgniteTxManager method onCreated.
/**
* @param cacheCtx Cache context.
* @param tx Created transaction.
* @return Started transaction.
*/
@Nullable
public <T extends IgniteInternalTx> T onCreated(@Nullable GridCacheContext cacheCtx, T tx) {
ConcurrentMap<GridCacheVersion, IgniteInternalTx> txIdMap = transactionMap(tx);
// Start clean.
resetContext();
if (isCompleted(tx)) {
if (log.isDebugEnabled())
log.debug("Attempt to create a completed transaction (will ignore): " + tx);
return null;
}
IgniteInternalTx t;
if ((t = txIdMap.putIfAbsent(tx.xidVersion(), tx)) == null) {
if (tx.local() && !tx.dht()) {
assert tx instanceof GridNearTxLocal : tx;
if (!tx.implicit()) {
if (cacheCtx == null || !cacheCtx.systemTx())
threadMap.put(tx.threadId(), tx);
else
sysThreadMap.put(new TxThreadKey(tx.threadId(), cacheCtx.cacheId()), tx);
}
((GridNearTxLocal) tx).recordStateChangedEvent(EVT_TX_STARTED);
}
// Handle mapped versions.
if (tx instanceof GridCacheMappedVersion) {
GridCacheMappedVersion mapped = (GridCacheMappedVersion) tx;
GridCacheVersion from = mapped.mappedVersion();
if (from != null)
mappedVers.put(from, tx.xidVersion());
if (log.isDebugEnabled())
log.debug("Added transaction version mapping [from=" + from + ", to=" + tx.xidVersion() + ", tx=" + tx + ']');
}
} else {
if (log.isDebugEnabled())
log.debug("Attempt to create an existing transaction (will ignore) [newTx=" + tx + ", existingTx=" + t + ']');
return null;
}
if (log.isDebugEnabled())
log.debug("Transaction created: " + tx);
return tx;
}
Aggregations