Search in sources :

Example 36 with GridCacheAdapter

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

the class AbstractReadRepairTest method setDifferentValuesForSameKey.

/**
 */
private InconsistentMapping setDifferentValuesForSameKey(int key, boolean misses, boolean nulls, ReadRepairStrategy strategy) throws Exception {
    List<Ignite> nodes = new ArrayList<>();
    Map<Ignite, T2<Integer, GridCacheVersion>> mapping = new HashMap<>();
    Ignite primary = primaryNode(key, DEFAULT_CACHE_NAME);
    ThreadLocalRandom rnd = ThreadLocalRandom.current();
    if (rnd.nextBoolean()) {
        // Reversed order.
        nodes.addAll(backupNodes(key, DEFAULT_CACHE_NAME));
        nodes.add(primary);
    } else {
        nodes.add(primary);
        nodes.addAll(backupNodes(key, DEFAULT_CACHE_NAME));
    }
    if (// Random order.
    rnd.nextBoolean())
        Collections.shuffle(nodes);
    IgniteInternalCache<Integer, Integer> internalCache = (grid(1)).cachex(DEFAULT_CACHE_NAME);
    GridCacheVersionManager mgr = ((GridCacheAdapter) internalCache.cache()).context().shared().versions();
    int incVal = 0;
    Integer primVal = null;
    Collection<T2<Integer, GridCacheVersion>> vals = new ArrayList<>();
    if (misses) {
        List<Ignite> keeped = nodes.subList(0, rnd.nextInt(1, nodes.size()));
        nodes.stream().filter(node -> !keeped.contains(node)).forEach(node -> {
            T2<Integer, GridCacheVersion> nullT2 = new T2<>(null, null);
            vals.add(nullT2);
            mapping.put(node, nullT2);
        });
        // Recording nulls (missed values).
        nodes = keeped;
    }
    boolean rmvd = false;
    boolean incVer = rnd.nextBoolean();
    GridCacheVersion ver = null;
    for (Ignite node : nodes) {
        IgniteInternalCache<Integer, Integer> cache = ((IgniteEx) node).cachex(DEFAULT_CACHE_NAME);
        GridCacheAdapter<Integer, Integer> adapter = (GridCacheAdapter) cache.cache();
        GridCacheEntryEx entry = adapter.entryEx(key);
        if (ver == null || incVer)
            // Incremental version.
            ver = mgr.next(entry.context().kernalContext().discovery().topologyVersion());
        boolean rmv = nulls && (!rmvd || rnd.nextBoolean());
        Integer val = rmv ? null : rnd.nextBoolean() ? /*increment or same as previously*/
        ++incVal : incVal;
        T2<Integer, GridCacheVersion> valVer = new T2<>(val, val != null ? ver : null);
        vals.add(valVer);
        mapping.put(node, valVer);
        GridKernalContext kctx = ((IgniteEx) node).context();
        // Incremental value.
        byte[] bytes = kctx.cacheObjects().marshal(entry.context().cacheObjectContext(), rmv ? -1 : val);
        try {
            kctx.cache().context().database().checkpointReadLock();
            boolean init = entry.initialValue(new CacheObjectImpl(null, bytes), ver, 0, 0, false, AffinityTopologyVersion.NONE, GridDrType.DR_NONE, false, false);
            if (rmv) {
                if (cache.configuration().getAtomicityMode() == ATOMIC)
                    entry.innerUpdate(ver, ((IgniteEx) node).localNode().id(), ((IgniteEx) node).localNode().id(), GridCacheOperation.DELETE, null, null, false, false, false, false, null, false, false, false, false, AffinityTopologyVersion.NONE, null, GridDrType.DR_NONE, 0, 0, null, false, false, null, null, null, null, false);
                else
                    entry.innerRemove(null, ((IgniteEx) node).localNode().id(), ((IgniteEx) node).localNode().id(), false, false, false, false, false, null, AffinityTopologyVersion.NONE, CU.empty0(), GridDrType.DR_NONE, null, null, null, 1L);
                rmvd = true;
                assertFalse(entry.hasValue());
            } else
                assertTrue(entry.hasValue());
            assertTrue("iterableKey " + key + " already inited", init);
            if (node.equals(primary))
                primVal = val;
        } finally {
            ((IgniteEx) node).context().cache().context().database().checkpointReadUnlock();
        }
    }
    assertEquals(vals.size(), mapping.size());
    assertEquals(vals.size(), internalCache.configuration().getCacheMode() == REPLICATED ? serverNodesCount() : backupsCount() + 1);
    if (!misses && !nulls)
        // Primary value set.
        assertTrue(primVal != null);
    Integer fixed;
    boolean consistent;
    boolean repairable;
    if (vals.stream().distinct().count() == 1) {
        // Consistent value.
        consistent = true;
        repairable = true;
        fixed = vals.iterator().next().getKey();
    } else {
        consistent = false;
        // Currently, Atomic caches can not be repaired.
        repairable = atomicityMode() != ATOMIC;
        switch(strategy) {
            case LWW:
                if (misses || rmvd || !incVer) {
                    repairable = false;
                    // Should never be returned.
                    fixed = Integer.MIN_VALUE;
                } else
                    fixed = incVal;
                break;
            case PRIMARY:
                fixed = primVal;
                break;
            case RELATIVE_MAJORITY:
                // Should never be returned.
                fixed = Integer.MIN_VALUE;
                Map<T2<Integer, GridCacheVersion>, Integer> counts = new HashMap<>();
                for (T2<Integer, GridCacheVersion> val : vals) {
                    counts.putIfAbsent(val, 0);
                    counts.compute(val, (k, v) -> v + 1);
                }
                int[] sorted = counts.values().stream().sorted(Comparator.reverseOrder()).mapToInt(v -> v).toArray();
                int max = sorted[0];
                if (sorted.length > 1 && sorted[1] == max)
                    repairable = false;
                if (repairable)
                    for (Map.Entry<T2<Integer, GridCacheVersion>, Integer> count : counts.entrySet()) if (count.getValue().equals(max)) {
                        fixed = count.getKey().getKey();
                        break;
                    }
                break;
            case REMOVE:
                fixed = null;
                break;
            case CHECK_ONLY:
                repairable = false;
                // Should never be returned.
                fixed = Integer.MIN_VALUE;
                break;
            default:
                throw new UnsupportedOperationException(strategy.toString());
        }
    }
    return new InconsistentMapping(mapping, primVal, fixed, repairable, consistent);
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) Map(java.util.Map) PARTITIONED(org.apache.ignite.cache.CacheMode.PARTITIONED) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) EventType(org.apache.ignite.events.EventType) Collection(java.util.Collection) Event(org.apache.ignite.events.Event) ReadRepairStrategy(org.apache.ignite.cache.ReadRepairStrategy) Collectors(java.util.stream.Collectors) IgniteCache(org.apache.ignite.IgniteCache) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CU(org.apache.ignite.internal.util.typedef.internal.CU) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) ClusterState(org.apache.ignite.cluster.ClusterState) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) IgniteIrreparableConsistencyViolationException(org.apache.ignite.internal.processors.cache.distributed.near.consistency.IgniteIrreparableConsistencyViolationException) GridDrType(org.apache.ignite.internal.processors.dr.GridDrType) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IgniteEvents(org.apache.ignite.IgniteEvents) G(org.apache.ignite.internal.util.typedef.G) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) Ignite(org.apache.ignite.Ignite) CacheConsistencyViolationEvent(org.apache.ignite.events.CacheConsistencyViolationEvent) CacheObjectImpl(org.apache.ignite.internal.processors.cache.CacheObjectImpl) FULL_SYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) T2(org.apache.ignite.internal.util.typedef.T2) REPLICATED(org.apache.ignite.cache.CacheMode.REPLICATED) Consumer(java.util.function.Consumer) GridCacheVersionManager(org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager) TreeMap(java.util.TreeMap) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) ATOMIC(org.apache.ignite.cache.CacheAtomicityMode.ATOMIC) EVT_CONSISTENCY_VIOLATION(org.apache.ignite.events.EventType.EVT_CONSISTENCY_VIOLATION) Comparator(java.util.Comparator) Collections(java.util.Collections) CacheMode(org.apache.ignite.cache.CacheMode) HashMap(java.util.HashMap) GridKernalContext(org.apache.ignite.internal.GridKernalContext) ArrayList(java.util.ArrayList) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Ignite(org.apache.ignite.Ignite) T2(org.apache.ignite.internal.util.typedef.T2) CacheObjectImpl(org.apache.ignite.internal.processors.cache.CacheObjectImpl) GridCacheVersionManager(org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) IgniteEx(org.apache.ignite.internal.IgniteEx)

