Search in sources :

Example 6 with GridDhtPartitionTopologyImpl

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopologyImpl in project ignite by apache.

the class ResetLostPartitionTest method getPartitionsStates.

/**
 * @param gridNumber Grid number.
 * @param cacheName Cache name.
 * @return Partitions states for given cache name.
 */
private List<GridDhtPartitionState> getPartitionsStates(int gridNumber, String cacheName) {
    CacheGroupContext cgCtx = grid(gridNumber).context().cache().cacheGroup(CU.cacheId(cacheName));
    GridDhtPartitionTopologyImpl top = (GridDhtPartitionTopologyImpl) cgCtx.topology();
    return top.localPartitions().stream().map(GridDhtLocalPartition::state).collect(Collectors.toList());
}
Also used : CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) GridDhtPartitionTopologyImpl(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopologyImpl)

Example 7 with GridDhtPartitionTopologyImpl

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopologyImpl in project ignite by apache.

the class TxCrossCacheRemoteMultiplePartitionReservationTest method testRemoteCommitPartitionReservations.

/**
 */
@Test
public void testRemoteCommitPartitionReservations() throws Exception {
    try {
        IgniteEx crd = startGrids(2);
        awaitPartitionMapExchange();
        IgniteEx client = startClientGrid("client");
        IgniteCache<Object, Object> cache1 = client.cache(CACHE1);
        IgniteCache<Object, Object> cache2 = client.cache(CACHE2);
        List<Integer> evictingIds = evictingPartitionsAfterJoin(crd, crd.cache(CACHE1), 10);
        int[] backupParts = crd.affinity(CACHE1).backupPartitions(crd.localNode());
        Arrays.sort(backupParts);
        int evictingBackupPartId = -1;
        for (int id : evictingIds) {
            if (Arrays.binarySearch(backupParts, id) >= 0) {
                evictingBackupPartId = id;
                break;
            }
        }
        assertTrue(evictingBackupPartId != -1);
        startGrid(2);
        awaitPartitionMapExchange(true, true, null);
        // Mock partition after re-create.
        final int finalEvictingBackupPartId = evictingBackupPartId;
        Map<Integer, AtomicInteger> reserveCntrs = new ConcurrentHashMap<>();
        GridDhtPartitionTopologyImpl.PartitionFactory factory = new GridDhtPartitionTopologyImpl.PartitionFactory() {

            @Override
            public GridDhtLocalPartition create(GridCacheSharedContext ctx, CacheGroupContext grp, int id, boolean recovery) {
                return id != finalEvictingBackupPartId ? new GridDhtLocalPartition(ctx, grp, id, recovery) : new GridDhtLocalPartition(ctx, grp, id, recovery) {

                    @Override
                    public boolean reserve() {
                        reserveCntrs.computeIfAbsent(grp.groupId(), integer -> new AtomicInteger()).incrementAndGet();
                        return super.reserve();
                    }
                };
            }
        };
        Stream.of(CACHE1, CACHE2).map(cache -> (GridDhtPartitionTopologyImpl) crd.cachex(cache).context().topology()).forEach(topology -> topology.partitionFactory(factory));
        stopGrid(2);
        awaitPartitionMapExchange(true, true, null);
        reserveCntrs.values().forEach(cntr -> cntr.set(0));
        // backup commits.
        try (Transaction tx = client.transactions().txStart()) {
            cache1.put(evictingBackupPartId, 0);
            cache2.put(evictingBackupPartId, 0);
            tx.commit();
        }
        assertEquals("Expecting same reservations count for all caches [cntrs=" + reserveCntrs.toString() + ']', 1, reserveCntrs.values().stream().map(AtomicInteger::get).distinct().count());
    } finally {
        stopAllGrids();
    }
}
Also used : Arrays(java.util.Arrays) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Transaction(org.apache.ignite.transactions.Transaction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) FULL_SYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC) IgniteCache(org.apache.ignite.IgniteCache) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Stream(java.util.stream.Stream) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Map(java.util.Map) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridDhtPartitionTopologyImpl(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopologyImpl) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Transaction(org.apache.ignite.transactions.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) GridDhtPartitionTopologyImpl(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopologyImpl) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

GridDhtPartitionTopologyImpl (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopologyImpl)7 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)5 IgniteEx (org.apache.ignite.internal.IgniteEx)4 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)2 Transaction (org.apache.ignite.transactions.Transaction)2 Test (org.junit.Test)2 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 Stream (java.util.stream.Stream)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 TRANSACTIONAL (org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL)1 FULL_SYNC (org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC)1