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;
}
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);
}
}
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);
}
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;
}
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());
}
Aggregations