Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-24424 Move cacheWorkDir, cacheDir to NodeFileTree #11857

Merged
merged 11 commits into from
Feb 10, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public class AbstractBasicIntegrationTest extends GridCommonAbstractTest {

/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
cleanPersistenceDir();

startGrids(nodeCount());

client = startClientGrid("client");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.ignite.cluster.ClusterState;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.G;
import org.apache.ignite.lang.IgnitePredicate;
Expand Down Expand Up @@ -343,11 +342,7 @@ private Ignite prepareGridForTest() throws Exception {
* Get index partition file for specific node and cache.
*/
private File indexPartition(Ignite ig, String groupName) {
IgniteEx ig0 = (IgniteEx)ig;

FilePageStoreManager pageStoreMgr = ((FilePageStoreManager)ig0.context().cache().context().pageStore());

return new File(pageStoreMgr.cacheWorkDir(true, groupName), INDEX_FILE_NAME);
return new File(((IgniteEx)ig).context().pdsFolderResolver().fileTree().cacheStorage(true, groupName), INDEX_FILE_NAME);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ private CdcFileLockHolder lockPds() throws IgniteCheckedException {
CdcFileLockHolder lock = settings.getLockedFileLockHolder();

if (lock == null) {
File consIdDir = settings.persistentStoreNodePath();
File consIdDir = ft.nodeStorage();

lock = tryLock(consIdDir);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.apache.ignite.internal.processors.cache.GridCacheProcessor;
import org.apache.ignite.internal.processors.cache.persistence.CheckCorruptedCacheStoresCleanAction;
import org.apache.ignite.internal.processors.cache.persistence.CleanCacheStoresMaintenanceAction;
import org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager;
import org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree;
import org.apache.ignite.internal.processors.task.GridInternal;
import org.apache.ignite.internal.util.typedef.internal.CU;
import org.apache.ignite.internal.util.typedef.internal.U;
Expand All @@ -57,7 +57,6 @@
import org.jetbrains.annotations.Nullable;

import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.CORRUPTED_DATA_FILES_MNTC_TASK_NAME;
import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.cacheDirName;

/** */
@GridInternal
Expand All @@ -78,6 +77,9 @@ private static class PersistenceJob extends VisorJob<PersistenceTaskArg, Persist
/** */
private static final long serialVersionUID = 0L;

/** Node file tree. */
private transient NodeFileTree ft;

/**
* Create job with specified argument.
*
Expand All @@ -93,6 +95,8 @@ protected PersistenceJob(@Nullable PersistenceTaskArg arg, boolean debug) {
if (!ignite.context().maintenanceRegistry().isMaintenanceMode())
return new PersistenceTaskResult(false);

ft = ignite.context().pdsFolderResolver().fileTree();

if (arg instanceof PersistenceCleanAllTaskArg
|| arg instanceof PersistenceCleanCorruptedTaskArg
|| arg instanceof PersistenceCleanCachesTaskArg)
Expand All @@ -110,32 +114,30 @@ private PersistenceTaskResult backup(PersistenceTaskArg arg) {
MaintenanceRegistry mntcReg = ignite.context().maintenanceRegistry();
MaintenanceTask task = mntcReg.activeMaintenanceTask(CORRUPTED_DATA_FILES_MNTC_TASK_NAME);

File workDir = ignite.context().pdsFolderResolver().fileTree().nodeStorage();

if (arg instanceof PersistenceBackupAllTaskArg)
return backupAll(workDir);
return backupAll();
else if (arg instanceof PersistenceBackupCorruptedTaskArg)
return backupCaches(workDir, corruptedCacheDirectories(task));
return backupCaches(corruptedCacheDirectories(task));
else
return backupCaches(workDir, cacheDirectoriesFromCacheNames(((PersistenceBackupCachesTaskArg)arg).caches()));
return backupCaches(cacheDirectoriesFromCacheNames(((PersistenceBackupCachesTaskArg)arg).caches()));
}

/** */
private PersistenceTaskResult backupAll(File workDir) {
private PersistenceTaskResult backupAll() {
GridCacheProcessor cacheProc = ignite.context().cache();

List<String> allCacheDirs = cacheProc.cacheDescriptors()
.values()
.stream()
.map(desc -> cacheDirName(desc.cacheConfiguration()))
.map(desc -> ft.cacheDirName(desc.cacheConfiguration()))
.distinct()
.collect(Collectors.toList());

return backupCaches(workDir, allCacheDirs);
return backupCaches(allCacheDirs);
}

/** */
private PersistenceTaskResult backupCaches(File workDir, List<String> cacheDirs) {
private PersistenceTaskResult backupCaches(List<String> cacheDirs) {
PersistenceTaskResult res = new PersistenceTaskResult(true);

List<String> backupCompletedCaches = new ArrayList<>();
Expand All @@ -144,13 +146,13 @@ private PersistenceTaskResult backupCaches(File workDir, List<String> cacheDirs)
for (String dir : cacheDirs) {
String backupDirName = BACKUP_FOLDER_PREFIX + dir;

File backupDir = new File(workDir, backupDirName);
File backupDir = new File(ft.nodeStorage(), backupDirName);

if (!backupDir.exists()) {
try {
U.ensureDirectory(backupDir, backupDirName, null);

copyCacheFiles(workDir.toPath().resolve(dir).toFile(), backupDir);
copyCacheFiles(ft.nodeStorage().toPath().resolve(dir).toFile(), backupDir);

backupCompletedCaches.add(backupDirName);
}
Expand Down Expand Up @@ -228,7 +230,7 @@ private PersistenceTaskResult cleanCaches(
try {
pageStore.cleanupPersistentSpace(cacheDescr.cacheConfiguration());

cleanedCaches.add(cacheDirName(cacheDescr.cacheConfiguration()));
cleanedCaches.add(ft.cacheDirName(cacheDescr.cacheConfiguration()));
}
catch (IgniteCheckedException e) {
failedToCleanCaches.add(name);
Expand Down Expand Up @@ -268,7 +270,7 @@ private PersistenceTaskResult cleanAll(GridCacheProcessor cacheProc, Maintenance
List<String> allCacheDirs = cacheProc.cacheDescriptors()
.values()
.stream()
.map(desc -> cacheDirName(desc.cacheConfiguration()))
.map(desc -> ft.cacheDirName(desc.cacheConfiguration()))
.collect(Collectors.toList());

try {
Expand Down Expand Up @@ -392,7 +394,7 @@ private List<String> cacheDirectoriesFromCacheNames(String[] cacheNames) {
.filter(s ->
CU.isPersistentCache(cacheProc.cacheDescriptor(s).cacheConfiguration(), dsCfg))
.map(s -> cacheProc.cacheDescriptor(s).cacheConfiguration())
.map(FilePageStoreManager::cacheDirName)
.map(ft::cacheDirName)
.distinct()
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private IgniteInternalFuture<?> persistCacheConfigurations(List<StoredCacheData>
for (StoredCacheData data : cacheConfigsToPersist) {
try {
FilePageStoreManager.checkAndInitCacheWorkDir(
cctx.cache().configManager().cacheWorkDir(data.config()),
cctx.kernalContext().pdsFolderResolver().fileTree().cacheStorage(data.config()),
log
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
import static org.apache.ignite.internal.GridComponent.DiscoveryDataExchangeType.CACHE_PROC;
import static org.apache.ignite.internal.processors.cache.GridCacheProcessor.CLUSTER_READ_ONLY_MODE_ERROR_MSG_FORMAT;
import static org.apache.ignite.internal.processors.cache.GridLocalConfigManager.validateIncomingConfiguration;
import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.cacheDirName;
import static org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.SNP_IN_PROGRESS_ERR_MSG;

/**
Expand Down Expand Up @@ -1202,7 +1201,7 @@ private boolean containsInvalidFileNameChars(CacheConfiguration<?, ?> ccfg) {
if (!CU.isPersistentCache(ccfg, ctx.config().getDataStorageConfiguration()))
return false;

String expDir = cacheDirName(ccfg);
String expDir = ctx.pdsFolderResolver().fileTree().cacheDirName(ccfg);

try {
return !expDir.equals(Paths.get(expDir).toFile().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import org.apache.ignite.failure.FailureType;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager;
import org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings;
import org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.T2;
import org.apache.ignite.internal.util.typedef.internal.CU;
Expand Down Expand Up @@ -100,8 +100,8 @@ public class GridLocalConfigManager {
/** Cache processor. */
private final GridCacheProcessor cacheProcessor;

/** Absolute directory for file page store. Includes consistent id based folder. */
private final File storeWorkDir;
/** Node file tree. */
private final NodeFileTree ft;

/** Marshaller. */
private final Marshaller marshaller;
Expand All @@ -124,16 +124,10 @@ public GridLocalConfigManager(
ctx = kernalCtx;
log = ctx.log(getClass());
marshaller = ctx.marshallerContext().jdkMarshaller();
ft = ctx.pdsFolderResolver().fileTree();

PdsFolderSettings<?> folderSettings = ctx.pdsFolderResolver().resolveFolders();

if (!ctx.clientNode() && folderSettings.persistentStoreRootPath() != null) {
storeWorkDir = folderSettings.persistentStoreNodePath();

U.ensureDirectory(storeWorkDir, "page store work directory", log);
}
else
storeWorkDir = null;
if (!ctx.clientNode() && ft.nodeStorage() != null)
U.ensureDirectory(ft.nodeStorage(), "page store work directory", log);
}

/**
Expand All @@ -148,7 +142,7 @@ public void readConfigurationFiles(

try {
for (CacheConfiguration<?, ?> ccfg : ccfgs) {
File cacheDir = cacheWorkDir(ccfg);
File cacheDir = ft.cacheStorage(ccfg);

if (!cacheDir.exists())
continue;
Expand All @@ -175,7 +169,7 @@ public Map<String, StoredCacheData> readCacheConfigurations() throws IgniteCheck
if (ctx.clientNode())
return Collections.emptyMap();

File[] files = storeWorkDir.listFiles();
File[] files = ft.nodeStorage().listFiles();

if (files == null)
return Collections.emptyMap();
Expand Down Expand Up @@ -293,7 +287,7 @@ public void saveCacheConfiguration(
if (!CU.storeCacheConfig(cacheProcessor.context(), ccfg))
return;

File cacheWorkDir = cacheWorkDir(ccfg);
File cacheWorkDir = ft.cacheStorage(ccfg);

FilePageStoreManager.checkAndInitCacheWorkDir(cacheWorkDir, log);

Expand Down Expand Up @@ -426,7 +420,7 @@ public void removeConfigurationChangeListener(BiConsumer<String, File> lsnr) {
* @throws IgniteCheckedException If fails.
*/
public void removeCacheGroupConfigurationData(CacheGroupContext ctx) throws IgniteCheckedException {
File cacheGrpDir = cacheWorkDir(ctx.sharedGroup(), ctx.cacheOrGroupName());
File cacheGrpDir = ft.cacheStorage(ctx.config());

if (cacheGrpDir != null && cacheGrpDir.exists()) {
DirectoryStream.Filter<Path> cacheCfgFileFilter = new DirectoryStream.Filter<Path>() {
Expand Down Expand Up @@ -537,33 +531,14 @@ private boolean inMemoryCdcCache(CacheConfiguration<?, ?> cfg) {
* @return Cache configuration file with respect to {@link CacheConfiguration#getGroupName} value.
*/
public File cacheConfigurationFile(CacheConfiguration<?, ?> ccfg) {
File cacheWorkDir = cacheWorkDir(ccfg);

return new File(cacheWorkDir, cacheDataFilename(ccfg));
return new File(ft.cacheStorage(ccfg), cacheDataFilename(ccfg));
}

/** @return Name of cache data filename. */
public static String cacheDataFilename(CacheConfiguration<?, ?> ccfg) {
return ccfg.getGroupName() == null ? CACHE_DATA_FILENAME : (ccfg.getName() + CACHE_DATA_FILENAME);
}

/**
* @param ccfg Cache configuration.
* @return Store dir for given cache.
*/
public File cacheWorkDir(CacheConfiguration<?, ?> ccfg) {
return FilePageStoreManager.cacheWorkDir(storeWorkDir, FilePageStoreManager.cacheDirName(ccfg));
}

/**
* @param isSharedGroup {@code True} if cache is sharing the same `underlying` cache.
* @param cacheOrGroupName Cache name.
* @return Store directory for given cache.
*/
public File cacheWorkDir(boolean isSharedGroup, String cacheOrGroupName) {
return FilePageStoreManager.cacheWorkDir(storeWorkDir, FilePageStoreManager.cacheDirName(isSharedGroup, cacheOrGroupName));
}

/**
* @return {@code True} if need locally start all existing caches on client node start.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.apache.ignite.internal.processors.cache.persistence.checkpoint.LightweightCheckpointManager;
import org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager;
import org.apache.ignite.internal.processors.cache.persistence.file.FileVersionCheckingFactory;
import org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree;
import org.apache.ignite.internal.processors.cache.persistence.freelist.AbstractFreeList;
import org.apache.ignite.internal.processors.cache.persistence.freelist.SimpleDataRow;
import org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx;
Expand Down Expand Up @@ -290,10 +291,12 @@ public void executeDefragmentation() throws IgniteCheckedException {
IgniteInternalFuture<?> idxDfrgFut = null;
DataPageEvictionMode prevPageEvictionMode = null;

NodeFileTree ft = sharedCtx.kernalContext().pdsFolderResolver().fileTree();

for (CacheGroupContext oldGrpCtx : cacheGrpCtxsForDefragmentation) {
int grpId = oldGrpCtx.groupId();

File workDir = filePageStoreMgr.cacheWorkDir(oldGrpCtx.sharedGroup(), oldGrpCtx.cacheOrGroupName());
File workDir = ft.cacheStorage(oldGrpCtx.config());

List<CacheDataStore> oldCacheDataStores = oldStores.get(grpId);

Expand Down
Loading