Denovo1998 commented on PR #25514:
URL: https://github.com/apache/pulsar/pull/25514#issuecomment-4304763201

   @geniusjoe @dao-jun @codelipenghui @hanmz 
   
   Seems like there are some issues?
   
   ```
   Request A and Request B create a schema for a new topic simultaneously.
   
   T1: A finds the locator does not exist.
   
   T2: B also finds the locator does not exist.
   
   T3: A creates BK ledger L1 and writes the schema entry.
   
   T4: B creates BK ledger L2 and writes the schema entry.
   
   T5: A's createSchemaLocator is successful, and the locator points to L1.
   
   T6: B's createSchemaLocator fails, receiving a BadVersionException / 
AlreadyExistsException.
   
   T7: B's whenComplete calls asyncDeleteLedger(L2).
   
   T8: asyncDeleteLedger only asynchronously commits deletion and returns 
immediately.
   
   T9: B's createNewSchema future still completes with a BadVersionException.
   
   T10: The upper BookkeeperSchemaStorage#put catches the BadVersionException 
and immediately retries.
   
   T11: The retry re-reads the locator, finds that the schema already exists, 
and the request succeeds and returns.
   
   T12: But the deletion callback of L2 may not have finished executing.
   ```
   
   `whenComplete` only waits for this callback to return, but the callback 
starts a callback-based `bookKeeper.asyncDeleteLedger(...)` and returns before 
the ledger deletion is confirmed. As a result, the outer `put(...)` can observe 
the original `BadVersionException` / `AlreadyExistsException`, retry 
immediately, and complete the schema creation before the orphan ledger is 
actually removed. This makes the new `getLedgerMap()` assertion 
timing-sensitive, and also weakens the cleanup guarantee exposed to callers. 
Could we wrap `asyncDeleteLedger` in a `CompletableFuture` and compose it 
before rethrowing the original CAS exception so the existing retry happens 
after the delete callback completes?
   


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