Search in sources :

Example 61 with GridCacheVersion

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

the class GridCacheMvccSelfTest method testNearRemoteWithOwned2.

/**
 * Tests that orderOwned does not reorder owned locks.
 */
@Test
public void testNearRemoteWithOwned2() {
    GridCacheAdapter<String, String> cache = grid.internalCache(DEFAULT_CACHE_NAME);
    GridCacheTestEntryEx entry = new GridCacheTestEntryEx(cache.context(), "1");
    UUID node1 = UUID.randomUUID();
    GridCacheVersion ver0 = version(0);
    GridCacheVersion ver1 = version(1);
    GridCacheVersion ver2 = version(2);
    GridCacheVersion ver3 = version(3);
    GridCacheVersion ver4 = version(4);
    GridCacheVersion ver5 = version(5);
    GridCacheVersion ver6 = version(6);
    GridCacheMvccCandidate c0 = entry.addRemote(node1, 1, ver0, true);
    GridCacheMvccCandidate c1 = entry.addRemote(node1, 1, ver1, true);
    GridCacheMvccCandidate c2 = entry.addRemote(node1, 1, ver2, true);
    GridCacheMvccCandidate c3 = entry.addRemote(node1, 1, ver3, true);
    GridCacheMvccCandidate c4 = entry.addRemote(node1, 1, ver4, true);
    GridCacheMvccCandidate c5 = entry.addRemote(node1, 1, ver5, true);
    GridCacheMvccCandidate c6 = entry.addRemote(node1, 1, ver6, true);
    GridCacheMvccCandidate[] candArr = new GridCacheMvccCandidate[] { c0, c1, c2, c3, c4, c5, c6 };
    Collection<GridCacheMvccCandidate> cands = entry.remoteMvccSnapshot();
    assert cands.size() == 7;
    assert cands.iterator().next().version().equals(ver0);
    entry.orderOwned(ver1, ver2);
    cands = entry.remoteMvccSnapshot();
    int i = 0;
    for (GridCacheMvccCandidate cand : cands) {
        assert cand == candArr[i];
        assertTrue(ver2.equals(cand.ownerVersion()) || cand != c1);
        i++;
    }
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 62 with GridCacheVersion

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

the class GridCacheMvccSelfTest method testCompletedWithBaseInTheBeginningNoChange.

/**
 * This case should never happen, nevertheless we need to test for it.
 */
@Test
public void testCompletedWithBaseInTheBeginningNoChange() {
    GridCacheAdapter<String, String> cache = grid.internalCache(DEFAULT_CACHE_NAME);
    GridCacheTestEntryEx entry = new GridCacheTestEntryEx(cache.context(), "1");
    UUID node1 = UUID.randomUUID();
    UUID node2 = UUID.randomUUID();
    GridCacheVersion ver1 = version(1);
    GridCacheVersion ver2 = version(2);
    GridCacheVersion ver3 = version(3);
    GridCacheVersion ver4 = version(4);
    GridCacheVersion ver5 = version(5);
    GridCacheVersion ver6 = version(6);
    GridCacheVersion ver7 = version(7);
    entry.addRemote(node1, 1, ver1, false);
    entry.addRemote(node2, 2, ver2, false);
    entry.addRemote(node1, 3, ver3, false);
    entry.addRemote(node2, 4, ver4, false);
    entry.addRemote(node1, 5, ver5, false);
    List<GridCacheVersion> committed = Arrays.asList(ver6, ver7);
    entry.orderCompleted(ver1, committed, Collections.<GridCacheVersion>emptyList());
    checkOrder(entry.remoteMvccSnapshot(), ver1, ver2, ver3, ver4, ver5);
    // Nothing set to owner since there is no change.
    checkRemote(entry.candidate(ver1), ver1, false, false);
    checkRemote(entry.candidate(ver2), ver2, false, false);
    checkRemote(entry.candidate(ver3), ver3, false, false);
    checkRemote(entry.candidate(ver4), ver4, false, false);
    checkRemote(entry.candidate(ver5), ver5, false, false);
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 63 with GridCacheVersion

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

the class GridCacheMvccSelfTest method testMultipleLocalLocks.

/**
 * @throws Exception If test failed.
 */
@Test
public void testMultipleLocalLocks() throws Exception {
    GridCacheAdapter<String, String> cache = grid.internalCache(DEFAULT_CACHE_NAME);
    GridCacheContext<String, String> ctx = cache.context();
    GridCacheTestEntryEx entry1 = new GridCacheTestEntryEx(ctx, "1");
    GridCacheTestEntryEx entry2 = new GridCacheTestEntryEx(ctx, "2");
    GridCacheVersion ver1 = version(1);
    GridCacheVersion ver3 = version(3);
    GridCacheMvccCandidate c13 = entry1.addLocal(1, ver3, 0, true, false);
    entry1.readyLocal(ver3);
    checkLocalOwner(entry1.candidate(ver3), ver3, false);
    GridCacheMvccCandidate c11 = entry1.addLocal(2, ver1, 0, true, true);
    GridCacheMvccCandidate c21 = entry2.addLocal(2, ver1, 0, true, false);
    linkCandidates(ctx, c11, c21);
    entry1.readyLocal(ver1);
    entry2.readyLocal(ver1);
    checkLocal(entry1.candidate(ver1), ver1, true, false, false);
    checkLocal(entry2.candidate(ver1), ver1, true, false, false);
    GridCacheMvccCandidate c23 = entry2.addLocal(1, ver3, 0, true, true);
    linkCandidates(ctx, c13, c23);
    entry2.readyLocal(ver3);
    checkLocalOwner(entry2.candidate(ver3), ver3, false);
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 64 with GridCacheVersion

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

the class GridCacheMvccFlagsTest method testAllFalseFlags.

/**
 */
@Test
public void testAllFalseFlags() {
    GridCacheAdapter<String, String> cache = grid.internalCache(DEFAULT_CACHE_NAME);
    GridCacheTestEntryEx entry = new GridCacheTestEntryEx(cache.context(), "1");
    UUID id = UUID.randomUUID();
    GridCacheVersion ver = new GridCacheVersion(1, 0, 0, 0);
    GridCacheMvccCandidate c = new GridCacheMvccCandidate(entry, id, id, ver, 1, ver, false, false, false, false, false, false, null, false);
    short flags = c.flags();
    info("Candidate: " + c);
    for (GridCacheMvccCandidate.Mask mask : GridCacheMvccCandidate.Mask.values()) assertFalse("Mask check failed [mask=" + mask + ", c=" + c + ']', mask.get(flags));
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 65 with GridCacheVersion

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

the class GridDhtLockFuture method loadMissingFromStore.

/**
 */
private void loadMissingFromStore() {
    if (!skipStore && (read || cctx.loadPreviousValue()) && cctx.readThrough() && (needReturnVal || read)) {
        final Map<KeyCacheObject, GridDhtCacheEntry> loadMap = new LinkedHashMap<>();
        final GridCacheVersion ver = version();
        for (GridDhtCacheEntry entry : entries) {
            try {
                entry.unswap(false);
                if (!entry.hasValue())
                    loadMap.put(entry.key(), entry);
            } catch (GridCacheEntryRemovedException e) {
                assert false : "Should not get removed exception while holding lock on entry " + "[entry=" + entry + ", e=" + e + ']';
            } catch (IgniteCheckedException e) {
                onDone(e);
                return;
            }
        }
        try {
            cctx.store().loadAll(null, loadMap.keySet(), new CI2<KeyCacheObject, Object>() {

                @Override
                public void apply(KeyCacheObject key, Object val) {
                    // No value loaded from store.
                    if (val == null)
                        return;
                    GridDhtCacheEntry entry0 = loadMap.get(key);
                    try {
                        CacheObject val0 = cctx.toCacheObject(val);
                        long ttl = createTtl;
                        long expireTime;
                        if (ttl == CU.TTL_ZERO)
                            expireTime = CU.expireTimeInPast();
                        else {
                            if (ttl == CU.TTL_NOT_CHANGED)
                                ttl = CU.TTL_ETERNAL;
                            expireTime = CU.toExpireTime(ttl);
                        }
                        entry0.initialValue(val0, ver, ttl, expireTime, false, topVer, GridDrType.DR_LOAD, true, false);
                    } catch (GridCacheEntryRemovedException e) {
                        assert false : "Should not get removed exception while holding lock on entry " + "[entry=" + entry0 + ", e=" + e + ']';
                    } catch (IgniteCheckedException e) {
                        onDone(e);
                    }
                }
            });
        } catch (IgniteCheckedException e) {
            onDone(e);
        }
    }
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) LinkedHashMap(java.util.LinkedHashMap)

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