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

   ## Problem
   
   `AlignedWritableMemChunk.encode` narrowed 
`BatchEncodeInfo.maxNumberOfPointsInChunk` in place:
   
   ```java
   encodeInfo.maxNumberOfPointsInChunk =
       Math.min(
           encodeInfo.maxNumberOfPointsInChunk,
           encodeInfo.targetChunkSize / getAvgPointSizeOfLargestColumn());
   ```
   
   `BatchEncodeInfo` is shared by every device encoded by one 
`MemTableFlushTask`, and `reset()` only clears the point/size counters. The 
narrowed cap therefore leaked into all following devices and series of the same 
flush.
   
   ## Example
   
   A flush task encodes device A (one wide TEXT column) and then device B:
   
   - Target chunk size: 4096 bytes; largest average point size of A: 1024 
bytes. A's effective cap becomes 4 points.
   - Before: after encoding A, `BatchEncodeInfo.maxNumberOfPointsInChunk` stays 
4. Device B, which has only INT64 columns and an original cap of 100000 points, 
is also encoded with a cap of 4 → many small chunks, more chunk metadata and 
compression calls, worse file layout.
   - After: A still uses 4, but the shared value is restored in a `finally` 
block, so B uses the original 100000.
   
   The non-aligned `WritableMemChunk.encode` path never modified this field, so 
the behavior is now symmetric.
   
   ## Fix
   
   The narrowed cap is now computed and used only inside the aligned `encode` 
call. The original value is saved before the computation and restored in a 
`finally` block, so early returns and exceptions cannot leak it either.
   
   ## Validation
   
   ```bash
   mvn -pl iotdb-core/datanode -am \
     -Dtest=AlignedWritableMemChunkTest \
     -Dsurefire.failIfNoSpecifiedTests=false test
   ```
   
   Result: 5 tests run, 0 failures, 0 errors.
   
   A new regression test writes 10 TEXT points with a 1024-byte average point 
size and a 4096-byte target chunk size, verifies that the local cap is actually 
applied (more than one chunk is produced), and asserts that 
`BatchEncodeInfo.maxNumberOfPointsInChunk` still holds the original value after 
`encode`.
   


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