Skip to content
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

MINOR: improve RecordCollectorImpl #17185

Merged
merged 4 commits into from
Oct 1, 2024
Merged

Conversation

mjsax
Copy link
Member

@mjsax mjsax commented Sep 13, 2024

Found this while working on #17169, but did not want to piggy-back this change to the other PR but isolate as it's unrelated cleanup.

@mjsax mjsax added the streams label Sep 13, 2024
@@ -81,7 +81,7 @@ public class RecordCollectorImpl implements RecordCollector {
private final Sensor droppedRecordsSensor;
private final Map<String, Sensor> producedSensorByTopic = new HashMap<>();

private final AtomicReference<KafkaException> sendException;
private final AtomicReference<KafkaException> sendException = new AtomicReference<>(null);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no reason to get this from StreamsProducer so pulling it into this class.

@@ -529,7 +528,7 @@ private void checkForException() {
final KafkaException exception = sendException.get();

if (exception != null) {
sendException.set(null);
sendException.compareAndSet(exception, null);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is actually fixing a race condition... with set() we might overwrite (and thus drop) and exception which is set after we called get() (even if I am not 100% sure how bad it is if we drop it, give that we throw exception; below anyway...?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... not sure that part makes a difference. But I guess there is nothing wrong with it?

The rest of PR makes sense to me

Copy link
Member

@lucasbru lucasbru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@mjsax
Copy link
Member Author

mjsax commented Sep 28, 2024

After re-thinking, the test we remove because it failed actually exposed that the original idea of this PR is incorrect. We need to keep sendException inside StreamsProducer as we need a single instance per thread, shared across all tasks (ie, all RecordCollectorImpl -- we have one per task).

@mjsax mjsax merged commit 4312ce6 into apache:trunk Oct 1, 2024
9 checks passed
@mjsax mjsax deleted the minor-recordcollectorimpl branch October 1, 2024 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants