Search in sources :

Example 41 with GridCacheMvccCandidate

use of org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate in project ignite by apache.

the class GridCacheColocatedDebugTest method checkPutsMultithreaded.

/**
 * @param loc Local puts.
 * @param remote Remote puts.
 * @param maxIterCnt Number of iterations.
 * @throws Exception If failed.
 */
public void checkPutsMultithreaded(boolean loc, boolean remote, final long maxIterCnt) throws Exception {
    storeEnabled = false;
    assert loc || remote;
    startGridsMultiThreaded(3);
    try {
        final Ignite g0 = grid(0);
        Ignite g1 = grid(1);
        final Collection<Integer> keys = new ConcurrentLinkedQueue<>();
        if (loc) {
            Integer key = -1;
            for (int i = 0; i < 20; i++) {
                key = forPrimary(g0, key);
                keys.add(key);
            }
        }
        if (remote) {
            Integer key = -1;
            for (int i = 0; i < 20; i++) {
                key = forPrimary(g1, key);
                keys.add(key);
            }
        }
        final AtomicLong iterCnt = new AtomicLong();
        final int keysCnt = 10;
        IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {

            @Override
            public void run() {
                // Make thread-local copy to shuffle keys.
                List<Integer> threadKeys = new ArrayList<>(keys);
                long threadId = Thread.currentThread().getId();
                long itNum;
                while ((itNum = iterCnt.getAndIncrement()) < maxIterCnt) {
                    Collections.shuffle(threadKeys);
                    List<Integer> iterKeys = threadKeys.subList(0, keysCnt);
                    Collections.sort(iterKeys);
                    Map<Integer, String> vals = U.newLinkedHashMap(keysCnt);
                    for (Integer key : iterKeys) vals.put(key, String.valueOf(key) + threadId);
                    jcache(0).putAll(vals);
                    if (itNum > 0 && itNum % 5000 == 0)
                        info(">>> " + itNum + " iterations completed.");
                }
            }
        }, THREAD_CNT);
        fut.get();
        Thread.sleep(1000);
        // Check that all transactions are committed.
        for (int i = 0; i < 3; i++) {
            GridCacheAdapter<Object, Object> cache = ((IgniteKernal) grid(i)).internalCache(DEFAULT_CACHE_NAME);
            for (Integer key : keys) {
                GridCacheEntryEx entry = cache.peekEx(key);
                if (entry != null) {
                    Collection<GridCacheMvccCandidate> locCands = entry.localCandidates();
                    Collection<GridCacheMvccCandidate> rmtCands = entry.remoteMvccSnapshot();
                    assert locCands == null || locCands.isEmpty() : "Local candidates is not empty [idx=" + i + ", entry=" + entry + ']';
                    assert rmtCands == null || rmtCands.isEmpty() : "Remote candidates is not empty [idx=" + i + ", entry=" + entry + ']';
                }
            }
        }
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) AtomicLong(java.util.concurrent.atomic.AtomicLong) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) Ignite(org.apache.ignite.Ignite) ArrayList(java.util.ArrayList) List(java.util.List) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Map(java.util.Map) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)

Aggregations

GridCacheMvccCandidate (org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)41 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)17 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)15 Nullable (org.jetbrains.annotations.Nullable)14 GridCacheMvcc (org.apache.ignite.internal.processors.cache.GridCacheMvcc)13 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)11 ClusterNode (org.apache.ignite.cluster.ClusterNode)11 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)11 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)10 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 CacheLockCandidates (org.apache.ignite.internal.processors.cache.CacheLockCandidates)9 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)8 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)6 IgniteTxKey (org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey)6 UUID (java.util.UUID)5 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)5 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)5 GridDistributedCacheEntry (org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry)5 Collection (java.util.Collection)4