luoluoyuyu commented on PR #19258:
URL: https://github.com/apache/iotdb/pull/19258#issuecomment-6849719099

   A few more findings after re-reading the final patch. The ownership scoping, 
the `Set`-based cleanup, the canonical paths and the cleaner prefix matching 
all re-check out; the items below are about the copy fallback and one guard. I 
believe none of them blocks the PR, but item 1 is a real failure mode.
   
   ### 1. `.mod` copies are neither atomic nor overwrite-safe, so one transient 
failure makes the TsFile unpinnable
   
   `increaseFileReference()` still uses the plain copy for non-TsFiles, both 
for the private reference and for the public one in `increasePublicReference()` 
(line 119–125):
   
   ```java
   resultFile =
       isTsFile
           ? createHardLinkOrCopy(source, hardlinkOrCopiedFile, resource)
           : FileUtils.copyFile(source, hardlinkOrCopiedFile);
   ```
   
   `FileUtils.copyFile()` is `Files.copy(source, target)` **without 
`REPLACE_EXISTING`** (verified: it throws `FileAlreadyExistsException` when the 
target exists). So:
   
   - if the copy is interrupted (ENOSPC, any exception, a kill in the middle), 
a partial `<name>.mods` stays in `<dataDir>/pipe/tsfile/<pipeName>/`;
   - **every later pin of the same TsFile** then fails at this copy with 
`FileAlreadyExistsException`, and the rollback only releases the TsFile 
reference, so the leftover stays and the pin fails again on every retry — 
effectively permanently, with `pinFailedCount` growing;
   - the public copy in `increasePublicReference()` has the same problem, and 
there it blocks every pipe, not only the one being pinned.
   
   This is the same failure class that the atomic copy removes for TsFiles, so 
I would route all copies through it:
   
   ```java
   resultFile =
       isTsFile
           ? createHardLinkOrCopy(source, hardlinkOrCopiedFile, resource)
           : copyFileAtomically(source, hardlinkOrCopiedFile);
   ```
   
   and delete a leftover temporary file before copying, because 
`<target>.unfinished` left by a kill would otherwise fail the same way (today 
only the startup cleaner removes it):
   
   ```java
   try {
     FileUtils.deleteFileIfExist(unfinishedFile);
     FileUtils.copyFile(sourceFile, unfinishedFile);
   ```
   
   With that, the "**The copy is atomic**" sentence in the description also 
holds for every copy, not only for TsFiles.
   
   ### 2. The atomic copy has no test coverage, and the leftover test exercises 
a different path
   
   `testTruncatedLeftoverPipeFileIsReplaced()` writes a 3-byte file at the pipe 
path, but on the same file system `FileUtils.createHardLink()` already handles 
an existing target by comparing the MD5 and relinking, so 
`copyFileAtomically()` is never entered; the test actually covers the 
pre-existing `commons` behaviour. Its comment ("whose hardlink can not be 
created") and its name suggest otherwise. Suggest re-wording it to what it 
verifies (a stale pipe file with different content is replaced instead of being 
reused) and either forcing the copy path through a `@TestOnly` seam around the 
hardlink call, or saying in the description that `ATOMIC_MOVE` is only 
exercised by the multi-disk manual run.
   
   ### 3. The self-link guard can silently return a nonexistent file
   
   ```java
   if 
(sourceFile.getAbsoluteFile().equals(hardlinkOrCopiedFile.getAbsoluteFile())) {
     // A pipe file left by a previous process: never link it onto itself, and 
never delete the
     // target of a failed link, because that target is the source here.
     return hardlinkOrCopiedFile;
   }
   ```
   
   Returning the target is right for a leftover pipe file, but 
`getHardlinkOrCopiedFileInPipeDir()` also returns paths in the requesting scope 
whose file is gone — e.g. an event that pins a pipe path after `drop pipe` 
moved that directory aside, or a historical event whose pin was skipped. In 
that case a `PipeTsFileResource` with a reference count is registered for a 
missing file and the sink fails when it opens it; before this PR the same 
situation failed the pin immediately with `NoSuchFileException`. Cheap, and 
consistent with the "fail the pin loudly" approach of this PR:
   
   ```java
   if 
(sourceFile.getAbsoluteFile().equals(hardlinkOrCopiedFile.getAbsoluteFile())) {
     if (!hardlinkOrCopiedFile.isFile()) {
       throw new IOException(
           String.format(
               DataNodePipeMessages.EXCEPTION_..._HASH, 
hardlinkOrCopiedFile.getPath()));
     }
     return hardlinkOrCopiedFile;
   }
   ```
   
   (a new `EXCEPTION_` constant in both locales).
   
   ### 4. Nit: `refresh()` takes the resolver monitor on every pin
   
   `refresh()` is `synchronized` as a whole now, so every 
`getHardlinkOrCopiedFileInPipeDir()` call — once per TsFile on the assigner and 
historical extractor path — enters the monitor. The previous double-checked 
version kept the common case lock-free:
   
   ```java
   @Nonnull
   PipeTsFileDirPathMapping refresh(final @Nonnull String[] localDataDirs) {
     if (Arrays.equals(localDataDirs, resolvedLocalDataDirs)) {
       return mapping;
     }
     synchronized (this) {
       if (!Arrays.equals(localDataDirs, resolvedLocalDataDirs)) {
         mapping = new PipeTsFileDirPathMapping(localDataDirs, 
pipeHardlinkBaseDirName, pipeHardlinkTsFileDirName);
         resolvedLocalDataDirs = localDataDirs;
       }
       return mapping;
     }
   }
   ```
   
   Nothing else from my side. Still open from the checklist: the CI run (it was 
pending when I looked) and the manual multi-disk verification. I will push 
items 1–3 in a follow-up commit.
   


-- 
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]

Reply via email to