luoluoyuyu opened a new pull request, #19258: URL: https://github.com/apache/iotdb/pull/19258
## Description `pipe` pins a TsFile before sending it by creating a hardlink (or a copy of it) under the pipe directory. That directory has always been `<dataDirectory>/pipe`, which only works while the pipe directory and the data directory are on the same file system. A DataRegion is not bound to one disk: every new TsFile, including compaction targets, is allocated by `FolderManager` according to `dn_multi_dir_strategy`. The TsFiles of one DataRegion — and therefore of one pipe — can be spread over all data disks. The pipe directory must be resolved per TsFile, not per DataRegion or per pipe. ### Content1: per-TsFile pipe directory resolution `PipeTsFileDirPathMapping` resolves the pipe directory of a given TsFile (or its `.resource` / `.mod` file): - The owning data directory is matched by the longest canonical-path prefix, and the TsFile goes to `<pipe dir of that data directory>/tsfile/<pipeName>/<relative path>`. - Files outside the configured data directories (tests, restored paths, data directories changed by an operator) keep the previous path-derived layout, so the behavior does not regress. - Files that are already under a pipe directory are returned as is instead of being linked/copied again. ### Content2: configuration and startup validation - New property `dn_pipe_hardlink_dirs` (comma-separated, absolute or relative to `IOTDB_HOME`, `dn_`-prefixed, restart-only). Each local data directory is bound at startup to the configured pipe directory on the same file system (mount point). One pipe directory can be shared by all the data directories on the same disk. - When the property is unset, the legacy `<dataDirectory>/pipe` layout is kept and the behavior is unchanged. - A local data directory without a same-disk pipe directory makes the DataNode fail fast at startup, with a message listing the uncovered data directories and the configured pipe directories. This avoids silently copying every TsFile at runtime. ### Content3: robustness, external storage and cleanup - `FileUtils.createHardLinkOrCopy` falls back to copying the TsFile when a hardlink cannot be created (e.g., the pipe directory is on another device, or the file system does not support hardlinks), with a warning, so a pipe task does not fail because of the storage layout. - TsFiles on non-local storage (HDFS / object storage) are read in place: they are neither hardlinked nor copied, and the pipe reference count never deletes them. - The files of one pipe may now live in several directories. `cleanPipeTsFileDir` moves every directory of the pipe aside, and the startup cleaner cleans `<pipe dir>/tsfile` (plus interrupted `*.startup-cleaning-*` directories) for the default and for every configured pipe directory. - The resolved mapping is logged at startup, so operators can check which data directory is bound to which pipe directory. ### Example #### Before `dn_pipe_hardlink_dirs` does not exist; the hardlink of every TsFile is always created under `<dataDirectory>/pipe`. If that path is on another file system than the TsFile (for example `sequence`/`unsequence` is mounted separately, or the data directory is a symlink), `Files.createLink` throws `Invalid cross-device link` and every pipe task touching the TsFile keeps failing. #### After ```properties dn_data_dirs=/mnt/disk1/iotdb/data,/mnt/disk2/iotdb/data dn_pipe_hardlink_dirs=/mnt/pipe1,/mnt/pipe2 ``` - TsFile on disk 1 -> `/mnt/pipe1/tsfile/<pipeName>/sequence-root.db-0-0-1-0-0.tsfile` - TsFile on disk 2 -> `/mnt/pipe2/tsfile/<pipeName>/sequence-root.db-0-0-1-0-0.tsfile` If `/mnt/pipe2` is omitted, the DataNode refuses to start with: ``` Pipe hardlink directories ... The configured pipe hardlink directories [/mnt/pipe1] do not cover data directories [/mnt/disk2/iotdb/data]. Please configure a pipe hardlink directory on the same disk as every data directory. ``` If the pipe directory ends up on another device at runtime (e.g., a mount changes), the TsFile is copied instead of hardlinked and a warning is logged. Leaving `dn_pipe_hardlink_dirs` unset keeps the previous `<dataDirectory>/pipe` layout. ## Test plan - New `PipeTsFileDirPathMappingTest`: default layout, per-disk binding (injected and real mount-point detection), uncovered data directory fails, files outside data directories fall back to the legacy layout, non-local files are returned as is, files already in a pipe directory are not linked again. `OK (7 tests)`. - `mvn spotless:apply` / `mvn checkstyle:check` on `node-commons` and `datanode`. - English and Chinese message classes compile (`-P with-zh-locale` parity preserved: same constant names, same placeholders). - Existing `PipeTsFileResourceManagerTest` should be unaffected when `dn_pipe_hardlink_dirs` is unset (same directory layout and the same link-or-copy semantics on the same disk). <hr> This PR has: - [x] been self-reviewed. - [x] added documentation for new or modified features or behaviors. - [x] added Javadocs for most classes and all non-trivial methods. - [x] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader. - [x] added unit tests or modified existing tests to cover new code paths. - [ ] added integration tests. - [ ] been tested in a test IoTDB cluster. <hr> ##### Key changed/added classes (or packages if there are too many classes) in this PR - `org.apache.iotdb.db.pipe.resource.tsfile.PipeTsFileDirPathMapping` (new) - `org.apache.iotdb.db.pipe.resource.tsfile.PipeTsFileDirPathResolver` (new) - `org.apache.iotdb.db.pipe.resource.tsfile.PipeTsFileResourceManager` - `org.apache.iotdb.db.pipe.resource.PipeDataNodeHardlinkOrCopiedFileDirStartupCleaner` - `org.apache.iotdb.db.conf.IoTDBConfig` / `IoTDBDescriptor` - `org.apache.iotdb.commons.utils.FileUtils` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
