Repository: apache/ignite
Pull request #12091: IGNITE-25427 Move CdcConsumerState file logic to NodeFileTree
Author: login: wernerdv
Created: 2025-05-22T14:37:09Z | Merged: 2025-05-26T18:57:50Z

Thank you for submitting the pull request to the Apache Ignite.

In order to streamline the review of the contribution 
we ask you to ensure the following steps have been taken:

### The Contribution Checklist
- [ ] There is a single JIRA ticket related to the pull request. 
- [ ] The web-link to the pull request is attached to the JIRA ticket.
- [ ] The JIRA ticket has the _Patch Available_ state.
- [ ] The pull request body describes changes that have been made. 
The description explains _WHAT_ and _WHY_ was made instead of _HOW_.
- [ ] The pull request title is treated as the final commit message. 
The following pattern must be used: `IGNITE-XXXX Change summary` where `XXXX` - number of JIRA issue.
- [ ] A reviewer has been mentioned through the JIRA comments 
(see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers)) 
- [ ] The pull request has been checked by the Teamcity Bot and 
the `green visa` attached to the JIRA ticket (see [TC.Bot: Check PR](https://mtcga.gridgain.com/prs.html))

### Notes
- [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
- [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
- [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
- [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)

If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.



Diff:
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cdc/CdcConsumerState.java b/modules/core/src/main/java/org/apache/ignite/internal/cdc/CdcConsumerState.java
index 29ac25caf4c0f..7b5b87734e3f6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cdc/CdcConsumerState.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cdc/CdcConsumerState.java
@@ -38,13 +38,12 @@
 import org.apache.ignite.cdc.CdcEvent;
 import org.apache.ignite.internal.pagemem.wal.record.DataEntry;
 import org.apache.ignite.internal.pagemem.wal.record.DataRecord;
+import org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree;
 import org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer;
 import org.apache.ignite.internal.util.typedef.T2;
 
 import static java.nio.file.StandardCopyOption.ATOMIC_MOVE;
 import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
-import static org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree.FILE_SUFFIX;
-import static org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree.TMP_SUFFIX;
 import static org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer.POINTER_SIZE;
 
 /**
@@ -59,75 +58,20 @@
  * @see CdcMain
  */
 public class CdcConsumerState {
-    /** */
-    public static final String WAL_STATE_FILE_NAME = "cdc-wal-state" + FILE_SUFFIX;
-
-    /** */
-    public static final String TYPES_STATE_FILE_NAME = "cdc-types-state" + FILE_SUFFIX;
-
-    /** */
-    public static final String MAPPINGS_STATE_FILE_NAME = "cdc-mappings-state" + FILE_SUFFIX;
-
-    /** */
-    public static final String CACHES_STATE_FILE_NAME = "cdc-caches-state" + FILE_SUFFIX;
-
-    /**
-     * The file stores state of CDC mode. Content of the file is a {@link CdcMode} value:
-     * <ul>
-     *     <li>{@link CdcMode#CDC_UTILITY_ACTIVE} means that {@link CdcMain} utility captures data.</li>
-     *     <li>{@link CdcMode#IGNITE_NODE_ACTIVE} means that {@link CdcManager} captures data within Ignite node.</li>
-     * </ul>
-     */
-    public static final String CDC_MODE_FILE_NAME = "cdc-mode" + FILE_SUFFIX;
 
     /** Log. */
     private final IgniteLogger log;
 
-    /** WAL pointer state file. */
-    private final Path walPtr;
-
-    /** Temp WAL pointer state file. */
-    private final Path tmpWalPtr;
-
-    /** Types state file. */
-    private final Path types;
-
-    /** Temp types state file. */
-    private final Path tmpTypes;
-
-    /** Mappings state file. */
-    private final Path mappings;
-
-    /** Mappings types state file. */
-    private final Path tmpMappings;
-
-    /** Cache state file. */
-    private final Path caches;
-
-    /** Mappings types state file. */
-    private final Path tmpCaches;
-
-    /** CDC manager mode state file. */
-    private final Path cdcMode;
-
-    /** Temp CDC manager mode state file. */
-    private final Path tmpCdcMode;
+    /** Node file tree. */
+    private final NodeFileTree ft;
 
     /**
-     * @param stateDir State directory.
+     * @param log Logger.
+     * @param ft Node file tree.
      */
-    public CdcConsumerState(IgniteLogger log, Path stateDir) {
+    public CdcConsumerState(IgniteLogger log, NodeFileTree ft) {
         this.log = log.getLogger(CdcConsumerState.class);
-        walPtr = stateDir.resolve(WAL_STATE_FILE_NAME);
-        tmpWalPtr = stateDir.resolve(WAL_STATE_FILE_NAME + TMP_SUFFIX);
-        types = stateDir.resolve(TYPES_STATE_FILE_NAME);
-        tmpTypes = stateDir.resolve(TYPES_STATE_FILE_NAME + TMP_SUFFIX);
-        mappings = stateDir.resolve(MAPPINGS_STATE_FILE_NAME);
-        tmpMappings = stateDir.resolve(MAPPINGS_STATE_FILE_NAME + TMP_SUFFIX);
-        caches = stateDir.resolve(CACHES_STATE_FILE_NAME);
-        tmpCaches = stateDir.resolve(CACHES_STATE_FILE_NAME + TMP_SUFFIX);
-        cdcMode = stateDir.resolve(CDC_MODE_FILE_NAME);
-        tmpCdcMode = stateDir.resolve(CDC_MODE_FILE_NAME + TMP_SUFFIX);
+        this.ft = ft;
     }
 
     /**
@@ -143,13 +87,15 @@ public void saveWal(T2<WALPointer, Integer> state) throws IOException {
         buf.putInt(state.get2());
         buf.flip();
 
+        Path tmpWalPtr = ft.tmpCdcWalState();
+
         try (FileChannel ch = FileChannel.open(tmpWalPtr, StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {
             ch.write(buf);
 
             ch.force(true);
         }
 
-        Files.move(tmpWalPtr, walPtr, ATOMIC_MOVE, REPLACE_EXISTING);
+        Files.move(tmpWalPtr, ft.cdcWalState(), ATOMIC_MOVE, REPLACE_EXISTING);
     }
 
     /**
@@ -158,7 +104,7 @@ public void saveWal(T2<WALPointer, Integer> state) throws IOException {
      * @param typesState State of types.
      */
     public void saveTypes(Map<Integer, Long> typesState) throws IOException {
-        save(typesState, tmpTypes, types);
+        save(typesState, ft.tmpCdcTypesState(), ft.cdcTypesState());
     }
 
     /**
@@ -167,7 +113,7 @@ public void saveTypes(Map<Integer, Long> typesState) throws IOException {
      * @param mappingsState Mappings state.
      */
     public void saveMappings(Set<T2<Integer, Byte>> mappingsState) throws IOException {
-        save(mappingsState, tmpMappings, mappings);
+        save(mappingsState, ft.tmpCdcMappingsState(), ft.cdcMappingsState());
     }
 
     /**
@@ -176,6 +122,8 @@ public void saveMappings(Set<T2<Integer, Byte>> mappingsState) throws IOExceptio
      * @return Saved state.
      */
     public T2<WALPointer, Integer> loadWalState() {
+        Path walPtr = ft.cdcWalState();
+
         if (!Files.exists(walPtr))
             return null;
 
@@ -213,7 +161,7 @@ public T2<WALPointer, Integer> loadWalState() {
      * @return Saved state.
      */
     public Map<Integer, Long> loadCaches() {
-        Map<Integer, Long> state = load(caches, HashMap::new);
+        Map<Integer, Long> state = load(ft.cdcCachesState(), HashMap::new);
 
         log.info("Initial caches state loaded [cachesCnt=" + state.size() + ']');
 
@@ -230,7 +178,7 @@ public Map<Integer, Long> loadCaches() {
      * @param cachesState State of caches.
      */
     public void saveCaches(Map<Integer, Long> cachesState) throws IOException {
-        save(cachesState, tmpCaches, caches);
+        save(cachesState, ft.tmpCdcCachesState(), ft.cdcCachesState());
     }
 
     /**
@@ -239,7 +187,7 @@ public void saveCaches(Map<Integer, Long> cachesState) throws IOException {
      * @return Saved state.
      */
     public Set<T2<Integer, Byte>> loadMappingsState() {
-        Set<T2<Integer, Byte>> state = load(mappings, HashSet::new);
+        Set<T2<Integer, Byte>> state = load(ft.cdcMappingsState(), HashSet::new);
 
         assert state != null;
 
@@ -259,7 +207,7 @@ public Set<T2<Integer, Byte>> loadMappingsState() {
      * @return Saved state.
      */
     public Map<Integer, Long> loadTypesState() {
-        Map<Integer, Long> state = load(types, HashMap::new);
+        Map<Integer, Long> state = load(ft.cdcTypesState(), HashMap::new);
 
         assert state != null;
 
@@ -302,7 +250,7 @@ private <D> D load(Path state, Supplier<D> dflt) {
      * @return CDC mode state.
      */
     public CdcMode loadCdcMode() {
-        CdcMode state = load(cdcMode, () -> CdcMode.IGNITE_NODE_ACTIVE);
+        CdcMode state = load(ft.cdcModeState(), () -> CdcMode.IGNITE_NODE_ACTIVE);
 
         log.info("CDC mode loaded [" + state + ']');
 
@@ -315,6 +263,6 @@ public CdcMode loadCdcMode() {
      * @param mode CDC mode.
      */
     public void saveCdcMode(CdcMode mode) throws IOException {
-        save(mode, tmpCdcMode, cdcMode);
+        save(mode, ft.tmpCdcModeState(), ft.cdcModeState());
     }
 }
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cdc/CdcMain.java b/modules/core/src/main/java/org/apache/ignite/internal/cdc/CdcMain.java
index 09c528350d119..45ed9b1ac9aad 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cdc/CdcMain.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cdc/CdcMain.java
@@ -136,9 +136,6 @@ public class CdcMain implements Runnable {
     /** */
     public static final String ERR_MSG = "Persistence and CDC disabled. Capture Data Change can't run!";
 
-    /** State dir. */
-    public static final String STATE_DIR = "state";
-
     /** Current segment index metric name. */
     public static final String CUR_SEG_IDX = "CurrentSegmentIndex";
 
@@ -315,7 +312,7 @@ public void runX() throws Exception {
         }
 
         try (CdcFileLockHolder lock = lockPds()) {
-            Files.createDirectories(ft.walCdc().toPath().resolve(STATE_DIR));
+            Files.createDirectories(ft.cdcState());
 
             if (log.isInfoEnabled()) {
                 log.info("Change Data Capture [dir=" + ft.walCdc() + ']');
@@ -330,7 +327,7 @@ public void runX() throws Exception {
             try {
                 kctx.resource().injectGeneric(consumer.consumer());
 
-                state = createState(ft.walCdc().toPath().resolve(STATE_DIR));
+                state = createState(ft);
 
                 walState = state.loadWalState();
                 typesState = state.loadTypesState();
@@ -364,8 +361,8 @@ public void runX() throws Exception {
     }
 
     /** Creates consumer state. */
-    protected CdcConsumerState createState(Path stateDir) {
-        return new CdcConsumerState(log, stateDir);
+    protected CdcConsumerState createState(NodeFileTree ft) {
+        return new CdcConsumerState(log, ft);
     }
 
     /**
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cdc/CdcUtilityActiveCdcManager.java b/modules/core/src/main/java/org/apache/ignite/internal/cdc/CdcUtilityActiveCdcManager.java
index b2ff2a814f2f0..1fe3d07d045b6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cdc/CdcUtilityActiveCdcManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cdc/CdcUtilityActiveCdcManager.java
@@ -19,7 +19,6 @@
 
 import java.io.File;
 import java.nio.ByteBuffer;
-import java.nio.file.Paths;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.pagemem.wal.record.CdcManagerStopRecord;
 import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter;
@@ -27,9 +26,6 @@
 import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware;
 import org.apache.ignite.internal.util.typedef.internal.U;
 
-import static org.apache.ignite.internal.cdc.CdcConsumerState.CDC_MODE_FILE_NAME;
-import static org.apache.ignite.internal.cdc.CdcMain.STATE_DIR;
-
 /**
  * CDC manager that delegates consuming CDC events to the {@link CdcMain} utility.
  */
@@ -43,10 +39,7 @@ public class CdcUtilityActiveCdcManager extends GridCacheSharedManagerAdapter im
     @Override public void onDoneAfterTopologyUnlock(GridDhtPartitionsExchangeFuture fut) {
         if (fut.localJoinExchange() || fut.activateCluster()) {
             try {
-                File cdcModeFile = Paths.get(
-                    cctx.kernalContext().pdsFolderResolver().fileTree().walCdc().getAbsolutePath(),
-                    STATE_DIR,
-                    CDC_MODE_FILE_NAME).toFile();
+                File cdcModeFile = cctx.kernalContext().pdsFolderResolver().fileTree().cdcModeState().toAbsolutePath().toFile();
 
                 if (!cdcModeFile.exists())
                     cctx.wal(true).log(new CdcManagerStopRecord());
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/management/cdc/CdcDeleteLostSegmentsTask.java b/modules/core/src/main/java/org/apache/ignite/internal/management/cdc/CdcDeleteLostSegmentsTask.java
index b30302885e379..2330c7034d378 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/management/cdc/CdcDeleteLostSegmentsTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/management/cdc/CdcDeleteLostSegmentsTask.java
@@ -41,8 +41,6 @@
 import org.apache.ignite.resources.LoggerResource;
 import org.jetbrains.annotations.Nullable;
 
-import static org.apache.ignite.internal.cdc.CdcConsumerState.WAL_STATE_FILE_NAME;
-import static org.apache.ignite.internal.cdc.CdcMain.STATE_DIR;
 import static org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager.WAL_SEGMENT_FILE_FILTER;
 
 /**
@@ -139,10 +137,8 @@ protected CdcDeleteLostSegmentsJob(CdcDeleteLostSegmentLinksCommandArg arg, bool
                         log.info("Segment CDC link deleted [file=" + file.getAbsolutePath() + ']');
                     });
 
-                    Path stateDir = ft.walCdc().toPath().resolve(STATE_DIR);
-
-                    if (stateDir.toFile().exists()) {
-                        File walState = stateDir.resolve(WAL_STATE_FILE_NAME).toFile();
+                    if (ft.cdcState().toFile().exists()) {
+                        File walState = ft.cdcWalState().toFile();
 
                         if (walState.exists() && !walState.delete()) {
                             throw new IgniteException("Failed to delete wal state file [file=" +
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/NodeFileTree.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/NodeFileTree.java
index f8af446426ba1..61c1e2a9a44bf 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/NodeFileTree.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/NodeFileTree.java
@@ -33,6 +33,9 @@
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.DataStorageConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.cdc.CdcMain;
+import org.apache.ignite.internal.cdc.CdcManager;
+import org.apache.ignite.internal.cdc.CdcMode;
 import org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.A;
@@ -179,7 +182,7 @@ public class NodeFileTree extends SharedFileTree {
     public static final String WAL_SEGMENT_FILE_EXT = ".wal";
 
     /** File suffix. */
-    public static final String FILE_SUFFIX = ".bin";
+    static final String FILE_SUFFIX = ".bin";
 
     /** Suffix for tmp files */
     public static final String TMP_SUFFIX = ".tmp";
@@ -231,6 +234,30 @@ public class NodeFileTree extends SharedFileTree {
     /** Prefix for {@link #cacheStorage(CacheConfiguration)} directory in case of cache group. */
     private static final String CACHE_GRP_DIR_PREFIX = "cacheGroup-";
 
+    /** CDC state directory name. */
+    private static final String CDC_STATE_DIR = "state";
+
+    /**
+     * The file stores state of CDC mode. Content of the file is a {@link CdcMode} value:
+     * <ul>
+     *     <li>{@link CdcMode#CDC_UTILITY_ACTIVE} means that {@link CdcMain} utility captures data.</li>
+     *     <li>{@link CdcMode#IGNITE_NODE_ACTIVE} means that {@link CdcManager} captures data within Ignite node.</li>
+     * </ul>
+     */
+    private static final String CDC_MODE_FILE_NAME = "cdc-mode" + FILE_SUFFIX;
+
+    /** CDC WAL state file name. */
+    private static final String CDC_WAL_STATE_FILE_NAME = "cdc-wal-state" + FILE_SUFFIX;
+
+    /** CDC types state file name. */
+    private static final String CDC_TYPES_STATE_FILE_NAME = "cdc-types-state" + FILE_SUFFIX;
+
+    /** CDC mappings state file name. */
+    private static final String CDC_MAPPINGS_STATE_FILE_NAME = "cdc-mappings-state" + FILE_SUFFIX;
+
+    /** CDC caches state file name. */
+    private static final String CDC_CACHES_STATE_FILE_NAME = "cdc-caches-state" + FILE_SUFFIX;
+
     /** Folder name for consistent id. */
     private final String folderName;
 
@@ -817,6 +844,61 @@ public CacheFileTree cacheTree(CacheConfiguration<?, ?> ccfg) {
         return new CacheFileTree(this, false, ccfg);
     }
 
+    /** @return CDC state directory path. */
+    public Path cdcState() {
+        return walCdc().toPath().resolve(CDC_STATE_DIR);
+    }
+
+    /** @return CDC WAL state file path. */
+    public Path cdcWalState() {
+        return cdcState().resolve(CDC_WAL_STATE_FILE_NAME);
+    }
+
+    /** @return Temp CDC WAL state file path. */
+    public Path tmpCdcWalState() {
+        return cdcState().resolve(CDC_WAL_STATE_FILE_NAME + TMP_SUFFIX);
+    }
+
+    /** @return CDC types state file path. */
+    public Path cdcTypesState() {
+        return cdcState().resolve(CDC_TYPES_STATE_FILE_NAME);
+    }
+
+    /** @return Temp CDC types state file path. */
+    public Path tmpCdcTypesState() {
+        return cdcState().resolve(CDC_TYPES_STATE_FILE_NAME + TMP_SUFFIX);
+    }
+
+    /** @return CDC mappings state file path. */
+    public Path cdcMappingsState() {
+        return cdcState().resolve(CDC_MAPPINGS_STATE_FILE_NAME);
+    }
+
+    /** @return Temp CDC mappings state file path. */
+    public Path tmpCdcMappingsState() {
+        return cdcState().resolve(CDC_MAPPINGS_STATE_FILE_NAME + TMP_SUFFIX);
+    }
+
+    /** @return CDC caches state file path. */
+    public Path cdcCachesState() {
+        return cdcState().resolve(CDC_CACHES_STATE_FILE_NAME);
+    }
+
+    /** @return Temp CDC caches state file path. */
+    public Path tmpCdcCachesState() {
+        return cdcState().resolve(CDC_CACHES_STATE_FILE_NAME + TMP_SUFFIX);
+    }
+
+    /** @return CDC manager mode state file path. */
+    public Path cdcModeState() {
+        return cdcState().resolve(CDC_MODE_FILE_NAME);
+    }
+
+    /** @return Temp CDC manager mode state file path. */
+    public Path tmpCdcModeState() {
+        return cdcState().resolve(CDC_MODE_FILE_NAME + TMP_SUFFIX);
+    }
+
     /**
      * @param includeMeta If {@code true} then include metadata directory into results.
      * @param filter Cache group names to filter.
diff --git a/modules/core/src/test/java/org/apache/ignite/cdc/AbstractCdcTest.java b/modules/core/src/test/java/org/apache/ignite/cdc/AbstractCdcTest.java
index 12a3b2d037e9c..12206c1ac5813 100644
--- a/modules/core/src/test/java/org/apache/ignite/cdc/AbstractCdcTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/cdc/AbstractCdcTest.java
@@ -19,7 +19,6 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
@@ -40,6 +39,7 @@
 import org.apache.ignite.internal.IgniteInterruptedCheckedException;
 import org.apache.ignite.internal.cdc.CdcConsumerState;
 import org.apache.ignite.internal.cdc.CdcMain;
+import org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree;
 import org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer;
 import org.apache.ignite.internal.util.lang.GridAbsPredicate;
 import org.apache.ignite.internal.util.typedef.CI3;
@@ -120,8 +120,8 @@ protected CdcMain createCdc(
         cdcCfg.setMetricExporterSpi(metricExporters());
 
         return new CdcMain(cfg, null, cdcCfg) {
-            @Override protected CdcConsumerState createState(Path stateDir) {
-                return new CdcConsumerState(log, stateDir) {
+            @Override protected CdcConsumerState createState(NodeFileTree ft) {
+                return new CdcConsumerState(log, ft) {
                     @Override public void saveWal(T2<WALPointer, Integer> state) throws IOException {
                         super.saveWal(state);
 


Reviews:
user: login: nizhikov
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-24T18:49:43Z
user: login: nizhikov
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-24T18:50:18Z
user: login: nizhikovprivate
state: COMMENTED
author_association: NONE
submitted_at: 2025-05-26T09:17:51Z
user: login: nizhikov
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-26T10:25:34Z
user: login: nizhikov
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-26T10:32:06Z
user: login: nizhikov
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-26T10:33:34Z
user: login: nizhikov
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-05-26T10:58:10Z
user: login: nizhikovprivate
state: APPROVED
author_association: NONE
submitted_at: 2025-05-26T18:32:02Z

Review comments:
diff_hunk: @@ -118,16 +97,16 @@ public class CdcConsumerState {
      */
     public CdcConsumerState(IgniteLogger log, Path stateDir) {
         this.log = log.getLogger(CdcConsumerState.class);
-        walPtr = stateDir.resolve(WAL_STATE_FILE_NAME);
-        tmpWalPtr = stateDir.resolve(WAL_STATE_FILE_NAME + TMP_SUFFIX);
-        types = stateDir.resolve(TYPES_STATE_FILE_NAME);
-        tmpTypes = stateDir.resolve(TYPES_STATE_FILE_NAME + TMP_SUFFIX);
-        mappings = stateDir.resolve(MAPPINGS_STATE_FILE_NAME);
-        tmpMappings = stateDir.resolve(MAPPINGS_STATE_FILE_NAME + TMP_SUFFIX);
-        caches = stateDir.resolve(CACHES_STATE_FILE_NAME);
-        tmpCaches = stateDir.resolve(CACHES_STATE_FILE_NAME + TMP_SUFFIX);
-        cdcMode = stateDir.resolve(CDC_MODE_FILE_NAME);
-        tmpCdcMode = stateDir.resolve(CDC_MODE_FILE_NAME + TMP_SUFFIX);
+        walPtr = NodeFileTree.walStateFilePath(stateDir, false);
path: modules/core/src/main/java/org/apache/ignite/internal/cdc/CdcConsumerState.java
user: login: nizhikov
body: Let's inline all usages of `walPtr` and other class variables and remove them from `CdcConsumerState`.
created_at: 2025-05-24T18:49:43Z
author_association: CONTRIBUTOR
diff_hunk: @@ -142,7 +141,7 @@ protected CdcDeleteLostSegmentsJob(CdcDeleteLostSegmentLinksCommandArg arg, bool
                     Path stateDir = ft.walCdc().toPath().resolve(STATE_DIR);
 
                     if (stateDir.toFile().exists()) {
-                        File walState = stateDir.resolve(WAL_STATE_FILE_NAME).toFile();
+                        File walState = NodeFileTree.walStateFilePath(stateDir, false).toFile();
path: modules/core/src/main/java/org/apache/ignite/internal/management/cdc/CdcDeleteLostSegmentsTask.java
user: login: nizhikov
body: This must be NOT static method - we have all information inside `NodeFileTree`, already.
created_at: 2025-05-24T18:50:18Z
author_association: CONTRIBUTOR
diff_hunk: @@ -879,6 +903,51 @@ public static int typeId(String fileName) {
         return Integer.parseInt(fileName.substring(0, fileName.length() - FILE_SUFFIX.length()));
     }
 
+    /**
+     * @param stateDir State directory.
+     * @param isTmp {@code True} if the temporary file.
+     * @return WAL state file path.
+     */
+    public static Path walStateFilePath(Path stateDir, boolean isTmp) {
path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/NodeFileTree.java
user: login: nizhikovprivate
body: This and all the new methods below must NOT be static.

```
    private File cdcState() {
        return new File(walCdc(), CDC_STATE_DIR);
    }

    public Path cdcWalState() {
        Path.resolve(cdcState().toPath(), WAL_STATE_FILE_NAME);
    }

    public Path tmpCdcWalState() {
        Path.resolve(cdcState(), WAL_STATE_FILE_NAME + TMP_SUFFIX);
    }
created_at: 2025-05-26T09:17:51Z
author_association: NONE
diff_hunk: @@ -246,6 +244,9 @@ public class NodeFileTree extends SharedFileTree {
     /** Prefix for {@link #cacheStorage(CacheConfiguration)} directory in case of cache group. */
     private static final String CACHE_GRP_DIR_PREFIX = "cacheGroup-";
 
+    /** WAL state file name. */
+    private static final String WAL_STATE_FILE_NAME = "cdc-wal-state" + FILE_SUFFIX;
path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/NodeFileTree.java
user: login: nizhikov
body: FILE_SUFFIX must be made package private.
created_at: 2025-05-26T10:25:34Z
author_association: CONTRIBUTOR
diff_hunk: @@ -49,6 +49,7 @@
 import static org.apache.ignite.configuration.DataStorageConfiguration.DFLT_WAL_ARCHIVE_PATH;
 import static org.apache.ignite.configuration.DataStorageConfiguration.DFLT_WAL_CDC_PATH;
 import static org.apache.ignite.configuration.DataStorageConfiguration.DFLT_WAL_PATH;
+import static org.apache.ignite.internal.cdc.CdcMain.STATE_DIR;
path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/NodeFileTree.java
user: login: nizhikov
body: `STATE_DIR` must be moved to `NodeFileTree`
created_at: 2025-05-26T10:32:06Z
author_association: CONTRIBUTOR
diff_hunk: @@ -246,6 +244,9 @@ public class NodeFileTree extends SharedFileTree {
     /** Prefix for {@link #cacheStorage(CacheConfiguration)} directory in case of cache group. */
     private static final String CACHE_GRP_DIR_PREFIX = "cacheGroup-";
 
+    /** WAL state file name. */
+    private static final String WAL_STATE_FILE_NAME = "cdc-wal-state" + FILE_SUFFIX;
path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/filename/NodeFileTree.java
user: login: nizhikov
body: CdcUtilityActiveCdcManager:

```
                File cdcModeFile = Paths.get(
                   cctx.kernalContext().pdsFolderResolver().fileTree().walCdc().getAbsolutePath(),
                    STATE_DIR,
                    CDC_MODE_FILE_NAME).toFile();

```

Path to the file must be calculated in `NodeFileTree`.
created_at: 2025-05-26T10:33:34Z
author_association: CONTRIBUTOR

PR comments:
user: login: sonarqubecloud[bot]
created_at: 2025-05-26T18:41:30Z
body: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=12091) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_ignite&pullRequest=12091&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_ignite&pullRequest=12091&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_ignite&pullRequest=12091&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_ignite&pullRequest=12091&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_ignite&pullRequest=12091&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=12091)


author_association: NONE