use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.
the class InitNewCoordinatorFuture method onAllReceived.
/**
*/
private void onAllReceived() {
if (fullMsg != null) {
AffinityTopologyVersion resVer = fullMsg.resultTopologyVersion();
for (Iterator<Map.Entry<ClusterNode, GridDhtPartitionsSingleMessage>> it = msgs.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<ClusterNode, GridDhtPartitionsSingleMessage> e = it.next();
GridDhtPartitionExchangeId msgVer = joinedNodes.get(e.getKey().id());
if (msgVer != null) {
assert msgVer.topologyVersion().compareTo(initTopVer) > 0 : msgVer;
if (log.isInfoEnabled()) {
log.info("Process joined node message [resVer=" + resVer + ", initTopVer=" + initTopVer + ", msgVer=" + msgVer.topologyVersion() + ']');
}
if (msgVer.topologyVersion().compareTo(resVer) > 0)
it.remove();
else {
GridDhtPartitionsSingleMessage msg = e.getValue();
msg.exchangeId(msgVer);
if (joinExchMsgs == null)
joinExchMsgs = new HashMap<>();
joinExchMsgs.put(e.getKey().id(), msg);
}
}
}
} else {
for (Iterator<Map.Entry<ClusterNode, GridDhtPartitionsSingleMessage>> it = msgs.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<ClusterNode, GridDhtPartitionsSingleMessage> e = it.next();
GridDhtPartitionExchangeId msgVer = joinedNodes.get(e.getKey().id());
if (msgVer != null) {
it.remove();
assert msgVer.topologyVersion().compareTo(initTopVer) > 0 : msgVer;
if (log.isInfoEnabled()) {
log.info("Process joined node message [initTopVer=" + initTopVer + ", msgVer=" + msgVer.topologyVersion() + ']');
}
if (joinExchMsgs == null)
joinExchMsgs = new HashMap<>();
e.getValue().exchangeId(msgVer);
joinExchMsgs.put(e.getKey().id(), e.getValue());
}
}
}
}
use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.
the class InitNewCoordinatorFuture method init.
/**
* @param exchFut Current future.
* @throws IgniteCheckedException If failed.
*/
public void init(GridDhtPartitionsExchangeFuture exchFut) throws IgniteCheckedException {
initTopVer = exchFut.initialVersion();
GridCacheSharedContext cctx = exchFut.sharedContext();
restoreState = exchangeProtocolVersion(exchFut.context().events().discoveryCache().minimumNodeVersion()) > 1;
boolean newAff = exchFut.localJoinExchange();
IgniteInternalFuture<?> fut = cctx.affinity().initCoordinatorCaches(exchFut, newAff);
if (fut != null)
add(fut);
if (restoreState) {
DiscoCache curDiscoCache = cctx.discovery().discoCache();
DiscoCache discoCache = exchFut.events().discoveryCache();
List<ClusterNode> nodes = new ArrayList<>();
synchronized (this) {
for (ClusterNode node : discoCache.allNodes()) {
if (!node.isLocal() && cctx.discovery().alive(node)) {
awaited.add(node.id());
nodes.add(node);
} else if (!node.isLocal()) {
if (log.isInfoEnabled())
log.info("Init new coordinator future will skip remote node: " + node);
}
}
if (exchFut.context().mergeExchanges() && !curDiscoCache.version().equals(discoCache.version())) {
for (ClusterNode node : curDiscoCache.allNodes()) {
if (discoCache.node(node.id()) == null) {
if (exchangeProtocolVersion(node.version()) == 1)
break;
awaited.add(node.id());
nodes.add(node);
if (joinedNodes == null)
joinedNodes = new HashMap<>();
GridDhtPartitionExchangeId exchId = new GridDhtPartitionExchangeId(node.id(), EVT_NODE_JOINED, new AffinityTopologyVersion(node.order()));
joinedNodes.put(node.id(), exchId);
}
}
}
if (joinedNodes == null)
joinedNodes = Collections.emptyMap();
if (!awaited.isEmpty()) {
restoreStateFut = new GridFutureAdapter();
add(restoreStateFut);
}
}
if (log.isInfoEnabled()) {
log.info("Try restore exchange result [awaited=" + awaited + ", joined=" + joinedNodes.keySet() + ", nodes=" + U.nodeIds(nodes) + ", discoAllNodes=" + U.nodeIds(discoCache.allNodes()) + ']');
}
if (!nodes.isEmpty()) {
GridDhtPartitionsSingleRequest req = GridDhtPartitionsSingleRequest.restoreStateRequest(exchFut.exchangeId(), exchFut.exchangeId());
for (ClusterNode node : nodes) {
try {
GridDhtPartitionsSingleRequest sndReq = req;
if (joinedNodes.containsKey(node.id())) {
sndReq = GridDhtPartitionsSingleRequest.restoreStateRequest(joinedNodes.get(node.id()), exchFut.exchangeId());
}
cctx.io().send(node, sndReq, GridIoPolicy.SYSTEM_POOL);
} catch (ClusterTopologyCheckedException e) {
if (log.isDebugEnabled())
log.debug("Failed to send partitions request, node failed: " + node);
onNodeLeft(node.id());
}
}
}
}
markInitialized();
}
use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.
the class GridNearAtomicCache method processNearAtomicUpdateResponse.
/**
* @param ver Version.
* @param key Key.
* @param val Value.
* @param ttl TTL.
* @param expireTime Expire time.
* @param nodeId Node ID.
* @param subjId Subject ID.
* @param taskName Task name.
* @throws IgniteCheckedException If failed.
*/
private void processNearAtomicUpdateResponse(GridCacheVersion ver, KeyCacheObject key, @Nullable CacheObject val, long ttl, long expireTime, boolean keepBinary, UUID nodeId, UUID subjId, String taskName) throws IgniteCheckedException {
try {
while (true) {
GridCacheEntryEx entry = null;
AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
try {
entry = entryEx(key, topVer);
GridCacheOperation op = val != null ? UPDATE : DELETE;
GridCacheUpdateAtomicResult updRes = entry.innerUpdate(ver, nodeId, nodeId, op, val, null, /*write-through*/
false, /*read-through*/
false, /*retval*/
false, keepBinary, /*expiry policy*/
null, /*event*/
true, /*metrics*/
true, /*primary*/
false, /*check version*/
true, topVer, CU.empty0(), DR_NONE, ttl, expireTime, null, false, false, subjId, taskName, null, null, null);
if (updRes.removeVersion() != null)
ctx.onDeferredDelete(entry, updRes.removeVersion());
// While.
break;
} catch (GridCacheEntryRemovedException ignored) {
if (log.isDebugEnabled())
log.debug("Got removed entry while updating near cache value (will retry): " + key);
entry = null;
} finally {
if (entry != null)
ctx.evicts().touch(entry, topVer);
}
}
} catch (GridDhtInvalidPartitionException ignored) {
// Ignore.
}
}
use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.
the class GridNearAtomicSingleUpdateFuture method onDhtResponse.
/**
* {@inheritDoc}
*/
@Override
public void onDhtResponse(UUID nodeId, GridDhtAtomicNearResponse res) {
GridCacheReturn opRes0;
CachePartialUpdateCheckedException err0;
AffinityTopologyVersion remapTopVer0;
synchronized (this) {
if (!checkFutureId(res.futureId()))
return;
assert reqState != null;
assert reqState.req.nodeId().equals(res.primaryId());
if (opRes == null && res.hasResult())
opRes = res.result();
if (reqState.onDhtResponse(nodeId, res)) {
opRes0 = opRes;
err0 = err;
remapTopVer0 = onAllReceived();
} else
return;
}
UpdateErrors errors = res.errors();
if (errors != null) {
assert errors.error() != null;
completeFuture(null, errors.error(), res.futureId());
return;
}
finishUpdateFuture(opRes0, err0, remapTopVer0, res.futureId());
}
use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.
the class GridNearAtomicSingleUpdateFuture method checkDhtNodes.
/**
* @param futId Future ID.
*/
private void checkDhtNodes(long futId) {
GridCacheReturn opRes0 = null;
CachePartialUpdateCheckedException err0 = null;
AffinityTopologyVersion remapTopVer0 = null;
GridNearAtomicCheckUpdateRequest checkReq = null;
synchronized (this) {
if (!checkFutureId(futId))
return;
assert reqState != null;
DhtLeftResult res = reqState.checkDhtNodes(cctx);
if (res == DhtLeftResult.DONE) {
opRes0 = opRes;
err0 = err;
remapTopVer0 = onAllReceived();
} else if (res == DhtLeftResult.ALL_RCVD_CHECK_PRIMARY)
checkReq = new GridNearAtomicCheckUpdateRequest(reqState.req);
else
return;
}
if (checkReq != null)
sendCheckUpdateRequest(checkReq);
else
finishUpdateFuture(opRes0, err0, remapTopVer0, futId);
}
Aggregations