Search in sources :

Example 41 with GridKernalContext

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());
    }
}
Also used : IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) GridKernalContext(org.apache.ignite.internal.GridKernalContext) LightweightCheckpointManager(org.apache.ignite.internal.processors.cache.persistence.checkpoint.LightweightCheckpointManager) CheckpointManager(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointManager) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager)

Example 42 with GridKernalContext

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;
}
Also used : GridKernalContext(org.apache.ignite.internal.GridKernalContext) CacheStore(org.apache.ignite.cache.store.CacheStore) CacheJdbcPojoStore(org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStore) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CacheStoreBalancingWrapper(org.apache.ignite.internal.processors.cache.CacheStoreBalancingWrapper)

Example 43 with GridKernalContext

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);
        }
    });
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) GridQueryTypeDescriptor(org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor) Collection(java.util.Collection) GridQueryIndexDescriptor(org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor) Map(java.util.Map) HashSet(java.util.HashSet)

Example 44 with GridKernalContext

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;
}
Also used : GridKernalContext(org.apache.ignite.internal.GridKernalContext) StateChangeRequest(org.apache.ignite.internal.processors.cache.StateChangeRequest) IgniteChangeGlobalStateSupport(org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport) DiscoveryDataClusterState(org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 45 with GridKernalContext

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);
    }
}
Also used : GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) CacheGroupDescriptor(org.apache.ignite.internal.processors.cache.CacheGroupDescriptor) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) File(java.io.File)

Aggregations

GridKernalContext (org.apache.ignite.internal.GridKernalContext)61 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)14 IgniteEx (org.apache.ignite.internal.IgniteEx)13 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)12 ClusterNode (org.apache.ignite.cluster.ClusterNode)11 ArrayList (java.util.ArrayList)10 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)10 List (java.util.List)9 IgniteLogger (org.apache.ignite.IgniteLogger)9 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)9 File (java.io.File)8 Map (java.util.Map)8 UUID (java.util.UUID)8 Ignite (org.apache.ignite.Ignite)8 IgniteKernal (org.apache.ignite.internal.IgniteKernal)8 Nullable (org.jetbrains.annotations.Nullable)8 Test (org.junit.Test)8 Collection (java.util.Collection)7 IgniteException (org.apache.ignite.IgniteException)7 FilePageStoreManager (org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager)7