-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix][broker] Copy proto command fields into final variables in ServerCnx #18987
Merged
michaeljmarshall
merged 5 commits into
apache:master
from
michaeljmarshall:use-final-variable
Dec 20, 2022
Merged
[fix][broker] Copy proto command fields into final variables in ServerCnx #18987
michaeljmarshall
merged 5 commits into
apache:master
from
michaeljmarshall:use-final-variable
Dec 20, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nicoloboschi
approved these changes
Dec 19, 2022
Codecov Report
@@ Coverage Diff @@
## master #18987 +/- ##
============================================
+ Coverage 46.35% 46.41% +0.06%
- Complexity 8939 10461 +1522
============================================
Files 597 703 +106
Lines 56858 68866 +12008
Branches 5905 7389 +1484
============================================
+ Hits 26357 31967 +5610
- Misses 27616 33292 +5676
- Partials 2885 3607 +722
Flags with carried forward coverage won't be shown. Click here to find out more.
|
codelipenghui
approved these changes
Dec 20, 2022
mattisonchao
approved these changes
Dec 20, 2022
nodece
approved these changes
Dec 20, 2022
lhotari
reviewed
Dec 20, 2022
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
Show resolved
Hide resolved
Merged
4 tasks
4 tasks
When attempting to cherry-pick this to |
michaeljmarshall
added a commit
that referenced
this pull request
Dec 21, 2022
…rCnx (#18987) In the `PulsarDecoder`, we use a single `BaseCommand` object and overwrite it for each incoming protocol message. As a result, it is not safe to publish any references to a proto command to other threads. Here is the single `BaseCommand`: https://github.com/apache/pulsar/blob/82237d3684fe506bcb6426b3b23f413422e6e4fb/pulsar-common/src/main/java/org/apache/pulsar/common/protocol/PulsarDecoder.java#L99 Here is the method call that resets the object: https://github.com/apache/pulsar/blob/82237d3684fe506bcb6426b3b23f413422e6e4fb/pulsar-common/src/main/java/org/apache/pulsar/common/protocol/PulsarDecoder.java#L114 Note that the call to `parseFrom` first calls `clear()`, which resets all values on the object. This PR copies relevant values or objects into other variables. * Replace `command` with `tcId` since the latter is a final variable meant to be published to another thread. * Move logic to copy certain command fields to earlier in method for `handleSubscribe` * Copy `ack` object to new `CommandAck` when there is a broker interceptor. Note that copying this command is likely somewhat costly, so we only do it when there is an interceptor configured. This is a trivial change that is already covered by tests. - [x] `doc-not-needed` This is an internal change. PR in forked repository: michaeljmarshall#8 (cherry picked from commit a408e9e)
michaeljmarshall
added a commit
that referenced
this pull request
Dec 21, 2022
…rCnx (#18987) In the `PulsarDecoder`, we use a single `BaseCommand` object and overwrite it for each incoming protocol message. As a result, it is not safe to publish any references to a proto command to other threads. Here is the single `BaseCommand`: https://github.com/apache/pulsar/blob/82237d3684fe506bcb6426b3b23f413422e6e4fb/pulsar-common/src/main/java/org/apache/pulsar/common/protocol/PulsarDecoder.java#L99 Here is the method call that resets the object: https://github.com/apache/pulsar/blob/82237d3684fe506bcb6426b3b23f413422e6e4fb/pulsar-common/src/main/java/org/apache/pulsar/common/protocol/PulsarDecoder.java#L114 Note that the call to `parseFrom` first calls `clear()`, which resets all values on the object. This PR copies relevant values or objects into other variables. * Replace `command` with `tcId` since the latter is a final variable meant to be published to another thread. * Move logic to copy certain command fields to earlier in method for `handleSubscribe` * Copy `ack` object to new `CommandAck` when there is a broker interceptor. Note that copying this command is likely somewhat costly, so we only do it when there is an interceptor configured. This is a trivial change that is already covered by tests. - [x] `doc-not-needed` This is an internal change. PR in forked repository: michaeljmarshall#8 (cherry picked from commit a408e9e)
michaeljmarshall
added a commit
that referenced
this pull request
Dec 21, 2022
…rCnx (#18987) In the `PulsarDecoder`, we use a single `BaseCommand` object and overwrite it for each incoming protocol message. As a result, it is not safe to publish any references to a proto command to other threads. Here is the single `BaseCommand`: https://github.com/apache/pulsar/blob/82237d3684fe506bcb6426b3b23f413422e6e4fb/pulsar-common/src/main/java/org/apache/pulsar/common/protocol/PulsarDecoder.java#L99 Here is the method call that resets the object: https://github.com/apache/pulsar/blob/82237d3684fe506bcb6426b3b23f413422e6e4fb/pulsar-common/src/main/java/org/apache/pulsar/common/protocol/PulsarDecoder.java#L114 Note that the call to `parseFrom` first calls `clear()`, which resets all values on the object. This PR copies relevant values or objects into other variables. * Replace `command` with `tcId` since the latter is a final variable meant to be published to another thread. * Move logic to copy certain command fields to earlier in method for `handleSubscribe` * Copy `ack` object to new `CommandAck` when there is a broker interceptor. Note that copying this command is likely somewhat costly, so we only do it when there is an interceptor configured. This is a trivial change that is already covered by tests. - [x] `doc-not-needed` This is an internal change. PR in forked repository: michaeljmarshall#8 (cherry picked from commit a408e9e)
michaeljmarshall
added a commit
to datastax/pulsar
that referenced
this pull request
Dec 21, 2022
…rCnx (apache#18987) In the `PulsarDecoder`, we use a single `BaseCommand` object and overwrite it for each incoming protocol message. As a result, it is not safe to publish any references to a proto command to other threads. Here is the single `BaseCommand`: https://github.com/apache/pulsar/blob/82237d3684fe506bcb6426b3b23f413422e6e4fb/pulsar-common/src/main/java/org/apache/pulsar/common/protocol/PulsarDecoder.java#L99 Here is the method call that resets the object: https://github.com/apache/pulsar/blob/82237d3684fe506bcb6426b3b23f413422e6e4fb/pulsar-common/src/main/java/org/apache/pulsar/common/protocol/PulsarDecoder.java#L114 Note that the call to `parseFrom` first calls `clear()`, which resets all values on the object. This PR copies relevant values or objects into other variables. * Replace `command` with `tcId` since the latter is a final variable meant to be published to another thread. * Move logic to copy certain command fields to earlier in method for `handleSubscribe` * Copy `ack` object to new `CommandAck` when there is a broker interceptor. Note that copying this command is likely somewhat costly, so we only do it when there is an interceptor configured. This is a trivial change that is already covered by tests. - [x] `doc-not-needed` This is an internal change. PR in forked repository: michaeljmarshall#8 (cherry picked from commit a408e9e)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area/broker
area/transaction
cherry-picked/branch-2.9
Archived: 2.9 is end of life
cherry-picked/branch-2.10
cherry-picked/branch-2.11
doc-not-needed
Your PR changes do not impact docs
ready-to-test
release/2.9.5
release/2.10.4
release/2.11.1
type/bug
The PR fixed a bug or issue reported a bug
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
In the
PulsarDecoder
, we use a singleBaseCommand
object and overwrite it for each incoming protocol message. As a result, it is not safe to publish any references to a proto command to other threads.Here is the single
BaseCommand
:pulsar/pulsar-common/src/main/java/org/apache/pulsar/common/protocol/PulsarDecoder.java
Line 99 in 82237d3
Here is the method call that resets the object:
pulsar/pulsar-common/src/main/java/org/apache/pulsar/common/protocol/PulsarDecoder.java
Line 114 in 82237d3
Note that the call to
parseFrom
first callsclear()
, which resets all values on the object.This PR copies relevant values or objects into other variables.
Modifications
command
withtcId
since the latter is a final variable meant to be published to another thread.handleSubscribe
ack
object to newCommandAck
when there is a broker interceptor. Note that copying this command is likely somewhat costly, so we only do it when there is an interceptor configured.Verifying this change
This is a trivial change that is already covered by tests.
Documentation
doc-not-needed
This is an internal change.
Matching PR in forked repository
PR in forked repository: michaeljmarshall#8