Search in sources :

Example 36 with GridKernalContext

use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.

the class IgniteSnapshotManager method checkSnapshot.

/**
 * The check snapshot procedure performs compute operation over the whole cluster to verify the snapshot
 * entirety and partitions consistency. The result future will be completed with an exception if this
 * exception is not related to the check procedure, and will be completed normally with the {@code IdleVerifyResult}.
 *
 * @param name Snapshot name.
 * @param grps Collection of cache group names to check.
 * @param includeCustomHandlers {@code True} to invoke all user-defined {@link SnapshotHandlerType#RESTORE}
 *                              handlers, otherwise only system consistency check will be performed.
 * @return Future with the result of execution snapshot partitions verify task, which besides calculating partition
 *         hashes of {@link IdleVerifyResultV2} also contains the snapshot metadata distribution across the cluster.
 */
public IgniteInternalFuture<SnapshotPartitionsVerifyTaskResult> checkSnapshot(String name, @Nullable Collection<String> grps, boolean includeCustomHandlers) {
    A.notNullOrEmpty(name, "Snapshot name cannot be null or empty.");
    A.ensure(U.alphanumericUnderscore(name), "Snapshot name must satisfy the following name pattern: a-zA-Z0-9_");
    A.ensure(grps == null || grps.stream().filter(Objects::isNull).collect(Collectors.toSet()).isEmpty(), "Collection of cache groups names cannot contain null elements.");
    GridFutureAdapter<SnapshotPartitionsVerifyTaskResult> res = new GridFutureAdapter<>();
    GridKernalContext kctx0 = cctx.kernalContext();
    Collection<ClusterNode> bltNodes = F.view(cctx.discovery().serverNodes(AffinityTopologyVersion.NONE), (node) -> CU.baselineNode(node, kctx0.state().clusterState()));
    kctx0.task().setThreadContext(TC_SKIP_AUTH, true);
    kctx0.task().setThreadContext(TC_SUBGRID, bltNodes);
    kctx0.task().execute(SnapshotMetadataCollectorTask.class, name).listen(f0 -> {
        if (f0.error() == null) {
            Map<ClusterNode, List<SnapshotMetadata>> metas = f0.result();
            Map<Integer, String> grpIds = grps == null ? Collections.emptyMap() : grps.stream().collect(Collectors.toMap(CU::cacheId, v -> v));
            for (List<SnapshotMetadata> nodeMetas : metas.values()) {
                for (SnapshotMetadata meta : nodeMetas) grpIds.keySet().removeAll(meta.partitions().keySet());
            }
            if (!grpIds.isEmpty()) {
                res.onDone(new SnapshotPartitionsVerifyTaskResult(metas, new IdleVerifyResultV2(Collections.singletonMap(cctx.localNode(), new IllegalArgumentException("Cache group(s) was not " + "found in the snapshot [groups=" + grpIds.values() + ", snapshot=" + name + ']')))));
                return;
            }
            kctx0.task().setThreadContext(TC_SKIP_AUTH, true);
            kctx0.task().setThreadContext(TC_SUBGRID, new ArrayList<>(metas.keySet()));
            Class<? extends AbstractSnapshotVerificationTask> cls = includeCustomHandlers ? SnapshotHandlerRestoreTask.class : SnapshotPartitionsVerifyTask.class;
            kctx0.task().execute(cls, new SnapshotPartitionsVerifyTaskArg(grps, metas)).listen(f1 -> {
                if (f1.error() == null)
                    res.onDone(f1.result());
                else if (f1.error() instanceof IgniteSnapshotVerifyException)
                    res.onDone(new SnapshotPartitionsVerifyTaskResult(metas, new IdleVerifyResultV2(((IgniteSnapshotVerifyException) f1.error()).exceptions())));
                else
                    res.onDone(f1.error());
            });
        } else {
            if (f0.error() instanceof IgniteSnapshotVerifyException)
                res.onDone(new SnapshotPartitionsVerifyTaskResult(null, new IdleVerifyResultV2(((IgniteSnapshotVerifyException) f0.error()).exceptions())));
            else
                res.onDone(f0.error());
        }
    });
    return res;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) StandaloneGridKernalContext(org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext) GridKernalContext(org.apache.ignite.internal.GridKernalContext) PageIdUtils.toDetailString(org.apache.ignite.internal.pagemem.PageIdUtils.toDetailString) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CU(org.apache.ignite.internal.util.typedef.internal.CU) Objects(java.util.Objects) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) List(java.util.List) IdleVerifyResultV2(org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2)

