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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
