use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.
the class GridCacheDatabaseSharedManager method start0.
/**
* {@inheritDoc}
*/
@Override
protected void start0() throws IgniteCheckedException {
super.start0();
snapshotMgr = cctx.snapshot();
IgnitePageStoreManager store = cctx.pageStore();
assert store instanceof FilePageStoreManager : "Invalid page store manager was created: " + store;
storeMgr = (FilePageStoreManager) store;
final GridKernalContext kernalCtx = cctx.kernalContext();
assert !kernalCtx.clientNode();
initWalRebalanceThreshold();
if (!kernalCtx.clientNode()) {
kernalCtx.internalSubscriptionProcessor().registerDatabaseListener(new MetastorageRecoveryLifecycle());
cpFreqDeviation = new SimpleDistributedProperty<>("checkpoint.deviation", Integer::parseInt);
kernalCtx.internalSubscriptionProcessor().registerDistributedConfigurationListener(dispatcher -> {
cpFreqDeviation.addListener((name, oldVal, newVal) -> U.log(log, "Checkpoint frequency deviation changed [oldVal=" + oldVal + ", newVal=" + newVal + "]"));
dispatcher.registerProperty(cpFreqDeviation);
});
checkpointManager = new CheckpointManager(kernalCtx::log, cctx.igniteInstanceName(), "db-checkpoint-thread", cctx.wal(), kernalCtx.workersRegistry(), persistenceCfg, storeMgr, this::isCheckpointInapplicableForWalRebalance, this::checkpointedDataRegions, this::cacheGroupContexts, this::getPageMemoryForCacheGroup, resolveThrottlingPolicy(), snapshotMgr, persistentStoreMetricsImpl(), kernalCtx.longJvmPauseDetector(), kernalCtx.failure(), kernalCtx.cache(), () -> cpFreqDeviation.getOrDefault(DEFAULT_CHECKPOINT_DEVIATION), kernalCtx.pools().getSystemExecutorService());
final NodeFileLockHolder preLocked = kernalCtx.pdsFolderResolver().resolveFolders().getLockedFileLockHolder();
acquireFileLock(preLocked);
cleanupTempCheckpointDirectory();
persStoreMetrics.wal(cctx.wal());
}
}
use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.
the class GridCacheStoreManagerAdapter method initialize.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public void initialize(@Nullable CacheStore cfgStore, Map sesHolders) throws IgniteCheckedException {
GridKernalContext ctx = igniteContext();
CacheConfiguration cfg = cacheConfiguration();
writeThrough = cfg.isWriteThrough();
readThrough = cfg.isReadThrough();
this.cfgStore = cfgStore;
store = cacheStoreWrapper(ctx, cfgStore, cfg);
singleThreadGate = store == null ? null : new CacheStoreBalancingWrapper<>(store, cfg.getStoreConcurrentLoadAllThreshold());
ThreadLocal<SessionData> sesHolder0 = null;
if (cfgStore != null) {
sesHolder0 = ((Map<CacheStore, ThreadLocal>) sesHolders).get(cfgStore);
if (sesHolder0 == null) {
sesHolder0 = new ThreadLocal<>();
locSes = new ThreadLocalSession(sesHolder0);
if (ctx.resource().injectStoreSession(cfgStore, locSes))
sesHolders.put(cfgStore, sesHolder0);
} else
locSes = new ThreadLocalSession(sesHolder0);
}
sesHolder = sesHolder0;
locStore = U.hasAnnotation(cfgStore, CacheLocalStore.class);
if (cfgStore instanceof CacheJdbcPojoStore)
alwaysKeepBinary = true;
}
use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.
the class GridCacheQuerySqlMetadataJobV2 method call.
/**
* {@inheritDoc}
*/
@Override
public Collection<GridCacheQueryManager.CacheSqlMetadata> call() {
final GridKernalContext ctx = ((IgniteKernal) ignite).context();
Collection<String> cacheNames = F.viewReadOnly(ctx.cache().caches(), new C1<IgniteInternalCache<?, ?>, String>() {
@Override
public String apply(IgniteInternalCache<?, ?> c) {
return c.name();
}
}, new P1<IgniteInternalCache<?, ?>>() {
@Override
public boolean apply(IgniteInternalCache<?, ?> c) {
return !CU.isSystemCache(c.name()) && !DataStructuresProcessor.isDataStructureCache(c.name());
}
});
return F.transform(cacheNames, new C1<String, GridCacheQueryManager.CacheSqlMetadata>() {
@Override
public GridCacheQueryManager.CacheSqlMetadata apply(String cacheName) {
Collection<GridQueryTypeDescriptor> types = ctx.query().types(cacheName);
Collection<String> names = U.newHashSet(types.size());
Map<String, String> keyClasses = U.newHashMap(types.size());
Map<String, String> valClasses = U.newHashMap(types.size());
Map<String, Map<String, String>> fields = U.newHashMap(types.size());
Map<String, Collection<GridCacheSqlIndexMetadata>> indexes = U.newHashMap(types.size());
Map<String, Set<String>> notNullFields = U.newHashMap(types.size());
for (GridQueryTypeDescriptor type : types) {
// Filter internal types (e.g., data structures).
if (type.name().startsWith("GridCache"))
continue;
names.add(type.name());
keyClasses.put(type.name(), type.keyClass().getName());
valClasses.put(type.name(), type.valueClass().getName());
int size = type.fields().isEmpty() ? NO_FIELDS_COLUMNS_COUNT : type.fields().size();
Map<String, String> fieldsMap = U.newLinkedHashMap(size);
HashSet<String> notNullFieldsSet = U.newHashSet(1);
// _KEY and _VAL are not included in GridIndexingTypeDescriptor.valueFields
if (type.fields().isEmpty()) {
fieldsMap.put("_KEY", type.keyClass().getName());
fieldsMap.put("_VAL", type.valueClass().getName());
}
for (Map.Entry<String, Class<?>> e : type.fields().entrySet()) {
String fieldName = e.getKey();
fieldsMap.put(fieldName.toUpperCase(), e.getValue().getName());
if (type.property(fieldName).notNull())
notNullFieldsSet.add(fieldName.toUpperCase());
}
fields.put(type.name(), fieldsMap);
notNullFields.put(type.name(), notNullFieldsSet);
Map<String, GridQueryIndexDescriptor> idxs = type.indexes();
Collection<GridCacheSqlIndexMetadata> indexesCol = new ArrayList<>(idxs.size());
for (Map.Entry<String, GridQueryIndexDescriptor> e : idxs.entrySet()) {
GridQueryIndexDescriptor desc = e.getValue();
// Add only SQL indexes.
if (desc.type() == QueryIndexType.SORTED) {
Collection<String> idxFields = new LinkedList<>();
Collection<String> descendings = new LinkedList<>();
for (String idxField : e.getValue().fields()) {
String idxFieldUpper = idxField.toUpperCase();
idxFields.add(idxFieldUpper);
if (desc.descending(idxField))
descendings.add(idxFieldUpper);
}
indexesCol.add(new GridCacheQueryManager.CacheSqlIndexMetadata(e.getKey().toUpperCase(), idxFields, descendings, false));
}
}
indexes.put(type.name(), indexesCol);
}
return new GridCacheQuerySqlMetadataV2(cacheName, names, keyClasses, valClasses, fields, indexes, notNullFields);
}
});
}
use of org.apache.ignite.internal.GridKernalContext 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.GridKernalContext in project ignite by apache.
the class AbstractSnapshotSelfTest method ensureCacheAbsent.
/**
* @param ccfg Cache configuration.
* @throws IgniteCheckedException if failed.
*/
protected void ensureCacheAbsent(CacheConfiguration<?, ?> ccfg) throws IgniteCheckedException {
String cacheName = ccfg.getName();
for (Ignite ignite : G.allGrids()) {
GridKernalContext kctx = ((IgniteEx) ignite).context();
if (kctx.clientNode())
continue;
CacheGroupDescriptor desc = kctx.cache().cacheGroupDescriptors().get(CU.cacheId(cacheName));
assertNull("nodeId=" + kctx.localNodeId() + ", cache=" + cacheName, desc);
boolean success = GridTestUtils.waitForCondition(() -> !kctx.cache().context().snapshotMgr().isRestoring(), TIMEOUT);
assertTrue("The process has not finished on the node " + kctx.localNodeId(), success);
File dir = ((FilePageStoreManager) kctx.cache().context().pageStore()).cacheWorkDir(ccfg);
String errMsg = String.format("%s, dir=%s, exists=%b, files=%s", ignite.name(), dir, dir.exists(), Arrays.toString(dir.list()));
assertTrue(errMsg, !dir.exists() || dir.list().length == 0);
}
}
Aggregations