Search in sources :

Example 1 with ListValueStoreBuilder

use of org.apache.kafka.streams.state.internals.ListValueStoreBuilder in project kafka by apache.

the class KStreamImplJoin method sharedOuterJoinWindowStoreBuilder.

private <K, V1, V2> StoreBuilder<KeyValueStore<TimestampedKeyAndJoinSide<K>, LeftOrRightValue<V1, V2>>> sharedOuterJoinWindowStoreBuilder(final JoinWindows windows, final StreamJoinedInternal<K, V1, V2> streamJoinedInternal, final String joinThisGeneratedName) {
    final boolean persistent = streamJoinedInternal.thisStoreSupplier() == null || streamJoinedInternal.thisStoreSupplier().get().persistent();
    final String storeName = buildOuterJoinWindowStoreName(streamJoinedInternal, joinThisGeneratedName) + "-store";
    // we are using a key-value store with list-values for the shared store, and have the window retention / grace period
    // handled totally on the processor node level, and hence here we are only validating these values but not using them at all
    final Duration retentionPeriod = Duration.ofMillis(windows.size() + windows.gracePeriodMs());
    final Duration windowSize = Duration.ofMillis(windows.size());
    final String rpMsgPrefix = prepareMillisCheckFailMsgPrefix(retentionPeriod, "retentionPeriod");
    final long retentionMs = validateMillisecondDuration(retentionPeriod, rpMsgPrefix);
    final String wsMsgPrefix = prepareMillisCheckFailMsgPrefix(windowSize, "windowSize");
    final long windowSizeMs = validateMillisecondDuration(windowSize, wsMsgPrefix);
    if (retentionMs < 0L) {
        throw new IllegalArgumentException("retentionPeriod cannot be negative");
    }
    if (windowSizeMs < 0L) {
        throw new IllegalArgumentException("windowSize cannot be negative");
    }
    if (windowSizeMs > retentionMs) {
        throw new IllegalArgumentException("The retention period of the window store " + storeName + " must be no smaller than its window size. Got size=[" + windowSizeMs + "], retention=[" + retentionMs + "]");
    }
    final TimestampedKeyAndJoinSideSerde<K> timestampedKeyAndJoinSideSerde = new TimestampedKeyAndJoinSideSerde<>(streamJoinedInternal.keySerde());
    final LeftOrRightValueSerde<V1, V2> leftOrRightValueSerde = new LeftOrRightValueSerde<>(streamJoinedInternal.valueSerde(), streamJoinedInternal.otherValueSerde());
    final StoreBuilder<KeyValueStore<TimestampedKeyAndJoinSide<K>, LeftOrRightValue<V1, V2>>> builder = new ListValueStoreBuilder<>(persistent ? Stores.persistentKeyValueStore(storeName) : Stores.inMemoryKeyValueStore(storeName), timestampedKeyAndJoinSideSerde, leftOrRightValueSerde, Time.SYSTEM);
    if (streamJoinedInternal.loggingEnabled()) {
        builder.withLoggingEnabled(streamJoinedInternal.logConfig());
    } else {
        builder.withLoggingDisabled();
    }
    return builder;
}
Also used : Duration(java.time.Duration) ApiUtils.validateMillisecondDuration(org.apache.kafka.streams.internals.ApiUtils.validateMillisecondDuration) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) ListValueStoreBuilder(org.apache.kafka.streams.state.internals.ListValueStoreBuilder) TimestampedKeyAndJoinSideSerde(org.apache.kafka.streams.state.internals.TimestampedKeyAndJoinSideSerde) LeftOrRightValueSerde(org.apache.kafka.streams.state.internals.LeftOrRightValueSerde)

Aggregations

Duration (java.time.Duration)1 ApiUtils.validateMillisecondDuration (org.apache.kafka.streams.internals.ApiUtils.validateMillisecondDuration)1 KeyValueStore (org.apache.kafka.streams.state.KeyValueStore)1 LeftOrRightValueSerde (org.apache.kafka.streams.state.internals.LeftOrRightValueSerde)1 ListValueStoreBuilder (org.apache.kafka.streams.state.internals.ListValueStoreBuilder)1 TimestampedKeyAndJoinSideSerde (org.apache.kafka.streams.state.internals.TimestampedKeyAndJoinSideSerde)1