Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KIP-924: Custom assignment integration test #309

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ plugins {
}

repositories {
mavenLocal()
gradlePluginPortal()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ checkstyle {

repositories {
mavenCentral()
mavenLocal()
}

tasks.test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import dev.responsive.kafka.api.async.internals.AsyncThreadPoolRegistry;
import dev.responsive.kafka.api.config.CompatibilityMode;
import dev.responsive.kafka.api.config.ResponsiveConfig;
import dev.responsive.kafka.api.stores.ResponsiveDslStoreSuppliers;
import dev.responsive.kafka.internal.clients.ResponsiveKafkaClientSupplier;
import dev.responsive.kafka.internal.config.ConfigUtils;
import dev.responsive.kafka.internal.config.InternalSessionConfigs;
Expand Down Expand Up @@ -271,7 +272,6 @@ private static Properties propsWithOverrides(
) {
final Properties propsWithOverrides = new Properties();


final InternalSessionConfigs.Builder internalConfBuilder = new InternalSessionConfigs.Builder()
.withSessionClients(sessionClients)
.withStoreRegistry(storeRegistry)
Expand Down Expand Up @@ -313,6 +313,11 @@ private static Properties propsWithOverrides(
throw new ConfigException(errorMsg);
}

propsWithOverrides.putIfAbsent(
StreamsConfig.DSL_STORE_SUPPLIERS_CLASS_CONFIG,
ResponsiveDslStoreSuppliers.class.getName()
);

return propsWithOverrides;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2023 Responsive Computing, Inc.
*
* Licensed 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 dev.responsive.kafka.api.stores;

import org.apache.kafka.streams.state.DslKeyValueParams;
import org.apache.kafka.streams.state.DslSessionParams;
import org.apache.kafka.streams.state.DslStoreSuppliers;
import org.apache.kafka.streams.state.DslWindowParams;
import org.apache.kafka.streams.state.KeyValueBytesStoreSupplier;
import org.apache.kafka.streams.state.SessionBytesStoreSupplier;
import org.apache.kafka.streams.state.WindowBytesStoreSupplier;

public class ResponsiveDslStoreSuppliers implements DslStoreSuppliers {

@Override
public KeyValueBytesStoreSupplier keyValueStore(final DslKeyValueParams dslKeyValueParams) {
return ResponsiveStores.keyValueStore(
ResponsiveKeyValueParams.keyValue(dslKeyValueParams.name())
);
}

@Override
public WindowBytesStoreSupplier windowStore(final DslWindowParams dslWindowParams) {
return ResponsiveStores.windowStoreSupplier(
ResponsiveWindowParams.window(
dslWindowParams.name(),
dslWindowParams.windowSize(),
dslWindowParams.retentionPeriod().minus(dslWindowParams.windowSize())
)
);
}

@Override
public SessionBytesStoreSupplier sessionStore(final DslSessionParams dslSessionParams) {
return ResponsiveStores.sessionStoreSupplier(
ResponsiveSessionParams.session(
dslSessionParams.name(),
dslSessionParams.retentionPeriod()
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,36 @@ public final class ResponsiveSessionParams {

private final TableName name;
private final SessionSchema schemaType;
private final long inactivityGapMs;
private final long gracePeriodMs;
private final long retentionPeriodMs;

private long numSegments;
private final long numSegments;

private ResponsiveSessionParams(
final String name,
final SessionSchema schemaType,
final Duration inactivityGap,
final Duration gracePeriod
final long retentionPeriodMs
) {
this.name = new TableName(name);
this.schemaType = schemaType;
this.inactivityGapMs = durationToMillis(inactivityGap, "inactivityGap");
this.gracePeriodMs = durationToMillis(gracePeriod, "gracePeriod");

this.retentionPeriodMs = this.inactivityGapMs + this.gracePeriodMs;
this.retentionPeriodMs = retentionPeriodMs;
this.numSegments = computeDefaultNumSegments(retentionPeriodMs);
}

public static ResponsiveSessionParams session(
final String name,
final Duration retention
) {
return new ResponsiveSessionParams(name, SessionSchema.SESSION, retention.toMillis());
}

public static ResponsiveSessionParams session(
final String name,
final Duration inactivityGap,
final Duration gracePeriod
) {
return new ResponsiveSessionParams(
name, SessionSchema.SESSION, inactivityGap, gracePeriod
);
final long inactivityGapMs = durationToMillis(inactivityGap, "inactivityGap");
final long gracePeriodMs = durationToMillis(gracePeriod, "gracePeriod");
final long retentionPeriodMs = inactivityGapMs + gracePeriodMs;
return new ResponsiveSessionParams(name, SessionSchema.SESSION, retentionPeriodMs);
}

public SessionSchema schemaType() {
Expand All @@ -75,10 +76,6 @@ public long numSegments() {
return this.numSegments;
}

public long gracePeriodMs() {
return this.gracePeriodMs;
}

private static long computeDefaultNumSegments(final long retentionPeriodMs) {
// TODO: Smart implementation.
return DEFAULT_NUM_SEGMENTS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,19 @@ public static <K, V> Materialized<K, V, WindowStore<Bytes, byte[]>> windowMateri
);
}

/**
* See for example {@link Stores#inMemorySessionStore(String, Duration)}
*
* @param params the {@link ResponsiveSessionParams} for this store
* @return a supplier for a session store with the given options
* that uses Responsive's storage for its backend
*/
public static SessionBytesStoreSupplier sessionStoreSupplier(
final ResponsiveSessionParams params
) {
return new ResponsiveSessionStoreSupplier(params);
}

/**
* Create a {@link StoreBuilder} that can be used to build a Responsive
* {@link SessionStore} and connect it via the Processor API. If using the DSL, use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.kafka.common.MetricName;
import org.apache.kafka.common.PartitionInfo;
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.Uuid;

public abstract class DelegatingConsumer<K, V> implements Consumer<K, V> {

Expand Down Expand Up @@ -292,4 +293,9 @@ public void close(final Duration timeout) {
public void wakeup() {
delegate.wakeup();
}

@Override
public Uuid clientInstanceId(final Duration duration) {
return delegate.clientInstanceId(duration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.kafka.common.MetricName;
import org.apache.kafka.common.PartitionInfo;
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.Uuid;
import org.apache.kafka.common.errors.ProducerFencedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -146,6 +147,11 @@ public List<PartitionInfo> partitionsFor(final String topic) {
return wrapped.metrics();
}

@Override
public Uuid clientInstanceId(final Duration duration) {
return wrapped.clientInstanceId(duration);
}

@Override
public void close() {
wrapped.close();
Expand Down
Loading