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

   ### What problem does this PR solve?
   
   Problem Summary:
   
   Analyzing an `ALTER TABLE ... ADD INDEX` / `CREATE INDEX` statement 
allocated a
   persistent index id via `Env.getNextId()` inside `CreateIndexOp.validate()`
   (`IndexDefinition.translateToCatalogStyle()`). `getNextId()` may write an
   `OP_SAVE_NEXTID` edit log entry.
   
   Statement analysis is **not** master-only — audit plugins re-parse SQL on
   follower FEs. Allocating an id there writes the edit log on a non-master 
node.
   If the BDBJE journal database handle has been replicated-removed in the
   meantime, `BDBJEJournal.write()` throws `DatabasePreemptedException`, 
retries a
   few times and then exits the FE process (`System.exit(-1)`), restarting the 
FE.
   
   Observed call chain on a follower FE:
   
   ```
   BDBJEJournal.write()
     <- EditLog.logSaveNextId()
     <- MetaIdGenerator.getNextId() / Env.getNextId()
     <- CreateIndexOp.validate() -> IndexDefinition.translateToCatalogStyle()
     <- audit plugin re-parsing the audited SQL
     <- AuditEventProcessor.handleAuditEvent()
     <- WorkloadRuntimeStatusMgr.runAfterCatalogReady()   // runs on all FEs
   ```
   
   This PR defers index id allocation from the analysis phase to the master DDL
   execution path:
   
   - `IndexDefinition`: add a side-effect-free 
`translateToCatalogStyleWithoutId()`
     (the id keeps `Index.INDEX_ID_INIT_VALUE`); `translateToCatalogStyle()` now
     delegates to it and then allocates the id.
   - `CreateIndexOp.validate()`: use the non-allocating variant, so statement
     analysis writes no edit log.
   - `SchemaChangeHandler.processAddIndex()`: allocate the real index id here,
     which only runs on the master during DDL execution.
   
   The `CREATE TABLE` inline-index path is intentionally unchanged: its
   `translateToCatalogStyle()` runs during master-side table creation, not 
during
   analysis.
   
   ### Release note
   
   Fix a possible FE restart: a non-master FE could exit while an audit plugin
   re-parsed a `CREATE INDEX` / `ALTER TABLE ... ADD INDEX` statement, because
   allocating the index id during analysis wrote an edit log entry on the 
follower.
   
   ### Check List (For Author)
   
   - Test
       - [x] Unit Test
       - [ ] Regression test
       - [ ] Manual test (add detailed scripts or steps below)
       - [ ] No need to test or manual test.
   
   - Behavior changed:
       - [x] No.
       - [ ] Yes.
   
   - Does this need documentation?
       - [x] No.
       - [ ] Yes.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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