lollipopjin commented on code in PR #10473:
URL: https://github.com/apache/rocketmq/pull/10473#discussion_r3400275230


##########
tieredstore/src/main/java/org/apache/rocketmq/tieredstore/file/FlatAppendFile.java:
##########
@@ -81,22 +81,15 @@ public void recover() {
      * @see <a href="https://github.com/apache/rocketmq/issues/9544";>Related 
GitHub Issue</a>
      */
     public long getFileCorrectSize(FileSegment fileSegment) {
-        while (true) {
+        for (int retry = 0; retry < 3; retry++) {
             long fileSize = fileSegment.getSize();
             if (fileSize != GET_FILE_SIZE_ERROR) {
-                log.debug("FlatAppendFile get file correct size, filePath={} 
fileType={}, fileSize={}",
-                    fileSegment.getPath(), fileSegment.getFileType(), 
fileSize);
                 return fileSize;
-            } else {
-                log.warn("FlatAppendFile get file correct size error, 
filePath={}, fileType={}",
-                    fileSegment.getPath(), fileSegment.getFileType());
-                try {
-                    TimeUnit.MILLISECONDS.sleep(50);
-                } catch (InterruptedException e) {
-                    log.warn("FlatAppendFile get file correct size 
interrupted", e);
-                }
             }
         }
+        log.error("FlatAppendFile#getFileCorrectSize, get file correct size 
failed after 3 retries, path={}, type={}",
+            fileSegment.getPath(), fileSegment.getFileType());
+        return GET_FILE_SIZE_ERROR;

Review Comment:
   [FileSegment state corruption risk]
   
   The change from infinite-retry to bounded-retry in `getFileCorrectSize()` 
   introduces a new failure path: returning GET_FILE_SIZE_ERROR (-1).
   
   However, callers `recoverFileSize()` and `initOffset()` pass the return 
value 
   directly to `fileSegment.initPosition(fileSize)` without checking for -1.
   
   If initPosition(-1) is called, it sets commitPosition=-1 and 
appendPosition=-1, 
   which corrupts the segment state — readAsync() will reject all reads, and 
append() 
   overflow checks will malfunction.



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