-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-3522: Add TimestampedWindowStore builder/runtime classes #6173
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 2 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,41 @@ | ||
| /* | ||
| * 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.utils.Bytes; | ||
| import org.apache.kafka.streams.state.WindowStore; | ||
|
|
||
| import static org.apache.kafka.streams.state.internals.ValueAndTimestampDeserializer.rawValue; | ||
| import static org.apache.kafka.streams.state.internals.ValueAndTimestampDeserializer.timestamp; | ||
|
|
||
| class ChangeLoggingTimestampedWindowBytesStore extends ChangeLoggingWindowBytesStore { | ||
|
|
||
| ChangeLoggingTimestampedWindowBytesStore(final WindowStore<Bytes, byte[]> bytesStore, | ||
| final boolean retainDuplicates) { | ||
| super(bytesStore, retainDuplicates); | ||
| } | ||
|
|
||
| @Override | ||
| void log(final Bytes key, | ||
| final byte[] valueAndTimestamp) { | ||
| if (valueAndTimestamp != null) { | ||
| changeLogger.logChange(key, rawValue(valueAndTimestamp), timestamp(valueAndTimestamp)); | ||
| } else { | ||
| changeLogger.logChange(key, null); | ||
|
Contributor
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. This is not specifically related to this line of code but when I read about this, I was thinking about some correlated topic: when we call
Member
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.
In fact, we plan to deprecate and remove Also note, that for timestamped-store, the call would be I agree that calling
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. I am just adding my 2 cents here. I understand what you are saying @mjsax, but I think if we should have a follow-up PR to update the docs to fully explain the semantic operations and differences between (
Member
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. We have many gaps in store documentation, and I agree it would be worth to do a follow up for this. I also think I understand now why
Contributor
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. Thanks for the explanation @mjsax , yes we were trying to "reuse" the window store for stream-stream windowed join, which, as an after-thought is not a very good design. I think we do not need to make any code changes atm (as for doc changes maybe we can track those as a separate ticket / PR). |
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,30 +36,49 @@ class ChangeLoggingWindowBytesStore | |
| implements WindowStore<Bytes, byte[]> { | ||
|
|
||
| private final boolean retainDuplicates; | ||
| private StoreChangeLogger<Bytes, byte[]> changeLogger; | ||
| private ProcessorContext context; | ||
| private int seqnum = 0; | ||
|
|
||
| StoreChangeLogger<Bytes, byte[]> changeLogger; | ||
|
|
||
| ChangeLoggingWindowBytesStore(final WindowStore<Bytes, byte[]> bytesStore, | ||
| final boolean retainDuplicates) { | ||
| super(bytesStore); | ||
| this.retainDuplicates = retainDuplicates; | ||
| } | ||
|
|
||
| @Override | ||
| public byte[] fetch(final Bytes key, final long timestamp) { | ||
| public void init(final ProcessorContext context, | ||
|
Member
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. init() is just moved from below. |
||
| final StateStore root) { | ||
| this.context = context; | ||
| super.init(context, root); | ||
| final String topic = ProcessorStateManager.storeChangelogTopic(context.applicationId(), name()); | ||
| changeLogger = new StoreChangeLogger<>( | ||
| name(), | ||
| context, | ||
| new StateSerdes<>(topic, Serdes.Bytes(), Serdes.ByteArray())); | ||
| } | ||
|
|
||
| @Override | ||
| public byte[] fetch(final Bytes key, | ||
| final long timestamp) { | ||
| return wrapped().fetch(key, timestamp); | ||
| } | ||
|
|
||
| @SuppressWarnings("deprecation") | ||
| @Override | ||
| public WindowStoreIterator<byte[]> fetch(final Bytes key, final long from, final long to) { | ||
| public WindowStoreIterator<byte[]> fetch(final Bytes key, | ||
| final long from, | ||
| final long to) { | ||
| return wrapped().fetch(key, from, to); | ||
| } | ||
|
|
||
| @SuppressWarnings("deprecation") | ||
| @Override | ||
| public KeyValueIterator<Windowed<Bytes>, byte[]> fetch(final Bytes keyFrom, final Bytes keyTo, final long from, final long to) { | ||
| public KeyValueIterator<Windowed<Bytes>, byte[]> fetch(final Bytes keyFrom, | ||
| final Bytes keyTo, | ||
| final long from, | ||
| final long to) { | ||
| return wrapped().fetch(keyFrom, keyTo, from, to); | ||
| } | ||
|
|
||
|
|
@@ -70,7 +89,8 @@ public KeyValueIterator<Windowed<Bytes>, byte[]> all() { | |
|
|
||
| @SuppressWarnings("deprecation") | ||
| @Override | ||
| public KeyValueIterator<Windowed<Bytes>, byte[]> fetchAll(final long timeFrom, final long timeTo) { | ||
| public KeyValueIterator<Windowed<Bytes>, byte[]> fetchAll(final long timeFrom, | ||
| final long timeTo) { | ||
| return wrapped().fetchAll(timeFrom, timeTo); | ||
| } | ||
|
|
||
|
|
@@ -84,20 +104,16 @@ public void put(final Bytes key, final byte[] value) { | |
| } | ||
|
|
||
| @Override | ||
| public void put(final Bytes key, final byte[] value, final long windowStartTimestamp) { | ||
| public void put(final Bytes key, | ||
| final byte[] value, | ||
| final long windowStartTimestamp) { | ||
| wrapped().put(key, value, windowStartTimestamp); | ||
| changeLogger.logChange(WindowKeySchema.toStoreKeyBinary(key, windowStartTimestamp, maybeUpdateSeqnumForDups()), value); | ||
| log(WindowKeySchema.toStoreKeyBinary(key, windowStartTimestamp, maybeUpdateSeqnumForDups()), value); | ||
| } | ||
|
|
||
| @Override | ||
| public void init(final ProcessorContext context, final StateStore root) { | ||
| this.context = context; | ||
| super.init(context, root); | ||
| final String topic = ProcessorStateManager.storeChangelogTopic(context.applicationId(), name()); | ||
| changeLogger = new StoreChangeLogger<>( | ||
| name(), | ||
| context, | ||
| new StateSerdes<>(topic, Serdes.Bytes(), Serdes.ByteArray())); | ||
| void log(final Bytes key, | ||
| final byte[] value) { | ||
| changeLogger.logChange(key, value); | ||
| } | ||
|
|
||
| private int maybeUpdateSeqnumForDups() { | ||
|
|
||
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.
Since the new classes are static maybe they could go in their own package along with the other pre-existing
decorators? Probably not on this PR but in a follow-up.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 am open to add new packages -- @vvcephei was suggestion this too (for example for RocksDB classes). I would prefer to do this a follow up PRs (it's internal anyway).