You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/07/05 03:47:08 UTC
[GitHub] [pulsar] hangc0276 opened a new pull request, #16390: [fix][broker] Fix RawReader out of order
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] hangc0276 commented on a diff in pull request #16390: [fix][broker] Fix RawReader out of order
Posted by GitBox <gi...@apache.org>.
hangc0276 commented on code in PR #16390:
URL: https://github.com/apache/pulsar/pull/16390#discussion_r913377703
##########
pulsar-broker/src/main/java/org/apache/pulsar/client/impl/RawReaderImpl.java:
##########
@@ -213,7 +213,7 @@ void messageReceived(CommandMessage commandMessage, ByteBuf headersAndPayload, C
}
incomingRawMessages.add(
new RawMessageAndCnx(new RawMessageImpl(messageId, headersAndPayload), cnx));
- tryCompletePending();
+ internalPinnedExecutor.execute(this::tryCompletePending);
Review Comment:
done
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] merlimat merged pull request #16390: [fix][broker] Fix RawReader out of order
Posted by GitBox <gi...@apache.org>.
merlimat merged PR #16390:
URL: https://github.com/apache/pulsar/pull/16390
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui commented on a diff in pull request #16390: [fix][broker] Fix RawReader out of order
Posted by GitBox <gi...@apache.org>.
codelipenghui commented on code in PR #16390:
URL: https://github.com/apache/pulsar/pull/16390#discussion_r913367052
##########
pulsar-broker/src/main/java/org/apache/pulsar/client/impl/RawReaderImpl.java:
##########
@@ -213,7 +213,7 @@ void messageReceived(CommandMessage commandMessage, ByteBuf headersAndPayload, C
}
incomingRawMessages.add(
new RawMessageAndCnx(new RawMessageImpl(messageId, headersAndPayload), cnx));
- tryCompletePending();
+ internalPinnedExecutor.execute(this::tryCompletePending);
Review Comment:
Is it better to also run lines 214-215 in the internalPinnedExecutor? So that the IO thread only has 1 time add queue operation. Currently, the IO thread will have 2 add queue operations.
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org