Search in sources :

Example 71 with GridCacheVersion

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();
    }
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCacheMvcc(org.apache.ignite.internal.processors.cache.GridCacheMvcc) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate) Nullable(org.jetbrains.annotations.Nullable)

Example 72 with GridCacheVersion

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()));
        }
    }
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)

Example 73 with GridCacheVersion

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;
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) ArrayList(java.util.ArrayList) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)

Example 74 with GridCacheVersion

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);
    }
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Transaction(org.apache.ignite.transactions.Transaction) HashMap(java.util.HashMap) IgniteException(org.apache.ignite.IgniteException) KeyCacheObjectImpl(org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 75 with GridCacheVersion

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;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) TxVerboseId(org.apache.ignite.internal.visor.tx.TxVerboseId) VisorTxTaskResult(org.apache.ignite.internal.visor.tx.VisorTxTaskResult)

Aggregations

GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)247 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)81 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)70 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)60 UUID (java.util.UUID)58 Test (org.junit.Test)58 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)55 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)51 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)34 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)32 Map (java.util.Map)30 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)30 ArrayList (java.util.ArrayList)29 ClusterNode (org.apache.ignite.cluster.ClusterNode)26 Collection (java.util.Collection)24 HashMap (java.util.HashMap)24 IgniteException (org.apache.ignite.IgniteException)22 Nullable (org.jetbrains.annotations.Nullable)22 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)21 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)20