You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "aliehsaeedii (via GitHub)" <gi...@apache.org> on 2026/02/25 19:14:12 UTC
[PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
aliehsaeedii opened a new pull request, #21580:
URL: https://github.com/apache/kafka/pull/21580
This PR enables DSL for `KTable Source` (KIP-1285)
Modifed test:
- KTableSourceTest.java
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20194: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2922784937
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -45,70 +48,81 @@ public class KeyValueStoreWrapper<K, V> implements StateStore {
public static final long PUT_RETURN_CODE_IS_LATEST
= VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED;
- private TimestampedKeyValueStore<K, V> timestampedStore = null;
+ private TimestampedKeyValueStoreWithHeaders<K, V> headersStore = null;
private VersionedKeyValueStore<K, V> versionedStore = null;
- // same as either timestampedStore or versionedStore above. kept merely as a convenience
- // to simplify implementation for methods which do not depend on store type.
private StateStore store;
+ @SuppressWarnings("unchecked")
public KeyValueStoreWrapper(final ProcessorContext<?, ?> context, final String storeName) {
+ final StateStore rawStore = context.getStateStore(storeName);
+
+ // Check if it's an OLD TimestampedKeyValueStore that needs adaptation
+ if (rawStore instanceof TimestampedKeyValueStore &&
+ !(rawStore instanceof TimestampedKeyValueStoreWithHeaders)) {
+ // Adapt OLD store to NEW type for backward compatibility
+ headersStore = new TimestampedKeyValueStoreToHeadersAdapter<>(
Review Comment:
Not sure if I understand. If the user does a manual `addStateStore` this store should only be used by custom `Processors`, not any pre-defined DSL Processor? So it's not clear to me, how/why things might break?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20194: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2922784937
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -45,70 +48,81 @@ public class KeyValueStoreWrapper<K, V> implements StateStore {
public static final long PUT_RETURN_CODE_IS_LATEST
= VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED;
- private TimestampedKeyValueStore<K, V> timestampedStore = null;
+ private TimestampedKeyValueStoreWithHeaders<K, V> headersStore = null;
private VersionedKeyValueStore<K, V> versionedStore = null;
- // same as either timestampedStore or versionedStore above. kept merely as a convenience
- // to simplify implementation for methods which do not depend on store type.
private StateStore store;
+ @SuppressWarnings("unchecked")
public KeyValueStoreWrapper(final ProcessorContext<?, ?> context, final String storeName) {
+ final StateStore rawStore = context.getStateStore(storeName);
+
+ // Check if it's an OLD TimestampedKeyValueStore that needs adaptation
+ if (rawStore instanceof TimestampedKeyValueStore &&
+ !(rawStore instanceof TimestampedKeyValueStoreWithHeaders)) {
+ // Adapt OLD store to NEW type for backward compatibility
+ headersStore = new TimestampedKeyValueStoreToHeadersAdapter<>(
Review Comment:
Not sure if I understand. If the user does a manual `addStateStore` this store should only be used by custom `Processors`, not any pre-defined DSL Processor? So it's not clear to me, how/why things might break and why we need an adaptor for this case? Can you elaborat?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20194: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "aliehsaeedii (via GitHub)" <gi...@apache.org>.
aliehsaeedii commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2936949422
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KTableTransformValues.java:
##########
@@ -192,9 +192,11 @@ private ValueAndTimestamp<VOut> transformValue(final K key, final ValueAndTimest
new RecordHeaders()
));
- final ValueAndTimestamp<VOut> result = ValueAndTimestamp.make(
- valueTransformer.transform(key, getValueOrNull(valueAndTimestamp)),
- valueAndTimestamp == null ? UNKNOWN : valueAndTimestamp.timestamp());
+ final ValueTimestampHeaders<VOut> result = ValueTimestampHeaders.make(
+ valueTransformer.transform(key, getValueOrNull(valueTimestampHeaders)),
+ valueTimestampHeaders == null ? UNKNOWN : valueTimestampHeaders.timestamp(),
+ valueTimestampHeaders == null ? null : valueTimestampHeaders.headers()
Review Comment:
Let's agree on `headers()`.
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/ProcessorStateManager.java:
##########
@@ -368,7 +368,8 @@ public void registerStore(final StateStore store,
@Override
public StateStore store(final String name) {
if (stores.containsKey(name)) {
- return stores.get(name).stateStore;
+ final StateStore stateStore = stores.get(name).stateStore;
+ return stateStore;
Review Comment:
left over from debugging phase:(
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/ProcessorContextImpl.java:
##########
@@ -181,7 +181,8 @@ public <S extends StateStore> S getStateStore(final String name) {
}
final StateStore store = stateManager.store(name);
- return (S) wrapWithReadWriteStore(store);
+ final StateStore wrappedStore = wrapWithReadWriteStore(store);
+ return (S) wrappedStore;
Review Comment:
left over from debugging phase:(
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20194: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2922771564
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -45,70 +48,81 @@ public class KeyValueStoreWrapper<K, V> implements StateStore {
public static final long PUT_RETURN_CODE_IS_LATEST
= VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED;
- private TimestampedKeyValueStore<K, V> timestampedStore = null;
+ private TimestampedKeyValueStoreWithHeaders<K, V> headersStore = null;
private VersionedKeyValueStore<K, V> versionedStore = null;
- // same as either timestampedStore or versionedStore above. kept merely as a convenience
- // to simplify implementation for methods which do not depend on store type.
Review Comment:
Why are we removing this comment? Seems to be still correct?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20194: Update Kafka Streams DSL to use header-stores [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax merged PR #21580:
URL: https://github.com/apache/kafka/pull/21580
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2887431348
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KStreamSlidingWindowAggregate.java:
##########
@@ -358,8 +359,8 @@ private void processEarly(final Record<KIn, VIn> record, final long windowCloseT
if (combinedWindow == null) {
final TimeWindow window = new TimeWindow(0, windows.timeDifferenceMs());
- final ValueAndTimestamp<VAgg> valueAndTime = ValueAndTimestamp.make(initializer.apply(), record.timestamp());
- updateWindowAndForward(window, valueAndTime, record, windowCloseTime);
+ final ValueTimestampHeaders<VAgg> valueTimestampHeaders = ValueTimestampHeaders.make(initializer.apply(), record.timestamp(), record.headers());
Review Comment:
`new RecordHeaders()` ?
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KStreamSlidingWindowAggregate.java:
##########
@@ -386,14 +387,14 @@ private void createWindows(final Record<KIn, VIn> record,
// create left window for new record
if (!leftWinAlreadyCreated) {
- final ValueAndTimestamp<VAgg> valueAndTime;
+ final ValueTimestampHeaders<VAgg> valueTimestampHeaders;
if (leftWindowNotEmpty(previousRecordTimestamp, record.timestamp())) {
- valueAndTime = ValueAndTimestamp.make(leftWinAgg.value(), record.timestamp());
+ valueTimestampHeaders = ValueTimestampHeaders.make(leftWinAgg.value(), record.timestamp(), record.headers());
Review Comment:
`new RecordHeaders()` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2887426008
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KStreamAggregate.java:
##########
@@ -94,7 +94,7 @@ public void init(final ProcessorContext<KIn, Change<VAgg>> context) {
tupleForwarder = new TimestampedTupleForwarder<>(
store.store(),
context,
- new TimestampedCacheFlushListener<>(context),
+ new TimestampedCacheFlushListenerWithHeaders<>(context),
Review Comment:
Is `TimestampedCacheFlushListener` still used after this update? I would believe not, and that `TimestampedCacheFlushListenerWithHeaders` just replaces it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20194: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2922687859
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KTableTransformValues.java:
##########
@@ -192,9 +192,11 @@ private ValueAndTimestamp<VOut> transformValue(final K key, final ValueAndTimest
new RecordHeaders()
Review Comment:
Do we want to change this and pass in `valueTimestampHeaders == null ? new RecordHeaders() : valueTimestampHeaders.headers()` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2887447794
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KTableSource.java:
##########
@@ -166,7 +166,8 @@ public void process(final Record<KIn, VIn> record) {
} else {
oldValue = null;
}
- final long putReturnCode = store.put(record.key(), record.value(), record.timestamp());
+ final long putReturnCode;
+ putReturnCode = store.put(record.key(), record.value(), record.timestamp(), record.headers());
Review Comment:
`new RecordHeaders()` ?
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KTableTransformValues.java:
##########
@@ -120,7 +120,7 @@ public void process(final Record<K, Change<V>> record) {
if (queryableName != null) {
final VOut oldValue = sendOldValues ? getValueOrNull(store.get(record.key())) : null;
- final long putReturnCode = store.put(record.key(), newValue, record.timestamp());
+ final long putReturnCode = store.put(record.key(), newValue, record.timestamp(), record.headers());
Review Comment:
`new RecordHeaders()` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20263: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2963404827
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -45,70 +49,72 @@ public class KeyValueStoreWrapper<K, V> implements StateStore {
public static final long PUT_RETURN_CODE_IS_LATEST
= VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED;
- private TimestampedKeyValueStore<K, V> timestampedStore = null;
+ private TimestampedKeyValueStoreWithHeaders<K, V> headersStore = null;
private VersionedKeyValueStore<K, V> versionedStore = null;
// same as either timestampedStore or versionedStore above. kept merely as a convenience
// to simplify implementation for methods which do not depend on store type.
private StateStore store;
+ @SuppressWarnings("unchecked")
public KeyValueStoreWrapper(final ProcessorContext<?, ?> context, final String storeName) {
+ final StateStore rawStore = context.getStateStore(storeName);
+
+ // Try headers-aware timestamped store
try {
- // first try timestamped store
- timestampedStore = context.getStateStore(storeName);
- store = timestampedStore;
+ headersStore = (TimestampedKeyValueStoreWithHeaders<K, V>) rawStore;
+ store = headersStore;
return;
} catch (final ClassCastException e) {
- // ignore since could be versioned store instead
+ // not headers store, try versioned
}
+ // Try versioned store
try {
- // next try versioned store
- versionedStore = context.getStateStore(storeName);
+ versionedStore = (VersionedKeyValueStore<K, V>) rawStore;
store = versionedStore;
} catch (final ClassCastException e) {
- store = context.getStateStore(storeName);
- final String storeType = store == null ? "null" : store.getClass().getName();
+ final String storeType = rawStore == null ? "null" : rawStore.getClass().getName();
throw new InvalidStateStoreException("KTable source state store must implement either "
- + "TimestampedKeyValueStore or VersionedKeyValueStore. Got: " + storeType);
+ + "TimestampedKeyValueStore, TimestampedKeyValueStoreWithHeaders, or VersionedKeyValueStore. Got: " + storeType);
Review Comment:
Addresse via https://github.com/apache/kafka/pull/21792
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "aliehsaeedii (via GitHub)" <gi...@apache.org>.
aliehsaeedii commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2884294379
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KStreamSlidingWindowAggregate.java:
##########
@@ -457,21 +458,22 @@ protected boolean shouldRangeFetch(final long emitRangeLowerBound, final long em
}
private void updateWindowAndForward(final Window window,
- final ValueAndTimestamp<VAgg> valueAndTime,
+ final ValueTimestampHeaders<VAgg> valueTimestampHeaders,
final Record<KIn, VIn> record,
final long windowCloseTime) {
final long windowStart = window.start();
final long windowEnd = window.end();
if (windowEnd >= windowCloseTime) {
// get aggregate from existing window
- final VAgg oldAgg = getValueOrNull(valueAndTime);
+ final VAgg oldAgg = getValueOrNull(valueTimestampHeaders);
final VAgg newAgg = aggregator.apply(record.key(), record.value(), oldAgg);
- final long newTimestamp = oldAgg == null ? record.timestamp() : Math.max(record.timestamp(), valueAndTime.timestamp());
+ final long newTimestamp = oldAgg == null ? record.timestamp() : Math.max(record.timestamp(), valueTimestampHeaders.timestamp());
+ final Headers headers = oldAgg == null ? record.headers() : valueTimestampHeaders.headers();
windowStore.put(
record.key(),
- ValueAndTimestamp.make(newAgg, newTimestamp),
+ ValueTimestampHeaders.make(newAgg, newTimestamp, headers),
Review Comment:
I assume this must be empty headers?!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "UladzislauBlok (via GitHub)" <gi...@apache.org>.
UladzislauBlok commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2886100657
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -45,70 +53,80 @@ public class KeyValueStoreWrapper<K, V> implements StateStore {
public static final long PUT_RETURN_CODE_IS_LATEST
= VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED;
- private TimestampedKeyValueStore<K, V> timestampedStore = null;
+ private TimestampedKeyValueStoreWithHeaders<K, V> headersStore = null;
private VersionedKeyValueStore<K, V> versionedStore = null;
Review Comment:
I saw it in the KIP, but you're right it's not implemented yet
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2887445584
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KTableMapValues.java:
##########
@@ -109,16 +110,18 @@ private VOut computeValue(final KIn key, final VIn value) {
return newValue;
}
- private ValueAndTimestamp<VOut> computeValueAndTimestamp(final KIn key, final ValueAndTimestamp<VIn> valueAndTimestamp) {
+ private ValueTimestampHeaders<VOut> computeValueAndTimestamp(final KIn key, final ValueTimestampHeaders<VIn> valueTimestampHeaders) {
VOut newValue = null;
long timestamp = 0;
+ Headers headers = null;
- if (valueAndTimestamp != null) {
- newValue = mapper.apply(key, valueAndTimestamp.value());
- timestamp = valueAndTimestamp.timestamp();
+ if (valueTimestampHeaders != null) {
+ newValue = mapper.apply(key, valueTimestampHeaders.value());
+ timestamp = valueTimestampHeaders.timestamp();
+ headers = valueTimestampHeaders.headers();
}
- return ValueAndTimestamp.make(newValue, timestamp);
+ return ValueTimestampHeaders.make(newValue, timestamp, headers);
Review Comment:
I think passing `headers` here is fine, as it's stateless map() operation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2887446759
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KTableReduce.java:
##########
@@ -125,7 +125,7 @@ public void process(final Record<K, Change<V>> record) {
}
// update the store with the new value
- final long putReturnCode = store.put(record.key(), newAgg, newTimestamp);
+ final long putReturnCode = store.put(record.key(), newAgg, newTimestamp, record.headers());
Review Comment:
`new RecordHeaders()` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20263: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2963400910
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/ReadOnlyWindowStoreWithHeadersFacade.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.streams.KeyValue;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.state.KeyValueIterator;
+import org.apache.kafka.streams.state.ReadOnlyWindowStore;
+import org.apache.kafka.streams.state.TimestampedWindowStoreWithHeaders;
+import org.apache.kafka.streams.state.ValueTimestampHeaders;
+import org.apache.kafka.streams.state.WindowStoreIterator;
+
+import java.time.Instant;
+
+/**
+ * A facade that wraps {@link TimestampedWindowStoreWithHeaders} to provide a
+ * {@link ReadOnlyWindowStore} interface with plain values.
+ * This facade converts {@link ValueTimestampHeaders} to plain values, discarding both timestamps and headers.
+ *
+ * @param <K> key type
+ * @param <V> value type
+ */
+public class ReadOnlyWindowStoreWithHeadersFacade<K, V> implements ReadOnlyWindowStore<K, V> {
Review Comment:
Addresse via https://github.com/apache/kafka/pull/21788
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20194: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2922738348
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/InMemoryTimeOrderedKeyValueChangeBuffer.java:
##########
@@ -447,7 +447,7 @@ public Maybe<ValueAndTimestamp<V>> priorValueForBuffered(final K key) {
// it's unfortunately not possible to know this, unless we materialize the suppressed result, since our only
// knowledge of the prior value is what the upstream processor sends us as the "old value" when we first
// buffer something.
- return Maybe.defined(ValueAndTimestamp.make(deserializedValue, RecordQueue.UNKNOWN));
+ return Maybe.defined(ValueTimestampHeaders.make(deserializedValue, RecordQueue.UNKNOWN, null));
Review Comment:
nit: `null` -> `new RecordHeaders()` (doesn't make a read difference; just for code consistency.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "zheguang (via GitHub)" <gi...@apache.org>.
zheguang commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2886144098
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/PlainToHeadersWindowStoreAdapter.java:
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.TopicPartition;
+import org.apache.kafka.common.utils.ByteUtils;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.processor.StateStore;
+import org.apache.kafka.streams.processor.StateStoreContext;
+import org.apache.kafka.streams.query.Position;
+import org.apache.kafka.streams.query.PositionBound;
+import org.apache.kafka.streams.query.Query;
+import org.apache.kafka.streams.query.QueryConfig;
+import org.apache.kafka.streams.query.QueryResult;
+import org.apache.kafka.streams.state.KeyValueIterator;
+import org.apache.kafka.streams.state.TimestampedWindowStoreWithHeaders;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.streams.state.WindowStoreIterator;
+
+import java.nio.ByteBuffer;
+import java.time.Instant;
+import java.util.Map;
+
+import static org.apache.kafka.streams.state.HeadersBytesStore.convertFromPlainToHeaderFormat;
+
+/**
+ * Adapter for backward compatibility between {@link TimestampedWindowStoreWithHeaders}
+ * and {@link WindowStore}.
+ * <p>
+ * If a user provides a supplier for {@code WindowStore} (without timestamp and headers) when building
+ * a {@code TimestampedWindowStoreWithHeaders}, this adapter translates between the plain
+ * {@code byte[]} format and the timestamped-with-headers {@code byte[]} format.
+ * <p>
+ * Format conversion:
+ * <ul>
+ * <li>Write: {@code [headers][timestamp][value]} → {@code [value]} (strip timestamp and headers)</li>
+ * <li>Read: {@code [value]} → {@code [headers][timestamp][value]} (add -1 as timestamp and empty headers)</li>
+ * </ul>
+ */
+public class PlainToHeadersWindowStoreAdapter implements WindowStore<Bytes, byte[]> {
Review Comment:
Interesting -- looks like this will allow skipping the intermediate upgrade to timestamped format. Do we also need to change the `RocksDBTimestampedStoreWithHeaders` such that the `openRocksDB` and `openInUpgradeMode` also supports this upgrade path?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2887442676
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KTableMapValues.java:
##########
@@ -146,7 +149,7 @@ public void process(final Record<KIn, Change<VIn>> record) {
final VOut oldValue = computeOldValue(record.key(), record.value());
if (queryableName != null) {
- final long putReturnCode = store.put(record.key(), newValue, record.timestamp());
+ final long putReturnCode = store.put(record.key(), newValue, record.timestamp(), record.headers());
Review Comment:
`new RecordHeaders()` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2887429744
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KStreamReduce.java:
##########
@@ -129,7 +129,7 @@ public void process(final Record<K, V> record) {
newTimestamp = Math.max(record.timestamp(), oldAggAndTimestamp.timestamp());
}
- final long putReturnCode = store.put(record.key(), newAgg, newTimestamp);
+ final long putReturnCode = store.put(record.key(), newAgg, newTimestamp, record.headers());
Review Comment:
`new RecordHeaders()` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2887490946
##########
streams/src/main/java/org/apache/kafka/streams/state/BuiltInDslStoreSuppliers.java:
##########
Review Comment:
Don't we need to have a "headers version" for this one, too?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20263: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2963402210
##########
streams/src/test/java/org/apache/kafka/streams/kstream/internals/foreignkeyjoin/ResponseJoinProcessorSupplierTest.java:
##########
@@ -61,8 +61,8 @@ public void init(final ProcessorContext<?, ?> context) {
}
@Override
- public ValueAndTimestamp<V> get(final K key) {
- return ValueAndTimestamp.make(map.get(key), -1);
+ public ValueTimestampHeaders<V> get(final K key) {
+ return ValueTimestampHeaders.make(map.get(key), -1, null);
Review Comment:
Addresse via https://github.com/apache/kafka/pull/21792
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "aliehsaeedii (via GitHub)" <gi...@apache.org>.
aliehsaeedii commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2884294379
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KStreamSlidingWindowAggregate.java:
##########
@@ -457,21 +458,22 @@ protected boolean shouldRangeFetch(final long emitRangeLowerBound, final long em
}
private void updateWindowAndForward(final Window window,
- final ValueAndTimestamp<VAgg> valueAndTime,
+ final ValueTimestampHeaders<VAgg> valueTimestampHeaders,
final Record<KIn, VIn> record,
final long windowCloseTime) {
final long windowStart = window.start();
final long windowEnd = window.end();
if (windowEnd >= windowCloseTime) {
// get aggregate from existing window
- final VAgg oldAgg = getValueOrNull(valueAndTime);
+ final VAgg oldAgg = getValueOrNull(valueTimestampHeaders);
final VAgg newAgg = aggregator.apply(record.key(), record.value(), oldAgg);
- final long newTimestamp = oldAgg == null ? record.timestamp() : Math.max(record.timestamp(), valueAndTime.timestamp());
+ final long newTimestamp = oldAgg == null ? record.timestamp() : Math.max(record.timestamp(), valueTimestampHeaders.timestamp());
+ final Headers headers = oldAgg == null ? record.headers() : valueTimestampHeaders.headers();
windowStore.put(
record.key(),
- ValueAndTimestamp.make(newAgg, newTimestamp),
+ ValueTimestampHeaders.make(newAgg, newTimestamp, headers),
Review Comment:
I assume this must be empty headers?!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2887436202
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KTableKTableJoinMerger.java:
##########
@@ -125,15 +125,15 @@ public void init(final ProcessorContext<K, Change<V>> context) {
tupleForwarder = new TimestampedTupleForwarder<>(
store.store(),
context,
- new TimestampedCacheFlushListener<>(context),
+ new TimestampedCacheFlushListenerWithHeaders<>(context),
sendOldValues);
}
}
@Override
public void process(final Record<K, Change<V>> record) {
if (queryableName != null) {
- final long putReturnCode = store.put(record.key(), record.value().newValue, record.timestamp());
+ final long putReturnCode = store.put(record.key(), record.value().newValue, record.timestamp(), record.headers());
Review Comment:
`new RecordHeaders()` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2887467634
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -45,70 +48,70 @@ public class KeyValueStoreWrapper<K, V> implements StateStore {
public static final long PUT_RETURN_CODE_IS_LATEST
= VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED;
- private TimestampedKeyValueStore<K, V> timestampedStore = null;
+ private TimestampedKeyValueStoreWithHeaders<K, V> headersStore = null;
private VersionedKeyValueStore<K, V> versionedStore = null;
- // same as either timestampedStore or versionedStore above. kept merely as a convenience
- // to simplify implementation for methods which do not depend on store type.
private StateStore store;
public KeyValueStoreWrapper(final ProcessorContext<?, ?> context, final String storeName) {
+ // Try headers-aware store first, then versioned store
try {
- // first try timestamped store
- timestampedStore = context.getStateStore(storeName);
- store = timestampedStore;
+ // first try headers-aware timestamped store
+ headersStore = context.getStateStore(storeName);
+ store = headersStore;
return;
} catch (final ClassCastException e) {
- // ignore since could be versioned store instead
+ // ignore since could be regular timestamped or versioned store instead
+ System.out.println(e.getMessage());
Review Comment:
Guess it's on left over debug statement that needs to get removed?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "aliehsaeedii (via GitHub)" <gi...@apache.org>.
aliehsaeedii commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2888533746
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/TimestampedWindowStoreWithHeadersBuilder.java:
##########
@@ -72,7 +72,11 @@ public TimestampedWindowStoreWithHeaders<K, V> build() {
if (!(store instanceof HeadersBytesStore)) {
if (store.persistent()) {
- store = new TimestampedToHeadersWindowStoreAdapter(store);
+ if (store instanceof TimestampedBytesStore) {
+ store = new TimestampedToHeadersWindowStoreAdapter(store);
+ } else {
+ store = new PlainToHeadersWindowStoreAdapter(store);
Review Comment:
For both cases we need. Please check `StreamJoinedStoreFactory`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20194: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2922801509
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -45,70 +48,81 @@ public class KeyValueStoreWrapper<K, V> implements StateStore {
public static final long PUT_RETURN_CODE_IS_LATEST
= VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED;
- private TimestampedKeyValueStore<K, V> timestampedStore = null;
+ private TimestampedKeyValueStoreWithHeaders<K, V> headersStore = null;
private VersionedKeyValueStore<K, V> versionedStore = null;
- // same as either timestampedStore or versionedStore above. kept merely as a convenience
- // to simplify implementation for methods which do not depend on store type.
private StateStore store;
+ @SuppressWarnings("unchecked")
public KeyValueStoreWrapper(final ProcessorContext<?, ?> context, final String storeName) {
+ final StateStore rawStore = context.getStateStore(storeName);
+
+ // Check if it's an OLD TimestampedKeyValueStore that needs adaptation
+ if (rawStore instanceof TimestampedKeyValueStore &&
+ !(rawStore instanceof TimestampedKeyValueStoreWithHeaders)) {
+ // Adapt OLD store to NEW type for backward compatibility
+ headersStore = new TimestampedKeyValueStoreToHeadersAdapter<>(
+ (TimestampedKeyValueStore<K, V>) rawStore
+ );
+ store = headersStore;
+ return;
+ }
+
+ // Try headers-aware timestamped store
try {
- // first try timestamped store
- timestampedStore = context.getStateStore(storeName);
- store = timestampedStore;
+ headersStore = (TimestampedKeyValueStoreWithHeaders<K, V>) rawStore;
+ store = headersStore;
return;
} catch (final ClassCastException e) {
- // ignore since could be versioned store instead
+ // not headers store, try versioned
}
+ // Try versioned store
try {
- // next try versioned store
- versionedStore = context.getStateStore(storeName);
+ versionedStore = (VersionedKeyValueStore<K, V>) rawStore;
store = versionedStore;
} catch (final ClassCastException e) {
- store = context.getStateStore(storeName);
- final String storeType = store == null ? "null" : store.getClass().getName();
+ final String storeType = rawStore == null ? "null" : rawStore.getClass().getName();
throw new InvalidStateStoreException("KTable source state store must implement either "
- + "TimestampedKeyValueStore or VersionedKeyValueStore. Got: " + storeType);
+ + "TimestampedKeyValueStore, TimestampedKeyValueStoreWithHeaders, or VersionedKeyValueStore. Got: " + storeType);
}
}
- public ValueAndTimestamp<V> get(final K key) {
- if (timestampedStore != null) {
- return timestampedStore.get(key);
+ public ValueTimestampHeaders<V> get(final K key) {
+ if (headersStore != null) {
+ return headersStore.get(key);
}
if (versionedStore != null) {
final VersionedRecord<V> versionedRecord = versionedStore.get(key);
return versionedRecord == null
? null
- : ValueAndTimestamp.make(versionedRecord.value(), versionedRecord.timestamp());
+ : ValueTimestampHeaders.make(versionedRecord.value(), versionedRecord.timestamp(), null);
}
- throw new IllegalStateException("KeyValueStoreWrapper must be initialized with either timestamped or versioned store");
+ throw new IllegalStateException("KeyValueStoreWrapper must be initialized with either timestamped, headers, or versioned store");
}
- public ValueAndTimestamp<V> get(final K key, final long asOfTimestamp) {
+ public ValueTimestampHeaders<V> get(final K key, final long asOfTimestamp) {
if (!isVersionedStore()) {
throw new UnsupportedOperationException("get(key, timestamp) is only supported for versioned stores");
}
final VersionedRecord<V> versionedRecord = versionedStore.get(key, asOfTimestamp);
- return versionedRecord == null ? null : ValueAndTimestamp.make(versionedRecord.value(), versionedRecord.timestamp());
+ return versionedRecord == null ? null : ValueTimestampHeaders.make(versionedRecord.value(), versionedRecord.timestamp(), null);
Review Comment:
`null` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20194: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2922779365
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -45,70 +48,81 @@ public class KeyValueStoreWrapper<K, V> implements StateStore {
public static final long PUT_RETURN_CODE_IS_LATEST
= VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED;
- private TimestampedKeyValueStore<K, V> timestampedStore = null;
+ private TimestampedKeyValueStoreWithHeaders<K, V> headersStore = null;
private VersionedKeyValueStore<K, V> versionedStore = null;
- // same as either timestampedStore or versionedStore above. kept merely as a convenience
- // to simplify implementation for methods which do not depend on store type.
private StateStore store;
+ @SuppressWarnings("unchecked")
public KeyValueStoreWrapper(final ProcessorContext<?, ?> context, final String storeName) {
+ final StateStore rawStore = context.getStateStore(storeName);
+
+ // Check if it's an OLD TimestampedKeyValueStore that needs adaptation
+ if (rawStore instanceof TimestampedKeyValueStore &&
+ !(rawStore instanceof TimestampedKeyValueStoreWithHeaders)) {
Review Comment:
Do we need this? I don't think that a `TimestampedKeyValueStore` can every be `TimestampedKeyValueStoreWithHeaders`? They do not inherit from each other, but both inherit from `KeyValueStore`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20263: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2963398700
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -45,70 +49,72 @@ public class KeyValueStoreWrapper<K, V> implements StateStore {
public static final long PUT_RETURN_CODE_IS_LATEST
= VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED;
- private TimestampedKeyValueStore<K, V> timestampedStore = null;
+ private TimestampedKeyValueStoreWithHeaders<K, V> headersStore = null;
private VersionedKeyValueStore<K, V> versionedStore = null;
// same as either timestampedStore or versionedStore above. kept merely as a convenience
// to simplify implementation for methods which do not depend on store type.
private StateStore store;
+ @SuppressWarnings("unchecked")
public KeyValueStoreWrapper(final ProcessorContext<?, ?> context, final String storeName) {
+ final StateStore rawStore = context.getStateStore(storeName);
+
+ // Try headers-aware timestamped store
try {
- // first try timestamped store
- timestampedStore = context.getStateStore(storeName);
- store = timestampedStore;
+ headersStore = (TimestampedKeyValueStoreWithHeaders<K, V>) rawStore;
+ store = headersStore;
return;
} catch (final ClassCastException e) {
- // ignore since could be versioned store instead
+ // not headers store, try versioned
}
+ // Try versioned store
try {
- // next try versioned store
- versionedStore = context.getStateStore(storeName);
+ versionedStore = (VersionedKeyValueStore<K, V>) rawStore;
store = versionedStore;
} catch (final ClassCastException e) {
- store = context.getStateStore(storeName);
- final String storeType = store == null ? "null" : store.getClass().getName();
+ final String storeType = rawStore == null ? "null" : rawStore.getClass().getName();
throw new InvalidStateStoreException("KTable source state store must implement either "
- + "TimestampedKeyValueStore or VersionedKeyValueStore. Got: " + storeType);
+ + "TimestampedKeyValueStore, TimestampedKeyValueStoreWithHeaders, or VersionedKeyValueStore. Got: " + storeType);
}
}
- public ValueAndTimestamp<V> get(final K key) {
- if (timestampedStore != null) {
- return timestampedStore.get(key);
+ public ValueTimestampHeaders<V> get(final K key) {
+ if (headersStore != null) {
+ return headersStore.get(key);
}
if (versionedStore != null) {
final VersionedRecord<V> versionedRecord = versionedStore.get(key);
return versionedRecord == null
? null
- : ValueAndTimestamp.make(versionedRecord.value(), versionedRecord.timestamp());
+ : ValueTimestampHeaders.make(versionedRecord.value(), versionedRecord.timestamp(), null);
}
- throw new IllegalStateException("KeyValueStoreWrapper must be initialized with either timestamped or versioned store");
+ throw new IllegalStateException("KeyValueStoreWrapper must be initialized with either timestamped, headers, or versioned store");
Review Comment:
Addressed via https://github.com/apache/kafka/pull/21792
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -45,70 +49,72 @@ public class KeyValueStoreWrapper<K, V> implements StateStore {
public static final long PUT_RETURN_CODE_IS_LATEST
= VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED;
- private TimestampedKeyValueStore<K, V> timestampedStore = null;
+ private TimestampedKeyValueStoreWithHeaders<K, V> headersStore = null;
private VersionedKeyValueStore<K, V> versionedStore = null;
// same as either timestampedStore or versionedStore above. kept merely as a convenience
// to simplify implementation for methods which do not depend on store type.
private StateStore store;
+ @SuppressWarnings("unchecked")
public KeyValueStoreWrapper(final ProcessorContext<?, ?> context, final String storeName) {
+ final StateStore rawStore = context.getStateStore(storeName);
+
+ // Try headers-aware timestamped store
try {
- // first try timestamped store
- timestampedStore = context.getStateStore(storeName);
- store = timestampedStore;
+ headersStore = (TimestampedKeyValueStoreWithHeaders<K, V>) rawStore;
+ store = headersStore;
return;
} catch (final ClassCastException e) {
- // ignore since could be versioned store instead
+ // not headers store, try versioned
}
+ // Try versioned store
try {
- // next try versioned store
- versionedStore = context.getStateStore(storeName);
+ versionedStore = (VersionedKeyValueStore<K, V>) rawStore;
store = versionedStore;
} catch (final ClassCastException e) {
- store = context.getStateStore(storeName);
- final String storeType = store == null ? "null" : store.getClass().getName();
+ final String storeType = rawStore == null ? "null" : rawStore.getClass().getName();
throw new InvalidStateStoreException("KTable source state store must implement either "
- + "TimestampedKeyValueStore or VersionedKeyValueStore. Got: " + storeType);
+ + "TimestampedKeyValueStore, TimestampedKeyValueStoreWithHeaders, or VersionedKeyValueStore. Got: " + storeType);
}
}
- public ValueAndTimestamp<V> get(final K key) {
- if (timestampedStore != null) {
- return timestampedStore.get(key);
+ public ValueTimestampHeaders<V> get(final K key) {
+ if (headersStore != null) {
+ return headersStore.get(key);
}
if (versionedStore != null) {
final VersionedRecord<V> versionedRecord = versionedStore.get(key);
return versionedRecord == null
? null
- : ValueAndTimestamp.make(versionedRecord.value(), versionedRecord.timestamp());
+ : ValueTimestampHeaders.make(versionedRecord.value(), versionedRecord.timestamp(), null);
}
- throw new IllegalStateException("KeyValueStoreWrapper must be initialized with either timestamped or versioned store");
+ throw new IllegalStateException("KeyValueStoreWrapper must be initialized with either timestamped, headers, or versioned store");
}
- public ValueAndTimestamp<V> get(final K key, final long asOfTimestamp) {
+ public ValueTimestampHeaders<V> get(final K key, final long asOfTimestamp) {
if (!isVersionedStore()) {
throw new UnsupportedOperationException("get(key, timestamp) is only supported for versioned stores");
}
final VersionedRecord<V> versionedRecord = versionedStore.get(key, asOfTimestamp);
- return versionedRecord == null ? null : ValueAndTimestamp.make(versionedRecord.value(), versionedRecord.timestamp());
+ return versionedRecord == null ? null : ValueTimestampHeaders.make(versionedRecord.value(), versionedRecord.timestamp(), new RecordHeaders());
}
/**
* @return {@code -1} if the put record is the latest for its key, and {@code Long.MIN_VALUE}
* if the put was rejected (i.e., due to grace period having elapsed for a versioned
* store). If neither, any other long value may be returned.
*/
- public long put(final K key, final V value, final long timestamp) {
- if (timestampedStore != null) {
- timestampedStore.put(key, ValueAndTimestamp.make(value, timestamp));
+ public long put(final K key, final V value, final long timestamp, final Headers headers) {
+ if (headersStore != null) {
+ headersStore.put(key, ValueTimestampHeaders.make(value, timestamp, headers));
return PUT_RETURN_CODE_IS_LATEST;
}
if (versionedStore != null) {
return versionedStore.put(key, value, timestamp);
}
- throw new IllegalStateException("KeyValueStoreWrapper must be initialized with either timestamped or versioned store");
+ throw new IllegalStateException("KeyValueStoreWrapper must be initialized with either timestamped, headers, or versioned store");
Review Comment:
Addressed via https://github.com/apache/kafka/pull/21792
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20263: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2963400175
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/ReadOnlyKeyValueStoreWithHeadersFacade.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.serialization.Serializer;
+import org.apache.kafka.streams.KeyValue;
+import org.apache.kafka.streams.state.KeyValueIterator;
+import org.apache.kafka.streams.state.ReadOnlyKeyValueStore;
+import org.apache.kafka.streams.state.TimestampedKeyValueStoreWithHeaders;
+import org.apache.kafka.streams.state.ValueTimestampHeaders;
+
+/**
+ * A facade that wraps {@link TimestampedKeyValueStoreWithHeaders} to provide a
+ * {@link ReadOnlyKeyValueStore} interface. This facade extracts the plain value
+ * from {@link ValueTimestampHeaders}, discarding timestamp and headers.
+ *
+ * @param <K> key type
+ * @param <V> value type
+ */
+public class ReadOnlyKeyValueStoreWithHeadersFacade<K, V> implements ReadOnlyKeyValueStore<K, V> {
Review Comment:
Addresse via https://github.com/apache/kafka/pull/21788
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/ReadOnlyTimestampedKeyValueStoreWithHeadersFacade.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.serialization.Serializer;
+import org.apache.kafka.streams.KeyValue;
+import org.apache.kafka.streams.state.KeyValueIterator;
+import org.apache.kafka.streams.state.ReadOnlyKeyValueStore;
+import org.apache.kafka.streams.state.TimestampedKeyValueStoreWithHeaders;
+import org.apache.kafka.streams.state.ValueAndTimestamp;
+import org.apache.kafka.streams.state.ValueTimestampHeaders;
+
+/**
+ * A facade that wraps {@link TimestampedKeyValueStoreWithHeaders} to provide a
+ * {@link ReadOnlyKeyValueStore} interface with {@link ValueAndTimestamp} values.
+ * This facade converts {@link ValueTimestampHeaders} to {@link ValueAndTimestamp}, discarding headers.
+ *
+ * Similar to {@link ReadOnlyKeyValueStoreWithHeadersFacade} but for timestamped queries.
+ *
+ * @param <K> key type
+ * @param <V> value type
+ */
+public class ReadOnlyTimestampedKeyValueStoreWithHeadersFacade<K, V> implements ReadOnlyKeyValueStore<K, ValueAndTimestamp<V>> {
Review Comment:
Addresse via https://github.com/apache/kafka/pull/21788
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/ReadOnlyTimestampedWindowStoreWithHeadersFacade.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.streams.KeyValue;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.state.KeyValueIterator;
+import org.apache.kafka.streams.state.ReadOnlyWindowStore;
+import org.apache.kafka.streams.state.TimestampedWindowStoreWithHeaders;
+import org.apache.kafka.streams.state.ValueAndTimestamp;
+import org.apache.kafka.streams.state.ValueTimestampHeaders;
+import org.apache.kafka.streams.state.WindowStoreIterator;
+
+import java.time.Instant;
+
+/**
+ * A facade that wraps {@link TimestampedWindowStoreWithHeaders} to provide a
+ * {@link ReadOnlyWindowStore} interface with {@link ValueAndTimestamp} values.
+ * This facade converts {@link ValueTimestampHeaders} to {@link ValueAndTimestamp}, discarding headers.
+ *
+ * @param <K> key type
+ * @param <V> value type
+ */
+public class ReadOnlyTimestampedWindowStoreWithHeadersFacade<K, V> implements ReadOnlyWindowStore<K, ValueAndTimestamp<V>> {
Review Comment:
Addresse via https://github.com/apache/kafka/pull/21788
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20194: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2943207276
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KTableMapValues.java:
##########
@@ -109,16 +111,18 @@ private VOut computeValue(final KIn key, final VIn value) {
return newValue;
}
- private ValueAndTimestamp<VOut> computeValueAndTimestamp(final KIn key, final ValueAndTimestamp<VIn> valueAndTimestamp) {
+ private ValueTimestampHeaders<VOut> computeValueAndTimestamp(final KIn key, final ValueTimestampHeaders<VIn> valueTimestampHeaders) {
VOut newValue = null;
long timestamp = 0;
+ Headers headers = null;
- if (valueAndTimestamp != null) {
- newValue = mapper.apply(key, valueAndTimestamp.value());
- timestamp = valueAndTimestamp.timestamp();
+ if (valueTimestampHeaders != null) {
+ newValue = mapper.apply(key, valueTimestampHeaders.value());
+ timestamp = valueTimestampHeaders.timestamp();
+ headers = valueTimestampHeaders.headers();
}
Review Comment:
If `valueTimestampHeaders == null`, should we set `headers = context.headers()` ?
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -45,70 +49,72 @@ public class KeyValueStoreWrapper<K, V> implements StateStore {
public static final long PUT_RETURN_CODE_IS_LATEST
= VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED;
- private TimestampedKeyValueStore<K, V> timestampedStore = null;
+ private TimestampedKeyValueStoreWithHeaders<K, V> headersStore = null;
private VersionedKeyValueStore<K, V> versionedStore = null;
// same as either timestampedStore or versionedStore above. kept merely as a convenience
// to simplify implementation for methods which do not depend on store type.
private StateStore store;
+ @SuppressWarnings("unchecked")
public KeyValueStoreWrapper(final ProcessorContext<?, ?> context, final String storeName) {
+ final StateStore rawStore = context.getStateStore(storeName);
Review Comment:
Why do we introduce `rawStore` ? The leads to the new to add `@SuppressWarnings("unchecked")` and cast below.
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -45,70 +49,72 @@ public class KeyValueStoreWrapper<K, V> implements StateStore {
public static final long PUT_RETURN_CODE_IS_LATEST
= VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED;
- private TimestampedKeyValueStore<K, V> timestampedStore = null;
+ private TimestampedKeyValueStoreWithHeaders<K, V> headersStore = null;
private VersionedKeyValueStore<K, V> versionedStore = null;
// same as either timestampedStore or versionedStore above. kept merely as a convenience
// to simplify implementation for methods which do not depend on store type.
private StateStore store;
+ @SuppressWarnings("unchecked")
public KeyValueStoreWrapper(final ProcessorContext<?, ?> context, final String storeName) {
+ final StateStore rawStore = context.getStateStore(storeName);
+
+ // Try headers-aware timestamped store
try {
- // first try timestamped store
- timestampedStore = context.getStateStore(storeName);
- store = timestampedStore;
+ headersStore = (TimestampedKeyValueStoreWithHeaders<K, V>) rawStore;
+ store = headersStore;
return;
} catch (final ClassCastException e) {
- // ignore since could be versioned store instead
+ // not headers store, try versioned
}
+ // Try versioned store
try {
- // next try versioned store
- versionedStore = context.getStateStore(storeName);
+ versionedStore = (VersionedKeyValueStore<K, V>) rawStore;
store = versionedStore;
} catch (final ClassCastException e) {
- store = context.getStateStore(storeName);
- final String storeType = store == null ? "null" : store.getClass().getName();
+ final String storeType = rawStore == null ? "null" : rawStore.getClass().getName();
throw new InvalidStateStoreException("KTable source state store must implement either "
- + "TimestampedKeyValueStore or VersionedKeyValueStore. Got: " + storeType);
+ + "TimestampedKeyValueStore, TimestampedKeyValueStoreWithHeaders, or VersionedKeyValueStore. Got: " + storeType);
Review Comment:
```suggestion
+ "TimestampedKeyValueStoreWithHeaders or VersionedKeyValueStore. Got: " + storeType);
```
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -45,70 +49,72 @@ public class KeyValueStoreWrapper<K, V> implements StateStore {
public static final long PUT_RETURN_CODE_IS_LATEST
= VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED;
- private TimestampedKeyValueStore<K, V> timestampedStore = null;
+ private TimestampedKeyValueStoreWithHeaders<K, V> headersStore = null;
private VersionedKeyValueStore<K, V> versionedStore = null;
// same as either timestampedStore or versionedStore above. kept merely as a convenience
// to simplify implementation for methods which do not depend on store type.
private StateStore store;
+ @SuppressWarnings("unchecked")
public KeyValueStoreWrapper(final ProcessorContext<?, ?> context, final String storeName) {
+ final StateStore rawStore = context.getStateStore(storeName);
+
+ // Try headers-aware timestamped store
try {
- // first try timestamped store
- timestampedStore = context.getStateStore(storeName);
- store = timestampedStore;
+ headersStore = (TimestampedKeyValueStoreWithHeaders<K, V>) rawStore;
+ store = headersStore;
return;
} catch (final ClassCastException e) {
- // ignore since could be versioned store instead
+ // not headers store, try versioned
}
+ // Try versioned store
try {
- // next try versioned store
- versionedStore = context.getStateStore(storeName);
+ versionedStore = (VersionedKeyValueStore<K, V>) rawStore;
store = versionedStore;
} catch (final ClassCastException e) {
- store = context.getStateStore(storeName);
- final String storeType = store == null ? "null" : store.getClass().getName();
+ final String storeType = rawStore == null ? "null" : rawStore.getClass().getName();
throw new InvalidStateStoreException("KTable source state store must implement either "
- + "TimestampedKeyValueStore or VersionedKeyValueStore. Got: " + storeType);
+ + "TimestampedKeyValueStore, TimestampedKeyValueStoreWithHeaders, or VersionedKeyValueStore. Got: " + storeType);
}
}
- public ValueAndTimestamp<V> get(final K key) {
- if (timestampedStore != null) {
- return timestampedStore.get(key);
+ public ValueTimestampHeaders<V> get(final K key) {
+ if (headersStore != null) {
+ return headersStore.get(key);
}
if (versionedStore != null) {
final VersionedRecord<V> versionedRecord = versionedStore.get(key);
return versionedRecord == null
? null
- : ValueAndTimestamp.make(versionedRecord.value(), versionedRecord.timestamp());
+ : ValueTimestampHeaders.make(versionedRecord.value(), versionedRecord.timestamp(), null);
}
- throw new IllegalStateException("KeyValueStoreWrapper must be initialized with either timestamped or versioned store");
+ throw new IllegalStateException("KeyValueStoreWrapper must be initialized with either timestamped, headers, or versioned store");
Review Comment:
```suggestion
throw new IllegalStateException("KeyValueStoreWrapper must be initialized with either headers or versioned store");
```
##########
streams/src/test/java/org/apache/kafka/streams/kstream/internals/foreignkeyjoin/ResponseJoinProcessorSupplierTest.java:
##########
@@ -61,8 +61,8 @@ public void init(final ProcessorContext<?, ?> context) {
}
@Override
- public ValueAndTimestamp<V> get(final K key) {
- return ValueAndTimestamp.make(map.get(key), -1);
+ public ValueTimestampHeaders<V> get(final K key) {
+ return ValueTimestampHeaders.make(map.get(key), -1, null);
Review Comment:
Nit: Should we align to prod-code and pass `new RecordHeaders()` instead of `null`?
Also elsewhere, if we change it -- I am fine either way.
##########
streams/src/test/java/org/apache/kafka/streams/StreamsBuilderTest.java:
##########
Review Comment:
It seems, we should pass in `Stores.persistentWindowStoreWithHeaders` here -- we change the DSL to work with header-store, so if we pass in a plain-store, the code inserts the adaptor?
Given that `Stores.persistentWindowStoreWithHeaders(...)` doesn't exists yet (seems this is something we should get fixed?), we could also just pass `new RocksDbWindowBytesStoreSupplier(...)` instead?
##########
streams/src/test/java/org/apache/kafka/test/GenericInMemoryTimestampedKeyValueStoreWithHeaders.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.test;
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.streams.KeyValue;
+import org.apache.kafka.streams.processor.StateStore;
+import org.apache.kafka.streams.processor.StateStoreContext;
+import org.apache.kafka.streams.state.KeyValueIterator;
+import org.apache.kafka.streams.state.TimestampedKeyValueStoreWithHeaders;
+import org.apache.kafka.streams.state.ValueTimestampHeaders;
+import org.apache.kafka.streams.state.internals.CacheFlushListener;
+import org.apache.kafka.streams.state.internals.DelegatingPeekingKeyValueIterator;
+import org.apache.kafka.streams.state.internals.WrappedStateStore;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.NavigableMap;
+import java.util.TreeMap;
+
+/**
+ * This class is a generic version of the in-memory key-value store that is useful for testing when you
+ * need a basic KeyValueStore for arbitrary types and don't have/want to write a serde
+ */
+@SuppressWarnings("deprecation")
+public class GenericInMemoryTimestampedKeyValueStoreWithHeaders<K extends Comparable, V>
+ extends WrappedStateStore<StateStore, K, ValueTimestampHeaders<V>>
+ implements TimestampedKeyValueStoreWithHeaders<K, V> {
+
+ private final String name;
+ private final NavigableMap<K, ValueTimestampHeaders<V>> map;
+ private volatile boolean open = false;
+
+ public GenericInMemoryTimestampedKeyValueStoreWithHeaders(final String name) {
+ // it's not really a `WrappedStateStore` so we pass `null`
+ // however, we need to implement `WrappedStateStore` to make the store usable
+ super(null);
+ this.name = name;
+
+ this.map = new TreeMap<>();
+ }
+
+ @Override
+ public String name() {
+ return this.name;
Review Comment:
```suggestion
return name;
```
##########
streams/src/test/java/org/apache/kafka/streams/StreamsBuilderTest.java:
##########
@@ -1222,7 +1222,7 @@ public void shouldUseSpecifiedStoreSupplierForEachOuterJoinOperationBetweenKStre
final ProcessorTopology topology = builder.internalTopologyBuilder.rewriteTopology(new StreamsConfig(props)).buildTopology();
assertTypesForStateStore(topology.stateStores(),
InMemoryWindowStore.class,
- RocksDBWindowStore.class,
+ PlainToHeadersWindowStoreAdapter.class,
Review Comment:
> We can either fix the test
Not sure what you exactly mean by this. But cf my comment above -- this is expected given how the test is setup -- but yes, we might want to update the test setup.
I don't think we need to change anything about `PlainToHeadersWindowStoreAdapter`.
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/ReadOnlyTimestampedWindowStoreWithHeadersFacade.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.streams.KeyValue;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.state.KeyValueIterator;
+import org.apache.kafka.streams.state.ReadOnlyWindowStore;
+import org.apache.kafka.streams.state.TimestampedWindowStoreWithHeaders;
+import org.apache.kafka.streams.state.ValueAndTimestamp;
+import org.apache.kafka.streams.state.ValueTimestampHeaders;
+import org.apache.kafka.streams.state.WindowStoreIterator;
+
+import java.time.Instant;
+
+/**
+ * A facade that wraps {@link TimestampedWindowStoreWithHeaders} to provide a
+ * {@link ReadOnlyWindowStore} interface with {@link ValueAndTimestamp} values.
+ * This facade converts {@link ValueTimestampHeaders} to {@link ValueAndTimestamp}, discarding headers.
+ *
+ * @param <K> key type
+ * @param <V> value type
+ */
+public class ReadOnlyTimestampedWindowStoreWithHeadersFacade<K, V> implements ReadOnlyWindowStore<K, ValueAndTimestamp<V>> {
Review Comment:
One more about `GenericXxx` ?
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/ReadOnlyTimestampedKeyValueStoreWithHeadersFacade.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.serialization.Serializer;
+import org.apache.kafka.streams.KeyValue;
+import org.apache.kafka.streams.state.KeyValueIterator;
+import org.apache.kafka.streams.state.ReadOnlyKeyValueStore;
+import org.apache.kafka.streams.state.TimestampedKeyValueStoreWithHeaders;
+import org.apache.kafka.streams.state.ValueAndTimestamp;
+import org.apache.kafka.streams.state.ValueTimestampHeaders;
+
+/**
+ * A facade that wraps {@link TimestampedKeyValueStoreWithHeaders} to provide a
+ * {@link ReadOnlyKeyValueStore} interface with {@link ValueAndTimestamp} values.
+ * This facade converts {@link ValueTimestampHeaders} to {@link ValueAndTimestamp}, discarding headers.
+ *
+ * Similar to {@link ReadOnlyKeyValueStoreWithHeadersFacade} but for timestamped queries.
+ *
+ * @param <K> key type
+ * @param <V> value type
+ */
+public class ReadOnlyTimestampedKeyValueStoreWithHeadersFacade<K, V> implements ReadOnlyKeyValueStore<K, ValueAndTimestamp<V>> {
Review Comment:
Similar question. Can we use `GenericXxx` to reduce boiler place code duplication?
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/ReadOnlyKeyValueStoreWithHeadersFacade.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.serialization.Serializer;
+import org.apache.kafka.streams.KeyValue;
+import org.apache.kafka.streams.state.KeyValueIterator;
+import org.apache.kafka.streams.state.ReadOnlyKeyValueStore;
+import org.apache.kafka.streams.state.TimestampedKeyValueStoreWithHeaders;
+import org.apache.kafka.streams.state.ValueTimestampHeaders;
+
+/**
+ * A facade that wraps {@link TimestampedKeyValueStoreWithHeaders} to provide a
+ * {@link ReadOnlyKeyValueStore} interface. This facade extracts the plain value
+ * from {@link ValueTimestampHeaders}, discarding timestamp and headers.
+ *
+ * @param <K> key type
+ * @param <V> value type
+ */
+public class ReadOnlyKeyValueStoreWithHeadersFacade<K, V> implements ReadOnlyKeyValueStore<K, V> {
Review Comment:
Should this be `ReadOnlyKeyValueStoreWithHeadersFacade extends GenericReadOnlyKeyValueStoreFacade` or maybe we can drop the class entirely and just use `new GenericReadOnlyKeyValueStoreFacade(...)` (similar to what we did for IQv1 and TTD case)?
We could do this also as follow up PR.
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/ReadOnlyWindowStoreWithHeadersFacade.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.streams.KeyValue;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.state.KeyValueIterator;
+import org.apache.kafka.streams.state.ReadOnlyWindowStore;
+import org.apache.kafka.streams.state.TimestampedWindowStoreWithHeaders;
+import org.apache.kafka.streams.state.ValueTimestampHeaders;
+import org.apache.kafka.streams.state.WindowStoreIterator;
+
+import java.time.Instant;
+
+/**
+ * A facade that wraps {@link TimestampedWindowStoreWithHeaders} to provide a
+ * {@link ReadOnlyWindowStore} interface with plain values.
+ * This facade converts {@link ValueTimestampHeaders} to plain values, discarding both timestamps and headers.
+ *
+ * @param <K> key type
+ * @param <V> value type
+ */
+public class ReadOnlyWindowStoreWithHeadersFacade<K, V> implements ReadOnlyWindowStore<K, V> {
Review Comment:
Another facede
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -45,70 +49,72 @@ public class KeyValueStoreWrapper<K, V> implements StateStore {
public static final long PUT_RETURN_CODE_IS_LATEST
= VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED;
- private TimestampedKeyValueStore<K, V> timestampedStore = null;
+ private TimestampedKeyValueStoreWithHeaders<K, V> headersStore = null;
private VersionedKeyValueStore<K, V> versionedStore = null;
// same as either timestampedStore or versionedStore above. kept merely as a convenience
// to simplify implementation for methods which do not depend on store type.
private StateStore store;
+ @SuppressWarnings("unchecked")
public KeyValueStoreWrapper(final ProcessorContext<?, ?> context, final String storeName) {
+ final StateStore rawStore = context.getStateStore(storeName);
+
+ // Try headers-aware timestamped store
try {
- // first try timestamped store
- timestampedStore = context.getStateStore(storeName);
- store = timestampedStore;
+ headersStore = (TimestampedKeyValueStoreWithHeaders<K, V>) rawStore;
+ store = headersStore;
return;
} catch (final ClassCastException e) {
- // ignore since could be versioned store instead
+ // not headers store, try versioned
}
+ // Try versioned store
try {
- // next try versioned store
- versionedStore = context.getStateStore(storeName);
+ versionedStore = (VersionedKeyValueStore<K, V>) rawStore;
store = versionedStore;
} catch (final ClassCastException e) {
- store = context.getStateStore(storeName);
- final String storeType = store == null ? "null" : store.getClass().getName();
+ final String storeType = rawStore == null ? "null" : rawStore.getClass().getName();
throw new InvalidStateStoreException("KTable source state store must implement either "
- + "TimestampedKeyValueStore or VersionedKeyValueStore. Got: " + storeType);
+ + "TimestampedKeyValueStore, TimestampedKeyValueStoreWithHeaders, or VersionedKeyValueStore. Got: " + storeType);
}
}
- public ValueAndTimestamp<V> get(final K key) {
- if (timestampedStore != null) {
- return timestampedStore.get(key);
+ public ValueTimestampHeaders<V> get(final K key) {
+ if (headersStore != null) {
+ return headersStore.get(key);
}
if (versionedStore != null) {
final VersionedRecord<V> versionedRecord = versionedStore.get(key);
return versionedRecord == null
? null
- : ValueAndTimestamp.make(versionedRecord.value(), versionedRecord.timestamp());
+ : ValueTimestampHeaders.make(versionedRecord.value(), versionedRecord.timestamp(), null);
}
- throw new IllegalStateException("KeyValueStoreWrapper must be initialized with either timestamped or versioned store");
+ throw new IllegalStateException("KeyValueStoreWrapper must be initialized with either timestamped, headers, or versioned store");
}
- public ValueAndTimestamp<V> get(final K key, final long asOfTimestamp) {
+ public ValueTimestampHeaders<V> get(final K key, final long asOfTimestamp) {
if (!isVersionedStore()) {
throw new UnsupportedOperationException("get(key, timestamp) is only supported for versioned stores");
}
final VersionedRecord<V> versionedRecord = versionedStore.get(key, asOfTimestamp);
- return versionedRecord == null ? null : ValueAndTimestamp.make(versionedRecord.value(), versionedRecord.timestamp());
+ return versionedRecord == null ? null : ValueTimestampHeaders.make(versionedRecord.value(), versionedRecord.timestamp(), new RecordHeaders());
}
/**
* @return {@code -1} if the put record is the latest for its key, and {@code Long.MIN_VALUE}
* if the put was rejected (i.e., due to grace period having elapsed for a versioned
* store). If neither, any other long value may be returned.
*/
- public long put(final K key, final V value, final long timestamp) {
- if (timestampedStore != null) {
- timestampedStore.put(key, ValueAndTimestamp.make(value, timestamp));
+ public long put(final K key, final V value, final long timestamp, final Headers headers) {
+ if (headersStore != null) {
+ headersStore.put(key, ValueTimestampHeaders.make(value, timestamp, headers));
return PUT_RETURN_CODE_IS_LATEST;
}
if (versionedStore != null) {
return versionedStore.put(key, value, timestamp);
}
- throw new IllegalStateException("KeyValueStoreWrapper must be initialized with either timestamped or versioned store");
+ throw new IllegalStateException("KeyValueStoreWrapper must be initialized with either timestamped, headers, or versioned store");
Review Comment:
```suggestion
throw new IllegalStateException("KeyValueStoreWrapper must be initialized with either headers or versioned store");
```
##########
streams/src/test/java/org/apache/kafka/streams/KeyValueTimestampHeaders.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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;
+
+import org.apache.kafka.common.header.Headers;
+
+import java.util.Objects;
+
+/**
+ * A key-value pair with timestamp and headers, used for testing KTable with headers support.
+ */
+public class KeyValueTimestampHeaders<K, V> {
Review Comment:
Wondering why we add this? Can't we use `Record` ? (might be another follow up PR to clean it up)
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/WindowStoreMaterializerTest.java:
##########
@@ -105,297 +101,146 @@ private void mockWindowStoreSupplier() {
}
@Test
- public void shouldCreateTimestampedBuilderWithCachingAndLoggingEnabledByDefault() {
+ public void shouldCreateHeadersBuilderWithCachingAndLoggingEnabledByDefault() {
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.as("store"), nameProvider, STORE_PREFIX);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore caching = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
final StateStore logging = caching.wrapped();
- assertInstanceOf(MeteredTimestampedWindowStore.class, store);
+ assertInstanceOf(MeteredTimestampedWindowStoreWithHeaders.class, store);
assertInstanceOf(CachingWindowStore.class, caching);
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStore.class, logging);
+ assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
}
@Test
- public void shouldCreateTimestampedBuilderWithCachingDisabled() {
+ public void shouldCreateHeadersBuilderWithCachingDisabled() {
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(
Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store").withCachingDisabled(), nameProvider, STORE_PREFIX
);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore logging = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStore.class, logging);
+ assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
}
@Test
- public void shouldCreateTimestampedBuilderWithLoggingDisabled() {
+ public void shouldCreateHeadersBuilderWithLoggingDisabled() {
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(
Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store").withLoggingDisabled(), nameProvider, STORE_PREFIX
);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore caching = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
assertInstanceOf(CachingWindowStore.class, caching);
- assertFalse(caching.wrapped() instanceof ChangeLoggingTimestampedWindowBytesStore);
+ assertFalse(caching.wrapped() instanceof ChangeLoggingTimestampedWindowBytesStoreWithHeaders);
}
@Test
- public void shouldCreateTimestampedBuilderWithCachingAndLoggingDisabled() {
+ public void shouldCreateHeadersBuilderWithCachingAndLoggingDisabled() {
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(
Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store").withCachingDisabled().withLoggingDisabled(), nameProvider, STORE_PREFIX
);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final StateStore wrapped = ((WrappedStateStore) store).wrapped();
assertFalse(wrapped instanceof CachingWindowStore);
- assertFalse(wrapped instanceof ChangeLoggingTimestampedWindowBytesStore);
+ assertFalse(wrapped instanceof ChangeLoggingTimestampedWindowBytesStoreWithHeaders);
}
@Test
- public void shouldCreateTimestampedStoreWithProvidedSupplierAndCachingAndLoggingEnabledByDefault() {
+ public void shouldCreateHeadersStoreWithProvidedSupplierAndCachingAndLoggingEnabledByDefault() {
mockWindowStoreSupplier();
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.as(windowStoreSupplier), nameProvider, STORE_PREFIX);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore caching = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
final StateStore logging = caching.wrapped();
assertEquals(innerWindowStore.name(), store.name());
- assertInstanceOf(MeteredTimestampedWindowStore.class, store);
+ assertInstanceOf(MeteredTimestampedWindowStoreWithHeaders.class, store);
assertInstanceOf(CachingWindowStore.class, caching);
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStore.class, logging);
+ assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
}
@Test
- public void shouldCreateTimestampedStoreWithProvidedSupplierAndCachingDisabled() {
+ public void shouldCreateHeadersStoreWithProvidedSupplierAndCachingDisabled() {
mockWindowStoreSupplier();
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.<String, String>as(windowStoreSupplier).withCachingDisabled(), nameProvider, STORE_PREFIX);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore logging = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
assertEquals(innerWindowStore.name(), store.name());
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStore.class, logging);
+ assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
}
@Test
- public void shouldCreateTimestampedStoreWithProvidedSupplierAndLoggingDisabled() {
+ public void shouldCreateHeadersStoreWithProvidedSupplierAndLoggingDisabled() {
mockWindowStoreSupplier();
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.<String, String>as(windowStoreSupplier).withLoggingDisabled(), nameProvider, STORE_PREFIX);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore caching = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
assertEquals(innerWindowStore.name(), store.name());
assertInstanceOf(CachingWindowStore.class, caching);
- assertFalse(caching.wrapped() instanceof ChangeLoggingTimestampedWindowBytesStore);
+ assertFalse(caching.wrapped() instanceof ChangeLoggingTimestampedWindowBytesStoreWithHeaders);
}
@Test
- public void shouldCreateTimestampedStoreWithProvidedSupplierAndCachingAndLoggingDisabled() {
+ public void shouldCreateHeadersStoreWithProvidedSupplierAndCachingAndLoggingDisabled() {
mockWindowStoreSupplier();
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.<String, String>as(windowStoreSupplier).withCachingDisabled().withLoggingDisabled(), nameProvider, STORE_PREFIX);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final StateStore wrapped = ((WrappedStateStore) store).wrapped();
assertEquals(innerWindowStore.name(), store.name());
assertFalse(wrapped instanceof CachingWindowStore);
- assertFalse(wrapped instanceof ChangeLoggingTimestampedWindowBytesStore);
- }
-
- @Test
- public void shouldCreateHeadersAwareStoreWithLoggingEnabledByDefault() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
- new MaterializedInternal<>(Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store")
- .withCachingDisabled(), nameProvider, STORE_PREFIX);
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
-
- final WrappedStateStore logging = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
- assertInstanceOf(MeteredTimestampedWindowStoreWithHeaders.class, store);
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
- }
-
- @Test
- public void shouldCreateHeadersAwareStoreWithLoggingDisabled() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(
- Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store").withLoggingDisabled(), nameProvider, STORE_PREFIX
- );
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
-
- final StateStore wrapped = ((WrappedStateStore) store).wrapped();
- assertFalse(wrapped instanceof ChangeLoggingTimestampedWindowBytesStore);
- }
-
- @Test
- public void shouldBuildHeadersAwareStoreWithCachingEnabledByDefault() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
- new MaterializedInternal<>(Materialized.as("store"), nameProvider, STORE_PREFIX);
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
-
- final StateStore wrapped = ((WrappedStateStore) store).wrapped();
- assertInstanceOf(CachingWindowStore.class, wrapped);
- }
-
- @Test
- public void shouldCreateHeadersAwareStoreWithProvidedSupplierAndLoggingEnabled() {
- mockWindowStoreSupplier();
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
- new MaterializedInternal<>(Materialized.<String, String>as(windowStoreSupplier).withCachingDisabled(), nameProvider, STORE_PREFIX);
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
-
- final WrappedStateStore logging = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
- assertEquals(innerWindowStore.name(), store.name());
- assertInstanceOf(MeteredTimestampedWindowStoreWithHeaders.class, store);
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
- }
-
- @Test
- public void shouldCreateHeadersAwareStoreWithCachingAndLoggingDisabled() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(
- Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store").withCachingDisabled().withLoggingDisabled(), nameProvider, STORE_PREFIX
- );
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
-
- final StateStore wrapped = ((WrappedStateStore) store).wrapped();
- assertFalse(wrapped instanceof CachingWindowStore);
assertFalse(wrapped instanceof ChangeLoggingTimestampedWindowBytesStoreWithHeaders);
}
@Test
- public void shouldCreateTimestampedStoreWithOnWindowClose() {
+ public void shouldCreateHeadersStoreWithOnWindowClose() {
emitStrategy = EmitStrategy.onWindowClose();
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store")
.withCachingDisabled(), nameProvider, STORE_PREFIX);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
-
- final WrappedStateStore logging = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
- assertInstanceOf(MeteredTimestampedWindowStore.class, store);
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStore.class, logging);
- }
-
- @Test
- public void shouldCreateTimestampedStoreWithOnWindowCloseAndCachingEnabled() {
- emitStrategy = EmitStrategy.onWindowClose();
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
- new MaterializedInternal<>(Materialized.as("store"), nameProvider, STORE_PREFIX);
-
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
-
- final StateStore wrapped = ((WrappedStateStore) store).wrapped();
- assertInstanceOf(TimeOrderedCachingWindowStore.class, wrapped);
- }
-
- @Test
- public void shouldCreateHeadersAwareStoreWithOnWindowClose() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
- emitStrategy = EmitStrategy.onWindowClose();
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
- new MaterializedInternal<>(Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store")
- .withCachingDisabled(), nameProvider, STORE_PREFIX);
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore logging = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
assertInstanceOf(MeteredTimestampedWindowStoreWithHeaders.class, store);
assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
}
@Test
- public void shouldCreateHeadersAwareStoreWithOnWindowCloseAndLoggingDisabled() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
- emitStrategy = EmitStrategy.onWindowClose();
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(
- Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store").withLoggingDisabled(), nameProvider, STORE_PREFIX
- );
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
-
- final StateStore wrapped = ((WrappedStateStore) store).wrapped();
- assertFalse(wrapped instanceof ChangeLoggingTimestampedWindowBytesStoreWithHeaders);
- }
-
- @Test
- public void shouldCreateHeadersAwareStoreWithOnWindowCloseAndCachingEnabled() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
+ public void shouldCreateHeadersStoreWithOnWindowCloseAndCachingEnabled() {
emitStrategy = EmitStrategy.onWindowClose();
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.as("store"), nameProvider, STORE_PREFIX);
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final StateStore wrapped = ((WrappedStateStore) store).wrapped();
- assertInstanceOf(TimeOrderedCachingWindowStore.class, wrapped);
Review Comment:
Btw: Thanks for highlighting this change -- I would have missed it most likely during review w/o your comment.
##########
streams/src/test/java/org/apache/kafka/test/GenericInMemoryTimestampedKeyValueStoreWithHeaders.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.test;
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.streams.KeyValue;
+import org.apache.kafka.streams.processor.StateStore;
+import org.apache.kafka.streams.processor.StateStoreContext;
+import org.apache.kafka.streams.state.KeyValueIterator;
+import org.apache.kafka.streams.state.TimestampedKeyValueStoreWithHeaders;
+import org.apache.kafka.streams.state.ValueTimestampHeaders;
+import org.apache.kafka.streams.state.internals.CacheFlushListener;
+import org.apache.kafka.streams.state.internals.DelegatingPeekingKeyValueIterator;
+import org.apache.kafka.streams.state.internals.WrappedStateStore;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.NavigableMap;
+import java.util.TreeMap;
+
+/**
+ * This class is a generic version of the in-memory key-value store that is useful for testing when you
+ * need a basic KeyValueStore for arbitrary types and don't have/want to write a serde
+ */
+@SuppressWarnings("deprecation")
+public class GenericInMemoryTimestampedKeyValueStoreWithHeaders<K extends Comparable, V>
+ extends WrappedStateStore<StateStore, K, ValueTimestampHeaders<V>>
+ implements TimestampedKeyValueStoreWithHeaders<K, V> {
+
+ private final String name;
+ private final NavigableMap<K, ValueTimestampHeaders<V>> map;
+ private volatile boolean open = false;
+
+ public GenericInMemoryTimestampedKeyValueStoreWithHeaders(final String name) {
+ // it's not really a `WrappedStateStore` so we pass `null`
+ // however, we need to implement `WrappedStateStore` to make the store usable
+ super(null);
+ this.name = name;
+
+ this.map = new TreeMap<>();
+ }
+
+ @Override
+ public String name() {
+ return this.name;
Review Comment:
nit: avoid unnecessary `this.` (similar below)
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/WindowStoreMaterializerTest.java:
##########
@@ -105,297 +101,146 @@ private void mockWindowStoreSupplier() {
}
@Test
- public void shouldCreateTimestampedBuilderWithCachingAndLoggingEnabledByDefault() {
+ public void shouldCreateHeadersBuilderWithCachingAndLoggingEnabledByDefault() {
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.as("store"), nameProvider, STORE_PREFIX);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore caching = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
final StateStore logging = caching.wrapped();
- assertInstanceOf(MeteredTimestampedWindowStore.class, store);
+ assertInstanceOf(MeteredTimestampedWindowStoreWithHeaders.class, store);
assertInstanceOf(CachingWindowStore.class, caching);
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStore.class, logging);
+ assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
}
@Test
- public void shouldCreateTimestampedBuilderWithCachingDisabled() {
+ public void shouldCreateHeadersBuilderWithCachingDisabled() {
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(
Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store").withCachingDisabled(), nameProvider, STORE_PREFIX
);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore logging = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStore.class, logging);
+ assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
}
@Test
- public void shouldCreateTimestampedBuilderWithLoggingDisabled() {
+ public void shouldCreateHeadersBuilderWithLoggingDisabled() {
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(
Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store").withLoggingDisabled(), nameProvider, STORE_PREFIX
);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore caching = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
assertInstanceOf(CachingWindowStore.class, caching);
- assertFalse(caching.wrapped() instanceof ChangeLoggingTimestampedWindowBytesStore);
+ assertFalse(caching.wrapped() instanceof ChangeLoggingTimestampedWindowBytesStoreWithHeaders);
}
@Test
- public void shouldCreateTimestampedBuilderWithCachingAndLoggingDisabled() {
+ public void shouldCreateHeadersBuilderWithCachingAndLoggingDisabled() {
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(
Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store").withCachingDisabled().withLoggingDisabled(), nameProvider, STORE_PREFIX
);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final StateStore wrapped = ((WrappedStateStore) store).wrapped();
assertFalse(wrapped instanceof CachingWindowStore);
- assertFalse(wrapped instanceof ChangeLoggingTimestampedWindowBytesStore);
+ assertFalse(wrapped instanceof ChangeLoggingTimestampedWindowBytesStoreWithHeaders);
}
@Test
- public void shouldCreateTimestampedStoreWithProvidedSupplierAndCachingAndLoggingEnabledByDefault() {
+ public void shouldCreateHeadersStoreWithProvidedSupplierAndCachingAndLoggingEnabledByDefault() {
mockWindowStoreSupplier();
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.as(windowStoreSupplier), nameProvider, STORE_PREFIX);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore caching = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
final StateStore logging = caching.wrapped();
assertEquals(innerWindowStore.name(), store.name());
- assertInstanceOf(MeteredTimestampedWindowStore.class, store);
+ assertInstanceOf(MeteredTimestampedWindowStoreWithHeaders.class, store);
assertInstanceOf(CachingWindowStore.class, caching);
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStore.class, logging);
+ assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
}
@Test
- public void shouldCreateTimestampedStoreWithProvidedSupplierAndCachingDisabled() {
+ public void shouldCreateHeadersStoreWithProvidedSupplierAndCachingDisabled() {
mockWindowStoreSupplier();
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.<String, String>as(windowStoreSupplier).withCachingDisabled(), nameProvider, STORE_PREFIX);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore logging = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
assertEquals(innerWindowStore.name(), store.name());
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStore.class, logging);
+ assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
}
@Test
- public void shouldCreateTimestampedStoreWithProvidedSupplierAndLoggingDisabled() {
+ public void shouldCreateHeadersStoreWithProvidedSupplierAndLoggingDisabled() {
mockWindowStoreSupplier();
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.<String, String>as(windowStoreSupplier).withLoggingDisabled(), nameProvider, STORE_PREFIX);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore caching = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
assertEquals(innerWindowStore.name(), store.name());
assertInstanceOf(CachingWindowStore.class, caching);
- assertFalse(caching.wrapped() instanceof ChangeLoggingTimestampedWindowBytesStore);
+ assertFalse(caching.wrapped() instanceof ChangeLoggingTimestampedWindowBytesStoreWithHeaders);
}
@Test
- public void shouldCreateTimestampedStoreWithProvidedSupplierAndCachingAndLoggingDisabled() {
+ public void shouldCreateHeadersStoreWithProvidedSupplierAndCachingAndLoggingDisabled() {
mockWindowStoreSupplier();
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.<String, String>as(windowStoreSupplier).withCachingDisabled().withLoggingDisabled(), nameProvider, STORE_PREFIX);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final StateStore wrapped = ((WrappedStateStore) store).wrapped();
assertEquals(innerWindowStore.name(), store.name());
assertFalse(wrapped instanceof CachingWindowStore);
- assertFalse(wrapped instanceof ChangeLoggingTimestampedWindowBytesStore);
- }
-
- @Test
- public void shouldCreateHeadersAwareStoreWithLoggingEnabledByDefault() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
- new MaterializedInternal<>(Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store")
- .withCachingDisabled(), nameProvider, STORE_PREFIX);
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
-
- final WrappedStateStore logging = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
- assertInstanceOf(MeteredTimestampedWindowStoreWithHeaders.class, store);
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
- }
-
- @Test
- public void shouldCreateHeadersAwareStoreWithLoggingDisabled() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(
- Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store").withLoggingDisabled(), nameProvider, STORE_PREFIX
- );
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
-
- final StateStore wrapped = ((WrappedStateStore) store).wrapped();
- assertFalse(wrapped instanceof ChangeLoggingTimestampedWindowBytesStore);
- }
-
- @Test
- public void shouldBuildHeadersAwareStoreWithCachingEnabledByDefault() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
- new MaterializedInternal<>(Materialized.as("store"), nameProvider, STORE_PREFIX);
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
-
- final StateStore wrapped = ((WrappedStateStore) store).wrapped();
- assertInstanceOf(CachingWindowStore.class, wrapped);
- }
-
- @Test
- public void shouldCreateHeadersAwareStoreWithProvidedSupplierAndLoggingEnabled() {
- mockWindowStoreSupplier();
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
- new MaterializedInternal<>(Materialized.<String, String>as(windowStoreSupplier).withCachingDisabled(), nameProvider, STORE_PREFIX);
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
-
- final WrappedStateStore logging = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
- assertEquals(innerWindowStore.name(), store.name());
- assertInstanceOf(MeteredTimestampedWindowStoreWithHeaders.class, store);
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
- }
-
- @Test
- public void shouldCreateHeadersAwareStoreWithCachingAndLoggingDisabled() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(
- Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store").withCachingDisabled().withLoggingDisabled(), nameProvider, STORE_PREFIX
- );
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
-
- final StateStore wrapped = ((WrappedStateStore) store).wrapped();
- assertFalse(wrapped instanceof CachingWindowStore);
assertFalse(wrapped instanceof ChangeLoggingTimestampedWindowBytesStoreWithHeaders);
}
@Test
- public void shouldCreateTimestampedStoreWithOnWindowClose() {
+ public void shouldCreateHeadersStoreWithOnWindowClose() {
emitStrategy = EmitStrategy.onWindowClose();
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store")
.withCachingDisabled(), nameProvider, STORE_PREFIX);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
-
- final WrappedStateStore logging = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
- assertInstanceOf(MeteredTimestampedWindowStore.class, store);
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStore.class, logging);
- }
-
- @Test
- public void shouldCreateTimestampedStoreWithOnWindowCloseAndCachingEnabled() {
- emitStrategy = EmitStrategy.onWindowClose();
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
- new MaterializedInternal<>(Materialized.as("store"), nameProvider, STORE_PREFIX);
-
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
-
- final StateStore wrapped = ((WrappedStateStore) store).wrapped();
- assertInstanceOf(TimeOrderedCachingWindowStore.class, wrapped);
- }
-
- @Test
- public void shouldCreateHeadersAwareStoreWithOnWindowClose() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
- emitStrategy = EmitStrategy.onWindowClose();
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
- new MaterializedInternal<>(Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store")
- .withCachingDisabled(), nameProvider, STORE_PREFIX);
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore logging = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
assertInstanceOf(MeteredTimestampedWindowStoreWithHeaders.class, store);
assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
}
@Test
- public void shouldCreateHeadersAwareStoreWithOnWindowCloseAndLoggingDisabled() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
- emitStrategy = EmitStrategy.onWindowClose();
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(
- Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store").withLoggingDisabled(), nameProvider, STORE_PREFIX
- );
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
-
- final StateStore wrapped = ((WrappedStateStore) store).wrapped();
- assertFalse(wrapped instanceof ChangeLoggingTimestampedWindowBytesStoreWithHeaders);
- }
-
- @Test
- public void shouldCreateHeadersAwareStoreWithOnWindowCloseAndCachingEnabled() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
+ public void shouldCreateHeadersStoreWithOnWindowCloseAndCachingEnabled() {
emitStrategy = EmitStrategy.onWindowClose();
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.as("store"), nameProvider, STORE_PREFIX);
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final StateStore wrapped = ((WrappedStateStore) store).wrapped();
- assertInstanceOf(TimeOrderedCachingWindowStore.class, wrapped);
Review Comment:
Seems this is still an open question? Let's me sure we don't drop it... \cc @frankvicky @bbejeck
Sound related to the fix that Frank is working on? So I assume we can merge this PR (including this change), and this test starts failing with Frank's fix and we need to update the test on the fix-PR?
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KTableTransformValues.java:
##########
@@ -192,9 +192,11 @@ private ValueAndTimestamp<VOut> transformValue(final K key, final ValueAndTimest
new RecordHeaders()
));
- final ValueAndTimestamp<VOut> result = ValueAndTimestamp.make(
- valueTransformer.transform(key, getValueOrNull(valueAndTimestamp)),
- valueAndTimestamp == null ? UNKNOWN : valueAndTimestamp.timestamp());
+ final ValueTimestampHeaders<VOut> result = ValueTimestampHeaders.make(
+ valueTransformer.transform(key, getValueOrNull(valueTimestampHeaders)),
+ valueTimestampHeaders == null ? UNKNOWN : valueTimestampHeaders.timestamp(),
+ valueTimestampHeaders == null ? null : valueTimestampHeaders.headers()
Review Comment:
Sound good -- wondering if we should use `context.headers()` instead of `null` if `valueTimestampHeaders == null` ? Similar question as for `KTable#mapValues`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2887434124
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KStreamWindowAggregate.java:
##########
@@ -143,13 +143,13 @@ public void process(final Record<KIn, VIn> record) {
oldAgg = initializer.apply();
newTimestamp = record.timestamp();
} else {
- newTimestamp = Math.max(record.timestamp(), oldAggAndTimestamp.timestamp());
+ newTimestamp = Math.max(record.timestamp(), oldAggTimestampHeaders.timestamp());
}
newAgg = aggregator.apply(record.key(), record.value(), oldAgg);
// update the store with the new value
- windowStore.put(record.key(), ValueAndTimestamp.make(newAgg, newTimestamp), windowStart);
+ windowStore.put(record.key(), ValueTimestampHeaders.make(newAgg, newTimestamp, record.headers()), windowStart);
Review Comment:
`new RecordHeaders()` ?
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KTableAggregate.java:
##########
@@ -133,7 +133,7 @@ public void process(final Record<KIn, Change<VIn>> record) {
}
// update the store with the new value
- final long putReturnCode = store.put(record.key(), newAgg, newTimestamp);
+ final long putReturnCode = store.put(record.key(), newAgg, newTimestamp, record.headers());
Review Comment:
`new RecordHeaders()` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2887434921
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KTableFilter.java:
##########
@@ -147,7 +147,7 @@ public void process(final Record<KIn, Change<VIn>> record) {
}
if (queryableName != null) {
- final long putReturnCode = store.put(key, newValue, record.timestamp());
+ final long putReturnCode = store.put(key, newValue, record.timestamp(), record.headers());
Review Comment:
`new RecordHeaders()` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2887480432
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/PlainToHeadersWindowStoreAdapter.java:
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.TopicPartition;
+import org.apache.kafka.common.utils.ByteUtils;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.processor.StateStore;
+import org.apache.kafka.streams.processor.StateStoreContext;
+import org.apache.kafka.streams.query.Position;
+import org.apache.kafka.streams.query.PositionBound;
+import org.apache.kafka.streams.query.Query;
+import org.apache.kafka.streams.query.QueryConfig;
+import org.apache.kafka.streams.query.QueryResult;
+import org.apache.kafka.streams.state.KeyValueIterator;
+import org.apache.kafka.streams.state.TimestampedWindowStoreWithHeaders;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.streams.state.WindowStoreIterator;
+
+import java.nio.ByteBuffer;
+import java.time.Instant;
+import java.util.Map;
+
+import static org.apache.kafka.streams.state.HeadersBytesStore.convertFromPlainToHeaderFormat;
+
+/**
+ * Adapter for backward compatibility between {@link TimestampedWindowStoreWithHeaders}
+ * and {@link WindowStore}.
+ * <p>
+ * If a user provides a supplier for {@code WindowStore} (without timestamp and headers) when building
+ * a {@code TimestampedWindowStoreWithHeaders}, this adapter translates between the plain
+ * {@code byte[]} format and the timestamped-with-headers {@code byte[]} format.
+ * <p>
+ * Format conversion:
+ * <ul>
+ * <li>Write: {@code [headers][timestamp][value]} → {@code [value]} (strip timestamp and headers)</li>
+ * <li>Read: {@code [value]} → {@code [headers][timestamp][value]} (add -1 as timestamp and empty headers)</li>
+ * </ul>
+ */
+public class PlainToHeadersWindowStoreAdapter implements WindowStore<Bytes, byte[]> {
Review Comment:
Alieh, can you clarify? I thought, we would need to add upgrading from plain-kv to header-kv store only? But not for window-store case?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2887463579
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/InMemoryTimeOrderedKeyValueChangeBuffer.java:
##########
@@ -447,7 +447,7 @@ public Maybe<ValueAndTimestamp<V>> priorValueForBuffered(final K key) {
// it's unfortunately not possible to know this, unless we materialize the suppressed result, since our only
// knowledge of the prior value is what the upstream processor sends us as the "old value" when we first
// buffer something.
- return Maybe.defined(ValueAndTimestamp.make(deserializedValue, RecordQueue.UNKNOWN));
+ return Maybe.defined(ValueTimestampHeaders.make(deserializedValue, RecordQueue.UNKNOWN, new RecordHeaders()));
Review Comment:
In other places we pass `null` as header as default (what is fine, because it's getting replace with `new RecordHeaders()` inside `ValueTimestampHeaders` constructor). But I think we should be consistent, so maybe pass in `null` here too?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "zheguang (via GitHub)" <gi...@apache.org>.
zheguang commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2886077267
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -45,70 +53,80 @@ public class KeyValueStoreWrapper<K, V> implements StateStore {
public static final long PUT_RETURN_CODE_IS_LATEST
= VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED;
- private TimestampedKeyValueStore<K, V> timestampedStore = null;
+ private TimestampedKeyValueStoreWithHeaders<K, V> headersStore = null;
private VersionedKeyValueStore<K, V> versionedStore = null;
Review Comment:
Looks like `VersionedKeyValueStoreWithHeaders` is not yet implemented/added. Do we want to have a JIRA issue to keep track?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2887431893
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KStreamSlidingWindowAggregate.java:
##########
@@ -386,14 +387,14 @@ private void createWindows(final Record<KIn, VIn> record,
// create left window for new record
if (!leftWinAlreadyCreated) {
- final ValueAndTimestamp<VAgg> valueAndTime;
+ final ValueTimestampHeaders<VAgg> valueTimestampHeaders;
if (leftWindowNotEmpty(previousRecordTimestamp, record.timestamp())) {
- valueAndTime = ValueAndTimestamp.make(leftWinAgg.value(), record.timestamp());
+ valueTimestampHeaders = ValueTimestampHeaders.make(leftWinAgg.value(), record.timestamp(), record.headers());
} else {
- valueAndTime = ValueAndTimestamp.make(initializer.apply(), record.timestamp());
+ valueTimestampHeaders = ValueTimestampHeaders.make(initializer.apply(), record.timestamp(), record.headers());
Review Comment:
`new RecordHeaders()` ?
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KStreamSlidingWindowAggregate.java:
##########
@@ -417,8 +418,8 @@ private void createPreviousRecordRightWindow(final long windowStart,
final Record<KIn, VIn> record,
final long closeTime) {
final TimeWindow window = new TimeWindow(windowStart, windowStart + windows.timeDifferenceMs());
- final ValueAndTimestamp<VAgg> valueAndTime = ValueAndTimestamp.make(initializer.apply(), record.timestamp());
- updateWindowAndForward(window, valueAndTime, record, closeTime);
+ final ValueTimestampHeaders<VAgg> valueTimestampHeaders = ValueTimestampHeaders.make(initializer.apply(), record.timestamp(), record.headers());
Review Comment:
`new RecordHeaders()` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20194: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2922690557
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KTableTransformValues.java:
##########
@@ -192,9 +192,11 @@ private ValueAndTimestamp<VOut> transformValue(final K key, final ValueAndTimest
new RecordHeaders()
));
- final ValueAndTimestamp<VOut> result = ValueAndTimestamp.make(
- valueTransformer.transform(key, getValueOrNull(valueAndTimestamp)),
- valueAndTimestamp == null ? UNKNOWN : valueAndTimestamp.timestamp());
+ final ValueTimestampHeaders<VOut> result = ValueTimestampHeaders.make(
+ valueTransformer.transform(key, getValueOrNull(valueTimestampHeaders)),
+ valueTimestampHeaders == null ? UNKNOWN : valueTimestampHeaders.timestamp(),
+ valueTimestampHeaders == null ? null : valueTimestampHeaders.headers()
Review Comment:
similar question as for `KTable#mapValues` -- do we pass `headers()` or `new RecordHeaders()` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20194: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2922705439
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/ProcessorContextImpl.java:
##########
@@ -181,7 +181,8 @@ public <S extends StateStore> S getStateStore(final String name) {
}
final StateStore store = stateManager.store(name);
- return (S) wrapWithReadWriteStore(store);
+ final StateStore wrappedStore = wrapWithReadWriteStore(store);
+ return (S) wrappedStore;
Review Comment:
Why do we need this change and introduce `wrappedStore` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20194: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "aliehsaeedii (via GitHub)" <gi...@apache.org>.
aliehsaeedii commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2942992944
##########
streams/src/test/java/org/apache/kafka/streams/StreamsBuilderTest.java:
##########
@@ -1222,7 +1222,7 @@ public void shouldUseSpecifiedStoreSupplierForEachOuterJoinOperationBetweenKStre
final ProcessorTopology topology = builder.internalTopologyBuilder.rewriteTopology(new StreamsConfig(props)).buildTopology();
assertTypesForStateStore(topology.stateStores(),
InMemoryWindowStore.class,
- RocksDBWindowStore.class,
+ PlainToHeadersWindowStoreAdapter.class,
Review Comment:
We can either fix the test or change the implementation of PlainToHeadersWindowStoreAdapter
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20263: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2963398380
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -45,70 +49,72 @@ public class KeyValueStoreWrapper<K, V> implements StateStore {
public static final long PUT_RETURN_CODE_IS_LATEST
= VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED;
- private TimestampedKeyValueStore<K, V> timestampedStore = null;
+ private TimestampedKeyValueStoreWithHeaders<K, V> headersStore = null;
private VersionedKeyValueStore<K, V> versionedStore = null;
// same as either timestampedStore or versionedStore above. kept merely as a convenience
// to simplify implementation for methods which do not depend on store type.
private StateStore store;
+ @SuppressWarnings("unchecked")
public KeyValueStoreWrapper(final ProcessorContext<?, ?> context, final String storeName) {
+ final StateStore rawStore = context.getStateStore(storeName);
Review Comment:
Addressed via https://github.com/apache/kafka/pull/21792
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20263: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2963403653
##########
streams/src/test/java/org/apache/kafka/streams/KeyValueTimestampHeaders.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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;
+
+import org.apache.kafka.common.header.Headers;
+
+import java.util.Objects;
+
+/**
+ * A key-value pair with timestamp and headers, used for testing KTable with headers support.
+ */
+public class KeyValueTimestampHeaders<K, V> {
Review Comment:
Addresse via https://github.com/apache/kafka/pull/21792
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2887433056
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KStreamSlidingWindowAggregate.java:
##########
@@ -457,21 +458,22 @@ protected boolean shouldRangeFetch(final long emitRangeLowerBound, final long em
}
private void updateWindowAndForward(final Window window,
- final ValueAndTimestamp<VAgg> valueAndTime,
+ final ValueTimestampHeaders<VAgg> valueTimestampHeaders,
final Record<KIn, VIn> record,
final long windowCloseTime) {
final long windowStart = window.start();
final long windowEnd = window.end();
if (windowEnd >= windowCloseTime) {
// get aggregate from existing window
- final VAgg oldAgg = getValueOrNull(valueAndTime);
+ final VAgg oldAgg = getValueOrNull(valueTimestampHeaders);
final VAgg newAgg = aggregator.apply(record.key(), record.value(), oldAgg);
- final long newTimestamp = oldAgg == null ? record.timestamp() : Math.max(record.timestamp(), valueAndTime.timestamp());
+ final long newTimestamp = oldAgg == null ? record.timestamp() : Math.max(record.timestamp(), valueTimestampHeaders.timestamp());
+ final Headers headers = oldAgg == null ? record.headers() : valueTimestampHeaders.headers();
windowStore.put(
record.key(),
- ValueAndTimestamp.make(newAgg, newTimestamp),
+ ValueTimestampHeaders.make(newAgg, newTimestamp, headers),
Review Comment:
`new RecordHeaders()` ?
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KStreamSlidingWindowAggregate.java:
##########
@@ -457,21 +458,22 @@ protected boolean shouldRangeFetch(final long emitRangeLowerBound, final long em
}
private void updateWindowAndForward(final Window window,
- final ValueAndTimestamp<VAgg> valueAndTime,
+ final ValueTimestampHeaders<VAgg> valueTimestampHeaders,
final Record<KIn, VIn> record,
final long windowCloseTime) {
final long windowStart = window.start();
final long windowEnd = window.end();
if (windowEnd >= windowCloseTime) {
// get aggregate from existing window
- final VAgg oldAgg = getValueOrNull(valueAndTime);
+ final VAgg oldAgg = getValueOrNull(valueTimestampHeaders);
final VAgg newAgg = aggregator.apply(record.key(), record.value(), oldAgg);
- final long newTimestamp = oldAgg == null ? record.timestamp() : Math.max(record.timestamp(), valueAndTime.timestamp());
+ final long newTimestamp = oldAgg == null ? record.timestamp() : Math.max(record.timestamp(), valueTimestampHeaders.timestamp());
+ final Headers headers = oldAgg == null ? record.headers() : valueTimestampHeaders.headers();
Review Comment:
I think we don't need this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2887428602
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KStreamAggregate.java:
##########
@@ -134,7 +134,7 @@ public void process(final Record<KIn, VIn> record) {
newAgg = aggregator.apply(record.key(), record.value(), oldAgg);
- final long putReturnCode = store.put(record.key(), newAgg, newTimestamp);
+ final long putReturnCode = store.put(record.key(), newAgg, newTimestamp, record.headers());
Review Comment:
I thought, for now, we wanted to use `new RecordHeaders()` when writing into the store?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2887483817
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/TimestampedWindowStoreWithHeadersBuilder.java:
##########
@@ -72,7 +72,11 @@ public TimestampedWindowStoreWithHeaders<K, V> build() {
if (!(store instanceof HeadersBytesStore)) {
if (store.persistent()) {
- store = new TimestampedToHeadersWindowStoreAdapter(store);
+ if (store instanceof TimestampedBytesStore) {
+ store = new TimestampedToHeadersWindowStoreAdapter(store);
+ } else {
+ store = new PlainToHeadersWindowStoreAdapter(store);
Review Comment:
Same question: do we actually need this for the window-store case? I though we only need it for kv-store case?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2887493506
##########
streams/src/main/java/org/apache/kafka/streams/state/BuiltInDslStoreSuppliers.java:
##########
@@ -63,7 +63,7 @@ public WindowBytesStoreSupplier windowStore(final DslWindowParams params) {
}
if (params.isTimestamped()) {
- return Stores.persistentTimestampedWindowStore(
+ return Stores.persistentTimestampedWindowStoreWithHeaders(
Review Comment:
Why is it correct to return a headers-supplier if `params` request a timestamped one? Don't we need to have a `switch(...)` here, similar to `keyValueStore` from above?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20194: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "aliehsaeedii (via GitHub)" <gi...@apache.org>.
aliehsaeedii commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2921520361
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -45,70 +48,81 @@ public class KeyValueStoreWrapper<K, V> implements StateStore {
public static final long PUT_RETURN_CODE_IS_LATEST
= VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED;
- private TimestampedKeyValueStore<K, V> timestampedStore = null;
+ private TimestampedKeyValueStoreWithHeaders<K, V> headersStore = null;
private VersionedKeyValueStore<K, V> versionedStore = null;
- // same as either timestampedStore or versionedStore above. kept merely as a convenience
- // to simplify implementation for methods which do not depend on store type.
private StateStore store;
+ @SuppressWarnings("unchecked")
public KeyValueStoreWrapper(final ProcessorContext<?, ?> context, final String storeName) {
+ final StateStore rawStore = context.getStateStore(storeName);
+
+ // Check if it's an OLD TimestampedKeyValueStore that needs adaptation
+ if (rawStore instanceof TimestampedKeyValueStore &&
+ !(rawStore instanceof TimestampedKeyValueStoreWithHeaders)) {
+ // Adapt OLD store to NEW type for backward compatibility
+ headersStore = new TimestampedKeyValueStoreToHeadersAdapter<>(
Review Comment:
The adapter is needed here for 100% backward compatibility. If the user specifies the store by `builder.addStateStore(OLD builder)`, the app breaks.
##########
streams/integration-tests/src/test/java/org/apache/kafka/streams/integration/HeadersStoreUpgradeIntegrationTest.java:
##########
@@ -567,7 +571,7 @@ private <K, V> void verifyLegacyValuesWithEmptyHeaders(final K key,
() -> {
try {
final ReadOnlyKeyValueStore<K, ValueTimestampHeaders<V>> store = IntegrationTestUtils
- .getStore(STORE_NAME, kafkaStreams, QueryableStoreTypes.keyValueStore());
Review Comment:
Because of the `Readonly*Facade` classes, the `QueryableStoreTypes.keyValueStore()` does not work here any more. Those `Facade`s convert the `ValueTimestampHeaders` to plain value and the test fails.
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/WindowStoreMaterializer.java:
##########
@@ -58,29 +59,22 @@ public WindowStoreMaterializer(
public StoreBuilder<?> builder() {
final DslStoreFormat storeFormat = dslStoreFormat() == null ? DslStoreFormat.TIMESTAMPED : dslStoreFormat();
final WindowBytesStoreSupplier supplier = materialized.storeSupplier() == null
- ? dslStoreSuppliers().windowStore(new DslWindowParams(
- materialized.storeName(),
- Duration.ofMillis(retentionPeriod),
- Duration.ofMillis(windows.size()),
- false,
- emitStrategy,
- false,
- storeFormat
- ))
- : (WindowBytesStoreSupplier) materialized.storeSupplier();
-
- final StoreBuilder<?> builder;
- if (storeFormat == DslStoreFormat.HEADERS) {
- builder = Stores.timestampedWindowStoreWithHeadersBuilder(
- supplier,
- materialized.keySerde(),
- materialized.valueSerde());
- } else {
- builder = Stores.timestampedWindowStoreBuilder(
- supplier,
- materialized.keySerde(),
- materialized.valueSerde());
- }
Review Comment:
I think we keep the supplier as-is, but the builder must always be the new one!
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -45,70 +53,80 @@ public class KeyValueStoreWrapper<K, V> implements StateStore {
public static final long PUT_RETURN_CODE_IS_LATEST
= VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED;
- private TimestampedKeyValueStore<K, V> timestampedStore = null;
+ private TimestampedKeyValueStoreWithHeaders<K, V> headersStore = null;
private VersionedKeyValueStore<K, V> versionedStore = null;
Review Comment:
Yes the headers versioned store is not implemented yet. Will be added later.
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KTableMapValues.java:
##########
@@ -109,16 +110,18 @@ private VOut computeValue(final KIn key, final VIn value) {
return newValue;
}
- private ValueAndTimestamp<VOut> computeValueAndTimestamp(final KIn key, final ValueAndTimestamp<VIn> valueAndTimestamp) {
+ private ValueTimestampHeaders<VOut> computeValueAndTimestamp(final KIn key, final ValueTimestampHeaders<VIn> valueTimestampHeaders) {
VOut newValue = null;
long timestamp = 0;
+ Headers headers = null;
- if (valueAndTimestamp != null) {
- newValue = mapper.apply(key, valueAndTimestamp.value());
- timestamp = valueAndTimestamp.timestamp();
+ if (valueTimestampHeaders != null) {
+ newValue = mapper.apply(key, valueTimestampHeaders.value());
+ timestamp = valueTimestampHeaders.timestamp();
+ headers = valueTimestampHeaders.headers();
}
- return ValueAndTimestamp.make(newValue, timestamp);
+ return ValueTimestampHeaders.make(newValue, timestamp, headers);
Review Comment:
I kept it, but should we be consistent?
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KStreamAggregate.java:
##########
@@ -94,7 +94,7 @@ public void init(final ProcessorContext<KIn, Change<VAgg>> context) {
tupleForwarder = new TimestampedTupleForwarder<>(
store.store(),
context,
- new TimestampedCacheFlushListener<>(context),
+ new TimestampedCacheFlushListenerWithHeaders<>(context),
Review Comment:
I deleted the class.
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/WindowStoreMaterializerTest.java:
##########
@@ -105,297 +101,146 @@ private void mockWindowStoreSupplier() {
}
@Test
- public void shouldCreateTimestampedBuilderWithCachingAndLoggingEnabledByDefault() {
+ public void shouldCreateHeadersBuilderWithCachingAndLoggingEnabledByDefault() {
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.as("store"), nameProvider, STORE_PREFIX);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore caching = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
final StateStore logging = caching.wrapped();
- assertInstanceOf(MeteredTimestampedWindowStore.class, store);
+ assertInstanceOf(MeteredTimestampedWindowStoreWithHeaders.class, store);
assertInstanceOf(CachingWindowStore.class, caching);
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStore.class, logging);
+ assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
}
@Test
- public void shouldCreateTimestampedBuilderWithCachingDisabled() {
+ public void shouldCreateHeadersBuilderWithCachingDisabled() {
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(
Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store").withCachingDisabled(), nameProvider, STORE_PREFIX
);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore logging = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStore.class, logging);
+ assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
}
@Test
- public void shouldCreateTimestampedBuilderWithLoggingDisabled() {
+ public void shouldCreateHeadersBuilderWithLoggingDisabled() {
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(
Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store").withLoggingDisabled(), nameProvider, STORE_PREFIX
);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore caching = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
assertInstanceOf(CachingWindowStore.class, caching);
- assertFalse(caching.wrapped() instanceof ChangeLoggingTimestampedWindowBytesStore);
+ assertFalse(caching.wrapped() instanceof ChangeLoggingTimestampedWindowBytesStoreWithHeaders);
}
@Test
- public void shouldCreateTimestampedBuilderWithCachingAndLoggingDisabled() {
+ public void shouldCreateHeadersBuilderWithCachingAndLoggingDisabled() {
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(
Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store").withCachingDisabled().withLoggingDisabled(), nameProvider, STORE_PREFIX
);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final StateStore wrapped = ((WrappedStateStore) store).wrapped();
assertFalse(wrapped instanceof CachingWindowStore);
- assertFalse(wrapped instanceof ChangeLoggingTimestampedWindowBytesStore);
+ assertFalse(wrapped instanceof ChangeLoggingTimestampedWindowBytesStoreWithHeaders);
}
@Test
- public void shouldCreateTimestampedStoreWithProvidedSupplierAndCachingAndLoggingEnabledByDefault() {
+ public void shouldCreateHeadersStoreWithProvidedSupplierAndCachingAndLoggingEnabledByDefault() {
mockWindowStoreSupplier();
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.as(windowStoreSupplier), nameProvider, STORE_PREFIX);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore caching = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
final StateStore logging = caching.wrapped();
assertEquals(innerWindowStore.name(), store.name());
- assertInstanceOf(MeteredTimestampedWindowStore.class, store);
+ assertInstanceOf(MeteredTimestampedWindowStoreWithHeaders.class, store);
assertInstanceOf(CachingWindowStore.class, caching);
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStore.class, logging);
+ assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
}
@Test
- public void shouldCreateTimestampedStoreWithProvidedSupplierAndCachingDisabled() {
+ public void shouldCreateHeadersStoreWithProvidedSupplierAndCachingDisabled() {
mockWindowStoreSupplier();
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.<String, String>as(windowStoreSupplier).withCachingDisabled(), nameProvider, STORE_PREFIX);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore logging = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
assertEquals(innerWindowStore.name(), store.name());
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStore.class, logging);
+ assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
}
@Test
- public void shouldCreateTimestampedStoreWithProvidedSupplierAndLoggingDisabled() {
+ public void shouldCreateHeadersStoreWithProvidedSupplierAndLoggingDisabled() {
mockWindowStoreSupplier();
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.<String, String>as(windowStoreSupplier).withLoggingDisabled(), nameProvider, STORE_PREFIX);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore caching = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
assertEquals(innerWindowStore.name(), store.name());
assertInstanceOf(CachingWindowStore.class, caching);
- assertFalse(caching.wrapped() instanceof ChangeLoggingTimestampedWindowBytesStore);
+ assertFalse(caching.wrapped() instanceof ChangeLoggingTimestampedWindowBytesStoreWithHeaders);
}
@Test
- public void shouldCreateTimestampedStoreWithProvidedSupplierAndCachingAndLoggingDisabled() {
+ public void shouldCreateHeadersStoreWithProvidedSupplierAndCachingAndLoggingDisabled() {
mockWindowStoreSupplier();
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.<String, String>as(windowStoreSupplier).withCachingDisabled().withLoggingDisabled(), nameProvider, STORE_PREFIX);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final StateStore wrapped = ((WrappedStateStore) store).wrapped();
assertEquals(innerWindowStore.name(), store.name());
assertFalse(wrapped instanceof CachingWindowStore);
- assertFalse(wrapped instanceof ChangeLoggingTimestampedWindowBytesStore);
- }
-
- @Test
- public void shouldCreateHeadersAwareStoreWithLoggingEnabledByDefault() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
- new MaterializedInternal<>(Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store")
- .withCachingDisabled(), nameProvider, STORE_PREFIX);
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
-
- final WrappedStateStore logging = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
- assertInstanceOf(MeteredTimestampedWindowStoreWithHeaders.class, store);
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
- }
-
- @Test
- public void shouldCreateHeadersAwareStoreWithLoggingDisabled() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(
- Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store").withLoggingDisabled(), nameProvider, STORE_PREFIX
- );
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
-
- final StateStore wrapped = ((WrappedStateStore) store).wrapped();
- assertFalse(wrapped instanceof ChangeLoggingTimestampedWindowBytesStore);
- }
-
- @Test
- public void shouldBuildHeadersAwareStoreWithCachingEnabledByDefault() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
- new MaterializedInternal<>(Materialized.as("store"), nameProvider, STORE_PREFIX);
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
-
- final StateStore wrapped = ((WrappedStateStore) store).wrapped();
- assertInstanceOf(CachingWindowStore.class, wrapped);
- }
-
- @Test
- public void shouldCreateHeadersAwareStoreWithProvidedSupplierAndLoggingEnabled() {
- mockWindowStoreSupplier();
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
- new MaterializedInternal<>(Materialized.<String, String>as(windowStoreSupplier).withCachingDisabled(), nameProvider, STORE_PREFIX);
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
-
- final WrappedStateStore logging = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
- assertEquals(innerWindowStore.name(), store.name());
- assertInstanceOf(MeteredTimestampedWindowStoreWithHeaders.class, store);
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
- }
-
- @Test
- public void shouldCreateHeadersAwareStoreWithCachingAndLoggingDisabled() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(
- Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store").withCachingDisabled().withLoggingDisabled(), nameProvider, STORE_PREFIX
- );
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
-
- final StateStore wrapped = ((WrappedStateStore) store).wrapped();
- assertFalse(wrapped instanceof CachingWindowStore);
assertFalse(wrapped instanceof ChangeLoggingTimestampedWindowBytesStoreWithHeaders);
}
@Test
- public void shouldCreateTimestampedStoreWithOnWindowClose() {
+ public void shouldCreateHeadersStoreWithOnWindowClose() {
emitStrategy = EmitStrategy.onWindowClose();
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store")
.withCachingDisabled(), nameProvider, STORE_PREFIX);
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
-
- final WrappedStateStore logging = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
- assertInstanceOf(MeteredTimestampedWindowStore.class, store);
- assertInstanceOf(ChangeLoggingTimestampedWindowBytesStore.class, logging);
- }
-
- @Test
- public void shouldCreateTimestampedStoreWithOnWindowCloseAndCachingEnabled() {
- emitStrategy = EmitStrategy.onWindowClose();
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
- new MaterializedInternal<>(Materialized.as("store"), nameProvider, STORE_PREFIX);
-
- final TimestampedWindowStore<String, String> store = getTimestampedStore(materialized);
-
- final StateStore wrapped = ((WrappedStateStore) store).wrapped();
- assertInstanceOf(TimeOrderedCachingWindowStore.class, wrapped);
- }
-
- @Test
- public void shouldCreateHeadersAwareStoreWithOnWindowClose() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
- emitStrategy = EmitStrategy.onWindowClose();
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
- new MaterializedInternal<>(Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store")
- .withCachingDisabled(), nameProvider, STORE_PREFIX);
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final WrappedStateStore logging = (WrappedStateStore) ((WrappedStateStore) store).wrapped();
assertInstanceOf(MeteredTimestampedWindowStoreWithHeaders.class, store);
assertInstanceOf(ChangeLoggingTimestampedWindowBytesStoreWithHeaders.class, logging);
}
@Test
- public void shouldCreateHeadersAwareStoreWithOnWindowCloseAndLoggingDisabled() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
- emitStrategy = EmitStrategy.onWindowClose();
-
- final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(
- Materialized.<String, String, WindowStore<Bytes, byte[]>>as("store").withLoggingDisabled(), nameProvider, STORE_PREFIX
- );
-
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
-
- final StateStore wrapped = ((WrappedStateStore) store).wrapped();
- assertFalse(wrapped instanceof ChangeLoggingTimestampedWindowBytesStoreWithHeaders);
- }
-
- @Test
- public void shouldCreateHeadersAwareStoreWithOnWindowCloseAndCachingEnabled() {
- doReturn("headers")
- .when(streamsConfig).getString(StreamsConfig.DSL_STORE_FORMAT_CONFIG);
+ public void shouldCreateHeadersStoreWithOnWindowCloseAndCachingEnabled() {
emitStrategy = EmitStrategy.onWindowClose();
final MaterializedInternal<String, String, WindowStore<Bytes, byte[]>> materialized =
new MaterializedInternal<>(Materialized.as("store"), nameProvider, STORE_PREFIX);
- final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersAwareStore(materialized);
+ final TimestampedWindowStoreWithHeaders<String, String> store = getHeadersStore(materialized);
final StateStore wrapped = ((WrappedStateStore) store).wrapped();
- assertInstanceOf(TimeOrderedCachingWindowStore.class, wrapped);
Review Comment:
I removed the assertion that test passes, I think we need to modify headers window store for this test to pass.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20194: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2922680047
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KTableMapValues.java:
##########
@@ -109,16 +110,18 @@ private VOut computeValue(final KIn key, final VIn value) {
return newValue;
}
- private ValueAndTimestamp<VOut> computeValueAndTimestamp(final KIn key, final ValueAndTimestamp<VIn> valueAndTimestamp) {
+ private ValueTimestampHeaders<VOut> computeValueAndTimestamp(final KIn key, final ValueTimestampHeaders<VIn> valueTimestampHeaders) {
VOut newValue = null;
long timestamp = 0;
+ Headers headers = null;
- if (valueAndTimestamp != null) {
- newValue = mapper.apply(key, valueAndTimestamp.value());
- timestamp = valueAndTimestamp.timestamp();
+ if (valueTimestampHeaders != null) {
+ newValue = mapper.apply(key, valueTimestampHeaders.value());
+ timestamp = valueTimestampHeaders.timestamp();
+ headers = valueTimestampHeaders.headers();
}
- return ValueAndTimestamp.make(newValue, timestamp);
+ return ValueTimestampHeaders.make(newValue, timestamp, headers);
Review Comment:
Whatever you prefer -- it should not make a difference in practice, because the DSL does never _read_ `Headers` atm.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20194: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2922707044
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/ProcessorStateManager.java:
##########
@@ -368,7 +368,8 @@ public void registerStore(final StateStore store,
@Override
public StateStore store(final String name) {
if (stores.containsKey(name)) {
- return stores.get(name).stateStore;
+ final StateStore stateStore = stores.get(name).stateStore;
+ return stateStore;
Review Comment:
Same question -- not sure why we introduce `stateStore` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20263: Change KeyValueStoreWrapper to have versioned and headersStore [kafka]
Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2963404285
##########
streams/src/test/java/org/apache/kafka/test/GenericInMemoryTimestampedKeyValueStoreWithHeaders.java:
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.test;
+
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.streams.KeyValue;
+import org.apache.kafka.streams.processor.StateStore;
+import org.apache.kafka.streams.processor.StateStoreContext;
+import org.apache.kafka.streams.state.KeyValueIterator;
+import org.apache.kafka.streams.state.TimestampedKeyValueStoreWithHeaders;
+import org.apache.kafka.streams.state.ValueTimestampHeaders;
+import org.apache.kafka.streams.state.internals.CacheFlushListener;
+import org.apache.kafka.streams.state.internals.DelegatingPeekingKeyValueIterator;
+import org.apache.kafka.streams.state.internals.WrappedStateStore;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.NavigableMap;
+import java.util.TreeMap;
+
+/**
+ * This class is a generic version of the in-memory key-value store that is useful for testing when you
+ * need a basic KeyValueStore for arbitrary types and don't have/want to write a serde
+ */
+@SuppressWarnings("deprecation")
+public class GenericInMemoryTimestampedKeyValueStoreWithHeaders<K extends Comparable, V>
+ extends WrappedStateStore<StateStore, K, ValueTimestampHeaders<V>>
+ implements TimestampedKeyValueStoreWithHeaders<K, V> {
+
+ private final String name;
+ private final NavigableMap<K, ValueTimestampHeaders<V>> map;
+ private volatile boolean open = false;
+
+ public GenericInMemoryTimestampedKeyValueStoreWithHeaders(final String name) {
+ // it's not really a `WrappedStateStore` so we pass `null`
+ // however, we need to implement `WrappedStateStore` to make the store usable
+ super(null);
+ this.name = name;
+
+ this.map = new TreeMap<>();
+ }
+
+ @Override
+ public String name() {
+ return this.name;
Review Comment:
Addresse via https://github.com/apache/kafka/pull/21792
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "frankvicky (via GitHub)" <gi...@apache.org>.
frankvicky commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2873702738
##########
streams/src/test/java/org/apache/kafka/streams/kstream/internals/KTableSourceTest.java:
##########
@@ -217,38 +292,71 @@ public void testValueGetter() {
final KTableValueGetter<String, String> getter1 = getterSupplier1.get();
getter1.init(driver.setCurrentNodeForProcessorContext(table1.name));
- inputTopic1.pipeInput("A", "01", 10L);
- inputTopic1.pipeInput("B", "01", 20L);
- inputTopic1.pipeInput("C", "01", 15L);
-
- assertEquals(ValueAndTimestamp.make("01", 10L), getter1.get("A"));
- assertEquals(ValueAndTimestamp.make("01", 20L), getter1.get("B"));
- assertEquals(ValueAndTimestamp.make("01", 15L), getter1.get("C"));
-
- inputTopic1.pipeInput("A", "02", 30L);
- inputTopic1.pipeInput("B", "02", 5L);
-
- assertEquals(ValueAndTimestamp.make("02", 30L), getter1.get("A"));
- assertEquals(ValueAndTimestamp.make("02", 5L), getter1.get("B"));
- assertEquals(ValueAndTimestamp.make("01", 15L), getter1.get("C"));
-
- inputTopic1.pipeInput("A", "03", 29L);
-
- assertEquals(ValueAndTimestamp.make("03", 29L), getter1.get("A"));
- assertEquals(ValueAndTimestamp.make("02", 5L), getter1.get("B"));
- assertEquals(ValueAndTimestamp.make("01", 15L), getter1.get("C"));
-
- inputTopic1.pipeInput("A", null, 50L);
- inputTopic1.pipeInput("B", null, 3L);
-
- assertNull(getter1.get("A"));
- assertNull(getter1.get("B"));
- assertEquals(ValueAndTimestamp.make("01", 15L), getter1.get("C"));
+ // Send records with unique headers for each key
+ final Headers headersA = makeHeaders("key", "A");
+ final Headers headersB = makeHeaders("key", "B");
+ final Headers headersC = makeHeaders("key", "C");
+
+ inputTopic1.pipeInput(new TestRecord<>("A", "01", headersA, 10L));
+ inputTopic1.pipeInput(new TestRecord<>("B", "01", headersB, 20L));
+ inputTopic1.pipeInput(new TestRecord<>("C", "01", headersC, 15L));
+
+ if (storeFormat.equals("defaults")) {
Review Comment:
We should introduce a const for `defaults` and `headers` since these two value are using everywhere.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20220: Enable TimestampedKVStoreWithHeaders in DSL (2/N) [kafka]
Posted by "UladzislauBlok (via GitHub)" <gi...@apache.org>.
UladzislauBlok commented on code in PR #21580:
URL: https://github.com/apache/kafka/pull/21580#discussion_r2869315709
##########
streams/src/test/java/org/apache/kafka/streams/kstream/internals/KTableSourceTest.java:
##########
@@ -270,38 +378,77 @@ public void testNotSendingOldValue() {
);
final MockApiProcessor<String, Integer, Void, Void> proc1 = supplier.theCapturedProcessor();
- inputTopic1.pipeInput("A", "01", 10L);
- inputTopic1.pipeInput("B", "01", 20L);
- inputTopic1.pipeInput("C", "01", 15L);
- proc1.checkAndClearProcessResult(
- new KeyValueTimestamp<>("A", new Change<>("01", null), 10),
- new KeyValueTimestamp<>("B", new Change<>("01", null), 20),
- new KeyValueTimestamp<>("C", new Change<>("01", null), 15)
- );
+ final Headers headers = makeHeaders("test", "header");
+ inputTopic1.pipeInput(new TestRecord<>("A", "01", headers, 10L));
+ inputTopic1.pipeInput(new TestRecord<>("B", "01", headers, 20L));
+ inputTopic1.pipeInput(new TestRecord<>("C", "01", headers, 15L));
- inputTopic1.pipeInput("A", "02", 8L);
- inputTopic1.pipeInput("B", "02", 22L);
- proc1.checkAndClearProcessResult(
- new KeyValueTimestamp<>("A", new Change<>("02", null), 8),
- new KeyValueTimestamp<>("B", new Change<>("02", null), 22)
- );
+ if (storeFormat.equals("default")) {
+ proc1.checkAndClearProcessResult(
+ new KeyValueTimestamp<>("A", new Change<>("01", null), 10),
+ new KeyValueTimestamp<>("B", new Change<>("01", null), 20),
+ new KeyValueTimestamp<>("C", new Change<>("01", null), 15)
+ );
+ } else if (storeFormat.equals("headers")) {
Review Comment:
We've reused `default` and `headers` many times. Can we use some constant? e.g., psf field or enum
##########
streams/src/test/java/org/apache/kafka/streams/kstream/internals/KTableSourceTest.java:
##########
@@ -217,38 +292,71 @@ public void testValueGetter() {
final KTableValueGetter<String, String> getter1 = getterSupplier1.get();
getter1.init(driver.setCurrentNodeForProcessorContext(table1.name));
- inputTopic1.pipeInput("A", "01", 10L);
- inputTopic1.pipeInput("B", "01", 20L);
- inputTopic1.pipeInput("C", "01", 15L);
-
- assertEquals(ValueAndTimestamp.make("01", 10L), getter1.get("A"));
- assertEquals(ValueAndTimestamp.make("01", 20L), getter1.get("B"));
- assertEquals(ValueAndTimestamp.make("01", 15L), getter1.get("C"));
-
- inputTopic1.pipeInput("A", "02", 30L);
- inputTopic1.pipeInput("B", "02", 5L);
-
- assertEquals(ValueAndTimestamp.make("02", 30L), getter1.get("A"));
- assertEquals(ValueAndTimestamp.make("02", 5L), getter1.get("B"));
- assertEquals(ValueAndTimestamp.make("01", 15L), getter1.get("C"));
-
- inputTopic1.pipeInput("A", "03", 29L);
-
- assertEquals(ValueAndTimestamp.make("03", 29L), getter1.get("A"));
- assertEquals(ValueAndTimestamp.make("02", 5L), getter1.get("B"));
- assertEquals(ValueAndTimestamp.make("01", 15L), getter1.get("C"));
-
- inputTopic1.pipeInput("A", null, 50L);
- inputTopic1.pipeInput("B", null, 3L);
-
- assertNull(getter1.get("A"));
- assertNull(getter1.get("B"));
- assertEquals(ValueAndTimestamp.make("01", 15L), getter1.get("C"));
+ // Send records with unique headers for each key
+ final Headers headersA = makeHeaders("key", "A");
+ final Headers headersB = makeHeaders("key", "B");
+ final Headers headersC = makeHeaders("key", "C");
+
+ inputTopic1.pipeInput(new TestRecord<>("A", "01", headersA, 10L));
+ inputTopic1.pipeInput(new TestRecord<>("B", "01", headersB, 20L));
+ inputTopic1.pipeInput(new TestRecord<>("C", "01", headersC, 15L));
+
+ if (storeFormat.equals("defaults")) {
+ assertFalse(getter1.supportsHeaders(), "Getter should not support headers with 'default' format");
+ assertEquals(ValueAndTimestamp.make("01", 10L), getter1.get("A"));
+ assertEquals(ValueAndTimestamp.make("01", 20L), getter1.get("B"));
+ assertEquals(ValueAndTimestamp.make("01", 15L), getter1.get("C"));
+ } else if (storeFormat.equals("headers")) {
+ assertTrue(getter1.supportsHeaders(), "Getter should support headers with 'headers' format");
+ assertEquals(ValueTimestampHeaders.make("01", 10L, headersA), getter1.getWithHeaders("A"));
+ assertEquals(ValueTimestampHeaders.make("01", 20L, headersB), getter1.getWithHeaders("B"));
+ assertEquals(ValueTimestampHeaders.make("01", 15L, headersC), getter1.getWithHeaders("C"));
+ }
+
+ inputTopic1.pipeInput(new TestRecord<>("A", "02", headersA, 30L));
+ inputTopic1.pipeInput(new TestRecord<>("B", "02", headersB, 5L));
Review Comment:
Why we send data out-of-order? Key `B` : 20L -> 5L
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/TimestampedCacheFlushListenerWithHeaders.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.streams.processor.api.ProcessorContext;
+import org.apache.kafka.streams.processor.api.Record;
+import org.apache.kafka.streams.processor.internals.InternalProcessorContext;
+import org.apache.kafka.streams.processor.internals.ProcessorNode;
+import org.apache.kafka.streams.state.ValueTimestampHeaders;
+import org.apache.kafka.streams.state.internals.CacheFlushListener;
+
+class TimestampedCacheFlushListenerWithHeaders<KOut, VOut> implements CacheFlushListener<KOut, ValueTimestampHeaders<VOut>> {
+
+ private final InternalProcessorContext<KOut, Change<VOut>> context;
+
+ @SuppressWarnings("rawtypes")
+ private final ProcessorNode myNode;
+
+ TimestampedCacheFlushListenerWithHeaders(final ProcessorContext<KOut, Change<VOut>> context) {
+ this.context = (InternalProcessorContext<KOut, Change<VOut>>) context;
+ myNode = this.context.currentNode();
+ }
+
+ @Override
+ public void apply(final Record<KOut, Change<ValueTimestampHeaders<VOut>>> record) {
+ @SuppressWarnings("rawtypes") final ProcessorNode prev = context.currentNode();
+ context.setCurrentNode(myNode);
+ try {
+ final VOut newValue = record.value().newValue != null ? record.value().newValue.value() : null;
+ final VOut oldValue = record.value().oldValue != null ? record.value().oldValue.value() : null;
+ final long timestamp = record.value().newValue != null ? record.value().newValue.timestamp() : record.timestamp();
+
+ context.forward(
+ record
+ .withValue(new Change<>(newValue, oldValue, record.value().isLatest))
+ .withTimestamp(timestamp)
Review Comment:
I think headers are here:
Line 54: .withHeaders(headers)
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KTableValueGetter.java:
##########
@@ -34,12 +35,32 @@ default ValueAndTimestamp<V> get(final K key, final long asOfTimestamp) {
throw new UnsupportedOperationException("get(key, timestamp) is only supported for versioned stores");
}
+ /**
+ * Returns the latest record with value, timestamp, and headers. This method may only be
+ * called if {@link #supportsHeaders()} is true.
+ *
+ * @param key the key to get
+ * @return the value with timestamp and headers, or null if not found
+ */
+ default ValueTimestampHeaders<V> getWithHeaders(final K key) {
Review Comment:
This is from the KIP:
The goal of this KIP is therefore:
- Provide a simple, explicit, and backwards-compatible way for DSL users to opt into headers-aware state stores, reusing the stores and upgrade paths defined in KIP-1271,
- while keeping headers semantics of DSL operators out of scope for now (headers should be considered “empty” from a DSL semantics point of view in this KIP).
I don't this this method is required for now, but from my perspective it's okay to introduce it
This way we can fully implement state stores side of DSL, and next KIP can concentrate on DSL headers aware operations only
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -45,70 +53,80 @@ public class KeyValueStoreWrapper<K, V> implements StateStore {
public static final long PUT_RETURN_CODE_IS_LATEST
= VersionedKeyValueStore.PUT_RETURN_CODE_VALID_TO_UNDEFINED;
- private TimestampedKeyValueStore<K, V> timestampedStore = null;
+ private TimestampedKeyValueStoreWithHeaders<K, V> headersStore = null;
private VersionedKeyValueStore<K, V> versionedStore = null;
Review Comment:
Why we leave non-headers versioned store?
As I understand we have `VersionedKeyValueStoreWithHeaders`
##########
streams/src/test/java/org/apache/kafka/streams/kstream/internals/KTableSourceTest.java:
##########
@@ -325,33 +472,139 @@ public void testSendingOldValue() {
);
final MockApiProcessor<String, Integer, Void, Void> proc1 = supplier.theCapturedProcessor();
- inputTopic1.pipeInput("A", "01", 10L);
- inputTopic1.pipeInput("B", "01", 20L);
- inputTopic1.pipeInput("C", "01", 15L);
- proc1.checkAndClearProcessResult(
- new KeyValueTimestamp<>("A", new Change<>("01", null), 10),
- new KeyValueTimestamp<>("B", new Change<>("01", null), 20),
- new KeyValueTimestamp<>("C", new Change<>("01", null), 15)
- );
+ final Headers headers = makeHeaders("test", "header");
+ inputTopic1.pipeInput(new TestRecord<>("A", "01", headers, 10L));
+ inputTopic1.pipeInput(new TestRecord<>("B", "01", headers, 20L));
+ inputTopic1.pipeInput(new TestRecord<>("C", "01", headers, 15L));
- inputTopic1.pipeInput("A", "02", 8L);
- inputTopic1.pipeInput("B", "02", 22L);
- proc1.checkAndClearProcessResult(
- new KeyValueTimestamp<>("A", new Change<>("02", "01"), 8),
- new KeyValueTimestamp<>("B", new Change<>("02", "01"), 22)
- );
+ if (storeFormat.equals("default")) {
+ proc1.checkAndClearProcessResult(
+ new KeyValueTimestamp<>("A", new Change<>("01", null), 10),
+ new KeyValueTimestamp<>("B", new Change<>("01", null), 20),
+ new KeyValueTimestamp<>("C", new Change<>("01", null), 15)
+ );
+ } else if (storeFormat.equals("headers")) {
+ proc1.checkAndClearProcessResultWithHeaders(
+ new KeyValueTimestampHeaders<>("A", new Change<>("01", null), 10, headers),
+ new KeyValueTimestampHeaders<>("B", new Change<>("01", null), 20, headers),
+ new KeyValueTimestampHeaders<>("C", new Change<>("01", null), 15, headers)
+ );
+ }
- inputTopic1.pipeInput("A", "03", 12L);
- proc1.checkAndClearProcessResult(
- new KeyValueTimestamp<>("A", new Change<>("03", "02"), 12)
- );
+ inputTopic1.pipeInput(new TestRecord<>("A", "02", headers, 8L));
+ inputTopic1.pipeInput(new TestRecord<>("B", "02", headers, 22L));
+
+ if (storeFormat.equals("default")) {
+ proc1.checkAndClearProcessResult(
+ new KeyValueTimestamp<>("A", new Change<>("02", "01"), 8),
+ new KeyValueTimestamp<>("B", new Change<>("02", "01"), 22)
+ );
+ } else if (storeFormat.equals("headers")) {
+ proc1.checkAndClearProcessResultWithHeaders(
+ new KeyValueTimestampHeaders<>("A", new Change<>("02", "01"), 8, headers),
+ new KeyValueTimestampHeaders<>("B", new Change<>("02", "01"), 22, headers)
+ );
+ }
+
+ inputTopic1.pipeInput(new TestRecord<>("A", "03", headers, 12L));
+
+ if (storeFormat.equals("default")) {
+ proc1.checkAndClearProcessResult(
+ new KeyValueTimestamp<>("A", new Change<>("03", "02"), 12)
+ );
+ } else if (storeFormat.equals("headers")) {
+ proc1.checkAndClearProcessResultWithHeaders(
+ new KeyValueTimestampHeaders<>("A", new Change<>("03", "02"), 12, headers)
+ );
+ }
+
+ inputTopic1.pipeInput(new TestRecord<>("A", null, headers, 15L));
+ inputTopic1.pipeInput(new TestRecord<>("B", null, headers, 20L));
- inputTopic1.pipeInput("A", null, 15L);
- inputTopic1.pipeInput("B", null, 20L);
- proc1.checkAndClearProcessResult(
- new KeyValueTimestamp<>("A", new Change<>(null, "03"), 15),
- new KeyValueTimestamp<>("B", new Change<>(null, "02"), 20)
+ if (storeFormat.equals("default")) {
+ proc1.checkAndClearProcessResult(
+ new KeyValueTimestamp<>("A", new Change<>(null, "03"), 15),
+ new KeyValueTimestamp<>("B", new Change<>(null, "02"), 20)
+ );
+ } else if (storeFormat.equals("headers")) {
+ proc1.checkAndClearProcessResultWithHeaders(
+ new KeyValueTimestampHeaders<>("A", new Change<>(null, "03"), 15, headers),
+ new KeyValueTimestampHeaders<>("B", new Change<>(null, "02"), 20, headers)
+ );
+ }
+ }
+ }
+
+ @ParameterizedTest
+ @MethodSource("storeFormats")
+ public void testKTableAcceptsInputsWithHeaders(final String storeFormat) {
+ final Properties props = getProps(storeFormat);
+ final StreamsBuilder builder = new StreamsBuilder();
+ final String topic1 = "topic1";
+ final String storeName = "input-headers-store";
+
+ final KTable<String, Integer> table1 = builder.table(topic1,
+ Consumed.with(Serdes.String(), Serdes.Integer()),
+ Materialized.as(storeName));
+
+ final MockApiProcessorSupplier<String, Integer, Void, Void> supplier = new MockApiProcessorSupplier<>();
+ table1.toStream().process(supplier);
+
+ try (final TopologyTestDriver driver = new TopologyTestDriver(builder.build(), props)) {
+ final TestInputTopic<String, Integer> inputTopic =
+ driver.createInputTopic(topic1, new StringSerializer(), new IntegerSerializer());
+
+ final Headers headers1 = makeHeaders("key1", "value1");
+ final Headers headers2 = makeHeaders("key2", "value2");
+
+ inputTopic.pipeInput(new TestRecord<>("A", 1, headers1, 10L));
+ inputTopic.pipeInput(new TestRecord<>("B", 2, headers2, 11L));
+
+ // Headers are forwarded in both modes
+ assertEquals(
+ asList(new KeyValueTimestampHeaders<>("A", 1, 10L, headers1),
+ new KeyValueTimestampHeaders<>("B", 2, 11L, headers2)),
+ supplier.theCapturedProcessor().processedWithHeaders()
);
+
+ // Headers are forwarded only in `headers` modes
Review Comment:
// Headers are forwarded in both modes
// Headers are forwarded only in `headers` modes
This is misleading a bit. I assume in second case this is about saved to state store
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueStoreWrapper.java:
##########
@@ -158,4 +176,157 @@ public <R> QueryResult<R> query(final Query<R> query, final PositionBound positi
public Position getPosition() {
return store.getPosition();
}
+
+ /**
+ * Adapter that makes a TimestampedKeyValueStore appear as a
+ * TimestampedKeyValueStoreWithHeaders by adding null headers support.
+ */
+ private static final class TimestampedKeyValueStoreHeadersAdapter<K, V>
+ extends WrappedStateStore<TimestampedKeyValueStore<K, V>, K, ValueTimestampHeaders<V>>
+ implements TimestampedKeyValueStoreWithHeaders<K, V> {
+
+ public TimestampedKeyValueStoreHeadersAdapter(final TimestampedKeyValueStore<K, V> store) {
+ super(store);
+ }
+
+ @Override
+ public void put(final K key, final ValueTimestampHeaders<V> value) {
+ if (value == null) {
+ wrapped().put(key, null);
+ } else {
+ wrapped().put(key, ValueAndTimestamp.make(value.value(), value.timestamp()));
+ }
+ }
+
+ @Override
+ public ValueTimestampHeaders<V> putIfAbsent(final K key, final ValueTimestampHeaders<V> value) {
+ final ValueAndTimestamp<V> valueAndTimestamp = value == null
+ ? wrapped().putIfAbsent(key, null)
+ : wrapped().putIfAbsent(key, ValueAndTimestamp.make(value.value(), value.timestamp()));
+ return valueAndTimestamp == null
+ ? null
+ : ValueTimestampHeaders.make(valueAndTimestamp.value(), valueAndTimestamp.timestamp(), null);
+ }
+
+ @Override
+ public void putAll(final List<KeyValue<K, ValueTimestampHeaders<V>>> entries) {
+ final List<KeyValue<K, ValueAndTimestamp<V>>> convertedEntries = new java.util.ArrayList<>(entries.size());
Review Comment:
```suggestion
final List<KeyValue<K, ValueAndTimestamp<V>>> convertedEntries = new ArrayList<>(entries.size());
```
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KTableSource.java:
##########
@@ -166,7 +166,12 @@ public void process(final Record<KIn, VIn> record) {
} else {
oldValue = null;
}
- final long putReturnCode = store.put(record.key(), record.value(), record.timestamp());
+ final long putReturnCode;
+// if (store.supportsHeaders()) {
+ putReturnCode = store.put(record.key(), record.value(), record.timestamp(), record.headers());
+// } else {
+// putReturnCode = store.put(record.key(), record.value(), record.timestamp());
+// }
Review Comment:
Do we want to keep commented code (for follow-up PRs), or it's leftover?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org