-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-3522: Add TimestampedKeyValueStore builder/runtime classes #6152
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,25 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| /** | ||
| * A key-(value/timestamp) store that supports put/get/delete and range queries. | ||
| * | ||
| * @param <K> The key type | ||
| * @param <V> The value type | ||
| */ | ||
| public interface TimestampedKeyValueStore<K, V> extends KeyValueStore<K, ValueAndTimestamp<V>> { } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| import org.apache.kafka.streams.KeyValue; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Combines a value from a {@link KeyValue} with a timestamp. | ||
| * | ||
| * @param <V> | ||
| */ | ||
| public class ValueAndTimestamp<V> { | ||
| private final V value; | ||
| private final long timestamp; | ||
|
|
||
| private ValueAndTimestamp(final V value, | ||
| final long timestamp) { | ||
| Objects.requireNonNull(value); | ||
| this.value = value; | ||
| this.timestamp = timestamp; | ||
| } | ||
|
|
||
| public static <V> ValueAndTimestamp<V> make(final V value, | ||
| final long timestamp) { | ||
| return value == null ? null : new ValueAndTimestamp<>(value, timestamp); | ||
| } | ||
|
|
||
| public V value() { | ||
| return value; | ||
| } | ||
|
|
||
| public long timestamp() { | ||
| return timestamp; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "<" + value + "," + timestamp + ">"; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(final Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| final ValueAndTimestamp<?> that = (ValueAndTimestamp<?>) o; | ||
| return timestamp == that.timestamp && | ||
| Objects.equals(value, that.value); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(value, timestamp); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * 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.KeyValueStore; | ||
|
|
||
| import static org.apache.kafka.streams.state.internals.ValueAndTimestampDeserializer.rawValue; | ||
| import static org.apache.kafka.streams.state.internals.ValueAndTimestampDeserializer.timestamp; | ||
|
|
||
| public class ChangeLoggingTimestampedKeyValueBytesStore extends ChangeLoggingKeyValueBytesStore { | ||
| ChangeLoggingTimestampedKeyValueBytesStore(final KeyValueStore<Bytes, byte[]> inner) { | ||
| super(inner); | ||
| } | ||
|
|
||
| @Override | ||
| void log(final Bytes key, | ||
| final byte[] valueAndTimestamp) { | ||
| if (valueAndTimestamp != 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. Ditto here, we can just reuse the logic of
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. I think I'm convinced that having added functions inside |
||
| changeLogger.logChange(key, rawValue(valueAndTimestamp), timestamp(valueAndTimestamp)); | ||
| } else { | ||
| changeLogger.logChange(key, null); | ||
| } | ||
| } | ||
| } | ||
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.
Is it worth mentioning here that this is a marker interface to notify Streams that this store uses the new (with timestamp) binary schema?
(note, I guess it will make more sense once KAFKA-7918 is complete)
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.
This is not a marker interface (the marker interface is
TimestampedBytesStore)