use of org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState in project ignite by apache.
the class GridDhtPartitionsExchangeFuture method onClusterStateChangeRequest.
/**
* @param crd Coordinator flag.
* @return Exchange type.
*/
private ExchangeType onClusterStateChangeRequest(boolean crd) {
assert exchActions != null && !exchActions.empty() : this;
StateChangeRequest req = exchActions.stateChangeRequest();
assert req != null : exchActions;
GridKernalContext kctx = cctx.kernalContext();
DiscoveryDataClusterState state = kctx.state().clusterState();
if (state.transitionError() != null)
exchangeLocE = state.transitionError();
if (req.activeChanged()) {
if (req.state().active()) {
if (log.isInfoEnabled()) {
log.info("Start activation process [nodeId=" + cctx.localNodeId() + ", client=" + kctx.clientNode() + ", topVer=" + initialVersion() + "]. New state: " + req.state());
}
try {
cctx.exchange().exchangerBlockingSectionBegin();
try {
cctx.activate();
} finally {
cctx.exchange().exchangerBlockingSectionEnd();
}
assert registerCachesFuture == null : "No caches registration should be scheduled before new caches have started.";
cctx.exchange().exchangerBlockingSectionBegin();
try {
registerCachesFuture = cctx.affinity().onCacheChangeRequest(this, crd, exchActions);
if (!kctx.clientNode())
cctx.cache().shutdownNotFinishedRecoveryCaches();
} finally {
cctx.exchange().exchangerBlockingSectionEnd();
}
if (log.isInfoEnabled()) {
log.info("Successfully activated caches [nodeId=" + cctx.localNodeId() + ", client=" + kctx.clientNode() + ", topVer=" + initialVersion() + ", newState=" + req.state() + "]");
}
} catch (Exception e) {
U.error(log, "Failed to activate node components [nodeId=" + cctx.localNodeId() + ", client=" + kctx.clientNode() + ", topVer=" + initialVersion() + ", newState=" + req.state() + "]", e);
exchangeLocE = e;
if (crd) {
cctx.exchange().exchangerBlockingSectionBegin();
try {
synchronized (mux) {
exchangeGlobalExceptions.put(cctx.localNodeId(), e);
}
} finally {
cctx.exchange().exchangerBlockingSectionEnd();
}
}
}
} else {
if (log.isInfoEnabled()) {
log.info("Start deactivation process [nodeId=" + cctx.localNodeId() + ", client=" + kctx.clientNode() + ", topVer=" + initialVersion() + "]");
}
cctx.exchange().exchangerBlockingSectionBegin();
try {
kctx.dataStructures().onDeActivate(kctx);
assert registerCachesFuture == null : "No caches registration should be scheduled before new caches have started.";
registerCachesFuture = cctx.affinity().onCacheChangeRequest(this, crd, exchActions);
kctx.encryption().onDeActivate(kctx);
((IgniteChangeGlobalStateSupport) kctx.distributedMetastorage()).onDeActivate(kctx);
if (log.isInfoEnabled()) {
log.info("Successfully deactivated data structures, services and caches [" + "nodeId=" + cctx.localNodeId() + ", client=" + kctx.clientNode() + ", topVer=" + initialVersion() + "]");
}
} catch (Exception e) {
U.error(log, "Failed to deactivate node components [nodeId=" + cctx.localNodeId() + ", client=" + kctx.clientNode() + ", topVer=" + initialVersion() + "]", e);
exchangeLocE = e;
} finally {
cctx.exchange().exchangerBlockingSectionEnd();
}
}
} else if (req.state().active()) {
cctx.exchange().exchangerBlockingSectionBegin();
// TODO: BLT changes on inactive cluster can't be handled easily because persistent storage hasn't been initialized yet.
try {
if (!forceAffReassignment) {
// possible only if cluster contains nodes without forceAffReassignment mode
assert firstEventCache().minimumNodeVersion().compareToIgnoreTimestamp(FORCE_AFF_REASSIGNMENT_SINCE) < 0 : firstEventCache().minimumNodeVersion();
cctx.affinity().onBaselineTopologyChanged(this, crd);
}
if (CU.isPersistenceEnabled(kctx.config()) && !kctx.clientNode())
kctx.state().onBaselineTopologyChanged(req.baselineTopology(), req.prevBaselineTopologyHistoryItem());
} catch (Exception e) {
U.error(log, "Failed to change baseline topology [nodeId=" + cctx.localNodeId() + ", client=" + kctx.clientNode() + ", topVer=" + initialVersion() + "]", e);
exchangeLocE = e;
} finally {
cctx.exchange().exchangerBlockingSectionEnd();
}
}
return kctx.clientNode() ? ExchangeType.CLIENT : ExchangeType.ALL;
}
use of org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState in project ignite by apache.
the class IgniteServiceProcessor method processServicesChangeRequest.
/**
* @param snd Sender.
* @param msg Message.
*/
private void processServicesChangeRequest(ClusterNode snd, ServiceChangeBatchRequest msg) {
DiscoveryDataClusterState state = ctx.state().clusterState();
if (!state.active() || state.transition()) {
for (ServiceChangeAbstractRequest req : msg.requests()) {
GridFutureAdapter<?> fut = null;
if (req instanceof ServiceDeploymentRequest)
fut = depFuts.remove(req.serviceId());
else if (req instanceof ServiceUndeploymentRequest)
fut = undepFuts.remove(req.serviceId());
if (fut != null) {
fut.onDone(new IgniteCheckedException("Operation has been canceled, cluster state " + "change is in progress."));
}
}
return;
}
Map<IgniteUuid, ServiceInfo> toDeploy = new HashMap<>();
Map<IgniteUuid, ServiceInfo> toUndeploy = new HashMap<>();
for (ServiceChangeAbstractRequest req : msg.requests()) {
IgniteUuid reqSrvcId = req.serviceId();
ServiceInfo oldDesc = registeredServices.get(reqSrvcId);
if (req instanceof ServiceDeploymentRequest) {
Exception err = null;
if (oldDesc != null) {
// In case of a collision of IgniteUuid.randomUuid() (almost impossible case)
err = new IgniteCheckedException("Failed to deploy service. Service with generated id already" + "exists : [" + "srvcId" + reqSrvcId + ", srvcTop=" + oldDesc.topologySnapshot() + ']');
} else {
ServiceConfiguration cfg = ((ServiceDeploymentRequest) req).configuration();
if (ctx.security().enabled())
err = checkPermissions(((ServiceDeploymentRequest) req).configuration().getName(), SERVICE_DEPLOY);
if (err == null) {
oldDesc = lookupInRegisteredServices(cfg.getName());
if (oldDesc == null) {
if (cfg.getCacheName() != null && ctx.cache().cacheDescriptor(cfg.getCacheName()) == null) {
err = new IgniteCheckedException("Failed to deploy service, " + "affinity cache is not found, cfg=" + cfg);
} else {
ServiceInfo desc = new ServiceInfo(snd.id(), reqSrvcId, cfg);
registerService(desc);
toDeploy.put(reqSrvcId, desc);
}
} else {
if (!oldDesc.configuration().equalsIgnoreNodeFilter(cfg)) {
err = new IgniteCheckedException("Failed to deploy service " + "(service already exists with different configuration) : " + "[deployed=" + oldDesc.configuration() + ", new=" + cfg + ']');
} else {
GridServiceDeploymentFuture<IgniteUuid> fut = depFuts.remove(reqSrvcId);
if (fut != null) {
fut.onDone();
if (log.isDebugEnabled()) {
log.debug("Service sent to deploy is already deployed : " + "[srvcId=" + oldDesc.serviceId() + ", cfg=" + oldDesc.configuration());
}
}
}
}
}
}
if (err != null) {
completeInitiatingFuture(true, reqSrvcId, err);
U.warn(log, err.getMessage(), err);
}
} else if (req instanceof ServiceUndeploymentRequest) {
ServiceInfo rmv = registeredServices.remove(reqSrvcId);
assert oldDesc == rmv : "Concurrent map modification.";
toUndeploy.put(reqSrvcId, rmv);
}
}
if (!toDeploy.isEmpty() || !toUndeploy.isEmpty()) {
ServiceDeploymentActions depActions = new ServiceDeploymentActions();
if (!toDeploy.isEmpty())
depActions.servicesToDeploy(toDeploy);
if (!toUndeploy.isEmpty())
depActions.servicesToUndeploy(toUndeploy);
msg.servicesDeploymentActions(depActions);
}
}
Aggregations