use of org.apache.ignite.internal.managers.discovery.DiscoCache in project ignite by apache.
the class CacheAffinitySharedManager method processClientCachesRequests.
/**
* Process non affinity node cache start/close requests, called from exchange thread.
*
* @param msg Change request.
*/
void processClientCachesRequests(ClientCacheChangeDummyDiscoveryMessage msg) {
// Get ready exchange version.
AffinityTopologyVersion topVer = cctx.exchange().readyAffinityVersion();
DiscoCache discoCache = cctx.discovery().discoCache(topVer);
ClusterNode node = discoCache.oldestAliveServerNode();
// Resolve coordinator for specific version.
boolean crd = node != null && node.isLocal();
Map<Integer, Boolean> startedCaches = null;
Set<Integer> closedCaches = null;
// Check and start caches via dummy message.
if (msg.startRequests() != null)
startedCaches = processClientCacheStartRequests(crd, msg, topVer, discoCache);
// Check and close caches via dummy message.
if (msg.cachesToClose() != null)
closedCaches = processCacheCloseRequests(msg, topVer);
// Shedule change message.
if (startedCaches != null || closedCaches != null)
scheduleClientChangeMessage(startedCaches, closedCaches);
}
use of org.apache.ignite.internal.managers.discovery.DiscoCache 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.managers.discovery.DiscoCache in project ignite by apache.
the class VisorTxTask method createVerboseInfo.
/**
* Constructs detailed transaction info for verbose mode.
*
* @param ignite Ignite.
* @param locTx Local tx.
*/
private static TxVerboseInfo createVerboseInfo(IgniteEx ignite, IgniteInternalTx locTx) {
TxVerboseInfo res = new TxVerboseInfo();
res.nearXidVersion(locTx.nearXidVersion());
Map<Integer, String> usedCaches = new HashMap<>();
Map<Integer, String> usedCacheGroups = new HashMap<>();
ClusterNode locNode = ignite.context().discovery().localNode();
res.localNodeId(locNode.id());
res.localNodeConsistentId(locNode.consistentId());
if (locTx instanceof GridNearTxLocal) {
IgniteTxMappings mappings = ((GridNearTxLocal) locTx).mappings();
List<IgniteTxEntry> nearOnlyEntries = new ArrayList<>();
List<IgniteTxEntry> locEntries = new ArrayList<>();
for (GridDistributedTxMapping mapping : mappings.mappings()) {
if (F.eqNodes(mapping.primary(), locNode))
locEntries.addAll(mapping.entries());
else
nearOnlyEntries.addAll(mapping.entries());
}
res.nearNodeId(locNode.id());
res.nearNodeConsistentId(locNode.consistentId());
res.txMappingType(TxMappingType.NEAR);
List<TxVerboseKey> nearOnlyTxKeys = fetchTxEntriesAndFillUsedCaches(ignite, locTx, usedCaches, usedCacheGroups, nearOnlyEntries, true);
List<TxVerboseKey> locTxKeys = fetchTxEntriesAndFillUsedCaches(ignite, locTx, usedCaches, usedCacheGroups, locEntries, false);
res.nearOnlyTxKeys(nearOnlyTxKeys);
res.localTxKeys(locTxKeys);
} else if (locTx instanceof GridDhtTxLocal) {
UUID nearNodeId = locTx.masterNodeIds().iterator().next();
DiscoCache discoCache = ignite.context().discovery().discoCache(locTx.topologyVersion());
if (discoCache == null)
discoCache = ignite.context().discovery().discoCache();
ClusterNode nearNode = discoCache.node(nearNodeId);
res.nearNodeId(nearNodeId);
res.nearNodeConsistentId(nearNode.consistentId());
res.txMappingType(TxMappingType.DHT);
res.localTxKeys(fetchTxEntriesAndFillUsedCaches(ignite, locTx, usedCaches, usedCacheGroups, locTx.allEntries(), false));
} else if (locTx instanceof GridDhtTxRemote) {
Iterator<UUID> masterNodesIter = locTx.masterNodeIds().iterator();
UUID nearNodeId = masterNodesIter.next();
UUID dhtNodeId = masterNodesIter.next();
DiscoCache discoCache = ignite.context().discovery().discoCache(locTx.topologyVersion());
if (discoCache == null)
discoCache = ignite.context().discovery().discoCache();
ClusterNode nearNode = discoCache.node(nearNodeId);
ClusterNode dhtNode = discoCache.node(dhtNodeId);
res.nearNodeId(nearNodeId);
res.nearNodeConsistentId(nearNode.consistentId());
res.txMappingType(TxMappingType.REMOTE);
res.dhtNodeId(dhtNodeId);
res.dhtNodeConsistentId(dhtNode.consistentId());
res.localTxKeys(fetchTxEntriesAndFillUsedCaches(ignite, locTx, usedCaches, usedCacheGroups, locTx.allEntries(), false));
}
res.usedCaches(usedCaches);
res.usedCacheGroups(usedCacheGroups);
return res;
}
use of org.apache.ignite.internal.managers.discovery.DiscoCache in project ignite by apache.
the class GridCachePartitionExchangeManager method onKernalStart.
/**
* @param active Cluster state.
* @param reconnect Reconnect flag.
* @return Topology version of local join exchange if cluster is active.
* Topology version NONE if cluster is not active or reconnect.
* @throws IgniteCheckedException If failed.
*/
public AffinityTopologyVersion onKernalStart(boolean active, boolean reconnect) throws IgniteCheckedException {
for (ClusterNode n : cctx.discovery().remoteNodes()) cctx.versions().onReceived(n.id(), n.metrics().getLastDataVersion());
DiscoveryLocalJoinData locJoin = cctx.discovery().localJoin();
GridDhtPartitionsExchangeFuture fut = null;
if (reconnect)
reconnectExchangeFut = new GridFutureAdapter<>();
if (active) {
DiscoveryEvent discoEvt = locJoin.event();
DiscoCache discoCache = locJoin.discoCache();
GridDhtPartitionExchangeId exchId = initialExchangeId();
fut = exchangeFuture(exchId, reconnect ? null : discoEvt, reconnect ? null : discoCache, null, null);
} else if (reconnect)
reconnectExchangeFut.onDone();
new IgniteThread(cctx.igniteInstanceName(), "exchange-worker", exchWorker).start();
if (reconnect) {
if (fut != null) {
fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
@Override
public void apply(IgniteInternalFuture<AffinityTopologyVersion> fut) {
try {
fut.get();
for (CacheGroupContext grp : cctx.cache().cacheGroups()) grp.preloader().onInitialExchangeComplete(null);
reconnectExchangeFut.onDone();
} catch (IgniteCheckedException e) {
for (CacheGroupContext grp : cctx.cache().cacheGroups()) grp.preloader().onInitialExchangeComplete(e);
reconnectExchangeFut.onDone(e);
}
}
});
}
} else if (fut != null) {
if (log.isDebugEnabled())
log.debug("Beginning to wait on local exchange future: " + fut);
boolean first = true;
while (true) {
try {
fut.get(cctx.preloadExchangeTimeout());
break;
} catch (IgniteFutureTimeoutCheckedException ignored) {
if (first) {
U.warn(log, "Failed to wait for initial partition map exchange. " + "Possible reasons are: " + U.nl() + " ^-- Transactions in deadlock." + U.nl() + " ^-- Long running transactions (ignore if this is the case)." + U.nl() + " ^-- Unreleased explicit locks.");
first = false;
} else
U.warn(log, "Still waiting for initial partition map exchange [fut=" + fut + ']');
} catch (IgniteNeedReconnectException e) {
throw e;
} catch (Exception e) {
if (fut.reconnectOnError(e))
throw new IgniteNeedReconnectException(cctx.localNode(), e);
throw e;
}
}
for (CacheGroupContext grp : cctx.cache().cacheGroups()) {
if (locJoin.joinTopologyVersion().equals(grp.localStartVersion()))
grp.preloader().onInitialExchangeComplete(null);
}
if (log.isDebugEnabled())
log.debug("Finished waiting for initial exchange: " + fut.exchangeId());
return fut.initialVersion();
}
return NONE;
}
use of org.apache.ignite.internal.managers.discovery.DiscoCache in project ignite by apache.
the class IgniteClusterImpl method validateBeforeBaselineChange.
/**
* Executes validation checks of cluster state and BaselineTopology before changing BaselineTopology to new one.
*/
private void validateBeforeBaselineChange(Collection<? extends BaselineNode> baselineTop) {
verifyBaselineTopologySupport(ctx.discovery().discoCache());
if (!ctx.state().clusterState().active())
throw new IgniteException("Changing BaselineTopology on inactive cluster is not allowed.");
if (baselineTop != null) {
if (baselineTop.isEmpty())
throw new IgniteException("BaselineTopology must contain at least one node.");
List<BaselineNode> currBlT = Optional.ofNullable(ctx.state().clusterState().baselineTopology()).map(BaselineTopology::currentBaseline).orElse(Collections.emptyList());
Collection<ClusterNode> srvrs = ctx.cluster().get().forServers().nodes();
for (BaselineNode node : baselineTop) {
Object consistentId = node.consistentId();
if (currBlT.stream().noneMatch(currBlTNode -> Objects.equals(currBlTNode.consistentId(), consistentId)) && srvrs.stream().noneMatch(currServersNode -> Objects.equals(currServersNode.consistentId(), consistentId)))
throw new IgniteException("Check arguments. Node with consistent ID [" + consistentId + "] not found in server nodes.");
}
Collection<Object> onlineNodes = onlineBaselineNodesRequestedForRemoval(baselineTop);
if (onlineNodes != null) {
if (!onlineNodes.isEmpty())
throw new IgniteException("Removing online nodes from BaselineTopology is not supported: " + onlineNodes);
}
}
}
Aggregations