use of org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.CACHE_GRP_DIR_PREFIX in project ignite by apache.
the class SnapshotRestoreProcess method prepareContext.
/**
* @param req Request to prepare cache group restore from the snapshot.
* @param metas Local snapshot metadatas.
* @return Snapshot restore operation context.
* @throws IgniteCheckedException If failed.
*/
private SnapshotRestoreContext prepareContext(SnapshotOperationRequest req, Collection<SnapshotMetadata> metas) throws IgniteCheckedException {
if (opCtx != null) {
throw new IgniteCheckedException(OP_REJECT_MSG + "The previous snapshot restore operation was not completed.");
}
GridCacheSharedContext<?, ?> cctx = ctx.cache().context();
// Collection of baseline nodes that must survive and additional discovery data required for the affinity calculation.
DiscoCache discoCache = ctx.discovery().discoCache();
if (!F.transform(discoCache.aliveBaselineNodes(), F.node2id()).containsAll(req.nodes()))
throw new IgniteCheckedException("Restore context cannot be inited since the required baseline nodes missed: " + discoCache);
DiscoCache discoCache0 = discoCache.copy(discoCache.version(), null);
if (F.isEmpty(metas))
return new SnapshotRestoreContext(req, discoCache0, Collections.emptyMap());
if (F.first(metas).pageSize() != cctx.database().pageSize()) {
throw new IgniteCheckedException("Incompatible memory page size " + "[snapshotPageSize=" + F.first(metas).pageSize() + ", local=" + cctx.database().pageSize() + ", snapshot=" + req.snapshotName() + ", nodeId=" + cctx.localNodeId() + ']');
}
Map<String, StoredCacheData> cfgsByName = new HashMap<>();
FilePageStoreManager pageStore = (FilePageStoreManager) cctx.pageStore();
// Metastorage can be restored only manually by directly copying files.
for (SnapshotMetadata meta : metas) {
for (File snpCacheDir : cctx.snapshotMgr().snapshotCacheDirectories(req.snapshotName(), meta.folderName(), name -> !METASTORAGE_CACHE_NAME.equals(name))) {
String grpName = FilePageStoreManager.cacheGroupName(snpCacheDir);
if (!F.isEmpty(req.groups()) && !req.groups().contains(grpName))
continue;
File cacheDir = pageStore.cacheWorkDir(snpCacheDir.getName().startsWith(CACHE_GRP_DIR_PREFIX), grpName);
if (cacheDir.exists()) {
if (!cacheDir.isDirectory()) {
throw new IgniteCheckedException("Unable to restore cache group, file with required directory " + "name already exists [group=" + grpName + ", file=" + cacheDir + ']');
}
if (cacheDir.list().length > 0) {
throw new IgniteCheckedException("Unable to restore cache group - directory is not empty. " + "Cache group should be destroyed manually before perform restore operation " + "[group=" + grpName + ", dir=" + cacheDir + ']');
}
if (!cacheDir.delete()) {
throw new IgniteCheckedException("Unable to remove empty cache directory " + "[group=" + grpName + ", dir=" + cacheDir + ']');
}
}
File tmpCacheDir = formatTmpDirName(cacheDir);
if (tmpCacheDir.exists()) {
throw new IgniteCheckedException("Unable to restore cache group, temp directory already exists " + "[group=" + grpName + ", dir=" + tmpCacheDir + ']');
}
pageStore.readCacheConfigurations(snpCacheDir, cfgsByName);
}
}
Map<Integer, StoredCacheData> cfgsById = cfgsByName.values().stream().collect(Collectors.toMap(v -> CU.cacheId(v.config().getName()), v -> v));
return new SnapshotRestoreContext(req, discoCache0, cfgsById);
}
Aggregations