LuciferYang opened a new pull request, #64676:
URL: https://github.com/apache/doris/pull/64676

   ### What problem does this PR solve?
   
   Problem Summary:
   
   `MetaLockUtils.commitLockTables` has a rollback bug: when `commitLock()` 
throws for the table at index `i`, the rollback loop iterates `j` from `i-1` 
down to `0` but unlocks `tableList.get(i)` (the table that failed to lock) 
instead of `tableList.get(j)` (the previously locked tables):
   
   ```java
   public static void commitLockTables(List<Table> tableList) {
       for (int i = 0; i < tableList.size(); i++) {
           try {
               tableList.get(i).commitLock();
           } catch (Exception e) {
               for (int j = i - 1; j >= 0; j--) {
                   tableList.get(i).commitUnlock();   // should be get(j)
               }
           }
       }
   }
   ```
   
   Consequences on the failure path:
   
   - The commit locks already acquired for tables `0..i-1` are never released 
(leak).
   - The failing table (`i`) is `commitUnlock()`-ed repeatedly on a lock it 
does not hold.
   - The exception is swallowed and the outer loop keeps trying to lock the 
remaining tables.
   
   This PR unlocks `get(j)` and rethrows after rollback, matching the existing 
correct siblings `tryCommitLockTables` and `writeLockTablesOrMetaException`.
   
   Note: in normal operation `commitLock()` → `MonitoredReentrantLock.lock()` 
does not throw, so this `catch` is defensive and the bug is latent. The fix 
makes the rare failure path correct: release the locks already acquired and 
fail loudly, instead of leaking locks and silently proceeding.
   
   ### Release note
   
   None
   
   ### Check List (For Author)
   
   - Test
       - [x] Unit Test (added `testCommitLockTablesReleasesLocksOnFailure` in 
`MetaLockUtilsTest`)
   
   - Behavior changed:
       - [x] Yes. On a commit-lock acquisition failure, previously acquired 
commit locks are now released and the failure is propagated instead of 
swallowed.
   
   - Does this need documentation?
       - [x] No.
   


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to