Skip to content

Commit 1afc0ad

Browse files
authored
IGNITE-24617 Move db to the private constants (#11893)
1 parent b1edb09 commit 1afc0ad

File tree

29 files changed

+102
-115
lines changed

29 files changed

+102
-115
lines changed

modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationAbstractTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.apache.ignite.configuration.DataStorageConfiguration;
2525
import org.apache.ignite.configuration.IgniteConfiguration;
2626
import org.apache.ignite.internal.processors.authentication.IgniteAccessControlException;
27-
import org.apache.ignite.internal.util.typedef.internal.U;
2827
import org.apache.ignite.testframework.GridTestUtils;
2928
import org.junit.Test;
3029

@@ -43,7 +42,7 @@ public abstract class JettyRestProcessorAuthenticationAbstractTest extends Jetty
4342

4443
/** {@inheritDoc} */
4544
@Override protected void beforeTestsStarted() throws Exception {
46-
U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true);
45+
recreateDefaultDb();
4746

4847
super.beforeTestsStarted();
4948
}

modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorBaselineSelfTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.apache.ignite.internal.IgniteEx;
3131
import org.apache.ignite.internal.processors.rest.handlers.cluster.GridBaselineCommandResponse;
3232
import org.apache.ignite.internal.util.typedef.F;
33-
import org.apache.ignite.internal.util.typedef.internal.U;
3433
import org.jetbrains.annotations.Nullable;
3534
import org.junit.Test;
3635

