use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.
the class GridClientPartitionTopology method beforeExchange0.
/**
* @param loc Local node.
* @param exchFut Exchange future.
*/
private void beforeExchange0(ClusterNode loc, GridDhtPartitionsExchangeFuture exchFut) {
GridDhtPartitionExchangeId exchId = exchFut.exchangeId();
if (exchFut.context().events().hasServerLeft()) {
for (DiscoveryEvent evt : exchFut.context().events().events()) {
if (ExchangeDiscoveryEvents.serverLeftEvent(evt))
removeNode(evt.eventNode().id());
}
}
// In case if node joins, get topology at the time of joining node.
ClusterNode oldest = discoCache.oldestAliveServerNode();
assert oldest != null;
if (log.isDebugEnabled())
log.debug("Partition map beforeExchange [exchId=" + exchId + ", fullMap=" + fullMapString() + ']');
long updateSeq = this.updateSeq.incrementAndGet();
// If this is the oldest node (coordinator) or cache was added during this exchange
if (oldest.id().equals(loc.id()) || exchFut.dynamicCacheGroupStarted(grpId)) {
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() + ']');
}
}
consistencyCheck();
if (log.isDebugEnabled())
log.debug("Partition map after beforeExchange [exchId=" + exchId + ", fullMap=" + fullMapString() + ']');
}
use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.
the class GridClientPartitionTopology method beforeExchange.
/**
* {@inheritDoc}
*/
@Override
public void beforeExchange(GridDhtPartitionsExchangeFuture exchFut, boolean initParts, boolean updateMoving) throws IgniteCheckedException {
ClusterNode loc = cctx.localNode();
U.writeLock(lock);
try {
if (stopping)
return;
discoCache = exchFut.events().discoveryCache();
beforeExchange0(loc, exchFut);
if (updateMoving) {
ExchangeDiscoveryEvents evts = exchFut.context().events();
GridAffinityAssignmentCache aff = cctx.affinity().affinity(grpId);
assert aff.lastVersion().equals(evts.topologyVersion());
createMovingPartitions(aff.readyAffinity(evts.topologyVersion()));
}
} finally {
lock.writeLock().unlock();
}
}
use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.
the class GridClientPartitionTopology method allOwners.
/**
* {@inheritDoc}
*/
@Override
public List<List<ClusterNode>> allOwners() {
lock.readLock().lock();
try {
int parts = partitions();
List<List<ClusterNode>> res = new ArrayList<>(parts);
for (int i = 0; i < parts; i++) res.add(new ArrayList<>());
List<ClusterNode> allNodes = discoCache.cacheGroupAffinityNodes(grpId);
for (int i = 0; i < allNodes.size(); i++) {
ClusterNode node = allNodes.get(i);
GridDhtPartitionMap nodeParts = node2part.get(node.id());
if (nodeParts != null) {
for (Map.Entry<Integer, GridDhtPartitionState> e : nodeParts.map().entrySet()) {
if (e.getValue() == OWNING) {
int part = e.getKey();
List<ClusterNode> owners = res.get(part);
owners.add(node);
}
}
}
}
return res;
} finally {
lock.readLock().unlock();
}
}
use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.
the class GridClientPartitionTopology method updateLocal.
/**
* Updates value for single partition.
*
* @param p Partition.
* @param nodeId Node ID.
* @param state State.
* @param updateSeq Update sequence.
*/
private void updateLocal(int p, UUID nodeId, GridDhtPartitionState state, long updateSeq) {
assert lock.isWriteLockedByCurrentThread();
assert nodeId.equals(cctx.localNodeId());
// In case if node joins, get topology at the time of joining node.
ClusterNode oldest = discoCache.oldestAliveServerNode();
// If this node became the oldest node.
if (cctx.localNode().equals(oldest)) {
long seq = node2part.updateSequence();
if (seq != updateSeq) {
if (seq > updateSeq) {
if (this.updateSeq.get() < seq) {
// Update global counter if necessary.
boolean b = this.updateSeq.compareAndSet(this.updateSeq.get(), seq + 1);
assert b : "Invalid update sequence [updateSeq=" + updateSeq + ", seq=" + seq + ", curUpdateSeq=" + this.updateSeq.get() + ", node2part=" + node2part.toFullString() + ']';
updateSeq = seq + 1;
} else
updateSeq = seq;
}
node2part.updateSequence(updateSeq);
}
}
GridDhtPartitionMap map = node2part.get(nodeId);
if (map == null)
node2part.put(nodeId, map = new GridDhtPartitionMap(nodeId, updateSeq, topVer, GridPartitionStateMap.EMPTY, false));
map.updateSequence(updateSeq, topVer);
map.put(p, state);
Set<UUID> ids = part2node.get(p);
if (ids == null)
part2node.put(p, ids = U.newHashSet(3));
ids.add(nodeId);
}
use of org.apache.ignite.cluster.ClusterNode in project ignite by apache.
the class GridClientPartitionTopology method nodes.
/**
* {@inheritDoc}
*/
@Override
public List<ClusterNode> nodes(int p, AffinityTopologyVersion topVer) {
lock.readLock().lock();
try {
assert node2part != null && node2part.valid() : "Invalid node-to-partitions map [topVer=" + topVer + ", node2part=" + node2part + ']';
List<ClusterNode> nodes = null;
Collection<UUID> nodeIds = part2node.get(p);
if (!F.isEmpty(nodeIds)) {
for (UUID nodeId : nodeIds) {
ClusterNode n = discoCache.node(nodeId);
if (n != null && (topVer.topologyVersion() < 0 || n.order() <= topVer.topologyVersion())) {
if (nodes == null)
nodes = new ArrayList<>(nodeIds.size());
nodes.add(n);
}
}
}
return nodes;
} finally {
lock.readLock().unlock();
}
}
Aggregations