use of org.apache.ignite.internal.processors.cache.version.GridCacheVersion in project ignite by apache.
the class GridDhtCacheEntry method localCandidateByNearVersion.
/**
* @param nearVer Near version.
* @param rmv If {@code true}, then add to removed list if not found.
* @return Local candidate by near version.
* @throws GridCacheEntryRemovedException If removed.
*/
@Nullable
GridCacheMvccCandidate localCandidateByNearVersion(GridCacheVersion nearVer, boolean rmv) throws GridCacheEntryRemovedException {
lockEntry();
try {
checkObsolete();
GridCacheMvcc mvcc = mvccExtras();
if (mvcc != null) {
for (GridCacheMvccCandidate c : mvcc.localCandidatesNoCopy(false)) {
GridCacheVersion ver = c.otherVersion();
if (ver != null && ver.equals(nearVer))
return c;
}
}
if (rmv)
addRemoved(nearVer);
return null;
} finally {
unlockEntry();
}
}
use of org.apache.ignite.internal.processors.cache.version.GridCacheVersion in project ignite by apache.
the class GridDistributedTxRemoteAdapter method doneRemote.
/**
* Adds completed versions to an entry.
*
* @param txEntry Entry.
* @param baseVer Base version for completed versions.
* @param committedVers Completed versions relative to base version.
* @param rolledbackVers Rolled back versions relative to base version.
* @param pendingVers Pending versions.
*
* @throws GridDhtInvalidPartitionException If entry partition was invalidated.
*/
private void doneRemote(IgniteTxEntry txEntry, GridCacheVersion baseVer, Collection<GridCacheVersion> committedVers, Collection<GridCacheVersion> rolledbackVers, Collection<GridCacheVersion> pendingVers) throws GridDhtInvalidPartitionException {
while (true) {
GridDistributedCacheEntry entry = (GridDistributedCacheEntry) txEntry.cached();
try {
// Handle explicit locks.
GridCacheVersion doneVer = txEntry.explicitVersion() != null ? txEntry.explicitVersion() : xidVer;
entry.doneRemote(doneVer, baseVer, pendingVers, committedVers, rolledbackVers, isSystemInvalidate());
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.version.GridCacheVersion in project ignite by apache.
the class VisorTxTask method fetchTxEntriesAndFillUsedCaches.
/**
* Retrieves detailed information about used keys and locks ownership.
*
* @param ignite Ignite.
* @param locTx Local tx.
* @param usedCaches Used caches.
* @param usedCacheGroups Used cache groups.
* @param locEntries Local entries.
* @param skipLocksCheck Skip locks check.
*/
private static List<TxVerboseKey> fetchTxEntriesAndFillUsedCaches(IgniteEx ignite, IgniteInternalTx locTx, Map<Integer, String> usedCaches, Map<Integer, String> usedCacheGroups, Collection<IgniteTxEntry> locEntries, boolean skipLocksCheck) {
List<TxVerboseKey> locTxKeys = new ArrayList<>();
for (IgniteTxEntry txEntry : locEntries) {
GridCacheContext cacheCtx = ignite.context().cache().context().cacheContext(txEntry.cacheId());
usedCaches.put(cacheCtx.cacheId(), cacheCtx.name());
usedCacheGroups.put(cacheCtx.groupId(), cacheCtx.group().cacheOrGroupName());
TxKeyLockType keyLockType = TxKeyLockType.NO_LOCK;
GridCacheVersion ownerVer = null;
if (!skipLocksCheck) {
GridCacheEntryEx entryEx = cacheCtx.cache().entryEx(txEntry.key(), locTx.topologyVersion());
Collection<GridCacheMvccCandidate> locCandidates;
try {
locCandidates = entryEx.localCandidates();
} catch (GridCacheEntryRemovedException ignored) {
U.warn(ignite.log(), "Failed to process TX key: entry was already removed: " + txEntry.txKey());
continue;
}
boolean owner = false;
boolean present = false;
for (GridCacheMvccCandidate mvccCandidate : locCandidates) {
if (mvccCandidate.owner())
ownerVer = mvccCandidate.version();
if (locTx.xidVersion().equals(mvccCandidate.version())) {
present = true;
if (mvccCandidate.owner())
owner = true;
}
}
keyLockType = present ? (owner ? TxKeyLockType.OWNS_LOCK : TxKeyLockType.AWAITS_LOCK) : TxKeyLockType.NO_LOCK;
}
TxVerboseKey txVerboseKey = new TxVerboseKey(txEntry.txKey().toString(), keyLockType, ownerVer, txEntry.isRead());
locTxKeys.add(txVerboseKey);
}
return locTxKeys;
}
use of org.apache.ignite.internal.processors.cache.version.GridCacheVersion in project ignite by apache.
the class CdcCacheVersionTest method removeConflictData.
/**
*/
private void removeConflictData(IgniteEx cli, IgniteCache<Integer, User> cache, int from, int to, TransactionConcurrency concurrency, TransactionIsolation isolation) {
try {
IgniteInternalCache<Integer, User> intCache = cli.cachex(cache.getName());
Map<KeyCacheObject, GridCacheVersion> drMap = new HashMap<>();
for (int i = from; i < to; i++) {
drMap.put(new KeyCacheObjectImpl(i, null, intCache.affinity().partition(i)), new GridCacheVersion(1, i, 1, OTHER_CLUSTER_ID));
}
if (concurrency != null) {
try (Transaction tx = cli.transactions().txStart(concurrency, isolation)) {
intCache.removeAllConflict(drMap);
tx.commit();
}
} else
intCache.removeAllConflict(drMap);
} catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
}
use of org.apache.ignite.internal.processors.cache.version.GridCacheVersion in project ignite by apache.
the class TxCommands method transactionInfo.
/**
* Executes --tx --info command.
*
* @param client Client.
*/
private Object transactionInfo(GridClient client, GridClientConfiguration conf) throws GridClientException {
checkFeatureSupportedByCluster(client, IgniteFeatures.TX_INFO_COMMAND, true, true);
GridCacheVersion nearXidVer = executeTask(client, FetchNearXidVersionTask.class, args.txInfoArgument(), conf);
boolean histMode = false;
if (nearXidVer != null) {
logger.info("Resolved transaction near XID version: " + nearXidVer);
args.txInfoArgument(new TxVerboseId(null, nearXidVer));
} else {
logger.info("Active transactions not found.");
if (args.txInfoArgument().gridCacheVersion() != null) {
logger.info("Will try to peek history to find out whether transaction was committed / rolled back.");
histMode = true;
} else {
logger.info("You can specify transaction in GridCacheVersion format in order to peek history " + "to find out whether transaction was committed / rolled back.");
return null;
}
}
Map<ClusterNode, VisorTxTaskResult> res = executeTask(client, VisorTxTask.class, args, conf);
if (histMode)
printTxInfoHistoricalResult(res);
else
printTxInfoResult(res);
return res;
}
Aggregations