Example 37 with GridCacheAdapter

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

the class IgniteTxPessimisticOriginatingNodeFailureAbstractSelfTest method checkPrimaryNodeCrash.

/**
 * Checks tx data consistency in case when primary node crashes.
 *
 * @param commmit Whether to commit or rollback a transaction.
 * @throws Exception If failed.
 */
private void checkPrimaryNodeCrash(final boolean commmit) throws Exception {
    Set<Integer> keys = new HashSet<>();
    for (int i = 0; i < 20; i++) keys.add(i);
    final Collection<IgniteKernal> grids = new ArrayList<>();
    ClusterNode primaryNode = grid(1).localNode();
    for (int i = 0; i < gridCount(); i++) {
        if (i != 1)
            grids.add((IgniteKernal) grid(i));
    }
    failingNodeId = primaryNode.id();
    final Map<Integer, String> map = new HashMap<>();
    final String initVal = "initialValue";
    for (Integer key : keys) {
        grid(originatingNode()).cache(DEFAULT_CACHE_NAME).put(key, initVal);
        map.put(key, String.valueOf(key));
    }
    Map<Integer, Collection<ClusterNode>> nodeMap = new HashMap<>();
    IgniteCache<Integer, String> cache = grid(0).cache(DEFAULT_CACHE_NAME);
    info("Failing node ID: " + grid(1).localNode().id());
    for (Integer key : keys) {
        Collection<ClusterNode> nodes = new ArrayList<>();
        nodes.addAll(affinity(cache).mapKeyToPrimaryAndBackups(key));
        nodes.remove(primaryNode);
        nodeMap.put(key, nodes);
    }
    info("Starting tx [values=" + map + ", topVer=" + grid(1).context().discovery().topologyVersion() + ']');
    assertNotNull(cache);
    try (Transaction tx = grid(0).transactions().txStart()) {
        cache.getAll(keys);
        // Should not send any messages.
        cache.putAll(map);
        TransactionProxyImpl txProxy = (TransactionProxyImpl) tx;
        GridNearTxLocal txEx = txProxy.tx();
        assertTrue(txEx.pessimistic());
        if (commmit) {
            txEx.prepare(true);
            // Fail the node in the middle of transaction.
            info(">>> Stopping primary node " + primaryNode);
            G.stop(Ignition.ignite(primaryNode.id()).name(), true);
            info(">>> Stopped originating node, finishing transaction: " + primaryNode.id());
            tx.commit();
        } else {
            // Fail the node in the middle of transaction.
            info(">>> Stopping primary node " + primaryNode);
            G.stop(G.ignite(primaryNode.id()).name(), true);
            info(">>> Stopped originating node, finishing transaction: " + primaryNode.id());
            tx.rollback();
        }
    }
    boolean txFinished = GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            for (IgniteKernal g : grids) {
                GridCacheAdapter<?, ?> cache = g.internalCache(DEFAULT_CACHE_NAME);
                IgniteTxManager txMgr = cache.isNear() ? ((GridNearCacheAdapter) cache).dht().context().tm() : cache.context().tm();
                int txNum = txMgr.idMapSize();
                if (txNum != 0)
                    return false;
            }
            return true;
        }
    }, 10000);
    assertTrue(txFinished);
    info("Transactions finished.");
    for (Map.Entry<Integer, Collection<ClusterNode>> e : nodeMap.entrySet()) {
        final Integer key = e.getKey();
        final String val = map.get(key);
        assertFalse(e.getValue().isEmpty());
        if (atomicityMode() == TRANSACTIONAL_SNAPSHOT)
            continue;
        for (ClusterNode node : e.getValue()) {
            final UUID checkNodeId = node.id();
            compute(G.ignite(checkNodeId).cluster().forNode(node)).call(new IgniteCallable<Void>() {

                /**
                 */
                @IgniteInstanceResource
                private Ignite ignite;

                @Override
                public Void call() throws Exception {
                    IgniteCache<Integer, String> cache = ignite.cache(DEFAULT_CACHE_NAME);
                    assertNotNull(cache);
                    assertEquals("Failed to check entry value on node: " + checkNodeId, !commmit ? initVal : val, cache.localPeek(key));
                    return null;
                }
            });
        }
    }
    awaitPartitionMapExchange();
    for (Map.Entry<Integer, String> e : map.entrySet()) {
        long cntr0 = -1;
        for (Ignite g : G.allGrids()) {
            Integer key = e.getKey();
            assertEquals(!commmit ? initVal : e.getValue(), g.cache(DEFAULT_CACHE_NAME).get(key));
            if (g.affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(((IgniteEx) g).localNode(), key)) {
                long nodeCntr = updateCoutner(g, key);
                if (cntr0 == -1)
                    cntr0 = nodeCntr;
                assertEquals(cntr0, nodeCntr);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) HashSet(java.util.HashSet) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteCache(org.apache.ignite.IgniteCache) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) IgniteException(org.apache.ignite.IgniteException) Transaction(org.apache.ignite.transactions.Transaction) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) TransactionProxyImpl(org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl)

Example 38 with GridCacheAdapter

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

the class IgniteCacheClientNodePartitionsExchangeTest method clientOnlyCacheStart.

/**
 * @param nearCache If {@code true} creates near cache on client.
 * @param srvNode If {@code true} creates client cache on server node.
 * @throws Exception If failed.
 */
private void clientOnlyCacheStart(boolean nearCache, boolean srvNode) throws Exception {
    Ignite ignite0 = startGrid(0);
    Ignite ignite1 = startGrid(1);
    boolean lateAff = ignite1.configuration().isLateAffinityAssignment();
    waitForTopologyUpdate(2, new AffinityTopologyVersion(2, lateAff ? 1 : 0));
    final String CACHE_NAME1 = "cache1";
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setName(CACHE_NAME1);
    if (srvNode)
        ccfg.setNodeFilter(new TestFilter(getTestIgniteInstanceName(2)));
    ignite0.createCache(ccfg);
    Ignite ignite2;
    ignite2 = !srvNode ? startClientGrid(2) : startGrid(2);
    int minorVer = srvNode && lateAff ? 1 : 0;
    waitForTopologyUpdate(3, new AffinityTopologyVersion(3, minorVer));
    TestCommunicationSpi spi0 = (TestCommunicationSpi) ignite0.configuration().getCommunicationSpi();
    TestCommunicationSpi spi1 = (TestCommunicationSpi) ignite1.configuration().getCommunicationSpi();
    TestCommunicationSpi spi2 = (TestCommunicationSpi) ignite2.configuration().getCommunicationSpi();
    spi0.reset();
    spi1.reset();
    spi2.reset();
    assertNull(((IgniteKernal) ignite2).context().cache().context().cache().internalCache(CACHE_NAME1));
    if (nearCache)
        ignite2.getOrCreateNearCache(CACHE_NAME1, new NearCacheConfiguration<>());
    else
        ignite2.cache(CACHE_NAME1);
    GridCacheAdapter cache = ((IgniteKernal) ignite2).context().cache().context().cache().internalCache(CACHE_NAME1);
    assertNotNull(cache);
    assertEquals(nearCache, cache.context().isNear());
    assertEquals(0, spi0.partitionsSingleMessages());
    assertEquals(0, spi0.partitionsFullMessages());
    assertEquals(0, spi1.partitionsSingleMessages());
    assertEquals(0, spi1.partitionsFullMessages());
    assertEquals(0, spi2.partitionsSingleMessages());
    assertEquals(0, spi2.partitionsFullMessages());
    final ClusterNode clientNode = ((IgniteKernal) ignite2).localNode();
    for (Ignite ignite : Ignition.allGrids()) {
        final GridDiscoveryManager disco = ((IgniteKernal) ignite).context().discovery();
        GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                return disco.cacheNode(clientNode, CACHE_NAME1);
            }
        }, 5000);
        assertTrue(disco.cacheNode(clientNode, CACHE_NAME1));
        assertFalse(disco.cacheAffinityNode(clientNode, CACHE_NAME1));
        assertEquals(nearCache, disco.cacheNearNode(clientNode, CACHE_NAME1));
    }
    spi0.reset();
    spi1.reset();
    spi2.reset();
    if (!srvNode) {
        log.info("Close client cache: " + CACHE_NAME1);
        ignite2.cache(CACHE_NAME1).close();
        assertNull(((IgniteKernal) ignite2).context().cache().context().cache().internalCache(CACHE_NAME1));
        assertEquals(0, spi0.partitionsSingleMessages());
        assertEquals(0, spi0.partitionsFullMessages());
        assertEquals(0, spi1.partitionsSingleMessages());
        assertEquals(0, spi1.partitionsFullMessages());
        assertEquals(0, spi2.partitionsSingleMessages());
        assertEquals(0, spi2.partitionsFullMessages());
    }
    final String CACHE_NAME2 = "cache2";
    ccfg = new CacheConfiguration(CACHE_NAME2);
    log.info("Create new cache: " + CACHE_NAME2);
    ignite2.createCache(ccfg);
    waitForTopologyUpdate(3, new AffinityTopologyVersion(3, ++minorVer));
    assertEquals(0, spi0.partitionsSingleMessages());
    assertEquals(2, spi0.partitionsFullMessages());
    assertEquals(1, spi1.partitionsSingleMessages());
    assertEquals(0, spi1.partitionsFullMessages());
    assertEquals(1, spi2.partitionsSingleMessages());
    assertEquals(0, spi2.partitionsFullMessages());
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) Ignite(org.apache.ignite.Ignite) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 39 with GridCacheAdapter

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

