Skip to content

KAFKA-10832: Fix Log to use the correct ProducerStateManager instance when updating producers#9718

Merged
junrao merged 4 commits into
apache:trunkfrom
kowshik:MINOR_fix_update_correct_ProducerStateManager_in_Log_updateProducers
Dec 12, 2020
Merged

KAFKA-10832: Fix Log to use the correct ProducerStateManager instance when updating producers#9718
junrao merged 4 commits into
apache:trunkfrom
kowshik:MINOR_fix_update_correct_ProducerStateManager_in_Log_updateProducers

Conversation

@kowshik

@kowshik kowshik commented Dec 9, 2020

Copy link
Copy Markdown
Contributor

I have fixed what looked like a potential bug to me.

Bug:
The bug is that from within Log.updateProducers(…), the code operates on the producerStateManager attribute of the Log instance instead of operating on an input parameter. Please see this LOC where it calls producerStateManager.prepareUpdate thus accessing the attribute from the Log object (see this). This looks unusual particularly for Log.loadProducersFromLog(...) path. Here I believe we should be using the instance passed to the method, rather than the attribute from the Log instance. I have fixed the same in this PR.

I'm not sure (yet) if this bug has any drastic consequences (probably not), but it is still worthwhile making things consistent.

Fix:
The fix is to explicitly pass the ProducerStateManager into Log.updateProducers and move the following methods: Log.loadProducersFromLog and Log.updateProducers into the Log companion object.

Tests:
Rely on existing tests.

@kowshik

kowshik commented Dec 9, 2020

Copy link
Copy Markdown
Contributor Author

cc @dhruvilshah3 @junrao @gardnervickers for review

@ijuma

ijuma commented Dec 9, 2020

Copy link
Copy Markdown
Member

Good catch. This looks a bit error prone. Should we be moving some of these methods to the companion object or something?

@kowshik

kowshik commented Dec 9, 2020

Copy link
Copy Markdown
Contributor Author

@ijuma Good idea. I can move Log.rebuildProducerState into the Log companion object, and consequently the following methods will move too: Log.loadProducersFromLog and Log.updateProducers.

@kowshik kowshik changed the title MINOR: Use the correct ProducerStateManager instance when updating producers KAFKA-10832: Use the correct ProducerStateManager instance when updating producers Dec 9, 2020
@kowshik

kowshik commented Dec 10, 2020

Copy link
Copy Markdown
Contributor Author

@ijuma Thanks for the review! I've addressed your comments in 6d348bc.

@kowshik kowshik changed the title KAFKA-10832: Use the correct ProducerStateManager instance when updating producers KAFKA-10832: Fix Log to use the correct ProducerStateManager instance when updating producers Dec 10, 2020

@junrao junrao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@kowshik : Thanks for the PR. Nice find. Just one comment below.

Comment thread core/src/main/scala/kafka/log/Log.scala Outdated

// Rebuild producer state until lastOffset. This method may be called from the recovery code path, and thus must be
// free of all side-effects, i.e. it must not update any log-specific state.
private def rebuildProducerState(log: Log,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems too large as a companion method. I am also not sure that we should pass along Log to this method since it exposes all internal states in Log, which make it harder to track usage.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That is true. Do you feel the original approach in f0466b2 was better, where, we didn't move methods into a companion object? I'd be happy to revert to that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can probably keep the two other two simpler methods (without Log as the input) as the companion methods.

@kowshik kowshik force-pushed the MINOR_fix_update_correct_ProducerStateManager_in_Log_updateProducers branch from eb9a449 to 31f95a0 Compare December 11, 2020 02:22
@kowshik kowshik force-pushed the MINOR_fix_update_correct_ProducerStateManager_in_Log_updateProducers branch from 31f95a0 to 5d798b7 Compare December 11, 2020 02:22
@kowshik

kowshik commented Dec 11, 2020

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @junrao! I've addressed the comments in 5d798b7.

@kowshik kowshik requested a review from junrao December 11, 2020 02:24

@junrao junrao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@kowshik : Thanks for the updated PR. Just a minor comment below. Also, is the test failure related to this PR?

Comment thread core/src/main/scala/kafka/log/Log.scala Outdated
private def isLogFile(file: File): Boolean =
file.getPath.endsWith(LogFileSuffix)

private def loadProducersFromLog(producerStateManager: ProducerStateManager, records: Records): Unit = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps this could be name loadProducersFromRecords?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@kowshik

kowshik commented Dec 11, 2020

Copy link
Copy Markdown
Contributor Author

Thanks for the review @junrao ! I've addressed the comment in ec00e9f. The JDK 15 test failure in org.apache.kafka.streams.integration.PurgeRepartitionTopicIntegrationTest.shouldRestoreState seems unrelated to this PR.

@junrao junrao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@kowshik : Thanks for the PR. LGTM

@junrao junrao merged commit cdf7258 into apache:trunk Dec 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants