lhotari opened a new pull request #11387: URL: https://github.com/apache/pulsar/pull/11387
### Motivation OpReadEntry is not multi-thread safe. OpReadEntry.entries is an ArrayList without any synchronization. However it is accessed from multiple threads. Here's an example of such code: OpReadEntry.entries mutated: https://github.com/apache/pulsar/blob/d383b22a63af45d810111af2e502e5c26774f82e/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpReadEntry.java#L81 Mutation triggered from multiple threads: https://github.com/apache/pulsar/blob/d383b22a63af45d810111af2e502e5c26774f82e/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpReadEntry.java#L137-L148 The operations seem to happen sequentially when OpReadEntry.entries is mutated or accessed, but this is not enough for ensuring thread safety in Java. The goal of this change is to improve Managed Ledger operations by running operations in the pinned executor thread where the thread is picked by the hash of the managed ledger name. This is how most of the code is already written, but there are some exceptions in the current code. **The goal of this PR change is to ensure that the pinned executor is used in all cases where work is scheduled to run using the ledger's executor.** ### Modifications - Don't expose OrderedExecutor from ManagedLedgerImpl.getExecutor - instead, return executor that is pinned to a single thread with `.chooseThread(getName())` - most usages of ManagedLedgerImpl.getExecutor were already calling `.chooseThread(ml.getName())`, however some locations were omitting it. It's better to always pin the ManagedLedgerImpl.getExecutor to a single thread. - this improves thread safety of Managed Ledger code base since more operations will happen in a single thread - some classes such as OpReadEntry are not multi-thread safe. OpReadEntry.entries is a ArrayList without any synchronization. -- 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]