Example 37 with GridKernalContext

use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.

the class CacheObjectImpl method value.

/**
 * {@inheritDoc}
 */
@Nullable
@Override
public <T> T value(CacheObjectValueContext ctx, boolean cpy, ClassLoader ldr) {
    cpy = cpy && needCopy(ctx);
    try {
        GridKernalContext kernalCtx = ctx.kernalContext();
        IgniteCacheObjectProcessor proc = ctx.kernalContext().cacheObjects();
        if (cpy) {
            if (valBytes == null) {
                assert val != null;
                valBytes = proc.marshal(ctx, val);
            }
            if (ldr == null) {
                if (val != null)
                    ldr = val.getClass().getClassLoader();
                else if (kernalCtx.config().isPeerClassLoadingEnabled())
                    ldr = kernalCtx.cache().context().deploy().globalLoader();
            }
            return (T) proc.unmarshal(ctx, valBytes, ldr);
        }
        if (val != null)
            return (T) val;
        assert valBytes != null;
        Object val = proc.unmarshal(ctx, valBytes, kernalCtx.config().isPeerClassLoadingEnabled() ? kernalCtx.cache().context().deploy().globalLoader() : null);
        if (ctx.storeValue())
            this.val = val;
        return (T) val;
    } catch (IgniteCheckedException e) {
        throw new IgniteException("Failed to unmarshall object.", e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteCacheObjectProcessor(org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor) IgniteException(org.apache.ignite.IgniteException) Nullable(org.jetbrains.annotations.Nullable)

Example 38 with GridKernalContext

use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.

the class IgniteWalIteratorFactory method prepareSharedCtx.

/**
 * @return Fake shared context required for create minimal services for record reading.
 */
@NotNull
private GridCacheSharedContext prepareSharedCtx(IteratorParametersBuilder iteratorParametersBuilder) throws IgniteCheckedException {
    GridKernalContext kernalCtx = new StandaloneGridKernalContext(log, iteratorParametersBuilder.binaryMetadataFileStoreDir, iteratorParametersBuilder.marshallerMappingFileStoreDir);
    StandaloneIgniteCacheDatabaseSharedManager dbMgr = new StandaloneIgniteCacheDatabaseSharedManager();
    dbMgr.setPageSize(iteratorParametersBuilder.pageSize);
    return new GridCacheSharedContext<>(kernalCtx, null, null, null, null, null, null, dbMgr, null, null, null, null, null, null, null, null, null, null, null, null, null);
}
Also used : GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) NotNull(org.jetbrains.annotations.NotNull)

Example 39 with GridKernalContext

use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.

the class JdbcQueryMultipleStatementsTask method call.

/**
 * {@inheritDoc}
 */
@Override
public List<JdbcStatementResultInfo> call() throws Exception {
    SqlFieldsQuery qry = (isQry != null ? new SqlFieldsQueryEx(sql, isQry) : new SqlFieldsQuery(sql)).setArgs(args);
    qry.setPageSize(fetchSize);
    qry.setLocal(locQry);
    qry.setCollocated(collocatedQry);
    qry.setDistributedJoins(distributedJoins);
    qry.setEnforceJoinOrder(enforceJoinOrder);
    qry.setLazy(lazy);
    qry.setSchema(schemaName);
    if (!F.isEmpty(queryInitiatorId()))
        qry.setQueryInitiatorId(queryInitiatorId());
    GridKernalContext ctx = ((IgniteKernal) ignite).context();
    List<FieldsQueryCursor<List<?>>> curs = ctx.query().querySqlFields(qry, true, !allowMultipleStatements());
    List<JdbcStatementResultInfo> resultsInfo = new ArrayList<>(curs.size());
    for (FieldsQueryCursor<List<?>> cur0 : curs) {
        if (cur0 instanceof BulkLoadContextCursor) {
            curs.forEach(QueryCursor::close);
            throw new SQLException("COPY command is currently supported only in thin JDBC driver.");
        }
        QueryCursorImpl<List<?>> cur = (QueryCursorImpl<List<?>>) cur0;
        long updCnt = -1;
        UUID qryId = null;
        if (!cur.isQuery()) {
            List<List<?>> items = cur.getAll();
            assert items != null && items.size() == 1 && items.get(0).size() == 1 && items.get(0).get(0) instanceof Long : "Invalid result set for not-SELECT query. [qry=" + sql + ", res=" + S.toString(List.class, items) + ']';
            updCnt = (Long) items.get(0).get(0);
            cur.close();
        } else {
            qryId = UUID.randomUUID();
            JdbcQueryTask.Cursor jdbcCur = new JdbcQueryTask.Cursor(cur, cur.iterator());
            JdbcQueryTask.addCursor(qryId, jdbcCur);
            if (!loc)
                JdbcQueryTask.scheduleRemoval(qryId);
        }
        JdbcStatementResultInfo resInfo = new JdbcStatementResultInfo(cur.isQuery(), qryId, updCnt);
        resultsInfo.add(resInfo);
    }
    return resultsInfo;
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) BulkLoadContextCursor(org.apache.ignite.cache.query.BulkLoadContextCursor) SQLException(java.sql.SQLException) GridKernalContext(org.apache.ignite.internal.GridKernalContext) ArrayList(java.util.ArrayList) QueryCursorImpl(org.apache.ignite.internal.processors.cache.QueryCursorImpl) QueryCursor(org.apache.ignite.cache.query.QueryCursor) BulkLoadContextCursor(org.apache.ignite.cache.query.BulkLoadContextCursor) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) QueryCursor(org.apache.ignite.cache.query.QueryCursor) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor)

