use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class GridEncryptionManager method onReadyForReadWrite.
/**
* {@inheritDoc}
*/
@Override
public void onReadyForReadWrite(ReadWriteMetastorage metaStorage) throws IgniteCheckedException {
withMasterKeyChangeReadLock(() -> {
synchronized (metaStorageMux) {
this.metaStorage = metaStorage;
writeToMetaStoreEnabled = true;
if (recoveryMasterKeyName)
writeKeysToWal();
writeKeysToMetaStore(restoredFromWAL || recoveryMasterKeyName);
restoredFromWAL = false;
recoveryMasterKeyName = false;
}
return null;
});
for (Map.Entry<Integer, Integer> entry : reencryptGroupsForced.entrySet()) {
int grpId = entry.getKey();
if (reencryptGroups.containsKey(grpId))
continue;
if (entry.getValue() != getActiveKey(grpId).unsignedId())
continue;
CacheGroupContext grp = ctx.cache().cacheGroup(grpId);
if (grp == null || !grp.affinityNode())
continue;
long[] offsets = pageScanner.pagesCount(grp);
reencryptGroups.put(grpId, offsets);
}
reencryptGroupsForced.clear();
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class MvccProcessorImpl method continueRunVacuum.
/**
* @param res Result.
* @param snapshot Snapshot.
*/
private void continueRunVacuum(GridFutureAdapter<VacuumMetrics> res, MvccSnapshot snapshot) {
ackTxCommit(snapshot).listen(new IgniteInClosure<IgniteInternalFuture>() {
@Override
public void apply(IgniteInternalFuture fut) {
Throwable err;
if ((err = fut.error()) != null) {
U.error(log, "Vacuum error.", err);
res.onDone(err);
} else if (snapshot.cleanupVersion() <= MVCC_COUNTER_NA)
res.onDone(new VacuumMetrics());
else {
try {
if (log.isDebugEnabled())
log.debug("Started vacuum with cleanup version=" + snapshot.cleanupVersion() + '.');
synchronized (mux) {
if (cleanupQueue == null) {
res.onDone(vacuumCancelledException());
return;
}
GridCompoundIdentityFuture<VacuumMetrics> res0 = new GridCompoundIdentityFuture<VacuumMetrics>(new VacuumMetricsReducer()) {
/**
* {@inheritDoc}
*/
@Override
protected void logError(IgniteLogger log, String msg, Throwable e) {
// no-op
}
/**
* {@inheritDoc}
*/
@Override
protected void logDebug(IgniteLogger log, String msg) {
// no-op
}
};
for (CacheGroupContext grp : ctx.cache().cacheGroups()) {
if (grp.mvccEnabled()) {
grp.topology().readLock();
try {
for (GridDhtLocalPartition part : grp.topology().localPartitions()) {
VacuumTask task = new VacuumTask(snapshot, part);
cleanupQueue.offer(task);
res0.add(task);
}
} finally {
grp.topology().readUnlock();
}
}
}
res0.markInitialized();
res0.listen(future -> {
VacuumMetrics metrics = null;
Throwable ex = null;
try {
metrics = future.get();
txLog.removeUntil(snapshot.coordinatorVersion(), snapshot.cleanupVersion());
if (log.isDebugEnabled())
log.debug("Vacuum completed. " + metrics);
} catch (Throwable e) {
if (X.hasCause(e, NodeStoppingException.class)) {
if (log.isDebugEnabled())
log.debug("Cannot complete vacuum (node is stopping).");
metrics = new VacuumMetrics();
} else
ex = new GridClosureException(e);
}
res.onDone(metrics, ex);
});
}
} catch (Throwable e) {
completeWithException(res, e);
}
}
}
});
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class SnapshotFutureTask method start.
/**
* Initiates snapshot task.
*
* @return {@code true} if task started by this call.
*/
@Override
public boolean start() {
if (stopping())
return false;
try {
if (!started.compareAndSet(false, true))
return false;
tmpConsIdDir = U.resolveWorkDirectory(tmpSnpWorkDir.getAbsolutePath(), databaseRelativePath(cctx.kernalContext().pdsFolderResolver().resolveFolders().folderName()), false);
for (Integer grpId : parts.keySet()) {
CacheGroupContext gctx = cctx.cache().cacheGroup(grpId);
if (gctx == null)
throw new IgniteCheckedException("Cache group context not found: " + grpId);
if (!CU.isPersistentCache(gctx.config(), cctx.kernalContext().config().getDataStorageConfiguration()))
throw new IgniteCheckedException("In-memory cache groups are not allowed to be snapshot: " + grpId);
// Create cache group snapshot directory on start in a single thread.
U.ensureDirectory(cacheWorkDir(tmpConsIdDir, FilePageStoreManager.cacheDirName(gctx.config())), "directory for snapshotting cache group", log);
}
if (withMetaStorage) {
U.ensureDirectory(cacheWorkDir(tmpConsIdDir, MetaStorage.METASTORAGE_DIR_NAME), "directory for snapshotting metastorage", log);
}
startedFut.listen(f -> ((GridCacheDatabaseSharedManager) cctx.database()).removeCheckpointListener(this));
// Listener will be removed right after first execution.
((GridCacheDatabaseSharedManager) cctx.database()).addCheckpointListener(this);
if (log.isInfoEnabled()) {
log.info("Snapshot operation is scheduled on local node and will be handled by the checkpoint " + "listener [sctx=" + this + ", topVer=" + cctx.discovery().topologyVersionEx() + ']');
}
} catch (IgniteCheckedException e) {
acceptException(e);
return false;
}
return true;
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class GridCommandHandlerBrokenIndexTest method addBadIndex.
/**
* Adds index that fails on {@code find()}.
*/
private void addBadIndex() {
IgniteEx ignite = grid(0);
int grpId = CU.cacheGroupId(CACHE_NAME, GROUP_NAME);
CacheGroupContext grpCtx = ignite.context().cache().cacheGroup(grpId);
assertNotNull(grpCtx);
GridQueryProcessor qry = ignite.context().query();
IgniteH2Indexing indexing = (IgniteH2Indexing) qry.getIndexing();
outer: for (GridCacheContext ctx : grpCtx.caches()) {
Collection<GridQueryTypeDescriptor> types = qry.types(ctx.name());
if (!F.isEmpty(types)) {
for (GridQueryTypeDescriptor type : types) {
GridH2Table gridH2Tbl = indexing.schemaManager().dataTable(ctx.name(), type.tableName());
if (gridH2Tbl == null)
continue;
ArrayList<Index> indexes = gridH2Tbl.getIndexes();
BadIndex bi = null;
for (Index idx : indexes) {
if (idx instanceof H2TreeIndexBase) {
bi = new BadIndex(gridH2Tbl, IDX_NAME, idx.getIndexColumns(), idx.getIndexType());
break;
}
}
if (bi != null) {
indexes.add(bi);
break outer;
}
}
}
}
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class GridCacheDatabaseSharedManager method onCacheGroupsStopped.
/**
* {@inheritDoc}
*/
@Override
public void onCacheGroupsStopped(Collection<IgniteBiTuple<CacheGroupContext, Boolean>> stoppedGrps) {
Map<PageMemoryEx, Collection<Integer>> destroyed = new HashMap<>();
List<Integer> stoppedGrpIds = stoppedGrps.stream().filter(IgniteBiTuple::get2).map(t -> t.get1().groupId()).collect(toList());
cctx.snapshotMgr().onCacheGroupsStopped(stoppedGrpIds);
initiallyLocWalDisabledGrps.removeAll(stoppedGrpIds);
initiallyGlobalWalDisabledGrps.removeAll(stoppedGrpIds);
for (IgniteBiTuple<CacheGroupContext, Boolean> tup : stoppedGrps) {
CacheGroupContext gctx = tup.get1();
boolean destroy = tup.get2();
int grpId = gctx.groupId();
DataRegion dataRegion = gctx.dataRegion();
if (dataRegion != null)
dataRegion.metrics().removeCacheGrpPageMetrics(grpId);
if (!gctx.persistenceEnabled())
continue;
snapshotMgr.onCacheGroupStop(gctx, destroy);
PageMemoryEx pageMem = (PageMemoryEx) dataRegion.pageMemory();
Collection<Integer> grpIds = destroyed.computeIfAbsent(pageMem, k -> new HashSet<>());
grpIds.add(grpId);
if (gctx.config().isEncryptionEnabled())
cctx.kernalContext().encryption().onCacheGroupStop(grpId);
pageMem.onCacheGroupDestroyed(grpId);
if (destroy)
cctx.kernalContext().encryption().onCacheGroupDestroyed(grpId);
}
Collection<IgniteInternalFuture<Void>> clearFuts = new ArrayList<>(destroyed.size());
for (Map.Entry<PageMemoryEx, Collection<Integer>> entry : destroyed.entrySet()) {
final Collection<Integer> grpIds = entry.getValue();
clearFuts.add(entry.getKey().clearAsync((grpId, pageIdg) -> grpIds.contains(grpId), false));
}
for (IgniteInternalFuture<Void> clearFut : clearFuts) {
try {
clearFut.get();
} catch (IgniteCheckedException e) {
log.error("Failed to clear page memory", e);
}
}
if (cctx.pageStore() != null) {
for (IgniteBiTuple<CacheGroupContext, Boolean> tup : stoppedGrps) {
CacheGroupContext grp = tup.get1();
try {
cctx.pageStore().shutdownForCacheGroup(grp, tup.get2());
} catch (IgniteCheckedException e) {
U.error(log, "Failed to gracefully clean page store resources for destroyed cache " + "[cache=" + grp.cacheOrGroupName() + "]", e);
}
}
}
}
Aggregations