use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState in project ignite by apache.
the class GridCacheRebalancingSyncSelfTest method checkPartitionMapExchangeFinished.
/**
*/
public static void checkPartitionMapExchangeFinished() {
for (Ignite g : G.allGrids()) {
IgniteKernal g0 = (IgniteKernal) g;
for (IgniteCacheProxy<?, ?> c : g0.context().cache().jcaches()) {
CacheConfiguration cfg = c.context().config();
if (cfg.getCacheMode() != LOCAL && cfg.getRebalanceMode() != NONE) {
GridDhtCacheAdapter<?, ?> dht = dht(c);
GridDhtPartitionTopology top = dht.topology();
List<GridDhtLocalPartition> locs = top.localPartitions();
for (GridDhtLocalPartition loc : locs) {
GridDhtPartitionState actl = loc.state();
boolean res = GridDhtPartitionState.OWNING.equals(actl);
if (!res)
printPartitionState(c);
assertTrue("Wrong local partition state part=" + loc.id() + ", should be OWNING [state=" + actl + "], node=" + g0.name() + " cache=" + c.getName(), res);
Collection<ClusterNode> affNodes = g0.affinity(cfg.getName()).mapPartitionToPrimaryAndBackups(loc.id());
assertTrue(affNodes.contains(g0.localNode()));
}
for (Ignite remote : G.allGrids()) {
IgniteKernal remote0 = (IgniteKernal) remote;
IgniteCacheProxy<?, ?> remoteC = remote0.context().cache().jcache(cfg.getName());
GridDhtCacheAdapter<?, ?> remoteDht = dht(remoteC);
GridDhtPartitionTopology remoteTop = remoteDht.topology();
GridDhtPartitionMap pMap = remoteTop.partitionMap(true).get(((IgniteKernal) g).localNodeId());
assertEquals(pMap.size(), locs.size());
for (Map.Entry entry : pMap.entrySet()) {
assertTrue("Wrong remote partition state part=" + entry.getKey() + ", should be OWNING [state=" + entry.getValue() + "], node=" + remote.name() + " cache=" + c.getName(), entry.getValue() == GridDhtPartitionState.OWNING);
}
for (GridDhtLocalPartition loc : locs) assertTrue(pMap.containsKey(loc.id()));
}
}
}
}
log.info("checkPartitionMapExchangeFinished finished");
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState in project ignite by apache.
the class GridPartitionStateMap method setState.
/**
*/
private GridDhtPartitionState setState(int part, GridDhtPartitionState st) {
GridDhtPartitionState old = state(part);
if (old == st)
return old;
int off = part * BITS;
// Reserve all zero bits for empty value
int ist = st == null ? 0 : st.ordinal() + 1;
for (int i = 0; i < BITS; i++) {
states.set(off + i, (ist & 1) == 1);
ist >>>= 1;
}
size += (st == null ? -1 : old == null ? 1 : 0);
return old;
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState in project ignite by apache.
the class GridCommonAbstractTest method printPartitionState.
/**
* @param cacheName Cache name.
* @param firstParts Count partition for print (will be print first count partition).
* @param nodes Grid nodes.
*
* Print partitionState for cache.
*/
protected static void printPartitionState(String cacheName, int firstParts, List<? extends Ignite> nodes) {
StringBuilder sb = new StringBuilder();
sb.append("----preload sync futures----\n");
for (Ignite ig : nodes) {
IgniteKernal k = ((IgniteKernal) ig);
GridCacheAdapter<Object, Object> adapter = k.internalCache(cacheName);
if (adapter == null)
continue;
IgniteInternalFuture<?> syncFut = adapter.preloader().syncFuture();
sb.append("nodeId=").append(k.context().localNodeId()).append(" consistentId=").append(k.localNode().consistentId()).append(" isDone=").append(syncFut.isDone()).append("\n");
}
sb.append("----rebalance futures----\n");
for (Ignite ig : nodes) {
IgniteKernal k = ((IgniteKernal) ig);
GridCacheAdapter<Object, Object> adapter = k.internalCache(cacheName);
if (adapter == null)
continue;
IgniteInternalFuture<?> f = adapter.preloader().rebalanceFuture();
try {
sb.append("nodeId=").append(k.context().localNodeId()).append(" isDone=").append(f.isDone()).append(" res=").append(f.isDone() ? f.get() : "N/A").append(" topVer=").append((U.hasField(f, "topVer") ? String.valueOf(U.<Object>field(f, "topVer")) : "N/A")).append("\n");
Map<UUID, IgniteDhtDemandedPartitionsMap> remaining = U.field(f, "remaining");
sb.append("remaining: ");
sb.append(remaining.toString());
sb.append("\n");
} catch (Throwable e) {
log.error(e.getMessage());
}
}
sb.append("----partition state----\n");
for (Ignite g : nodes) {
IgniteKernal g0 = (IgniteKernal) g;
sb.append("localNodeId=").append(g0.localNode().id()).append(" grid=").append(g0.name()).append("\n");
IgniteCacheProxy<?, ?> cache = null;
try {
cache = g0.context().cache().jcache(cacheName);
} catch (IllegalArgumentException e) {
// Client topology.
continue;
}
GridDhtCacheAdapter<?, ?> dht = dht(cache);
GridDhtPartitionTopology top = dht.topology();
int parts = firstParts == 0 ? cache.context().config().getAffinity().partitions() : firstParts;
for (int p = 0; p < parts; p++) {
AffinityTopologyVersion readyVer = dht.context().shared().exchange().readyAffinityVersion();
Collection<UUID> affNodes = F.nodeIds(dht.context().affinity().assignment(readyVer).idealAssignment().get(p));
GridDhtLocalPartition part = top.localPartition(p, AffinityTopologyVersion.NONE, false);
sb.append("local part=");
if (part != null) {
sb.append(p).append(" counters=").append(part.dataStore().partUpdateCounter()).append(" fullSize=").append(part.fullSize()).append(" state=").append(part.state()).append(" reservations=").append(part.reservations());
} else
sb.append(p).append(" is null");
sb.append(" isAffNode=").append(affNodes.contains(g0.localNode().id())).append("\n");
for (UUID nodeId : F.nodeIds(g0.context().discovery().allNodes())) {
if (!nodeId.equals(g0.localNode().id())) {
top.readLock();
// Peek to remote state directly to distinguish if a partition is EVICTED or yet not initialized.
GridDhtPartitionFullMap map = U.field(top, "node2part");
try {
final GridDhtPartitionMap nodeMap = map.get(nodeId);
if (nodeMap == null)
// Skip client node.
continue;
final GridDhtPartitionState rmtState = nodeMap.get(p);
if (rmtState != null) {
sb.append(" nodeId=").append(nodeId).append(" part=").append(p).append(" state=").append(rmtState).append(" isAffNode=").append(affNodes.contains(nodeId)).append("\n");
} else {
sb.append(" nodeId=").append(nodeId).append(" part=").append(p).append(" is null").append("\n");
}
} finally {
top.readUnlock();
}
}
}
}
sb.append("\n");
}
log.info("dump partitions state for <" + cacheName + ">:\n" + sb.toString());
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState in project ignite by apache.
the class GridPartitionMapSelfTest method testIteratorNext.
/**
* Tests that entries from {@link Iterator#next()} remain unaltered.
*/
@Test
public void testIteratorNext() {
GridPartitionStateMap map = new GridPartitionStateMap();
initMap(map);
Iterator<Map.Entry<Integer, GridDhtPartitionState>> iter = map.entrySet().iterator();
for (int i = 0; i < map.size() + 1; i++) assertTrue(iter.hasNext());
Map.Entry<Integer, GridDhtPartitionState> entry1 = iter.next();
for (int i = 0; i < map.size() + 1; i++) assertTrue(iter.hasNext());
Map.Entry<Integer, GridDhtPartitionState> entry2 = iter.next();
iter.remove();
assertNotNull(entry1.getValue());
assertNotNull(entry2.getValue());
assertEquals(Integer.valueOf(0), entry1.getKey());
assertEquals(Integer.valueOf(1), entry2.getKey());
assertEquals(GridDhtPartitionState.MOVING, entry1.getValue());
assertEquals(GridDhtPartitionState.RENTING, entry2.getValue());
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState in project ignite by apache.
the class GridPartitionMapSelfTest method testOnRandomOperations.
/**
* Tests {@link GridDhtPartitionState} compatibility with {@link TreeMap} on random operations.
*/
@Test
public void testOnRandomOperations() {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
Map<Integer, GridDhtPartitionState> treeMap = new TreeMap<>();
Map<Integer, GridDhtPartitionState> gridMap = new GridPartitionStateMap();
int statesNum = GridDhtPartitionState.values().length;
for (int i = 0; i < 10000; i++) {
Integer part = rnd.nextInt(65536);
GridDhtPartitionState state = GridDhtPartitionState.fromOrdinal(rnd.nextInt(statesNum));
int rndOperation = rnd.nextInt(9);
if (rndOperation <= 5) {
treeMap.put(part, state);
gridMap.put(part, state);
} else if (rndOperation == 6) {
treeMap.remove(part);
gridMap.remove(part);
} else if (!treeMap.isEmpty()) {
int n = rnd.nextInt(0, treeMap.size());
Iterator<Map.Entry<Integer, GridDhtPartitionState>> iter1 = treeMap.entrySet().iterator();
Iterator<Map.Entry<Integer, GridDhtPartitionState>> iter2 = gridMap.entrySet().iterator();
Map.Entry<Integer, GridDhtPartitionState> entry1 = iter1.next();
Map.Entry<Integer, GridDhtPartitionState> entry2 = iter2.next();
for (int j = 1; j <= n; j++) {
entry1 = iter1.next();
entry2 = iter2.next();
assertEquals(entry1.getValue(), entry2.getValue());
}
if (rndOperation == 7) {
entry1.setValue(state);
entry2.setValue(state);
} else {
iter1.remove();
iter2.remove();
}
}
assertEquals(treeMap.size(), gridMap.size());
}
assertEquals(treeMap, gridMap);
}
Aggregations