Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7280bf1
Implementation of InMemorySessionStore and Supplier
ableegoldman Mar 29, 2019
5f03dee
Added some missing instances of 'final' keyword in SessionStore inter…
ableegoldman Mar 29, 2019
b72d815
Return 1 for segmentInterval
ableegoldman Mar 29, 2019
df2ee5b
Fix wonky logic in remove()
ableegoldman Apr 2, 2019
256cb9e
Added basic test coverage
ableegoldman Apr 2, 2019
409b9a5
Adjust shouldFetchExactKey test for in-memory store
ableegoldman Apr 2, 2019
0ba2916
Expanded tests to cover restore, iterator peek, record expiration
ableegoldman Apr 3, 2019
77499fd
Added unit tests for put(key, null), fetch, and fetchSession
ableegoldman Apr 9, 2019
f16f9f3
Guard against negative key range queries and add tests following PR #…
ableegoldman Apr 10, 2019
9654e50
Apply suggestions from code review
vvcephei Apr 12, 2019
642c69d
Minor fixes and updates from PR review
ableegoldman Apr 12, 2019
786bf71
Merge branch with committed suggestions from Github
ableegoldman Apr 12, 2019
d417dfa
Forgot to use new registerIterator method
ableegoldman Apr 12, 2019
6a9555a
Cleanup conditional and early returns
ableegoldman Apr 12, 2019
bbb7f7e
Made iterator class static
ableegoldman Apr 12, 2019
e84a976
Changes to unit test class from PR review
ableegoldman Apr 12, 2019
43decb5
Removed unused import
ableegoldman Apr 12, 2019
d6f8999
Added test for logging and measuring expired record puts()
ableegoldman Apr 12, 2019
7caca0c
Add to docs
ableegoldman Apr 12, 2019
a70c166
Updated upgrade-guide docs
ableegoldman Apr 15, 2019
13682aa
Fixed log debug class name
ableegoldman Apr 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public interface SessionStore<K, AGG> extends StateStore, ReadOnlySessionStore<K
* @return iterator of sessions with the matching key and aggregated values
* @throws NullPointerException If null is used for key.
*/
KeyValueIterator<Windowed<K>, AGG> findSessions(final K key, long earliestSessionEndTime, final long latestSessionStartTime);
KeyValueIterator<Windowed<K>, AGG> findSessions(final K key, final long earliestSessionEndTime, final long latestSessionStartTime);

/**
* Fetch any sessions in the given range of keys and the sessions end is &ge; earliestSessionEndTime and the sessions
Expand All @@ -61,7 +61,7 @@ public interface SessionStore<K, AGG> extends StateStore, ReadOnlySessionStore<K
* @return iterator of sessions with the matching keys and aggregated values
* @throws NullPointerException If null is used for any key.
*/
KeyValueIterator<Windowed<K>, AGG> findSessions(final K keyFrom, final K keyTo, long earliestSessionEndTime, final long latestSessionStartTime);
KeyValueIterator<Windowed<K>, AGG> findSessions(final K keyFrom, final K keyTo, final long earliestSessionEndTime, final long latestSessionStartTime);

/**
* Get the value of key from a single session.
Expand All @@ -72,7 +72,7 @@ public interface SessionStore<K, AGG> extends StateStore, ReadOnlySessionStore<K
* @return The value or {@code null} if no session associated with the key can be found
* @throws NullPointerException If {@code null} is used for any key.
*/
AGG fetchSession(K key, long startTime, long endTime);
AGG fetchSession(final K key, final long startTime, final long endTime);

/**
* Remove the session aggregated with provided {@link Windowed} key from the store
Expand Down
21 changes: 21 additions & 0 deletions streams/src/main/java/org/apache/kafka/streams/state/Stores.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.kafka.common.utils.Time;
import org.apache.kafka.streams.internals.ApiUtils;
import org.apache.kafka.streams.state.internals.InMemoryKeyValueStore;
import org.apache.kafka.streams.state.internals.InMemorySessionBytesStoreSupplier;
import org.apache.kafka.streams.state.internals.InMemoryWindowBytesStoreSupplier;
import org.apache.kafka.streams.state.internals.KeyValueStoreBuilder;
import org.apache.kafka.streams.state.internals.MemoryNavigableLRUCache;
Expand Down Expand Up @@ -274,6 +275,26 @@ private static WindowBytesStoreSupplier persistentWindowStore(final String name,
false);
}

/**
* Create an in-memory {@link SessionBytesStoreSupplier}.
* @param name name of the store (cannot be {@code null})
* @param retentionPeriod length ot time to retain data in the store (cannot be negative)
* Note that the retention period must be at least long enough to contain the
* windowed data's entire life cycle, from window-start through window-end,
* and for the entire grace period.
* @return an instance of a {@link SessionBytesStoreSupplier}
*/
public static SessionBytesStoreSupplier inMemorySessionStore(final String name, final Duration retentionPeriod) {
Objects.requireNonNull(name, "name cannot be null");

final String msgPrefix = prepareMillisCheckFailMsgPrefix(retentionPeriod, "retentionPeriod");
final long retentionPeriodMs = ApiUtils.validateMillisecondDuration(retentionPeriod, msgPrefix);
if (retentionPeriodMs < 0) {
throw new IllegalArgumentException("retentionPeriod cannot be negative");
}
return new InMemorySessionBytesStoreSupplier(name, retentionPeriodMs);
}

/**
* Create a persistent {@link SessionBytesStoreSupplier}.
* @param name name of the store (cannot be {@code null})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.utils.Bytes;
import org.apache.kafka.streams.state.SessionBytesStoreSupplier;
import org.apache.kafka.streams.state.SessionStore;

public class InMemorySessionBytesStoreSupplier implements SessionBytesStoreSupplier {
private final String name;
private final long retentionPeriod;

public InMemorySessionBytesStoreSupplier(final String name,
final long retentionPeriod) {
this.name = name;
this.retentionPeriod = retentionPeriod;
}

@Override
public String name() {
return name;
}

@Override
public SessionStore<Bytes, byte[]> get() {
return new InMemorySessionStore(name, retentionPeriod, metricsScope());
}

@Override
public String metricsScope() {
return "in-memory-session-state";
}

// In-memory store is not *really* segmented, so just say it is 1 (for ordering consistency with caching enabled)
@Override
public long segmentIntervalMs() {
return 1;
}

@Override
public long retentionPeriod() {
return retentionPeriod;
}
}

Loading