Skip to content

Commit 2d68b60

Browse files
authored
KAFKA-20134: Implement TimestampedWindowStoreWithHeaders (2/N) (#21478)
This PR add `RocksDBTimestampedWindowStoreWithHeaders` for the `TimestampedWindowStoreWithHeaders` introduced in KIP-1271. Reviewers: lieh Saeedi <asaeedi@confluent.io>, Bill Bejeck <bill@confluent.io>
1 parent a48123e commit 2d68b60

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.kafka.streams.state.internals;
18+
19+
import org.apache.kafka.streams.state.HeadersBytesStore;
20+
import org.apache.kafka.streams.state.TimestampedBytesStore;
21+
22+
/**
23+
* RocksDB-backed timestamped window store with support for record headers.
24+
* <p>
25+
* This store extends {@link RocksDBWindowStore} and implements both
26+
* {@link TimestampedBytesStore} (for timestamp support) and {@link HeadersBytesStore}
27+
* (for header support) marker interfaces.
28+
* <p>
29+
* The storage format for values is: [headersSize(varint)][headersBytes][timestamp(8)][value]
30+
* <p>
31+
* This implementation uses segment-level versioning for backward compatibility:
32+
* <ul>
33+
* <li>Old segments continue to use the legacy format without headers</li>
34+
* <li>New segments use the header-embedded format</li>
35+
* <li>Legacy values are served with empty headers on read</li>
36+
* <li>All new writes use the new format</li>
37+
* </ul>
38+
*
39+
* @see RocksDBWindowStore
40+
* @see HeadersBytesStore
41+
* @see TimestampedBytesStore
42+
*/
43+
class RocksDBTimestampedWindowStoreWithHeaders extends RocksDBWindowStore implements TimestampedBytesStore, HeadersBytesStore {
44+
45+
RocksDBTimestampedWindowStoreWithHeaders(final SegmentedBytesStore bytesStore,
46+
final boolean retainDuplicates,
47+
final long windowSize) {
48+
super(bytesStore, retainDuplicates, windowSize);
49+
}
50+
}

streams/src/main/java/org/apache/kafka/streams/state/internals/RocksDbWindowBytesStoreSupplier.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
public class RocksDbWindowBytesStoreSupplier implements WindowBytesStoreSupplier {
2424
public enum WindowStoreTypes {
2525
DEFAULT_WINDOW_STORE,
26-
TIMESTAMPED_WINDOW_STORE
26+
TIMESTAMPED_WINDOW_STORE,
27+
TIMESTAMPED_WINDOW_STORE_WITH_HEADERS
2728
}
2829

2930
private final String name;
@@ -87,6 +88,16 @@ public WindowStore<Bytes, byte[]> get() {
8788
new WindowKeySchema()),
8889
retainDuplicates,
8990
windowSize);
91+
case TIMESTAMPED_WINDOW_STORE_WITH_HEADERS:
92+
return new RocksDBTimestampedWindowStoreWithHeaders(
93+
new RocksDBTimestampedSegmentedBytesStoreWithHeaders(
94+
name,
95+
metricsScope(),
96+
retentionPeriod,
97+
segmentInterval,
98+
new WindowKeySchema()),
99+
retainDuplicates,
100+
windowSize);
90101
default:
91102
throw new IllegalArgumentException("invalid window store type: " + windowStoreType);
92103
}

0 commit comments

Comments
 (0)