Example 40 with GridKernalContext

use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.

the class GridCacheDatabaseSharedManager method prepareCacheDefragmentation.

/**
 */
private void prepareCacheDefragmentation(List<String> cacheNames) throws IgniteCheckedException {
    GridKernalContext kernalCtx = cctx.kernalContext();
    DataStorageConfiguration dsCfg = kernalCtx.config().getDataStorageConfiguration();
    assert CU.isPersistenceEnabled(dsCfg);
    List<DataRegion> regions = Arrays.asList(dataRegion(DEFRAGMENTATION_MAPPING_REGION_NAME), dataRegion(DEFRAGMENTATION_PART_REGION_NAME));
    LightweightCheckpointManager lightCheckpointMgr = new LightweightCheckpointManager(kernalCtx::log, cctx.igniteInstanceName(), "db-checkpoint-thread-defrag", kernalCtx.workersRegistry(), persistenceCfg, () -> regions, this::getPageMemoryForCacheGroup, resolveThrottlingPolicy(), snapshotMgr, persistentStoreMetricsImpl(), kernalCtx.longJvmPauseDetector(), kernalCtx.failure(), kernalCtx.cache());
    lightCheckpointMgr.start();
    defrgMgr = new CachePartitionDefragmentationManager(cacheNames, cctx, this, (FilePageStoreManager) cctx.pageStore(), checkpointManager, lightCheckpointMgr, persistenceCfg.getPageSize(), persistenceCfg.getDefragmentationThreadPoolSize());
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) LightweightCheckpointManager(org.apache.ignite.internal.processors.cache.persistence.checkpoint.LightweightCheckpointManager) GridKernalContext(org.apache.ignite.internal.GridKernalContext) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) CachePartitionDefragmentationManager(org.apache.ignite.internal.processors.cache.persistence.defragmentation.CachePartitionDefragmentationManager)

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