Skip to content

KAFKA-12829: Remove the deprecated method init(ProcessorContext, StateStore) from the StateStore interface#16906

Merged
mjsax merged 7 commits intoapache:trunkfrom
xijiu:remove_deprecated_init_method
Aug 29, 2024
Merged

KAFKA-12829: Remove the deprecated method init(ProcessorContext, StateStore) from the StateStore interface#16906
mjsax merged 7 commits intoapache:trunkfrom
xijiu:remove_deprecated_init_method

Conversation

@xijiu
Copy link
Copy Markdown
Contributor

@xijiu xijiu commented Aug 17, 2024

See the discussion: (#11611 (comment))

I did the following three things:

  1. Find all the code that has invoked the init (ProcessorContext, StateStore) method. Actually, it is only called in one test class(MockProcessorContextTest), then I deleted the relevant test method.
  2. Delete the method init(ProcessorContext, StateStore) from the StateStore and Its implementation classes. If the implementation class contains both methods init(ProcessorContext, StateStore) and init(StateStoreContext, StateStore) simultaneously, then delete init(ProcessorContext, StateStore) directly. If the implementation class only contains methods init(ProcessorContext, StateStore), then I create a new method init(StateStoreContext, StateStore) and copy the relevant code to it. There are still many details in the code.
  3. The logic of generation of internal topic names in class TimeOrderedCachingWindowStore was not repalaced by ProcessorContextUtils#changelogFor, I moved it over while I was at it.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@xijiu
Copy link
Copy Markdown
Contributor Author

xijiu commented Aug 17, 2024

After that, I ran all the junit test in the module streams, and all of the tests are passed in about 30 min.

image

Copy link
Copy Markdown
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@xijiu thanks for your patch. one major comment is left.

default void init(final StateStoreContext context, final StateStore root) {
init(StoreToProcessorContextAdapter.adapt(context), root);
}
default void init(final StateStoreContext context, final StateStore root) {}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is used to replace the deprecated init, so I guess it should NOT have default implementation after removing the deprecated version?

@guozhangwang WDYT?

Copy link
Copy Markdown
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@xijiu thanks for your patch. Please remove all initInternal to simplify code.

@Override
public void init(final ProcessorContext context,
final StateStore root) {
private void initInternal(final ProcessorContext context,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you please merge initInternal into init? we don't need to have a private method used to generate a small public method :)

@Override
public void init(final ProcessorContext context,
final StateStore root) {
private void initInternal(final ProcessorContext context,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto

@mjsax mjsax added the streams label Aug 22, 2024
@mjsax mjsax requested a review from guozhangwang August 22, 2024 03:45
@xijiu
Copy link
Copy Markdown
Contributor Author

xijiu commented Aug 22, 2024

@chia7712 Thanks for the code review, I have fixed it, PTAL again

@mjsax mjsax changed the title KAFKA-13588: Remove the deprecated method init(ProcessorContext, StateStore) from the StateStore interface KAFKA-12829: Remove the deprecated method init(ProcessorContext, StateStore) from the StateStore interface Aug 22, 2024
this.context = context;
public void init(final StateStoreContext stateStoreContext, final StateStore root) {
this.stateStoreContext = stateStoreContext;
this.context = StoreToProcessorContextAdapter.adapt(stateStoreContext);
Copy link
Copy Markdown
Member

@mjsax mjsax Aug 22, 2024

Choose a reason for hiding this comment

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

This feels rather hacky -- using adapt was a workaround as long as we have both init() methods. I think, we need to do more cleanup/refactoring and get rid or this.context completely.

In other stores, we use InternalProcessorContext -- I think doing the same here would be the right way forward (and get rid of both stateStoreContext and context in favor of internalProcessorContext)?

Applies elsewhere, too.

(Ideally, we should be able to delete class StoreToProcessorContextAdapter entirely)

public void init(final ProcessorContext context, final StateStore root) {
throw new UnsupportedOperationException("cannot initialize a logical segment");
}
public void init(final StateStoreContext context, final StateStore root) {}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This method should throw (as the old one)

@Override
public void init(final ProcessorContext context,
final StateStore root) {
initInternal(asInternalProcessorContext(context));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we call initInternal only in a single place now, we might consider inlining it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

agree. @xijiu please apply "inline" to elsewhere, too

public void init(final ProcessorContext context,
public void init(final StateStoreContext stateStoreContext,
final StateStore root) {
final ProcessorContext context = StoreToProcessorContextAdapter.adapt(stateStoreContext);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need context at all? Seem we can use stateStoreContext below got call appConfigs() and register() ?

this.context = context;
final String topic = ProcessorStateManager.storeChangelogTopic(prefix, name(), context.taskId().topologyName());
this.context = asInternalProcessorContext(context);
final String topic = ProcessorContextUtils.changelogFor(context, name(), Boolean.TRUE);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we exclude this change from this PR, as this PR should only remove init() to address KAFKA-12829, and pull this change into a follow up PR for KAFKA-13588.

}

@Test
public void shouldStoreAndReturnStateStores() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we remove this test? Should we rather rewrite it calling the new init() passing in a mocked StateStoreContext object?

Copy link
Copy Markdown
Member

@mjsax mjsax left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Made a pass. This is a complex change. Not sure if I caught everything... Might find more in a second pass after the PR was updated.

@xijiu
Copy link
Copy Markdown
Contributor Author

xijiu commented Aug 24, 2024

@mjsax @chia7712 Thanks very much for these professional comments, they have greatly improved my understanding of the work.
I have revised the code, PTAL again

Copy link
Copy Markdown
Member

@mjsax mjsax left a comment

Choose a reason for hiding this comment

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

Thanks for updating the PR. A few more nits. Also, there are failing tests which seems to be related to the changes of this PR.


@Override
public void init(final StateStoreContext context, final StateStore root) {
final String changelogTopic = ProcessorContextUtils.changelogFor(context, name(), Boolean.TRUE);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we inline initInternal here, too?

public void init(final ProcessorContext context, final StateStore root) {
this.context = ProcessorContextUtils.asInternalProcessorContext(context);
changelogTopic = ProcessorContextUtils.changelogFor(context, name(), Boolean.TRUE);
init(root);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seem this init is the same and internalInit in other classes -- can we inline it?

@xijiu xijiu force-pushed the remove_deprecated_init_method branch from 512acb8 to 4f613c7 Compare August 26, 2024 13:37
@xijiu
Copy link
Copy Markdown
Contributor Author

xijiu commented Aug 26, 2024

hi @mjsax , I have improved the code based on the suggestions, include some junit test. And I also ran the stream moudle
all tests successfully before I update the PR.

PTAL, Thanks

image

}


public InternalProcessorContext getInternalProcessorContext() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

MockProcessorContext is public API and we cannot just add this. -- I assume this was necessary to fix some tests? For this case, we should do it differently.

Comment thread checkstyle/suppressions.xml Outdated

<suppress checks="MethodLength"
files="KTableImpl.java"/>
files="(KTableImpl|MockProcessorContext).java"/>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I hope we don't need this

this.context = null;
expiredRecordSensor = null;
}
this.context = asInternalProcessorContext(stateStoreContext);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems this change breaks the test -- let's not apply this change but keep the code as-is.

@xijiu xijiu force-pushed the remove_deprecated_init_method branch from 4f613c7 to 0dcddcf Compare August 28, 2024 16:44
@xijiu
Copy link
Copy Markdown
Contributor Author

xijiu commented Aug 28, 2024

hello @mjsax , I have fixed the code, PTAL

@mjsax mjsax merged commit 291523e into apache:trunk Aug 29, 2024
@mjsax
Copy link
Copy Markdown
Member

mjsax commented Aug 29, 2024

Thanks a ton for this PR @xijiu! Huge piece of work! Great job!

Merged to trunk.

@xijiu
Copy link
Copy Markdown
Contributor Author

xijiu commented Aug 29, 2024

Thanks a ton for this PR @xijiu! Huge piece of work! Great job!

Merged to trunk.

@mjsax I learned a lot during this process and gained a deeper understanding of streams. Thank you very much for code review and guidance.

bboyleonp666 pushed a commit to bboyleonp666/kafka that referenced this pull request Sep 4, 2024
…teStore)` from the `StateStore` interface (apache#16906)

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>, Matthias J. Sax <matthias@confluent.io>
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.

3 participants