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:PulsarKafkaProducer is not thread safe #4745
Conversation
String topic1 = "persistent://public/default/topic-" + System.currentTimeMillis(); | ||
ProducerRecord<String, String> record1 = new ProducerRecord<>(topic1, "Hello"); | ||
producer.send(record1, (recordMetadata, e) -> { | ||
throw new Error(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fxbing can you explain how does the test work here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sijie OK, I have added it.
I think the Kafka test failed. Can you take a look?
|
@sijie OK, I have updated it. |
run java8 tests |
3 similar comments
run java8 tests |
run java8 tests |
run java8 tests |
run integration tests |
String topic1 = "persistent://public/default/topic-" + System.currentTimeMillis(); | ||
ProducerRecord<String, String> record1 = new ProducerRecord<>(topic1, "Hello"); | ||
producer.send(record1, (recordMetadata, e) -> { | ||
throw new Error(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't understand why do you throw a new Error here? Can you explain it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sijie I understand the wrong usage of this callback funcition. In fact, threadSafe will not affect callback
.
May I change it to producer.send(record1);
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If PulsarKafkaProducer
is thread safe, test success.
If not, producer.send(record1);
will throw exception and test failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes you can change to use producer.send()
@fxbing can you rebase to latest master? |
run cpp tests |
run integration tests |
run integration tests |
run cpp tests |
2 similar comments
run cpp tests |
run cpp tests |
run cpp tests |
run integration tests |
1 similar comment
run integration tests |
run java8 tests |
run integration tests |
run java8 tests |
1 similar comment
run java8 tests |
fix #4707
https://github.com/apache/pulsar/blob/v2.3.2/pulsar-client-kafka-compat/pulsar-client-kafka/src/main/java/org/apache/kafka/clients/producer/PulsarKafkaProducer.java#L229
In this line, the update operation of
cluster
is not atomic. The new value ofcluster
is based on th old.But in multithreading,multiple threads may be dependent on the same old value for updating.
So in https://github.com/apache/pulsar/blob/v2.3.2/pulsar-client-kafka-compat/pulsar-client-kafka/src/main/java/org/apache/kafka/clients/producer/PulsarKafkaProducer.java#L270, thread which is executed at last can run normally, others can't.
And I have added a test for it.