the class IgnitePartitionedQueueNoBackupsTest method testCollocation.

/**
 * @throws Exception If failed.
 */
@Test
public void testCollocation() throws Exception {
    IgniteQueue<Integer> queue = grid(0).queue("queue", 0, config(true));
    for (int i = 0; i < 1000; i++) assertTrue(queue.add(i));
    assertEquals(1000, queue.size());
    GridCacheContext cctx = GridTestUtils.getFieldValue(queue, "cctx");
    UUID setNodeId = null;
    for (int i = 0; i < gridCount(); i++) {
        IgniteKernal grid = (IgniteKernal) grid(i);
        GridCacheAdapter cache = grid.context().cache().internalCache(cctx.name());
        Iterator<GridCacheMapEntry> entries = cache.map().entries(cache.context().cacheId()).iterator();
        if (entries.hasNext()) {
            if (setNodeId == null)
                setNodeId = grid.localNode().id();
            else
                fail("For collocated queue all items should be stored on single node.");
        }
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry) UUID(java.util.UUID) Test(org.junit.Test)

Example 40 with GridCacheAdapter

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

the class IgnitePartitionedSetNoBackupsSelfTest method testCollocation.

/**
 * @throws Exception If failed.
 */
@Test
public void testCollocation() throws Exception {
    Set<Integer> set0 = grid(0).set(SET_NAME, config(true));
    for (int i = 0; i < 1000; i++) assertTrue(set0.add(i));
    assertEquals(1000, set0.size());
    GridCacheContext cctx = GridTestUtils.getFieldValue(set0, "cctx");
    UUID setNodeId = null;
    for (int i = 0; i < gridCount(); i++) {
        IgniteKernal grid = (IgniteKernal) grid(i);
        GridCacheAdapter cache = grid.context().cache().internalCache(cctx.name());
        Iterator<GridCacheMapEntry> entries = cache.map().entries(cache.context().cacheId()).iterator();
        if (entries.hasNext()) {
            if (setNodeId == null)
                setNodeId = grid.localNode().id();
            else
                fail("For collocated set all items should be stored on single node.");
        }
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

GridCacheAdapter (org.apache.ignite.internal.processors.cache.GridCacheAdapter)50 IgniteEx (org.apache.ignite.internal.IgniteEx)18 Map (java.util.Map)15 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 Ignite (org.apache.ignite.Ignite)12 IgniteException (org.apache.ignite.IgniteException)12 IgniteKernal (org.apache.ignite.internal.IgniteKernal)12 ArrayList (java.util.ArrayList)11 UUID (java.util.UUID)11 Test (org.junit.Test)11 IgniteCache (org.apache.ignite.IgniteCache)10 HashMap (java.util.HashMap)9 ClusterNode (org.apache.ignite.cluster.ClusterNode)9 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)9 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)9 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)8 HashSet (java.util.HashSet)7 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)7 DynamicCacheDescriptor (org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor)7