Search in sources :

Example 11 with GridDhtPartitionState

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

the class GridPartitionMapSelfTest method testPartitionStateMap.

/**
 */
@Test
public void testPartitionStateMap() {
    GridPartitionStateMap map = initMap(new GridPartitionStateMap());
    Set<Map.Entry<Integer, GridDhtPartitionState>> entries = map.entrySet();
    assertEquals(10, map.size());
    for (Map.Entry<Integer, GridDhtPartitionState> entry : entries) entry.setValue(GridDhtPartitionState.OWNING);
    assertEquals(10, map.size());
    for (GridDhtPartitionState state : map.values()) assertEquals(GridDhtPartitionState.OWNING, state);
    Set<Map.Entry<Integer, GridDhtPartitionState>> tmp = new HashSet<>();
    for (Map.Entry<Integer, GridDhtPartitionState> entry : entries) {
        tmp.add(entry);
        entry.setValue(GridDhtPartitionState.LOST);
    }
    for (Map.Entry<Integer, GridDhtPartitionState> entry : tmp) entry.setValue(GridDhtPartitionState.LOST);
    for (GridDhtPartitionState state : map.values()) assertEquals(GridDhtPartitionState.LOST, state);
    assertFalse(map.containsKey(10));
    assertNull(map.remove(10));
    assertEquals(10, map.size());
    assertEquals(GridDhtPartitionState.LOST, map.put(9, GridDhtPartitionState.EVICTED));
    assertEquals(10, map.size());
    assertEquals(GridDhtPartitionState.EVICTED, map.put(9, GridDhtPartitionState.EVICTED));
    assertEquals(10, map.size());
    map.remove(5);
    assertEquals(9, map.size());
    assertEquals(9, map.keySet().size());
    assertEquals(9, map.values().size());
    map.clear();
    assertEquals(0, map.size());
    assertEquals(0, map.keySet().size());
    assertEquals(0, map.values().size());
}
Also used : GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) TreeMap(java.util.TreeMap) GridPartitionStateMap(org.apache.ignite.internal.util.GridPartitionStateMap) Map(java.util.Map) HashMap(java.util.HashMap) GridPartitionStateMap(org.apache.ignite.internal.util.GridPartitionStateMap) HashSet(java.util.HashSet) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest)

Example 12 with GridDhtPartitionState

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState 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 13 with GridDhtPartitionState

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

the class IgniteFailoverAbstractBenchmark method awaitPartitionMapExchange.

/**
 * Awaits for partitiona map exchage.
 *
 * @param ignite Ignite.
 * @throws Exception If failed.
 */
@SuppressWarnings("BusyWait")
protected static void awaitPartitionMapExchange(Ignite ignite) throws Exception {
    IgniteLogger log = ignite.log();
    log.info("Waiting for finishing of a partition exchange on node: " + ignite);
    IgniteKernal kernal = (IgniteKernal) ignite;
    while (true) {
        boolean partitionsExchangeFinished = true;
        for (IgniteInternalCache<?, ?> cache : kernal.cachesx(null)) {
            log.info("Checking cache: " + cache.name());
            GridCacheAdapter<?, ?> c = kernal.internalCache(cache.name());
            if (!(c instanceof GridDhtCacheAdapter))
                break;
            GridDhtCacheAdapter<?, ?> dht = (GridDhtCacheAdapter<?, ?>) c;
            GridDhtPartitionFullMap partMap = dht.topology().partitionMap(true);
            for (Map.Entry<UUID, GridDhtPartitionMap> e : partMap.entrySet()) {
                log.info("Checking node: " + e.getKey());
                for (Map.Entry<Integer, GridDhtPartitionState> e1 : e.getValue().entrySet()) {
                    if (e1.getValue() != GridDhtPartitionState.OWNING) {
                        log.info("Undesired state [id=" + e1.getKey() + ", state=" + e1.getValue() + ']');
                        partitionsExchangeFinished = false;
                        break;
                    }
                }
                if (!partitionsExchangeFinished)
                    break;
            }
            if (!partitionsExchangeFinished)
                break;
        }
        if (partitionsExchangeFinished)
            return;
        Thread.sleep(100);
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridDhtCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) IgniteLogger(org.apache.ignite.IgniteLogger) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)

Example 14 with GridDhtPartitionState

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

