aliehsaeedii commented on code in PR #22677: URL: https://github.com/apache/kafka/pull/22677#discussion_r3490251662
########## streams/src/main/java/org/apache/kafka/streams/processor/api/ReadOnlyRecord.java: ########## @@ -0,0 +1,55 @@ +/* + * 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.processor.api; + +import org.apache.kafka.common.header.Headers; + +/** + * A read-only view of a record's {@code key}, {@code value}, {@code timestamp}, and {@code headers}. + * + * <p>This is the shared read surface of a record: the processing-layer {@link Record} extends it with + * transform-and-forward builders ({@code withKey}/{@code withValue}/{@code withTimestamp}/{@code withHeaders}), + * while an Interactive Query (IQv2) result is exactly this read-only snapshot and exposes nothing more. + * It is the result type returned by the headers-aware IQv2 query types (e.g. + * {@code TimestampedKeyWithHeadersQuery}), which surface the record headers + * persisted by header-aware state stores. + * + * @param <K> The type of the key + * @param <V> The type of the value + */ +public interface ReadOnlyRecord<K, V> { + + /** + * The key of the record. May be null. + */ + K key(); + + /** + * The value of the record. May be null. + */ + V value(); + + /** + * The timestamp of the record. Will never be negative. + */ + long timestamp(); + + /** + * The headers of the record. Never null. + */ + Headers headers(); Review Comment: `headers()` is typed as `Headers`, which is mutable (`add`/`remove`). `Record.headers()` returns the live internal `RecordHeaders` reference, so for the IQv2 use case a caller could do `readOnlyRecord.headers().add(...)` and mutate whatever the store handed back — the "read-only" guarantee doesn't extend to the returned headers. `Record`'s class Javadoc already carries the caveat *"This class is immutable, though the objects referenced in the attributes of this class may themselves be mutable."* , we must return an unmodifiable view, so the read-only contract isn't oversold. ########## streams/src/main/java/org/apache/kafka/streams/processor/api/ReadOnlyRecord.java: ########## @@ -0,0 +1,55 @@ +/* + * 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.processor.api; + +import org.apache.kafka.common.header.Headers; + +/** + * A read-only view of a record's {@code key}, {@code value}, {@code timestamp}, and {@code headers}. + * + * <p>This is the shared read surface of a record: the processing-layer {@link Record} extends it with + * transform-and-forward builders ({@code withKey}/{@code withValue}/{@code withTimestamp}/{@code withHeaders}), + * while an Interactive Query (IQv2) result is exactly this read-only snapshot and exposes nothing more. + * It is the result type returned by the headers-aware IQv2 query types (e.g. + * {@code TimestampedKeyWithHeadersQuery}), which surface the record headers Review Comment: This Javadoc names `TimestampedKeyWithHeadersQuery` as the result-type example, but that query type doesn't exist yet (it lands in a later KIP-1356 PR). Consider softening to "the headers-aware IQv2 query types without committing to a concrete class name until it exists. BTW, not a blocking comment as we know we will introduce these q types soon! -- 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]
