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());
}
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;
}
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);
}
}
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);
}
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();
}
}
}
}
}
Aggregations