Skip to content

Commit dc959b9

Browse files
authored
IGNITE-24130 Support of data region storage path implemented (#11896)
1 parent 7596a31 commit dc959b9

File tree

50 files changed

+1374
-716
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1374
-716
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public void testRestoreNotCompressed_OnGridWithoutCompression() throws Exception
273273
}
274274

275275
/** */
276-
@Override protected void cleanPersistenceDir(boolean saveSnap) throws Exception {
276+
@Override protected void cleanPersistenceDir(boolean saveSnap) {
277277
assertTrue("Grids are not stopped", F.isEmpty(G.allGrids()));
278278

279279
String mask = U.maskForFileName(getTestIgniteInstanceName());

modules/core/src/main/java/org/apache/ignite/configuration/DataRegionConfiguration.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ public final class DataRegionConfiguration implements Serializable {
158158
/** Change Data Capture enabled flag. */
159159
private boolean cdcEnabled;
160160

161+
/** Directory where index and partition files are stored. */
162+
@Nullable private String storagePath;
163+
161164
/**
162165
* Gets data region name.
163166
*
@@ -580,6 +583,26 @@ public boolean isCdcEnabled() {
580583
return cdcEnabled;
581584
}
582585

586+
/**
587+
* @return A path to the root directory where the Persistent Store for data region will persist data and indexes.
588+
*/
589+
@Nullable public String getStoragePath() {
590+
return storagePath;
591+
}
592+
593+
/**
594+
* Sets a path to the root directory where the Persistent Store will persist data and indexes.
595+
* By default, the Persistent Store's files are located under Ignite work directory.
596+
*
597+
* @param storagePath Persistence store path.
598+
* @return {@code this} for chaining.
599+
*/
600+
public DataRegionConfiguration setStoragePath(String storagePath) {
601+
this.storagePath = storagePath;
602+
603+
return this;
604+
}
605+
583606
/** {@inheritDoc} */
584607
@Override public String toString() {
585608
return S.toString(DataRegionConfiguration.class, this);

modules/core/src/main/java/org/apache/ignite/configuration/DataStorageConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ public String getStoragePath() {
557557

558558
/**
559559
* Sets a path to the root directory where the Persistent Store will persist data and indexes.
560-
* By default the Persistent Store's files are located under Ignite work directory.
560+
* By default, the Persistent Store's files are located under Ignite work directory.
561561
*
562562
* @param persistenceStorePath Persistence store path.
563563
* @return {@code this} for chaining.

modules/core/src/main/java/org/apache/ignite/dump/DumpReader.java

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@
1717

1818
package org.apache.ignite.dump;
1919

20+
import java.io.BufferedInputStream;
2021
import java.io.File;
22+
import java.io.IOException;
23+
import java.io.InputStream;
24+
import java.nio.file.Files;
2125
import java.util.ArrayList;
2226
import java.util.Arrays;
27+
import java.util.Collections;
2328
import java.util.HashMap;
2429
import java.util.HashSet;
2530
import java.util.List;
@@ -29,19 +34,28 @@
2934
import java.util.concurrent.Executors;
3035
import java.util.concurrent.atomic.AtomicBoolean;
3136
import java.util.stream.Collectors;
37+
import org.apache.ignite.IgniteCheckedException;
3238
import org.apache.ignite.IgniteException;
3339
import org.apache.ignite.IgniteLogger;
40+
import org.apache.ignite.configuration.IgniteConfiguration;
41+
import org.apache.ignite.internal.GridKernalContext;
3442
import org.apache.ignite.internal.GridLoggerProxy;
3543
import org.apache.ignite.internal.cdc.CdcMain;
3644
import org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree;
45+
import org.apache.ignite.internal.processors.cache.persistence.filename.SharedFileTree;
46+
import org.apache.ignite.internal.processors.cache.persistence.filename.SnapshotFileTree;
3747
import org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotMetadata;
3848
import org.apache.ignite.internal.processors.cache.persistence.snapshot.dump.Dump;
3949
import org.apache.ignite.internal.processors.cache.persistence.snapshot.dump.Dump.DumpedPartitionIterator;
4050
import org.apache.ignite.internal.processors.cache.persistence.snapshot.dump.DumpConsumerKernalContextAware;
51+
import org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext;
4152
import org.apache.ignite.internal.util.typedef.F;
53+
import org.apache.ignite.internal.util.typedef.internal.A;
4254
import org.apache.ignite.internal.util.typedef.internal.CU;
4355
import org.apache.ignite.internal.util.typedef.internal.U;
56+
import org.apache.ignite.lang.IgniteBiTuple;
4457
import org.apache.ignite.lang.IgniteExperimental;
58+
import org.apache.ignite.marshaller.jdk.JdkMarshaller;
4559
import org.apache.ignite.spi.IgniteSpiAdapter;
4660
import org.apache.ignite.spi.encryption.EncryptionSpi;
4761

@@ -50,6 +64,8 @@
5064
import static org.apache.ignite.internal.IgniteKernal.SITE;
5165
import static org.apache.ignite.internal.IgniteVersionUtils.ACK_VER_STR;
5266
import static org.apache.ignite.internal.IgniteVersionUtils.COPYRIGHT;
67+
import static org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext.closeAllComponents;
68+
import static org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext.startAllComponents;
5369

5470
/**
5571
* Dump Reader application.
@@ -77,7 +93,11 @@ public DumpReader(DumpReaderConfiguration cfg, IgniteLogger log) {
7793
@Override public void run() {
7894
ackAsciiLogo();
7995

80-
try (Dump dump = new Dump(cfg.dumpRoot(), null, cfg.keepBinary(), cfg.keepRaw(), encryptionSpi(), log)) {
96+
IgniteBiTuple<List<SnapshotFileTree>, List<SnapshotMetadata>> data = readStoredData();
97+
98+
GridKernalContext cctx = standaloneKernalContext(F.first(data.get1()), log);
99+
100+
try (Dump dump = new Dump(cctx, data.get1(), data.get2(), cfg.keepBinary(), cfg.keepRaw(), encryptionSpi(), log)) {
81101
DumpConsumer cnsmr = cfg.consumer();
82102

83103
if (cnsmr instanceof DumpConsumerKernalContextAware)
@@ -185,6 +205,14 @@ public DumpReader(DumpReaderConfiguration cfg, IgniteLogger log) {
185205
catch (Exception e) {
186206
throw new IgniteException(e);
187207
}
208+
finally {
209+
try {
210+
closeAllComponents(cctx);
211+
}
212+
catch (IgniteCheckedException ignored) {
213+
// No-op.
214+
}
215+
}
188216
}
189217

190218
/** */
@@ -232,7 +260,7 @@ private void ackAsciiLogo() {
232260
U.quiet(false, " ^-- Logging by '" + ((GridLoggerProxy)log).getLoggerInfo() + '\'');
233261

234262
U.quiet(false,
235-
" ^-- To see **FULL** console log here add -DIGNITE_QUIET=false or \"-v\" to ignite-cdc.{sh|bat}",
263+
" ^-- To see **FULL** console log here add -DIGNITE_QUIET=false or \"-v\" to ignite-dump-reader.{sh|bat}",
236264
"");
237265
}
238266
}
@@ -251,4 +279,94 @@ private EncryptionSpi encryptionSpi() {
251279

252280
return encSpi;
253281
}
282+
283+
/**
284+
* @return Snapshot file tree for the dump
285+
*/
286+
private IgniteBiTuple<List<SnapshotFileTree>, List<SnapshotMetadata>> readStoredData() {
287+
final IgniteConfiguration icfg;
288+
final File root;
289+
final String name;
290+
final String path;
291+
292+
if (cfg.config() != null) {
293+
icfg = cfg.config();
294+
name = cfg.dumpName();
295+
path = cfg.dumpRoot();
296+
root = SnapshotFileTree.root(new SharedFileTree(icfg), name, path);
297+
}
298+
else {
299+
icfg = new IgniteConfiguration();
300+
301+
A.ensure(F.isEmpty(cfg.dumpName()), "Use dump path, only.");
302+
A.notNull(cfg.dumpRoot(), "Dump path must be provdied");
303+
304+
root = new File(cfg.dumpRoot());
305+
306+
A.ensure(root.isAbsolute(), "Dump path must be absolute or Ignite configuration provided");
307+
308+
name = root.getName();
309+
path = root.getParentFile().getAbsolutePath();
310+
}
311+
312+
List<SnapshotMetadata> metadata = metadata(root);
313+
314+
A.ensure(!F.isEmpty(metadata), "Dump metafiles not found: " + root.getAbsolutePath());
315+
316+
List<SnapshotFileTree> sfts = metadata.stream().map(m -> new SnapshotFileTree(
317+
icfg,
318+
new NodeFileTree(icfg, m.folderName()),
319+
name,
320+
path,
321+
m.folderName(),
322+
m.consistentId()
323+
)).collect(Collectors.toList());
324+
325+
return F.t(sfts, metadata);
326+
}
327+
328+
/**
329+
* @param dumpDir Dump root directory.
330+
* @return List of snapshot metadata saved in {@code #dumpDir}.
331+
*/
332+
public static List<SnapshotMetadata> metadata(File dumpDir) {
333+
JdkMarshaller marsh = new JdkMarshaller();
334+
335+
ClassLoader clsLdr = U.resolveClassLoader(new IgniteConfiguration());
336+
337+
// First filter only specific file to exclude overlapping with other nodes making dump on the local host.
338+
File[] files = dumpDir.listFiles(SnapshotFileTree::snapshotMetaFile);
339+
340+
if (files == null)
341+
return Collections.emptyList();
342+
343+
return Arrays.stream(files)
344+
.map(meta -> {
345+
try (InputStream in = new BufferedInputStream(Files.newInputStream(meta.toPath()))) {
346+
return marsh.<SnapshotMetadata>unmarshal(in, clsLdr);
347+
}
348+
catch (IOException | IgniteCheckedException e) {
349+
throw new IgniteException(e);
350+
}
351+
})
352+
.filter(SnapshotMetadata::dump)
353+
.collect(Collectors.toList());
354+
}
355+
356+
/**
357+
* @param log Logger.
358+
* @return Standalone kernal context.
359+
*/
360+
private static GridKernalContext standaloneKernalContext(SnapshotFileTree sft, IgniteLogger log) {
361+
try {
362+
GridKernalContext kctx = new StandaloneGridKernalContext(log, sft);
363+
364+
startAllComponents(kctx);
365+
366+
return kctx;
367+
}
368+
catch (IgniteCheckedException e) {
369+
throw new IgniteException(e);
370+
}
371+
}
254372
}

modules/core/src/main/java/org/apache/ignite/dump/DumpReaderConfiguration.java

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717

1818
package org.apache.ignite.dump;
1919

20-
import java.io.File;
2120
import java.time.Duration;
2221
import org.apache.ignite.binary.BinaryObject;
22+
import org.apache.ignite.configuration.IgniteConfiguration;
2323
import org.apache.ignite.internal.processors.cache.CacheObject;
2424
import org.apache.ignite.internal.processors.cache.KeyCacheObject;
2525
import org.apache.ignite.lang.IgniteExperimental;
2626
import org.apache.ignite.spi.encryption.EncryptionSpi;
27+
import org.jetbrains.annotations.Nullable;
2728

2829
/**
2930
* Configuration class of {@link DumpReader}.
@@ -39,8 +40,14 @@ public class DumpReaderConfiguration {
3940
/** Default thread count. */
4041
public static final int DFLT_THREAD_CNT = 1;
4142

43+
/** Dump name. */
44+
@Nullable private final String name;
45+
4246
/** Root dump directory. */
43-
private final File dir;
47+
@Nullable private final String path;
48+
49+
/** Optional Ignite configuration. */
50+
@Nullable private final IgniteConfiguration cfg;
4451

4552
/** Dump consumer. */
4653
private final DumpConsumer cnsmr;
@@ -76,15 +83,19 @@ public class DumpReaderConfiguration {
7683
private final EncryptionSpi encSpi;
7784

7885
/**
79-
* @param dir Root dump directory.
86+
* @param name Optional dump name.
87+
* @param path Optional path to the dump directory.
88+
* @param cfg Ignite configuration to resolve standart pathes.
8089
* @param cnsmr Dump consumer.
8190
*/
82-
public DumpReaderConfiguration(File dir, DumpConsumer cnsmr) {
83-
this(dir, cnsmr, DFLT_THREAD_CNT, DFLT_TIMEOUT, true, true, false, null, false, null);
91+
public DumpReaderConfiguration(String name, @Nullable String path, @Nullable IgniteConfiguration cfg, DumpConsumer cnsmr) {
92+
this(name, path, cfg, cnsmr, DFLT_THREAD_CNT, DFLT_TIMEOUT, true, true, false, null, false, null);
8493
}
8594

8695
/**
87-
* @param dir Root dump directory.
96+
* @param name Optional dump name.
97+
* @param path Optional path to the dump directory.
98+
* @param cfg Ignite configuration to resolve standart pathes.
8899
* @param cnsmr Dump consumer.
89100
* @param thCnt Count of threads to consume dumped partitions.
90101
* @param timeout Timeout of dump reader invocation.
@@ -99,7 +110,9 @@ public DumpReaderConfiguration(File dir, DumpConsumer cnsmr) {
99110
* @param encSpi Encryption SPI.
100111
*/
101112
public DumpReaderConfiguration(
102-
File dir,
113+
@Nullable String name,
114+
@Nullable String path,
115+
@Nullable IgniteConfiguration cfg,
103116
DumpConsumer cnsmr,
104117
int thCnt,
105118
Duration timeout,
@@ -110,7 +123,9 @@ public DumpReaderConfiguration(
110123
boolean skipCopies,
111124
EncryptionSpi encSpi
112125
) {
113-
this.dir = dir;
126+
this.name = name;
127+
this.path = path;
128+
this.cfg = cfg;
114129
this.cnsmr = cnsmr;
115130
this.thCnt = thCnt;
116131
this.timeout = timeout;
@@ -122,9 +137,19 @@ public DumpReaderConfiguration(
122137
this.encSpi = encSpi;
123138
}
124139

140+
/** @return Root dump name. */
141+
public @Nullable String dumpName() {
142+
return name;
143+
}
144+
125145
/** @return Root dump directiory. */
126-
public File dumpRoot() {
127-
return dir;
146+
public @Nullable String dumpRoot() {
147+
return path;
148+
}
149+
150+
/** @return Ignite configuration. */
151+
public @Nullable IgniteConfiguration config() {
152+
return cfg;
128153
}
129154

130155
/** @return Dump consumer instance. */

modules/core/src/main/java/org/apache/ignite/internal/cdc/CdcMain.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ protected CdcConsumerState createState(Path stateDir) {
372372
* @throws IgniteCheckedException If failed.
373373
*/
374374
private void startStandaloneKernal() throws IgniteCheckedException {
375-
kctx = new StandaloneGridKernalContext(log, ft.binaryMeta(), ft.marshaller()) {
375+
kctx = new StandaloneGridKernalContext(log, ft) {
376376
@Override protected IgniteConfiguration prepareIgniteConfiguration() {
377377
IgniteConfiguration cfg = super.prepareIgniteConfiguration();
378378

@@ -546,8 +546,7 @@ private boolean consumeSegment(Path segment) {
546546
IgniteWalIteratorFactory.IteratorParametersBuilder builder =
547547
new IgniteWalIteratorFactory.IteratorParametersBuilder()
548548
.log(log)
549-
.binaryMetadataFileStoreDir(ft.binaryMeta())
550-
.marshallerMappingFileStoreDir(ft.marshaller())
549+
.fileTree(ft)
551550
.igniteConfigurationModifier((cfg) -> cfg.setPluginProviders(igniteCfg.getPluginProviders()))
552551
.keepBinary(cdcCfg.isKeepBinary())
553552
.filesOrDirs(segment.toFile());

modules/core/src/main/java/org/apache/ignite/internal/maintenance/MaintenanceFileStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void init() throws IgniteCheckedException, IOException {
9999
if (disabled)
100100
return;
101101

102-
File storeDir = pdsFoldersResolver.resolveFolders().persistentStoreNodePath();
102+
File storeDir = pdsFoldersResolver.fileTree().nodeStorage();
103103
U.ensureDirectory(storeDir, "store directory for node persistent data", log);
104104

105105
mntcTasksFile = new File(storeDir, MAINTENANCE_FILE_NAME);

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridLocalConfigManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.apache.ignite.failure.FailureType;
5757
import org.apache.ignite.internal.GridKernalContext;
5858
import org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager;
59+
import org.apache.ignite.internal.processors.cache.persistence.filename.FileTreeUtils;
5960
import org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree;
6061
import org.apache.ignite.internal.util.typedef.F;
6162
import org.apache.ignite.internal.util.typedef.T2;
@@ -118,8 +119,8 @@ public GridLocalConfigManager(
118119
marshaller = ctx.marshallerContext().jdkMarshaller();
119120
ft = ctx.pdsFolderResolver().fileTree();
120121

121-
if (!ctx.clientNode() && ft.nodeStorage() != null)
122-
U.ensureDirectory(ft.nodeStorage(), "page store work directory", log);
122+
if (!ctx.clientNode())
123+
FileTreeUtils.createCacheStorages(ft, log);
123124
}
124125

125126
/**

0 commit comments

Comments
 (0)