use of org.apache.ignite.internal.processors.cache.DynamicCacheChangeRequest in project ignite by apache.
the class GridClusterStateProcessor method changeGlobalState.
/**
*
*/
public IgniteInternalFuture<?> changeGlobalState(final boolean activate) {
if (cacheProc.transactions().tx() != null || sharedCtx.lockedTopologyVersion(null) != null)
throw new IgniteException("Cannot " + prettyStr(activate) + " cluster, because cache locked on transaction.");
if ((globalState == ACTIVE && activate) || (this.globalState == INACTIVE && !activate))
return new GridFinishedFuture<>();
final UUID requestId = UUID.randomUUID();
final GridChangeGlobalStateFuture cgsFut = new GridChangeGlobalStateFuture(requestId, activate, ctx);
if (!cgsLocFut.compareAndSet(null, cgsFut)) {
GridChangeGlobalStateFuture locF = cgsLocFut.get();
if (locF.activate == activate)
return locF;
else
return new GridFinishedFuture<>(new IgniteException("fail " + prettyStr(activate) + ", because now in progress" + prettyStr(locF.activate)));
}
try {
if (ctx.clientNode()) {
AffinityTopologyVersion topVer = ctx.discovery().topologyVersionEx();
IgniteCompute comp = ((ClusterGroupAdapter) ctx.cluster().get().forServers()).compute().withAsync();
if (log.isInfoEnabled())
log.info("Send " + prettyStr(activate) + " request from client node [id=" + ctx.localNodeId() + " topVer=" + topVer + " ]");
comp.run(new ClientChangeGlobalStateComputeRequest(activate));
comp.future().listen(new CI1<IgniteFuture>() {
@Override
public void apply(IgniteFuture fut) {
try {
fut.get();
cgsFut.onDone();
} catch (Exception e) {
cgsFut.onDone(e);
}
}
});
} else {
List<DynamicCacheChangeRequest> reqs = new ArrayList<>();
DynamicCacheChangeRequest changeGlobalStateReq = new DynamicCacheChangeRequest(requestId, activate ? ACTIVE : INACTIVE, ctx.localNodeId());
reqs.add(changeGlobalStateReq);
reqs.addAll(activate ? cacheProc.startAllCachesRequests() : cacheProc.stopAllCachesRequests());
ChangeGlobalStateMessage changeGlobalStateMsg = new ChangeGlobalStateMessage(requestId, ctx.localNodeId(), activate, new DynamicCacheChangeBatch(reqs));
try {
ctx.discovery().sendCustomEvent(changeGlobalStateMsg);
if (ctx.isStopping())
cgsFut.onDone(new IgniteCheckedException("Failed to execute " + prettyStr(activate) + " request, " + "node is stopping."));
} catch (IgniteCheckedException e) {
log.error("Fail create or send change global state request." + cgsFut, e);
cgsFut.onDone(e);
}
}
} catch (IgniteCheckedException e) {
log.error("Fail create or send change global state request." + cgsFut, e);
cgsFut.onDone(e);
}
return cgsFut;
}
use of org.apache.ignite.internal.processors.cache.DynamicCacheChangeRequest in project ignite by apache.
the class GridClusterStateProcessor method onActivate.
/**
*
*/
private Exception onActivate(ChangeGlobalStateContext cgsCtx) {
final boolean client = ctx.clientNode();
if (log.isInfoEnabled())
log.info("Start activation process [nodeId=" + this.ctx.localNodeId() + ", client=" + client + ", topVer=" + cgsCtx.topVer + "]");
Collection<CacheConfiguration> cfgs = new ArrayList<>();
for (DynamicCacheChangeRequest req : cgsCtx.batch.requests()) {
if (req.startCacheConfiguration() != null)
cfgs.add(req.startCacheConfiguration());
}
try {
if (!client) {
sharedCtx.database().lock();
IgnitePageStoreManager pageStore = sharedCtx.pageStore();
if (pageStore != null)
pageStore.onActivate(ctx);
if (sharedCtx.wal() != null)
sharedCtx.wal().onActivate(ctx);
sharedCtx.database().initDataBase();
for (CacheConfiguration cfg : cfgs) {
if (CU.isSystemCache(cfg.getName()))
if (pageStore != null)
pageStore.initializeForCache(cfg);
}
for (CacheConfiguration cfg : cfgs) {
if (!CU.isSystemCache(cfg.getName()))
if (pageStore != null)
pageStore.initializeForCache(cfg);
}
sharedCtx.database().onActivate(ctx);
}
if (log.isInfoEnabled())
log.info("Success activate wal, dataBase, pageStore [nodeId=" + ctx.localNodeId() + ", client=" + client + ", topVer=" + cgsCtx.topVer + "]");
return null;
} catch (Exception e) {
log.error("Fail activate wal, dataBase, pageStore [nodeId=" + ctx.localNodeId() + ", client=" + client + ", topVer=" + cgsCtx.topVer + "]", e);
if (!ctx.clientNode())
sharedCtx.database().unLock();
return e;
}
}
use of org.apache.ignite.internal.processors.cache.DynamicCacheChangeRequest in project ignite by apache.
the class IgniteServiceProcessor method processDynamicCacheChangeRequest.
/**
* @param msg Message.
*/
private void processDynamicCacheChangeRequest(DynamicCacheChangeBatch msg) {
Map<IgniteUuid, ServiceInfo> toUndeploy = new HashMap<>();
for (DynamicCacheChangeRequest chReq : msg.requests()) {
if (chReq.stop()) {
registeredServices.entrySet().removeIf(e -> {
ServiceInfo desc = e.getValue();
if (Objects.equals(desc.cacheName(), chReq.cacheName())) {
toUndeploy.put(desc.serviceId(), desc);
return true;
}
return false;
});
}
}
if (!toUndeploy.isEmpty()) {
ServiceDeploymentActions depActions = new ServiceDeploymentActions();
depActions.servicesToUndeploy(toUndeploy);
msg.servicesDeploymentActions(depActions);
}
}
Aggregations