hongzhi-gao opened a new pull request, #18907:
URL: https://github.com/apache/iotdb/pull/18907

   ## Description
   
   ObjectWriter previously accepted consensus writes whose offset exceeded the 
file length. FileChannel.truncate does not extend the file, so positioning and 
writing at that offset could leave a zero-filled gap instead of the missing 
segment contents.
   
   Reject offsets beyond EOF with the existing IOException before truncating, 
repositioning, or writing. Preserve sequential appends, consensus 
rollback/rewrite, offset-zero overwrite, and rejection of ordinary nonzero 
rollback. Reuse the existing localized error message and leave the shared 
truncation helper unchanged.
   
   Add two JUnit tests using real temporary files and byte-content assertions. 
They cover missing first/middle segments for ordinary and consensus requests, 
unchanged contents after rejection, appending after filling the gap, and valid 
rewrites/appends/overwrites after reopening.
   
   ### Validation
   
   Executed on JDK 17:
   
   ```sh
   mvn spotless:apply -o -pl iotdb-core/datanode -Ddevelocity.off=true
   mvn test -o -pl iotdb-core/datanode -am -Dtest=ObjectWriterTest 
-Dsurefire.failIfNoSpecifiedTests=false -DfailIfNoTests=false 
-Ddevelocity.off=true
   git diff --check
   ```
   
   Formatting and diff checks passed. The reactor command compiled main/test 
sources and passed both tests (0 failures, 0 errors, 0 skipped). Running the 
same tests against the original implementation failed the missing-segment test 
because a consensus write beyond EOF did not throw IOException; the rewrite 
test passed.
   
   The initial single-module test command (`mvn test -o -pl iotdb-core/datanode 
-Dtest=ObjectWriterTest -Ddevelocity.off=true`) failed during compilation 
because installed dependencies lacked interfaces used by the current sources. 
The reactor command above resolved this mismatch.
   
   No cluster IT was added: DataExecutionVisitor.visitWriteObjectFile still 
throws UnsupportedOperationException, and no ObjectWriter instantiation was 
found in production sources. These tests establish the underlying file-writer 
behavior, not an end-to-end Apache cluster corruption scenario. No format, 
protocol, locking, WAL, snapshot, or resource-lifecycle change is introduced; 
performance was not benchmarked.
   
   <hr>
   
   This PR has:
   
   - [x] been self-reviewed.
   - [x] added unit tests covering the changed behavior with real files.
   
   <hr>
   
   ##### Key changed/added classes
   
   - ObjectWriter
   - ObjectWriterTest
   


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