@@ -43,7 +42,7 @@
4342
public class JettyRestProcessorBaselineSelfTest extends JettyRestProcessorCommonSelfTest {
4443
/** {@inheritDoc} */
4544
@Override protected void beforeTestsStarted() throws Exception {
46-
U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true);
45+
recreateDefaultDb();
4746

4847
super.beforeTestsStarted();
4948

modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinAuthenticateConnectionSelfTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.apache.ignite.configuration.DataRegionConfiguration;
2626
import org.apache.ignite.configuration.DataStorageConfiguration;
2727
import org.apache.ignite.configuration.IgniteConfiguration;
28-
import org.apache.ignite.internal.util.typedef.internal.U;
2928
import org.apache.ignite.testframework.GridTestUtils;
3029
import org.junit.Test;
3130

@@ -61,7 +60,7 @@ public class JdbcThinAuthenticateConnectionSelfTest extends JdbcThinAbstractSelf
6160
@Override protected void beforeTest() throws Exception {
6261
super.beforeTest();
6362

64-
U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true);
63+
recreateDefaultDb();
6564

6665
startGrids(2);
6766

modules/compatibility/src/test/java/org/apache/ignite/compatibility/persistence/FoldersReuseCompatibilityTest.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@
2424
import java.util.function.Consumer;
2525
import org.apache.ignite.Ignite;
2626
import org.apache.ignite.IgniteCache;
27-
import org.apache.ignite.IgniteCheckedException;
2827
import org.apache.ignite.compatibility.testframework.junits.SkipTestIfIsJdkNewer;
2928
import org.apache.ignite.configuration.IgniteConfiguration;
3029
import org.apache.ignite.configuration.MemoryConfiguration;
3130
import org.apache.ignite.configuration.MemoryPolicyConfiguration;
3231
import org.apache.ignite.configuration.PersistentStoreConfiguration;
3332
import org.apache.ignite.internal.IgniteEx;
3433
import org.apache.ignite.internal.processors.cache.GridCacheAbstractFullApiSelfTest;
35-
import org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager;
3634
import org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree;
3735
import org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderResolver;
3836
import org.apache.ignite.internal.util.typedef.internal.U;
@@ -190,18 +188,16 @@ private static void configPersistence(IgniteConfiguration cfg) {
190188

191189
/**
192190
* @param indexes expected new style node indexes in folders
193-
* @throws IgniteCheckedException if failed
194191
*/
195-
private void assertNodeIndexesInFolder(Integer... indexes) throws IgniteCheckedException {
192+
private void assertNodeIndexesInFolder(Integer... indexes) {
196193
assertEquals(new TreeSet<>(Arrays.asList(indexes)), getAllNodeIndexesInFolder());
197194
}
198195

199196
/**
200197
* @return set of all indexes of nodes found in work folder
201-
* @throws IgniteCheckedException if failed.
202198
*/
203-
@NotNull private Set<Integer> getAllNodeIndexesInFolder() throws IgniteCheckedException {
204-
final File curFolder = new File(U.defaultWorkDirectory(), FilePageStoreManager.DFLT_STORE_DIR);
199+
@NotNull private Set<Integer> getAllNodeIndexesInFolder() {
200+
final File curFolder = sharedFileTree().db();
205201
final Set<Integer> indexes = new TreeSet<>();
206202
final File[] files = curFolder.listFiles(PdsFolderResolver.DB_SUBFOLDERS_NEW_STYLE_FILTER);
207203

@@ -220,9 +216,8 @@ private void assertNodeIndexesInFolder(Integer... indexes) throws IgniteCheckedE
220216
* Checks existence of all storage-related directories
221217
*
222218
* @param subDirName sub directories name expected
223-
* @throws IgniteCheckedException if IO error occur
224219
*/
225-
private void assertPdsDirsDefaultExist(String subDirName) throws IgniteCheckedException {
220+
private void assertPdsDirsDefaultExist(String subDirName) {
226221
NodeFileTree ft = nodeFileTree(subDirName);
227222

228223
Consumer<File> check = dir -> assertTrue(dir.exists() && dir.isDirectory());

modules/compatibility/src/test/java/org/apache/ignite/compatibility/persistence/IgnitePersistenceCompatibilityAbstractTest.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,28 @@
2020
import java.io.File;
2121
import java.util.Arrays;
2222
import java.util.List;
23+
import java.util.function.Consumer;
2324
import org.apache.ignite.compatibility.testframework.junits.IgniteCompatibilityAbstractTest;
2425
import org.apache.ignite.compatibility.testframework.util.CompatibilityTestsUtils;
2526
import org.apache.ignite.internal.util.typedef.internal.U;
2627
import org.apache.ignite.spi.checkpoint.sharedfs.SharedFsCheckpointSpi;
2728

28-
import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.DFLT_STORE_DIR;
29-
import static org.apache.ignite.internal.processors.cache.persistence.filename.SharedFileTree.BINARY_METADATA_DIR;
30-
import static org.apache.ignite.internal.processors.cache.persistence.filename.SharedFileTree.MARSHALLER_DIR;
31-
3229
/**
3330
* Super class for all persistence compatibility tests.
3431
*/
3532
public abstract class IgnitePersistenceCompatibilityAbstractTest extends IgniteCompatibilityAbstractTest {
36-
/** Persistence directories. */
37-
private static final List<String> PERSISTENCE_DIRS
38-
= Arrays.asList(DFLT_STORE_DIR, BINARY_METADATA_DIR, SharedFsCheckpointSpi.DFLT_ROOT, MARSHALLER_DIR);
39-
4033
/** {@inheritDoc} */
4134
@Override protected void beforeTest() throws Exception {
4235
super.beforeTest();
4336

44-
for (String dirName : PERSISTENCE_DIRS) {
45-
File dir = U.resolveWorkDirectory(U.defaultWorkDirectory(), dirName, true);
37+
Consumer<File> recreate = dir -> {
38+
U.delete(dir);
39+
40+
assertTrue(dir.mkdirs());
41+
};
42+
43+
for (File dir : persistenceDirs()) {
44+
recreate.accept(dir);
4645

4746
if (!CompatibilityTestsUtils.isDirectoryEmpty(dir)) {
4847
throw new IllegalStateException("Directory is not empty and can't be cleaned: " +
@@ -58,7 +57,16 @@ public abstract class IgnitePersistenceCompatibilityAbstractTest extends IgniteC
5857
//protection if test failed to finish, e.g. by error
5958
stopAllGrids();
6059

61-
for (String dir : PERSISTENCE_DIRS)
62-
U.delete(U.resolveWorkDirectory(U.defaultWorkDirectory(), dir, false));
60+
persistenceDirs().forEach(U::delete);
61+
}
62+
63+
/** */
64+
private List<File> persistenceDirs() {
65+
return Arrays.asList(
66+
sharedFileTree().db(),
67+
sharedFileTree().binaryMetaRoot(),
68+
sharedFileTree().marshaller(),
69+
new File(sharedFileTree().root(), SharedFsCheckpointSpi.DFLT_ROOT));
70+
6371
}
6472
}

modules/compress/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotCompressionBasicTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
import static org.apache.ignite.events.EventType.EVTS_CLUSTER_SNAPSHOT;
6767
import static org.apache.ignite.events.EventType.EVT_CLUSTER_SNAPSHOT_RESTORE_FINISHED;
6868
import static org.apache.ignite.events.EventType.EVT_CLUSTER_SNAPSHOT_RESTORE_STARTED;
69-
import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.DFLT_STORE_DIR;
7069

7170
/** */
7271
public class SnapshotCompressionBasicTest extends AbstractSnapshotSelfTest {
@@ -403,7 +402,7 @@ protected void failCompressionProcessor(Ignite ignite, String... snpNames) {
403402
/** */
404403
protected long persistenseSize(Collection<Ignite> grids) {
405404
return grids.stream()
406-
.map(ig -> workingDirectory(ig).resolve(DFLT_STORE_DIR))
405+
.map(ig -> ((IgniteEx)ig).context().pdsFolderResolver().fileTree().nodeStorage().toPath())
407406
.reduce(0L, (acc, p) -> acc + directorySize(p), Long::sum);
408407
}
409408

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@
9494
*/
9595
public class FilePageStoreManager extends GridCacheSharedManagerAdapter implements IgnitePageStoreManager,
9696
PageStoreCollection {
97-
/** */
98-
public static final String DFLT_STORE_DIR = "db";
99-
10097
/** Matcher for searching of *.tmp files. */
10198
public static final PathMatcher TMP_FILE_MATCHER =
10299
FileSystems.getDefault().getPathMatcher("glob:**" + TMP_SUFFIX);

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/NodeFileTree.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import static org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION;
4545
import static org.apache.ignite.internal.pagemem.PageIdAllocator.MAX_PARTITION_ID;
4646
import static org.apache.ignite.internal.processors.cache.GridCacheUtils.UTILITY_CACHE_NAME;
47-
import static org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderResolver.DB_DEFAULT_FOLDER;
4847
import static org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage.METASTORAGE_CACHE_NAME;
4948
import static org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage.METASTORAGE_DIR_NAME;
5049

@@ -293,7 +292,7 @@ public NodeFileTree(File root, String folderName) {
293292
wal = rootRelative(DFLT_WAL_PATH);
294293
walArchive = rootRelative(DFLT_WAL_ARCHIVE_PATH);
295294
walCdc = rootRelative(DFLT_WAL_CDC_PATH);
296-
nodeStorage = rootRelative(DB_DEFAULT_FOLDER);
295+
nodeStorage = rootRelative(DB_DIR);
297296
snpTmpRoot = new File(nodeStorage, SNAPSHOT_TMP_DIR);
298297
checkpoint = new File(nodeStorage, CHECKPOINT_DIR);
299298
}
@@ -324,7 +323,7 @@ public NodeFileTree(IgniteConfiguration cfg, String folderName) {
324323

325324
if (CU.isPersistenceEnabled(cfg) || CU.isCdcEnabled(cfg)) {
326325
nodeStorage = dsCfg.getStoragePath() == null
327-
? rootRelative(DB_DEFAULT_FOLDER)
326+
? rootRelative(DB_DIR)
328327
: resolveDirectory(dsCfg.getStoragePath());
329328
snpTmpRoot = new File(nodeStorage, SNAPSHOT_TMP_DIR);
330329
checkpoint = new File(nodeStorage, CHECKPOINT_DIR);

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/PdsFolderResolver.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import static java.lang.Boolean.TRUE;
4848
import static org.apache.ignite.IgniteSystemProperties.IGNITE_DATA_STORAGE_FOLDER_BY_CONSISTENT_ID;
4949
import static org.apache.ignite.IgniteSystemProperties.getBoolean;
50+
import static org.apache.ignite.internal.processors.cache.persistence.filename.SharedFileTree.DB_DIR;
5051

5152
/**
5253
* This class contains logic to resolve and possibly lock PDS folder
@@ -91,9 +92,6 @@ public class PdsFolderResolver<L extends FileLockHolder> {
9192
}
9293
};
9394

94-
/** Database default folder. */
95-
static final String DB_DEFAULT_FOLDER = "db";
96-
9795
/** */
9896
private final IgniteConfiguration cfg;
9997

@@ -433,7 +431,7 @@ private static String padStart(String str, int minLength, char padChar) {
433431

434432
return U.resolveWorkDirectory(
435433
cfg.getWorkDirectory(),
436-
pstPath != null ? pstPath : DB_DEFAULT_FOLDER,
434+
pstPath != null ? pstPath : DB_DIR,
437435
false
438436
);
439437
}

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/SharedFileTree.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.apache.ignite.internal.util.typedef.internal.U;
2828

2929
import static org.apache.ignite.configuration.IgniteConfiguration.DFLT_SNAPSHOT_DIRECTORY;
30-
import static org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderResolver.DB_DEFAULT_FOLDER;
3130

3231
/**
3332
* Provides access to directories shared between all local nodes.
@@ -37,18 +36,21 @@
3736
* ├── db ← db (shared between all local nodes).
3837
* │ ├── binary_meta ← binaryMetaRoot (shared between all local nodes).
3938
* │ ├── marshaller ← marshaller (shared between all local nodes).
40-
* └── snapshots ← snapshotRoot (shared between all local nodes).
39+
* └── snapshots ← snpsRoot (shared between all local nodes).
4140
* </pre>
4241
*
4342
* @see NodeFileTree
4443
*/
4544
public class SharedFileTree {
4645
/** Name of binary metadata folder. */
47-
public static final String BINARY_METADATA_DIR = "binary_meta";
46+
protected static final String BINARY_METADATA_DIR = "binary_meta";
4847

4948
/** Name of marshaller mappings folder. */
5049
public static final String MARSHALLER_DIR = "marshaller";
5150

51+
/** Database default folder. */
52+
protected static final String DB_DIR = "db";
53+
5254
/** Root(work) directory. */
5355
protected final File root;
5456

@@ -73,8 +75,8 @@ private SharedFileTree(File root, String snpsRoot) {
7375

7476
String rootStr = root.getAbsolutePath();
7577

76-
marshaller = Paths.get(rootStr, DB_DEFAULT_FOLDER, MARSHALLER_DIR).toFile();
77-
binaryMetaRoot = Paths.get(rootStr, DB_DEFAULT_FOLDER, BINARY_METADATA_DIR).toFile();
78+
marshaller = Paths.get(rootStr, DB_DIR, MARSHALLER_DIR).toFile();
79+
binaryMetaRoot = Paths.get(rootStr, DB_DIR, BINARY_METADATA_DIR).toFile();
7880
}
7981

8082
/**
@@ -105,6 +107,13 @@ public File root() {
105107
return root;
106108
}
107109

110+
/**
111+
* @return Path to the {@code db} directory inside {@link #root()}.
112+
*/
113+
public File db() {
114+
return new File(root, DB_DIR);
115+
}
116+
108117
/**
109118
* @return Path to common binary metadata directory. Note, directory can contain data from several nodes.
110119
* Each node will create own directory inside this root.

0 commit comments

Comments
 (0)