the class CachePartitionStateTest method checkNodePartitions.

/**
 * @param assign Assignments.
 * @param clusterNode Node.
 * @param cacheName Cache name.
 * @param expState Expected partitions state.
 */
private void checkNodePartitions(AffinityAssignment assign, ClusterNode clusterNode, String cacheName, GridDhtPartitionState expState) {
    Affinity<Object> aff = ignite(0).affinity(cacheName);
    Set<Integer> nodeParts = new HashSet<>();
    nodeParts.addAll(assign.primaryPartitions(clusterNode.id()));
    nodeParts.addAll(assign.backupPartitions(clusterNode.id()));
    log.info("Test state [node=" + clusterNode.id() + ", cache=" + cacheName + ", parts=" + nodeParts.size() + ", state=" + expState + ']');
    if (grid(0).context().discovery().cacheAffinityNode(clusterNode, cacheName))
        assertFalse(nodeParts.isEmpty());
    boolean check = false;
    for (Ignite node : G.allGrids()) {
        GridCacheAdapter cache = ((IgniteKernal) node).context().cache().internalCache(cacheName);
        if (cache != null) {
            check = true;
            GridDhtPartitionTopology top = cache.context().topology();
            GridDhtPartitionMap partsMap = top.partitions(clusterNode.id());
            for (int p = 0; p < aff.partitions(); p++) {
                if (nodeParts.contains(p)) {
                    assertNotNull(partsMap);
                    GridDhtPartitionState state = partsMap.get(p);
                    assertEquals("Unexpected state [checkNode=" + clusterNode.id() + ", node=" + node.name() + ", state=" + state + ']', expState, partsMap.get(p));
                } else {
                    if (partsMap != null) {
                        GridDhtPartitionState state = partsMap.get(p);
                        assertTrue("Unexpected state [checkNode=" + clusterNode.id() + ", node=" + node.name() + ", state=" + state + ']', state == null || state == EVICTED);
                    }
                }
            }
        } else {
            assertEquals(0, aff.primaryPartitions(((IgniteKernal) node).localNode()).length);
            assertEquals(0, aff.backupPartitions(((IgniteKernal) node).localNode()).length);
        }
    }
    assertTrue(check);
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) Ignite(org.apache.ignite.Ignite) HashSet(java.util.HashSet)

Example 15 with GridDhtPartitionState

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

the class GridCacheDhtPreloadSelfTest method checkActiveState.

/**
 * @param grids Grids.
 */
private void checkActiveState(Iterable<Ignite> grids) {
    // Check that nodes don't have non-active information about other nodes.
    for (Ignite g : grids) {
        IgniteCache<Integer, String> c = g.cache(DEFAULT_CACHE_NAME);
        GridDhtCacheAdapter<Integer, String> dht = dht(c);
        GridDhtPartitionFullMap allParts = dht.topology().partitionMap(false);
        for (GridDhtPartitionMap parts : allParts.values()) {
            if (!parts.nodeId().equals(g.cluster().localNode().id())) {
                for (Map.Entry<Integer, GridDhtPartitionState> e : parts.entrySet()) {
                    int p = e.getKey();
                    GridDhtPartitionState state = e.getValue();
                    assert state == OWNING || state == MOVING || state == RENTING : "Invalid state [igniteInstanceName=" + g.name() + ", part=" + p + ", state=" + state + ", parts=" + parts + ']';
                    assert state.active();
                }
            }
        }
    }
}
Also used : GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) Ignite(org.apache.ignite.Ignite) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) HashMap(java.util.HashMap) Map(java.util.Map) GridDhtPartitionFullMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)

Aggregations

GridDhtPartitionState (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState)25 Map (java.util.Map)13 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)11 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)8 UUID (java.util.UUID)8 GridDhtPartitionMap (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)8 GridDhtPartitionTopology (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology)7 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 Ignite (org.apache.ignite.Ignite)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 IgniteException (org.apache.ignite.IgniteException)5 IgniteKernal (org.apache.ignite.internal.IgniteKernal)5 GridDhtPartitionFullMap (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap)5 HashSet (java.util.HashSet)4 GridPartitionStateMap (org.apache.ignite.internal.util.GridPartitionStateMap)4 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)4 U (org.apache.ignite.internal.util.typedef.internal.U)4