Jess668 commented on code in PR #22666: URL: https://github.com/apache/kafka/pull/22666#discussion_r3493770728
########## streams/src/main/java/org/apache/kafka/streams/query/TimestampedKeyWithHeadersQuery.java: ########## @@ -0,0 +1,87 @@ +/* + * 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.query; + +import org.apache.kafka.common.annotation.InterfaceStability.Evolving; +import org.apache.kafka.streams.processor.api.ReadOnlyRecord; +import org.apache.kafka.streams.state.TimestampedKeyValueStoreWithHeaders; + +import java.util.Objects; + +/** + * Interactive query for retrieving a single record, including its record headers, based on its key + * from a {@link TimestampedKeyValueStoreWithHeaders}. + * + * <p>This is the headers-aware parallel of {@link TimestampedKeyQuery}: it returns a + * {@link ReadOnlyRecord} carrying the key, value, timestamp, and headers, whereas + * {@link TimestampedKeyQuery} returns a {@link org.apache.kafka.streams.state.ValueAndTimestamp} + * (value and timestamp only, no key or headers). + * + * <p>Headers are only returned when the queried store was built with a KIP-1271 + * {@code WithHeaders} supplier. Against a plain (non-headers) store, this query type is + * unsupported and fails with {@link FailureReason#UNKNOWN_QUERY_TYPE}. + * + * @param <K> Type of keys + * @param <V> Type of values + */ +@Evolving +public final class TimestampedKeyWithHeadersQuery<K, V> implements Query<ReadOnlyRecord<K, V>> { Review Comment: Tests added. The result depends on whether the read is served from the record cache or the underlying store: - caching enabled, entry still warm: served from the cache (which holds the full serialized bytes the metered layer wrote), so the query returns the written value, timestamp, and headers (read-your-writes); - served from the store (caching disabled, or after the entry is evicted/flushed): - over a *timestamped* legacy supplier (e.g. `Stores.persistentTimestampedKeyValueStore`): the timestamp survives but headers are stripped, so the query succeeds with empty `headers()`; - over a *plain* legacy supplier (e.g. `Stores.persistentKeyValueStore`): the plain format keeps no timestamp either, so the read comes back with timestamp -1, which can't be represented as a `Record`, and the query fails with `STORE_EXCEPTION`. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
