use of org.apache.ignite.internal.processors.cache.ClusterState in project ignite by apache.
the class GridDhtPartitionTopologyImpl method beforeExchange.
/** {@inheritDoc} */
@Override
public void beforeExchange(GridDhtPartitionsExchangeFuture exchFut, boolean affReady) throws IgniteCheckedException {
DiscoveryEvent discoEvt = exchFut.discoveryEvent();
ClusterState newState = exchFut.newClusterState();
treatAllPartAsLoc = (newState != null && newState == ClusterState.ACTIVE) || (cctx.kernalContext().state().active() && discoEvt.type() == EventType.EVT_NODE_JOINED && discoEvt.eventNode().isLocal() && !cctx.kernalContext().clientNode());
// Wait for rent outside of checkpoint lock.
waitForRent();
ClusterNode loc = cctx.localNode();
cctx.shared().database().checkpointReadLock();
synchronized (cctx.shared().exchange().interruptLock()) {
if (Thread.currentThread().isInterrupted())
throw new IgniteInterruptedCheckedException("Thread is interrupted: " + Thread.currentThread());
try {
U.writeLock(lock);
} catch (IgniteInterruptedCheckedException e) {
cctx.shared().database().checkpointReadUnlock();
throw e;
}
try {
GridDhtPartitionExchangeId exchId = exchFut.exchangeId();
if (stopping)
return;
assert topVer.equals(exchId.topologyVersion()) : "Invalid topology version [topVer=" + topVer + ", exchId=" + exchId + ']';
if (exchId.isLeft())
removeNode(exchId.nodeId());
ClusterNode oldest = discoCache.oldestAliveServerNodeWithCache();
if (log.isDebugEnabled())
log.debug("Partition map beforeExchange [exchId=" + exchId + ", fullMap=" + fullMapString() + ']');
long updateSeq = this.updateSeq.incrementAndGet();
cntrMap.clear();
// If this is the oldest node.
if (oldest != null && (loc.equals(oldest) || exchFut.cacheAddedOnExchange(cctx.cacheId(), cctx.receivedFrom()))) {
if (node2part == null) {
node2part = new GridDhtPartitionFullMap(oldest.id(), oldest.order(), updateSeq);
if (log.isDebugEnabled())
log.debug("Created brand new full topology map on oldest node [exchId=" + exchId + ", fullMap=" + fullMapString() + ']');
} else if (!node2part.valid()) {
node2part = new GridDhtPartitionFullMap(oldest.id(), oldest.order(), updateSeq, node2part, false);
if (log.isDebugEnabled())
log.debug("Created new full topology map on oldest node [exchId=" + exchId + ", fullMap=" + node2part + ']');
} else if (!node2part.nodeId().equals(loc.id())) {
node2part = new GridDhtPartitionFullMap(oldest.id(), oldest.order(), updateSeq, node2part, false);
if (log.isDebugEnabled())
log.debug("Copied old map into new map on oldest node (previous oldest node left) [exchId=" + exchId + ", fullMap=" + fullMapString() + ']');
}
}
if (affReady)
initPartitions0(exchFut, updateSeq);
else {
List<List<ClusterNode>> aff = cctx.affinity().idealAssignment();
createPartitions(aff, updateSeq);
}
consistencyCheck();
if (log.isDebugEnabled())
log.debug("Partition map after beforeExchange [exchId=" + exchId + ", fullMap=" + fullMapString() + ']');
} finally {
lock.writeLock().unlock();
cctx.shared().database().checkpointReadUnlock();
}
}
// Wait for evictions.
waitForRent();
}
Aggregations