Search in sources :

Example 1 with GridCacheAffinityManager

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

the class CacheContinuousQueryHandler method getOrCreatePartitionRecovery.

/**
 * @param ctx Context.
 * @param partId Partition id.
 * @param topVer Topology version for current operation.
 * @return Partition recovery.
 */
@NotNull
private CacheContinuousQueryPartitionRecovery getOrCreatePartitionRecovery(GridKernalContext ctx, int partId, AffinityTopologyVersion topVer) {
    assert topVer != null && topVer.topologyVersion() > 0 : topVer;
    CacheContinuousQueryPartitionRecovery rec = rcvs.get(partId);
    if (rec == null) {
        T2<Long, Long> partCntrs = null;
        Map<UUID, Map<Integer, T2<Long, Long>>> initUpdCntrsPerNode = this.initUpdCntrsPerNode;
        if (initUpdCntrsPerNode != null) {
            GridCacheContext<K, V> cctx = cacheContext(ctx);
            GridCacheAffinityManager aff = cctx.affinity();
            for (ClusterNode node : aff.nodesByPartition(partId, topVer)) {
                Map<Integer, T2<Long, Long>> map = initUpdCntrsPerNode.get(node.id());
                if (map != null) {
                    partCntrs = map.get(partId);
                    break;
                }
            }
        } else if (initUpdCntrs != null)
            partCntrs = initUpdCntrs.get(partId);
        rec = new CacheContinuousQueryPartitionRecovery(ctx.log(CU.CONTINUOUS_QRY_LOG_CATEGORY), topVer, partCntrs != null ? partCntrs.get2() : null);
        CacheContinuousQueryPartitionRecovery oldRec = rcvs.putIfAbsent(partId, rec);
        if (oldRec != null)
            rec = oldRec;
    }
    return rec;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheAffinityManager(org.apache.ignite.internal.processors.cache.GridCacheAffinityManager) UUID(java.util.UUID) CachePartitionPartialCountersMap.toCountersMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap.toCountersMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) T2(org.apache.ignite.internal.util.typedef.T2) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GridCacheAffinityManager

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

the class CacheDataStructuresManager method removeSetData.

/**
 * @param setId Set ID.
 * @param topVer Topology version.
 * @throws IgniteCheckedException If failed.
 */
private void removeSetData(IgniteUuid setId, AffinityTopologyVersion topVer) throws IgniteCheckedException {
    boolean loc = cctx.isLocal();
    GridCacheAffinityManager aff = cctx.affinity();
    if (!loc) {
        aff.affinityReadyFuture(topVer).get();
        cctx.preloader().syncFuture().get();
    }
    IgniteInternalCache<?, ?> cache = cctx.cache();
    final int BATCH_SIZE = 100;
    Collection<SetItemKey> keys = new ArrayList<>(BATCH_SIZE);
    for (Cache.Entry entry : cache.localEntries(new CachePeekMode[] { CachePeekMode.PRIMARY })) {
        Object obj = entry.getKey();
        if (!(obj instanceof SetItemKey && setId.equals(((SetItemKey) obj).setId())))
            continue;
        keys.add((SetItemKey) obj);
        if (keys.size() == BATCH_SIZE) {
            retryRemoveAll(cache, keys);
            keys.clear();
        }
    }
    if (!keys.isEmpty())
        retryRemoveAll(cache, keys);
}
Also used : GridCacheAffinityManager(org.apache.ignite.internal.processors.cache.GridCacheAffinityManager) SetItemKey(org.apache.ignite.internal.processors.datastructures.SetItemKey) ArrayList(java.util.ArrayList) BinaryObject(org.apache.ignite.binary.BinaryObject) Cache(javax.cache.Cache) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache)

Example 3 with GridCacheAffinityManager

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

the class IgniteCacheClientNodeChangingTopologyTest method testPessimisticTx2.

/**
 * Tests specific scenario when mapping for first locked keys does not change, but changes for second one.
 *
 * @throws Exception If failed.
 */
