-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-7223: In-Memory Suppression Buffering #5693
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * 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.kstream.internals; | ||
|
|
||
| import org.apache.kafka.common.serialization.Serde; | ||
| import org.apache.kafka.common.serialization.Serdes; | ||
| import org.apache.kafka.streams.kstream.TimeWindowedDeserializer; | ||
| import org.apache.kafka.streams.kstream.TimeWindowedSerializer; | ||
| import org.apache.kafka.streams.kstream.Windowed; | ||
|
|
||
| class FullTimeWindowedSerde<T> extends Serdes.WrapperSerde<Windowed<T>> { | ||
| FullTimeWindowedSerde(final Serde<T> inner, final long windowSize) { | ||
| super( | ||
| new TimeWindowedSerializer<>(inner.serializer()), | ||
| new TimeWindowedDeserializer<>(inner.deserializer(), windowSize) | ||
| ); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,7 @@ | |
| import org.apache.kafka.streams.kstream.internals.graph.TableProcessorNode; | ||
| import org.apache.kafka.streams.kstream.internals.suppress.FinalResultsSuppressionBuilder; | ||
| import org.apache.kafka.streams.kstream.internals.suppress.KTableSuppressProcessor; | ||
| import org.apache.kafka.streams.kstream.internals.suppress.SuppressedImpl; | ||
| import org.apache.kafka.streams.kstream.internals.suppress.SuppressedInternal; | ||
| import org.apache.kafka.streams.processor.ProcessorSupplier; | ||
| import org.apache.kafka.streams.state.KeyValueStore; | ||
|
|
||
|
|
@@ -356,12 +356,11 @@ public <K1> KStream<K1, V> toStream(final KeyValueMapper<? super K, ? super V, ? | |
| public KTable<K, V> suppress(final Suppressed<K> suppressed) { | ||
| final String name = builder.newProcessorName(SUPPRESS_NAME); | ||
|
|
||
| // TODO: follow-up pr to forward the k/v serdes | ||
| final ProcessorSupplier<K, Change<V>> suppressionSupplier = | ||
| () -> new KTableSuppressProcessor<>( | ||
| buildSuppress(suppressed), | ||
| null, | ||
| null | ||
| keySerde, | ||
| valSerde == null ? null : new FullChangeSerde<>(valSerde) | ||
|
Member
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. Could we extend
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 can and will.
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've added that check because If it's ok with you, though, I prefer the current code right here. This code ensures that |
||
| ); | ||
|
|
||
| final ProcessorParameters<K, Change<V>> processorParameters = new ProcessorParameters<>( | ||
|
|
@@ -387,18 +386,18 @@ public KTable<K, V> suppress(final Suppressed<K> suppressed) { | |
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private SuppressedImpl<K> buildSuppress(final Suppressed<K> suppress) { | ||
| private SuppressedInternal<K> buildSuppress(final Suppressed<K> suppress) { | ||
| if (suppress instanceof FinalResultsSuppressionBuilder) { | ||
| final long grace = findAndVerifyWindowGrace(streamsGraphNode); | ||
|
|
||
| final FinalResultsSuppressionBuilder<?> builder = (FinalResultsSuppressionBuilder) suppress; | ||
|
|
||
| final SuppressedImpl<? extends Windowed> finalResultsSuppression = | ||
| final SuppressedInternal<? extends Windowed> finalResultsSuppression = | ||
| builder.buildFinalResultsSuppression(Duration.ofMillis(grace)); | ||
|
|
||
| return (SuppressedImpl<K>) finalResultsSuppression; | ||
| } else if (suppress instanceof SuppressedImpl) { | ||
| return (SuppressedImpl<K>) suppress; | ||
| return (SuppressedInternal<K>) finalResultsSuppression; | ||
| } else if (suppress instanceof SuppressedInternal) { | ||
| return (SuppressedInternal<K>) suppress; | ||
| } else { | ||
| throw new IllegalArgumentException("Custom subclasses of Suppressed are not allowed."); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,8 +20,8 @@ | |
|
|
||
| import static org.apache.kafka.streams.kstream.internals.suppress.BufferFullStrategy.SHUT_DOWN; | ||
|
|
||
| abstract class BufferConfigImpl<BC extends Suppressed.BufferConfig<BC>> implements Suppressed.BufferConfig<BC> { | ||
| public abstract long maxKeys(); | ||
| abstract class BufferConfigInternal<BC extends Suppressed.BufferConfig<BC>> implements Suppressed.BufferConfig<BC> { | ||
| public abstract long maxRecords(); | ||
|
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 realized belatedly that I missed this (internal) interface when I renamed "maxKeys" to "maxRecords" in Part 1. |
||
|
|
||
| public abstract long maxBytes(); | ||
|
|
||
|
|
@@ -39,12 +39,12 @@ public Suppressed.StrictBufferConfig withNoBound() { | |
|
|
||
| @Override | ||
| public Suppressed.StrictBufferConfig shutDownWhenFull() { | ||
| return new StrictBufferConfigImpl(maxKeys(), maxBytes(), SHUT_DOWN); | ||
| return new StrictBufferConfigImpl(maxRecords(), maxBytes(), SHUT_DOWN); | ||
| } | ||
|
|
||
| @Override | ||
| public Suppressed.BufferConfig emitEarlyWhenFull() { | ||
| return new EagerBufferConfigImpl(maxKeys(), maxBytes()); | ||
| return new EagerBufferConfigImpl(maxRecords(), maxBytes()); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
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.
Why this change? (Just for my own education.)
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.
It's just evidence of my mental slowness...
In the prior PR, Guozhang pointed out that my calling
buffer.array()was incorrect, since the backing array isn't guaranteed to be exactly within the bounds we allocated. I fixed it at the time by delegating to theByteBufferSerializer, which handles this.Later on I realized that there is a more efficient solution available. By pre-creating the backing array and wrapping it, we know that
buffer.array()returns what we needed. No need for the more general handling logic inByteBufferSerializer.