Caideyipi opened a new pull request, #19190:
URL: https://github.com/apache/iotdb/pull/19190

   ## Description
   
   Schema-file initialization, shutdown, and positional writes can leave 
incomplete data or open resources after an I/O failure. This change writes the 
initial header immediately, completes short header and page writes, and 
attempts all cleanup steps while preserving the original exception.
   
   - Write headers and pages until their buffers are exhausted, advancing the 
file offset by the actual number of bytes written. Fail immediately if a write 
makes no progress.
   - Keep a page dirty after a failed write. A subsequent flush starts at the 
beginning of the page and writes the entire page again.
   - Persist a valid initial header after creating or clearing a schema file. 
If initialization of a new file fails, close resources and truncate the partial 
file so initialization can be retried.
   - Close schema-file read, write, and log resources on shutdown and 
initialization/recovery failures. Report the first failure and retain later 
cleanup failures as suppressed exceptions.
   - Add regression tests and English/Chinese messages for writes that make no 
progress.
   
   ### Failure examples
   
   | Trigger | Previous behavior | Behavior with this change |
   | --- | --- | --- |
   | A 16 KiB page is written in chunks of 4,093 bytes | The first short write 
could be accepted as a complete flush and the page marked clean. | Writes 
continue for 4,093 + 4,093 + 4,093 + 4,093 + 12 bytes, advancing both the 
buffer position and file offset. The page becomes clean only after all 16,384 
bytes are written. |
   | A page write consumes 3 bytes, then the next write returns 0 or throws an 
`IOException` | A single short write could return successfully without 
attempting the remainder. | Zero progress fails immediately; an `IOException` 
is propagated unchanged. The page stays dirty, and a retry starts from the 
page's original file offset with the full page. |
   | `SchemaFile.clear()` recreates the file and it is reopened before a later 
header update | The new file could contain its root page without a valid 
persisted header. | Initialization persists the complete header, allowing the 
recreated file to be reopened. |
   | A header write or page-manager close fails during `SchemaFile.close()` | 
The exception could prevent subsequent resources from being closed. | Remaining 
cleanup steps are attempted, the first exception is rethrown, and later 
failures are attached as suppressed exceptions. |
   
   ### Validation
   
   - Spotless and `git diff --check` passed.
   - A local isolated build started from a clean source reactor: 
`SchemaPageTest` and `SchemaFileTest` passed, with 26 tests, 0 failures, 0 
errors, and 0 skipped. All newly added tests were run locally.
   - The initial isolated build stopped at formatting because patch application 
introduced CRLF line endings. After normalization to LF, the build and tests 
passed.
   - Chinese-locale `clean test-compile` passed for the 28 relevant reactor 
modules. This does not establish that the full repository compiles with the 
Chinese locale.
   - Remote tests were not run because Maven Central was unreachable. Cluster 
integration tests were not run.
   - These are the completed pre-publication checks; publication preserves the 
reviewed source contents without rerunning the checks.
   
   <hr>
   
   This PR has:
   
   - [x] been self-reviewed.
   - [x] added unit tests to cover the changed code paths.
   
   ##### Key changed classes
   
   `SchemaFile`, `SchemaPage`, `PageIOChannel`, `PageManager`
   


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