use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap 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.preloader.GridDhtPartitionMap 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.preloader.GridDhtPartitionMap 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.preloader.GridDhtPartitionMap 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();
}
}
}
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap in project ignite by apache.
the class GridClientPartitionTopology method update.
/** {@inheritDoc} */
@SuppressWarnings({ "MismatchedQueryAndUpdateOfCollection" })
@Nullable
@Override
public GridDhtPartitionMap update(@Nullable GridDhtPartitionExchangeId exchId, GridDhtPartitionMap parts) {
if (log.isDebugEnabled())
log.debug("Updating single partition map [exchId=" + exchId + ", parts=" + mapString(parts) + ']');
if (!cctx.discovery().alive(parts.nodeId())) {
if (log.isDebugEnabled())
log.debug("Received partition update for non-existing node (will ignore) [exchId=" + exchId + ", parts=" + parts + ']');
return null;
}
lock.writeLock().lock();
try {
if (stopping)
return null;
if (lastExchangeId != null && exchId != null && lastExchangeId.compareTo(exchId) > 0) {
if (log.isDebugEnabled())
log.debug("Stale exchange id for single partition map update (will ignore) [lastExchId=" + lastExchangeId + ", exchId=" + exchId + ']');
return null;
}
if (exchId != null)
lastExchangeId = exchId;
if (node2part == null)
// Create invalid partition map.
node2part = new GridDhtPartitionFullMap();
GridDhtPartitionMap cur = node2part.get(parts.nodeId());
if (cur != null && cur.updateSequence() >= parts.updateSequence()) {
if (log.isDebugEnabled())
log.debug("Stale update sequence for single partition map update (will ignore) [exchId=" + exchId + ", curSeq=" + cur.updateSequence() + ", newSeq=" + parts.updateSequence() + ']');
return null;
}
long updateSeq = this.updateSeq.incrementAndGet();
node2part = new GridDhtPartitionFullMap(node2part, updateSeq);
boolean changed = false;
if (cur == null || !cur.equals(parts))
changed = true;
node2part.put(parts.nodeId(), parts);
part2node = new HashMap<>(part2node);
// Add new mappings.
for (Integer p : parts.keySet()) {
Set<UUID> ids = part2node.get(p);
if (ids == null)
// Initialize HashSet to size 3 in anticipation that there won't be
// more than 3 nodes per partition.
part2node.put(p, ids = U.newHashSet(3));
changed |= ids.add(parts.nodeId());
}
// Remove obsolete mappings.
if (cur != null) {
for (Integer p : F.view(cur.keySet(), F0.notIn(parts.keySet()))) {
Set<UUID> ids = part2node.get(p);
if (ids != null)
changed |= ids.remove(parts.nodeId());
}
}
consistencyCheck();
if (log.isDebugEnabled())
log.debug("Partition map after single update: " + fullMapString());
return changed ? localPartitionMap() : null;
} finally {
lock.writeLock().unlock();
}
}
Aggregations