hangc0276 opened a new pull request, #16390: URL: https://github.com/apache/pulsar/pull/16390
### Motivation When using RawReader to read messages, we found some messages are out of order. For method `tryCompletePending`, we find there are two thread pools to call it, one is `pulsar-client-internal` and the other is `pulsar-io` https://github.com/apache/pulsar/blob/aabd5d020543210921f10648caf6720adc41d651/pulsar-broker/src/main/java/org/apache/pulsar/client/impl/RawReaderImpl.java#L131-L164 When triggered by `messageReceived()`, it will use `pulsar-io` thread pool. https://github.com/apache/pulsar/blob/aabd5d020543210921f10648caf6720adc41d651/pulsar-broker/src/main/java/org/apache/pulsar/client/impl/RawReaderImpl.java#L208-L218 If triggered by `receiveRawAsync`, it will use `pulsar-client-internal` thread pool. https://github.com/apache/pulsar/blob/aabd5d020543210921f10648caf6720adc41d651/pulsar-broker/src/main/java/org/apache/pulsar/client/impl/RawReaderImpl.java#L166-L171 However, `tryCompletePending()` is not thread-safe, even though we use synchronized for the following code block. https://github.com/apache/pulsar/blob/aabd5d020543210921f10648caf6720adc41d651/pulsar-broker/src/main/java/org/apache/pulsar/client/impl/RawReaderImpl.java#L135-L141 If two thread gets messages and runs to this line, which thread completes first is random. So it may lead to the message callback unorder. https://github.com/apache/pulsar/blob/aabd5d020543210921f10648caf6720adc41d651/pulsar-broker/src/main/java/org/apache/pulsar/client/impl/RawReaderImpl.java#L154 ### Modification Use `pulsar-client-internal` thread pool to execute `tryCompletePending()` in messageReceived() -- 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]
