Search in sources :

Example 31 with GridDhtPartitionTopology

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

the class ZkCommunicationFailureContext method cachePartitionOwners.

/**
 * {@inheritDoc}
 */
@Override
public List<List<ClusterNode>> cachePartitionOwners(String cacheName) {
    if (cacheName == null)
        throw new NullPointerException("Null cache name.");
    DynamicCacheDescriptor cacheDesc = ctx.affinity().caches().get(CU.cacheId(cacheName));
    if (cacheDesc == null)
        throw new IllegalArgumentException("Invalid cache name: " + cacheName);
    if (cacheDesc.cacheConfiguration().getCacheMode() == CacheMode.LOCAL)
        return Collections.emptyList();
    CacheGroupContext grp = ctx.cache().cacheGroup(cacheDesc.groupId());
    GridDhtPartitionTopology top;
    if (grp == null) {
        top = ctx.exchange().clientTopologyIfExists(cacheDesc.groupId());
        assert top != null : cacheName;
    } else
        top = grp.topology();
    return top.allOwners();
}
Also used : GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 32 with GridDhtPartitionTopology

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

the class IgniteWalRecoveryTest method testRandomCrash.

/**
 * @throws Exception if failed.
 */
@Test
public void testRandomCrash() throws Exception {
    checkpointFrequency = 2_000 + new Random().nextInt(4_000);
    IgniteEx ctrlGrid = startGrid(0);
    fork = true;
    IgniteEx cacheGrid = startGrid(1);
    ctrlGrid.cluster().active(true);
    IgniteCompute rmt = ctrlGrid.compute(ctrlGrid.cluster().forRemotes());
    rmt.run(new LoadRunnable(false));
    info(">>> Finished cache population.");
    rmt.run(new AsyncLoadRunnable());
    Thread.sleep(5_000);
    info(">>> Killing remote process...");
    ((IgniteProcessProxy) cacheGrid).kill();
    startGrid(1);
    final GridDhtPartitionTopology top = ctrlGrid.cachex(CACHE_NAME).context().topology();
    waitForReadyTopology(top, new AffinityTopologyVersion(3, 0));
    assertFalse(top.lostPartitions().isEmpty());
    int res = rmt.call(new VerifyCallable());
    assertEquals(0, res);
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Random(java.util.Random) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCompute(org.apache.ignite.IgniteCompute) IgniteProcessProxy(org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)

Example 33 with GridDhtPartitionTopology

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

the class IgniteWalRecoveryTest method testLargeRandomCrash.

/**
 * @throws Exception if failed.
 */
@Test
public void testLargeRandomCrash() throws Exception {
    checkpointFrequency = 2_000 + new Random().nextInt(4_000);
    IgniteEx ctrlGrid = startGrid(0);
    fork = true;
    IgniteEx cacheGrid = startGrid(1);
    ctrlGrid.cluster().active(true);
    IgniteCompute rmt = ctrlGrid.compute(ctrlGrid.cluster().forRemotes());
    rmt.run(new LargeLoadRunnable(false));
    info(">>> Finished cache population.");
    rmt.run(new AsyncLargeLoadRunnable());
    Thread.sleep(5_000);
    info(">>> Killing remote process...");
    ((IgniteProcessProxy) cacheGrid).kill();
    startGrid(1);
    final GridDhtPartitionTopology top = ctrlGrid.cachex(CACHE_NAME).context().topology();
    waitForReadyTopology(top, new AffinityTopologyVersion(3, 0));
    assertFalse(top.lostPartitions().isEmpty());
    int res = rmt.call(new VerifyLargeCallable());
    assertEquals(0, res);
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Random(java.util.Random) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCompute(org.apache.ignite.IgniteCompute) IgniteProcessProxy(org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)

Example 34 with GridDhtPartitionTopology

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

the class WaitMapExchangeFinishCallable method call.

/**
 * {@inheritDoc}
 */
@Override
public Void call() throws Exception {
    Collection<IgniteInternalCache<?, ?>> cachesx = ((IgniteKernal) ignite).cachesx(null);
    for (IgniteInternalCache<?, ?> cache : cachesx) {
        try {
            GridDhtPartitionTopology top = cache.context().isNear() ? cache.context().near().dht().topology() : cache.context().dht().topology();
            BenchmarkUtils.println("Validating cache: " + cache.name());
            for (; ; ) {
                boolean success = true;
                if (top.readyTopologyVersion().topologyVersion() == ignite.cluster().topologyVersion()) {
                    for (Map.Entry<UUID, GridDhtPartitionMap> e : top.partitionMap(true).entrySet()) {
                        for (Map.Entry<Integer, GridDhtPartitionState> p : e.getValue().entrySet()) {
                            if (p.getValue() != GridDhtPartitionState.OWNING) {
                                BenchmarkUtils.println("Not owning partition [part=" + p.getKey() + ", state=" + p.getValue() + ']');
                                success = false;
                                break;
                            }
                        }
                        if (!success)
                            break;
                    }
                } else {
                    BenchmarkUtils.println("Topology version is different [cache=" + top.readyTopologyVersion() + ", cluster=" + ignite.cluster().topologyVersion() + ']');
                    success = false;
                }
                if (!success)
                    Thread.sleep(1000);
                else {
                    BenchmarkUtils.println("Cache state is fine: " + cache.name());
                    break;
                }
            }
        } catch (RuntimeException e1) {
            BenchmarkUtils.println("Ignored exception: " + e1);
        }
    }
    return null;
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) UUID(java.util.UUID) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) Map(java.util.Map)

Example 35 with GridDhtPartitionTopology

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

the class CachePartitionLossWithRestartsTest method testPartitionLossDetectionOnClientTopology.

/**
 */
@Test
public void testPartitionLossDetectionOnClientTopology() throws Exception {
    final IgniteEx crd = startGrids(3);
    crd.cluster().baselineAutoAdjustEnabled(false);
    crd.cluster().active(true);
    assertTrue(grid(1).cache(DEFAULT_CACHE_NAME).lostPartitions().isEmpty());
    assertTrue(grid(2).cache(DEFAULT_CACHE_NAME).lostPartitions().isEmpty());
    final IgniteEx g3 = startGrid(3);
    awaitPartitionMapExchange();
    stopGrid(1);
    // Loss detection is done just before exchange future completion.
    // Will wait for it's finishing.
    AffinityTopologyVersion topVer = new AffinityTopologyVersion(5, 0);
    GridDhtPartitionTopology top0 = waitForDetection(crd, topVer);
    GridDhtPartitionTopology top1 = waitForDetection(grid(2), topVer);
    GridDhtPartitionTopology top2 = waitForDetection(g3, topVer);
    final Set<Integer> lost1 = new HashSet<>(top0.lostPartitions());
    final Set<Integer> lost2 = new HashSet<>(top1.lostPartitions());
    final Set<Integer> lost3 = new HashSet<>(top2.lostPartitions());
    assertFalse(lost1.isEmpty());
    assertEquals(lost1, lost2);
    assertEquals(lost1, lost3);
    GridDhtPartitionTopology top = startGrid(1).cachex(DEFAULT_CACHE_NAME).context().topology();
    assertEquals(lost1, top.lostPartitions());
    // TODO https://issues.apache.org/jira/browse/IGNITE-13053
    grid(1).resetLostPartitions(Collections.singleton(DEFAULT_CACHE_NAME));
    awaitPartitionMapExchange();
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) IgniteEx(org.apache.ignite.internal.IgniteEx) HashSet(java.util.HashSet) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

GridDhtPartitionTopology (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology)64 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)24 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)21 ClusterNode (org.apache.ignite.cluster.ClusterNode)20 Map (java.util.Map)18 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)18 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)17 HashMap (java.util.HashMap)15 ArrayList (java.util.ArrayList)14 Ignite (org.apache.ignite.Ignite)14 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)12 Test (org.junit.Test)12 IgniteEx (org.apache.ignite.internal.IgniteEx)11 UUID (java.util.UUID)10 IgniteKernal (org.apache.ignite.internal.IgniteKernal)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 IgniteException (org.apache.ignite.IgniteException)9 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)9 GridDhtPartitionMap (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)9 HashSet (java.util.HashSet)8