aliehsaeedii commented on code in PR #22975:
URL: https://github.com/apache/kafka/pull/22975#discussion_r3738681473
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/MeteredTimestampedKeyValueStoreWithHeaders.java:
##########
@@ -786,15 +747,10 @@ private
MeteredTimestampedKeyValueStoreWithHeadersReadOnlyRecordIterator(
final Sensor sensor,
final Function<byte[], ValueTimestampHeaders<V>>
valueTimestampHeadersDeserializer
) {
- super(iter, sensor);
+ super(iter, sensor, iteratorDurationSensor, time,
numOpenIterators, openIterators);
this.valueTimestampHeadersDeserializer =
valueTimestampHeadersDeserializer;
}
- @Override
- public boolean hasNext() {
- return iter.hasNext();
- }
-
@Override
public ReadOnlyRecord<K, V> next() {
Review Comment:
Pre-existing, not from this PR: `valueTimestampHeaders` can be null here —
`ValueTimestampHeaders.make()` returns null whenever the value deserializes to
null — so the `.headers()` deref two lines down NPEs. The window sibling guards
the same deref and throws a `StreamsException` naming the key. File a ticket
like KAFKA-20902.
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/AbstractMeteredIterator.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.metrics.Sensor;
+import org.apache.kafka.common.utils.Time;
+import org.apache.kafka.streams.state.KeyValueIterator;
+
+import java.util.Set;
+import java.util.concurrent.atomic.LongAdder;
+
+/**
+ * Shared metering lifecycle for the metered iterators of the {@code
Metered*WithHeaders} stores,
+ * whatever result type they yield: the {@code KeyValueIterator}s returned by
the store's own range/
+ * fetch/find methods and the {@code ReadOnlyRecordIterator}s that back the
headers-aware IQv2
+ * range/window/session query types.
+ *
+ * <p>Every such iterator opens over a raw {@code KeyValueIterator<RawKey,
byte[]>} and needs the
+ * same bookkeeping: stamp the open time (for the {@code
oldest-iterator-open-since-ms} metric),
+ * register in {@code numOpenIterators}/{@code openIterators}, and on {@link
#close()} record the
+ * operation and iterator-duration sensors and deregister. This base is
deliberately result-type
+ * agnostic -- it implements only {@link MeteredIterator} and does not bind
the yielded key/value
+ * types -- so each subclass declares its own result interface (a {@code
KeyValueIterator} or a
+ * {@code ReadOnlyRecordIterator}) and implements just the parts that
genuinely differ: the
+ * deserializing {@code next()} (and, for the {@code KeyValueIterator}s, a
peeking {@code hasNext()}
+ * and {@code peekNextKey()}).
+ *
+ * @param <RawKey> the raw iterator's key type
+ */
+abstract class AbstractMeteredIterator<RawKey> implements MeteredIterator {
Review Comment:
The PR title and description still describe the first design: they name
`AbstractMeteredReadOnlyRecordIterator<RawKey, K, V>` and say only the
read-only-record iterators change. It's `AbstractMeteredIterator<RawKey>` now,
and all seven iterators extend it including the four `KeyValueIterator` ones.
Do we need to update both? since they become the commit message.
--
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]