@Test
public void testPessimisticTx2() throws Exception {
    ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setCacheMode(PARTITIONED);
    ccfg.setBackups(1);
    ccfg.setAtomicityMode(TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setRebalanceMode(SYNC);
    IgniteEx ignite0 = startGrid(0);
    IgniteEx ignite1 = startGrid(1);
    IgniteEx ignite2 = startGrid(2);
    awaitPartitionMapExchange();
    final Ignite ignite3 = startClientGrid(3);
    assertTrue(ignite3.configuration().isClientMode());
    AffinityTopologyVersion topVer1 = new AffinityTopologyVersion(4, 0);
    assertEquals(topVer1, ignite0.context().cache().internalCache(DEFAULT_CACHE_NAME).context().topology().readyTopologyVersion());
    TestCommunicationSpi spi = (TestCommunicationSpi) ignite3.configuration().getCommunicationSpi();
    IgniteBiTuple<Integer, Integer> keys = findKeys(ignite0, ignite0.localNode(), ignite1.localNode(), ignite2.localNode());
    final Integer key1 = keys.get1();
    final Integer key2 = keys.get2();
    spi.blockMessages(GridNearLockRequest.class, ignite0.localNode().id());
    spi.blockMessages(GridNearLockRequest.class, ignite1.localNode().id());
    spi.blockMessages(GridNearLockRequest.class, ignite2.localNode().id());
    final IgniteCache<Integer, Integer> cache = ignite3.cache(DEFAULT_CACHE_NAME);
    IgniteInternalFuture<?> putFut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            Thread.currentThread().setName("put-thread");
            try (Transaction tx = ignite3.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
                cache.put(key1, 1);
                cache.put(key2, 2);
                tx.commit();
            }
            return null;
        }
    });
    IgniteEx ignite4 = startGrid(4);
    int minorVer = ignite4.configuration().isLateAffinityAssignment() ? 1 : 0;
    AffinityTopologyVersion topVer2 = new AffinityTopologyVersion(5, minorVer);
    ignite0.context().cache().context().exchange().affinityReadyFuture(topVer2).get();
    assertEquals(topVer2, ignite0.context().cache().internalCache(DEFAULT_CACHE_NAME).context().topology().readyTopologyVersion());
    GridCacheAffinityManager aff = ignite0.context().cache().internalCache(DEFAULT_CACHE_NAME).context().affinity();
    List<ClusterNode> nodes1 = aff.nodesByKey(key1, topVer1);
    List<ClusterNode> nodes2 = aff.nodesByKey(key1, topVer2);
    assertEquals(nodes1, nodes2);
    nodes1 = aff.nodesByKey(key2, topVer1);
    nodes2 = aff.nodesByKey(key2, topVer2);
    assertFalse(nodes1.get(0).equals(nodes2.get(0)));
    assertFalse(putFut.isDone());
    log.info("Stop block.");
    spi.stopBlock();
    putFut.get();
    checkData(F.asMap(key1, 1, key2, 2), null, cache, 5);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) TimeoutException(java.util.concurrent.TimeoutException) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) CacheException(javax.cache.CacheException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Transaction(org.apache.ignite.transactions.Transaction) GridCacheAffinityManager(org.apache.ignite.internal.processors.cache.GridCacheAffinityManager) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 4 with GridCacheAffinityManager

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

the class IgniteH2Indexing method backupFilter.

/** {@inheritDoc} */
@Override
public IndexingQueryFilter backupFilter(@Nullable final AffinityTopologyVersion topVer, @Nullable final int[] parts) {
    final AffinityTopologyVersion topVer0 = topVer != null ? topVer : AffinityTopologyVersion.NONE;
    return new IndexingQueryFilter() {

        @Nullable
        @Override
        public <K, V> IgniteBiPredicate<K, V> forCache(String cacheName) {
            final GridCacheAdapter<Object, Object> cache = ctx.cache().internalCache(cacheName);
            if (cache.context().isReplicated())
                return null;
            final GridCacheAffinityManager aff = cache.context().affinity();
            if (parts != null) {
                if (parts.length < 64) {
                    // Fast scan for small arrays.
                    return new IgniteBiPredicate<K, V>() {

                        @Override
                        public boolean apply(K k, V v) {
                            int p = aff.partition(k);
                            for (int p0 : parts) {
                                if (p0 == p)
                                    return true;
                                if (// Array is sorted.
                                p0 > p)
                                    return false;
                            }
                            return false;
                        }
                    };
                }
                return new IgniteBiPredicate<K, V>() {

                    @Override
                    public boolean apply(K k, V v) {
                        int p = aff.partition(k);
                        return Arrays.binarySearch(parts, p) >= 0;
                    }
                };
            }
            final ClusterNode locNode = ctx.discovery().localNode();
            return new IgniteBiPredicate<K, V>() {

                @Override
                public boolean apply(K k, V v) {
                    return aff.primaryByKey(locNode, k, topVer0);
                }
            };
        }

        @Override
        public boolean isValueRequired() {
            return false;
        }

        @Override
        public String toString() {
            return "IndexingQueryFilter [ver=" + topVer + ']';
        }
    };
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheAffinityManager(org.apache.ignite.internal.processors.cache.GridCacheAffinityManager) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) IndexingQueryFilter(org.apache.ignite.spi.indexing.IndexingQueryFilter) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) IgniteSystemProperties.getString(org.apache.ignite.IgniteSystemProperties.getString)

Example 5 with GridCacheAffinityManager

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

the class GridCacheAbstractQueueFailoverDataConsistencySelfTest method primaryQueueNode.

/**
 * @param queue Queue.
 * @return Primary node for queue's header.
 * @throws Exception If failed.
 */
private int primaryQueueNode(IgniteQueue queue) throws Exception {
    GridCacheContext cctx = GridTestUtils.getFieldValue(queue, "cctx");
    GridCacheAffinityManager aff = cctx.affinity();
    CachePeekMode[] modes = new CachePeekMode[] { CachePeekMode.ALL };
    for (int i = 0; i < gridCount(); i++) {
        for (Cache.Entry e : grid(i).context().cache().internalCache(cctx.name()).localEntries(modes)) {
            Object key = e.getKey();
            if (aff.primaryByKey(grid(i).localNode(), key, AffinityTopologyVersion.NONE) && key instanceof GridCacheQueueHeaderKey)
                return i;
        }
    }
    fail("Failed to find primary node for queue header.");
    return -1;
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridCacheAffinityManager(org.apache.ignite.internal.processors.cache.GridCacheAffinityManager) CachePeekMode(org.apache.ignite.cache.CachePeekMode) GridCacheQueueHeaderKey(org.apache.ignite.internal.processors.datastructures.GridCacheQueueHeaderKey) Cache(javax.cache.Cache)

Aggregations

GridCacheAffinityManager (org.apache.ignite.internal.processors.cache.GridCacheAffinityManager)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Cache (javax.cache.Cache)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)2 Transaction (org.apache.ignite.transactions.Transaction)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeoutException (java.util.concurrent.TimeoutException)1 CacheException (javax.cache.CacheException)1 Ignite (org.apache.ignite.Ignite)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteSystemProperties.getString (org.apache.ignite.IgniteSystemProperties.getString)1