forked from apache/kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KAFKA-16573: Specify node and store where serdes are needed (apache#1…
…5790) Reviewers: Matthias J. Sax <[email protected]>, Bruno Cadonna <[email protected]>, Anna Sophie Blee-Goldman <[email protected]>
- Loading branch information
Showing
14 changed files
with
433 additions
and
67 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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.