use of org.apache.ignite.internal.processors.cache.GridCacheProcessor in project ignite by apache.
the class IgniteKernal method stop0.
/**
* @param cancel Whether or not to cancel running jobs.
*/
private void stop0(boolean cancel) {
gw.compareAndSet(null, new GridKernalGatewayImpl(igniteInstanceName));
GridKernalGateway gw = this.gw.get();
if (stopGuard.compareAndSet(false, true)) {
// Only one thread is allowed to perform stop sequence.
boolean firstStop = false;
GridKernalState state = gw.getState();
if (state == STARTED || state == DISCONNECTED)
firstStop = true;
else if (state == STARTING)
U.warn(log, "Attempt to stop starting grid. This operation " + "cannot be guaranteed to be successful.");
if (firstStop) {
// Notify lifecycle beans.
if (log.isDebugEnabled())
log.debug("Notifying lifecycle beans.");
notifyLifecycleBeansEx(LifecycleEventType.BEFORE_NODE_STOP);
}
List<GridComponent> comps = ctx.components();
// if called in the same thread, at least.
for (ListIterator<GridComponent> it = comps.listIterator(comps.size()); it.hasPrevious(); ) {
GridComponent comp = it.previous();
try {
if (!skipDaemon(comp))
comp.onKernalStop(cancel);
} catch (Throwable e) {
errOnStop = true;
U.error(log, "Failed to pre-stop processor: " + comp, e);
if (e instanceof Error)
throw e;
}
}
if (starveTask != null)
starveTask.close();
if (metricsLogTask != null)
metricsLogTask.close();
if (longJVMPauseDetector != null)
longJVMPauseDetector.stop();
boolean interrupted = false;
while (true) {
try {
if (gw.tryWriteLock(10))
break;
} catch (InterruptedException ignored) {
// Preserve interrupt status & ignore.
// Note that interrupted flag is cleared.
interrupted = true;
}
}
if (interrupted)
Thread.currentThread().interrupt();
try {
assert gw.getState() == STARTED || gw.getState() == STARTING || gw.getState() == DISCONNECTED;
// No more kernal calls from this point on.
gw.setState(STOPPING);
ctx.cluster().get().clearNodeMap();
if (log.isDebugEnabled())
log.debug("Grid " + (igniteInstanceName == null ? "" : '\'' + igniteInstanceName + "' ") + "is stopping.");
} finally {
gw.writeUnlock();
}
// Stopping cache operations.
GridCacheProcessor cache = ctx.cache();
if (cache != null)
cache.blockGateways();
// Unregister MBeans.
if (!mBeansMgr.unregisterAllMBeans())
errOnStop = true;
// Stop components in reverse order.
for (ListIterator<GridComponent> it = comps.listIterator(comps.size()); it.hasPrevious(); ) {
GridComponent comp = it.previous();
try {
if (!skipDaemon(comp)) {
comp.stop(cancel);
if (log.isDebugEnabled())
log.debug("Component stopped: " + comp);
}
} catch (Throwable e) {
errOnStop = true;
U.error(log, "Failed to stop component (ignoring): " + comp, e);
if (e instanceof Error)
throw (Error) e;
}
}
// Stops lifecycle aware components.
U.stopLifecycleAware(log, lifecycleAwares(cfg));
// Lifecycle notification.
notifyLifecycleBeansEx(LifecycleEventType.AFTER_NODE_STOP);
// Clean internal class/classloader caches to avoid stopped contexts held in memory.
U.clearClassCache();
MarshallerExclusions.clearCache();
BinaryEnumCache.clear();
gw.writeLock();
try {
gw.setState(STOPPED);
} finally {
gw.writeUnlock();
}
// Ack stop.
if (log.isQuiet()) {
String nodeName = igniteInstanceName == null ? "" : "name=" + igniteInstanceName + ", ";
if (!errOnStop)
U.quiet(false, "Ignite node stopped OK [" + nodeName + "uptime=" + X.timeSpan2DHMSM(U.currentTimeMillis() - startTime) + ']');
else
U.quiet(true, "Ignite node stopped wih ERRORS [" + nodeName + "uptime=" + X.timeSpan2DHMSM(U.currentTimeMillis() - startTime) + ']');
}
if (log.isInfoEnabled())
if (!errOnStop) {
String ack = "Ignite ver. " + VER_STR + '#' + BUILD_TSTAMP_STR + "-sha1:" + REV_HASH_STR + " stopped OK";
String dash = U.dash(ack.length());
log.info(NL + NL + ">>> " + dash + NL + ">>> " + ack + NL + ">>> " + dash + NL + (igniteInstanceName == null ? "" : ">>> Ignite instance name: " + igniteInstanceName + NL) + ">>> Grid uptime: " + X.timeSpan2DHMSM(U.currentTimeMillis() - startTime) + NL + NL);
} else {
String ack = "Ignite ver. " + VER_STR + '#' + BUILD_TSTAMP_STR + "-sha1:" + REV_HASH_STR + " stopped with ERRORS";
String dash = U.dash(ack.length());
log.info(NL + NL + ">>> " + ack + NL + ">>> " + dash + NL + (igniteInstanceName == null ? "" : ">>> Ignite instance name: " + igniteInstanceName + NL) + ">>> Grid uptime: " + X.timeSpan2DHMSM(U.currentTimeMillis() - startTime) + NL + ">>> See log above for detailed error message." + NL + ">>> Note that some errors during stop can prevent grid from" + NL + ">>> maintaining correct topology since this node may have" + NL + ">>> not exited grid properly." + NL + NL);
}
try {
U.onGridStop();
} catch (InterruptedException ignored) {
// Preserve interrupt status.
Thread.currentThread().interrupt();
}
} else {
// Proper notification.
if (log.isDebugEnabled()) {
if (gw.getState() == STOPPED)
log.debug("Grid is already stopped. Nothing to do.");
else
log.debug("Grid is being stopped by another thread. Aborting this stop sequence " + "allowing other thread to finish.");
}
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheProcessor in project ignite by apache.
the class GridDhtPartitionsExchangeFuture method ensureClientCachesStarted.
/**
* Start client caches if absent.
*/
private void ensureClientCachesStarted() {
GridCacheProcessor cacheProcessor = cctx.cache();
Set<String> cacheNames = new HashSet<>(cacheProcessor.cacheNames());
List<CacheConfiguration> notStartedCacheConfigs = new ArrayList<>();
for (CacheConfiguration cCfg : cctx.gridConfig().getCacheConfiguration()) {
if (!cacheNames.contains(cCfg.getName()) && !GridCacheUtils.isCacheTemplateName(cCfg.getName()))
notStartedCacheConfigs.add(cCfg);
}
if (!notStartedCacheConfigs.isEmpty())
cacheProcessor.dynamicStartCaches(notStartedCacheConfigs, false, false, false);
}
use of org.apache.ignite.internal.processors.cache.GridCacheProcessor in project ignite by apache.
the class VisorNodeDataCollectorJob method caches.
/**
* Collect caches.
*
* @param res Job result.
* @param arg Task argument.
*/
protected void caches(VisorNodeDataCollectorJobResult res, VisorNodeDataCollectorTaskArg arg) {
try {
IgniteConfiguration cfg = ignite.configuration();
GridCacheProcessor cacheProc = ignite.context().cache();
Set<String> cacheGrps = arg.getCacheGroups();
boolean all = F.isEmpty(cacheGrps);
int partitions = 0;
double total = 0;
double ready = 0;
List<VisorCache> resCaches = res.getCaches();
boolean rebalanceInProgress = false;
for (CacheGroupContext grp : cacheProc.cacheGroups()) {
boolean first = true;
for (GridCacheContext cache : grp.caches()) {
long start0 = U.currentTimeMillis();
String cacheName = cache.name();
try {
if (isProxyCache(ignite, cacheName) || isRestartingCache(ignite, cacheName))
continue;
GridCacheAdapter ca = cacheProc.internalCache(cacheName);
if (ca == null || !ca.context().started())
continue;
if (first) {
CacheMetrics cm = ca.localMetrics();
partitions += cm.getTotalPartitionsCount();
long keysTotal = cm.getEstimatedRebalancingKeys();
long keysReady = cm.getRebalancedKeys();
if (keysReady >= keysTotal)
keysReady = Math.max(keysTotal - 1, 0);
total += keysTotal;
ready += keysReady;
if (!rebalanceInProgress && cm.getRebalancingPartitionsCount() > 0)
rebalanceInProgress = true;
first = false;
}
boolean addToRes = arg.getSystemCaches() || !(isSystemCache(cacheName));
if (addToRes && (all || cacheGrps.contains(ca.configuration().getGroupName())))
resCaches.add(new VisorCache(ignite, ca, arg.isCollectCacheMetrics()));
} catch (IllegalStateException | IllegalArgumentException e) {
if (debug && ignite.log() != null)
ignite.log().error("Ignored cache: " + cacheName, e);
} finally {
if (debug)
log(ignite.log(), "Collected cache: " + cacheName, getClass(), start0);
}
}
}
if (partitions == 0)
res.setRebalance(NOTHING_TO_REBALANCE);
else if (total == 0 && rebalanceInProgress)
res.setRebalance(MINIMAL_REBALANCE);
else
res.setRebalance(total > 0 && rebalanceInProgress ? Math.max(ready / total, MINIMAL_REBALANCE) : REBALANCE_COMPLETE);
} catch (Exception e) {
res.setRebalance(REBALANCE_NOT_AVAILABLE);
res.setCachesEx(new VisorExceptionWrapper(e));
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheProcessor in project ignite by apache.
the class GridHistoryAffinityAssignmentTest method affinityCache.
/**
* @param ignite Ignite.
*/
private GridAffinityAssignmentCache affinityCache(IgniteEx ignite) {
GridCacheProcessor proc = ignite.context().cache();
GridCacheContext cctx = proc.context().cacheContext(CU.cacheId(DEFAULT_CACHE_NAME));
return GridTestUtils.getFieldValue(cctx.affinity(), "aff");
}
use of org.apache.ignite.internal.processors.cache.GridCacheProcessor in project ignite by apache.
the class GridContinuousProcessor method processStartRequestV2.
/**
* @param topVer Current topology version.
* @param snd Sender.
* @param msg Start request.
*/
private void processStartRequestV2(final AffinityTopologyVersion topVer, final ClusterNode snd, final StartRoutineDiscoveryMessageV2 msg) {
StartRequestDataV2 reqData = msg.startRequestData();
ContinuousRoutineInfo routineInfo = new ContinuousRoutineInfo(snd.id(), msg.routineId(), reqData.handlerBytes(), reqData.nodeFilterBytes(), reqData.bufferSize(), reqData.interval(), reqData.autoUnsubscribe());
routinesInfo.addRoutineInfo(routineInfo);
final DiscoCache discoCache = ctx.discovery().discoCache(topVer);
// Should not use marshaller and send messages from discovery thread.
ctx.pools().getSystemExecutorService().execute(new Runnable() {
@Override
public void run() {
if (snd.id().equals(ctx.localNodeId())) {
StartFuture fut = startFuts.get(msg.routineId());
if (fut != null)
fut.initRemoteNodes(discoCache);
return;
}
StartRequestDataV2 reqData = msg.startRequestData();
Exception err = null;
IgnitePredicate<ClusterNode> nodeFilter = null;
byte[] cntrs = null;
if (reqData.nodeFilterBytes() != null) {
try {
if (ctx.config().isPeerClassLoadingEnabled() && reqData.className() != null) {
String clsName = reqData.className();
GridDeploymentInfo depInfo = reqData.deploymentInfo();
GridDeployment dep = ctx.deploy().getGlobalDeployment(depInfo.deployMode(), clsName, clsName, depInfo.userVersion(), snd.id(), depInfo.classLoaderId(), depInfo.participants(), null);
if (dep == null) {
throw new IgniteDeploymentCheckedException("Failed to obtain deployment " + "for class: " + clsName);
}
nodeFilter = U.unmarshal(marsh, reqData.nodeFilterBytes(), U.resolveClassLoader(dep.classLoader(), ctx.config()));
} else {
nodeFilter = U.unmarshal(marsh, reqData.nodeFilterBytes(), U.resolveClassLoader(ctx.config()));
}
if (nodeFilter != null)
ctx.resource().injectGeneric(nodeFilter);
} catch (Exception e) {
err = e;
U.error(log, "Failed to unmarshal continuous routine filter [" + "routineId=" + msg.routineId + ", srcNodeId=" + snd.id() + ']', e);
}
}
boolean register = err == null && (nodeFilter == null || nodeFilter.apply(ctx.discovery().localNode()));
if (register) {
try {
GridContinuousHandler hnd = U.unmarshal(marsh, reqData.handlerBytes(), U.resolveClassLoader(ctx.config()));
if (ctx.config().isPeerClassLoadingEnabled())
hnd.p2pUnmarshal(snd.id(), ctx);
if (msg.keepBinary()) {
assert hnd instanceof CacheContinuousQueryHandler : hnd;
((CacheContinuousQueryHandler) hnd).keepBinary(true);
}
registerHandler(snd.id(), msg.routineId, hnd, reqData.bufferSize(), reqData.interval(), reqData.autoUnsubscribe(), false);
if (hnd.isQuery()) {
GridCacheProcessor proc = ctx.cache();
if (proc != null) {
GridCacheAdapter cache = ctx.cache().internalCache(hnd.cacheName());
if (cache != null && !cache.isLocal() && cache.context().userCache()) {
CachePartitionPartialCountersMap cntrsMap = cache.context().topology().localUpdateCounters(false);
cntrs = U.marshal(marsh, cntrsMap);
}
}
}
} catch (Exception e) {
err = e;
U.error(log, "Failed to register continuous routine handler [" + "routineId=" + msg.routineId + ", srcNodeId=" + snd.id() + ']', e);
}
}
sendMessageStartResult(snd, msg.routineId(), cntrs, err);
}
});
}
Aggregations