-
Notifications
You must be signed in to change notification settings - Fork 15.1k
KAFKA-16573: Specify node and store where serdes are needed #15790
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3285ed1
KAFKA-16573: Specify node and store where serdes are needed
AyoubOm b720677
KAFKA-16573: add tests of serdes initialization exceptions
AyoubOm 95d3326
KAFKA-16573: parametrize valueSerde function for TimestampedStores
AyoubOm e7dadd6
KAFKA-16573: review improvements
AyoubOm a8e320f
KAFKA-16573: catch Config & Streams exceptions into StreamsException
AyoubOm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,7 +56,6 @@ | |
|
|
||
| import static org.apache.kafka.common.utils.Utils.mkEntry; | ||
| import static org.apache.kafka.common.utils.Utils.mkMap; | ||
| import static org.apache.kafka.streams.kstream.internals.WrappingNullableUtils.prepareKeySerde; | ||
| import static org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl.maybeMeasureLatency; | ||
| import static org.apache.kafka.streams.state.internals.StoreQueryUtils.getDeserializeValue; | ||
|
|
||
|
|
@@ -173,21 +172,15 @@ protected Serde<V> prepareValueSerdeForStore(final Serde<V> valueSerde, final Se | |
| protected void initStoreSerde(final ProcessorContext context) { | ||
| final String storeName = name(); | ||
| final String changelogTopic = ProcessorContextUtils.changelogFor(context, storeName, Boolean.FALSE); | ||
| serdes = new StateSerdes<>( | ||
| changelogTopic, | ||
| prepareKeySerde(keySerde, new SerdeGetter(context)), | ||
| prepareValueSerdeForStore(valueSerde, new SerdeGetter(context)) | ||
| ); | ||
| serdes = StoreSerdeInitializer.prepareStoreSerde( | ||
| context, storeName, changelogTopic, keySerde, valueSerde, this::prepareValueSerdeForStore); | ||
| } | ||
|
|
||
| protected void initStoreSerde(final StateStoreContext context) { | ||
| final String storeName = name(); | ||
| final String changelogTopic = ProcessorContextUtils.changelogFor(context, storeName, Boolean.FALSE); | ||
| serdes = new StateSerdes<>( | ||
| changelogTopic, | ||
| prepareKeySerde(keySerde, new SerdeGetter(context)), | ||
| prepareValueSerdeForStore(valueSerde, new SerdeGetter(context)) | ||
| ); | ||
| serdes = StoreSerdeInitializer.prepareStoreSerde( | ||
| context, storeName, changelogTopic, keySerde, valueSerde, this::prepareValueSerdeForStore); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a parameter function prepareValueSerde to be able to use the correct function in children TimestampedStore classes. These don't directly use |
||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
76 changes: 76 additions & 0 deletions
76
streams/src/main/java/org/apache/kafka/streams/state/internals/StoreSerdeInitializer.java
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.streams.state.internals; | ||
|
|
||
| import org.apache.kafka.common.config.ConfigException; | ||
| import org.apache.kafka.common.serialization.Serde; | ||
| import org.apache.kafka.streams.errors.StreamsException; | ||
| import org.apache.kafka.streams.kstream.internals.WrappingNullableUtils; | ||
| import org.apache.kafka.streams.processor.ProcessorContext; | ||
| import org.apache.kafka.streams.processor.StateStoreContext; | ||
| import org.apache.kafka.streams.processor.TaskId; | ||
| import org.apache.kafka.streams.processor.internals.SerdeGetter; | ||
| import org.apache.kafka.streams.state.StateSerdes; | ||
|
|
||
|
|
||
| public class StoreSerdeInitializer { | ||
| static <K, V> StateSerdes<K, V> prepareStoreSerde(final StateStoreContext context, | ||
| final String storeName, | ||
| final String changelogTopic, | ||
| final Serde<K> keySerde, | ||
| final Serde<V> valueSerde, | ||
| final PrepareFunc<V> prepareValueSerdeFunc) { | ||
| return new StateSerdes<>( | ||
| changelogTopic, | ||
| prepareSerde(WrappingNullableUtils::prepareKeySerde, storeName, keySerde, new SerdeGetter(context), true, context.taskId()), | ||
| prepareSerde(prepareValueSerdeFunc, storeName, valueSerde, new SerdeGetter(context), false, context.taskId()) | ||
| ); | ||
| } | ||
|
|
||
| static <K, V> StateSerdes<K, V> prepareStoreSerde(final ProcessorContext context, | ||
| final String storeName, | ||
| final String changelogTopic, | ||
| final Serde<K> keySerde, | ||
| final Serde<V> valueSerde, | ||
| final PrepareFunc<V> prepareValueSerdeFunc) { | ||
| return new StateSerdes<>( | ||
| changelogTopic, | ||
| prepareSerde(WrappingNullableUtils::prepareKeySerde, storeName, keySerde, new SerdeGetter(context), true, context.taskId()), | ||
| prepareSerde(prepareValueSerdeFunc, storeName, valueSerde, new SerdeGetter(context), false, context.taskId()) | ||
| ); | ||
| } | ||
|
|
||
| private static <T> Serde<T> prepareSerde(final PrepareFunc<T> prepare, | ||
| final String storeName, | ||
| final Serde<T> serde, | ||
| final SerdeGetter getter, | ||
| final Boolean isKey, | ||
| final TaskId taskId) { | ||
|
|
||
| final String serdeType = isKey ? "key" : "value"; | ||
| try { | ||
| return prepare.prepareSerde(serde, getter); | ||
| } catch (final ConfigException | StreamsException e) { | ||
| throw new StreamsException(String.format("Failed to initialize %s serdes for store %s", serdeType, storeName), e, taskId); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| interface PrepareFunc<T> { | ||
| Serde<T> prepareSerde(Serde<T> serde, SerdeGetter getter); | ||
| } | ||
|
|
Oops, something went wrong.
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.
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 did dig into
prepareKeySerializerandprepareValueSerializerwhich both useWrappingNullableUtils#prepareSerializer()which might call bothcontext.keySerde()andcontext.valueSerde(), and thus, I believe we could currently get an exception when trying to get the key serde, even if default key serde is set, but default value serde is not set?I think this internal helper method needs some updated, too.
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.
Nice catch ! Updated