Search in sources :

Example 1 with TimestampedWindowStore

use of org.apache.kafka.streams.state.TimestampedWindowStore in project kafka by apache.

the class TimeWindowedKStreamImpl method materialize.

private <VR> StoreBuilder<TimestampedWindowStore<K, VR>> materialize(final MaterializedInternal<K, VR, WindowStore<Bytes, byte[]>> materialized) {
    WindowBytesStoreSupplier supplier = (WindowBytesStoreSupplier) materialized.storeSupplier();
    if (supplier == null) {
        final long retentionPeriod = materialized.retention() != null ? materialized.retention().toMillis() : windows.size() + windows.gracePeriodMs();
        if ((windows.size() + windows.gracePeriodMs()) > retentionPeriod) {
            throw new IllegalArgumentException("The retention period of the window store " + name + " must be no smaller than its window size plus the grace period." + " Got size=[" + windows.size() + "]," + " grace=[" + windows.gracePeriodMs() + "]," + " retention=[" + retentionPeriod + "]");
        }
        supplier = Stores.persistentTimestampedWindowStore(materialized.storeName(), Duration.ofMillis(retentionPeriod), Duration.ofMillis(windows.size()), false);
    }
    final StoreBuilder<TimestampedWindowStore<K, VR>> builder = Stores.timestampedWindowStoreBuilder(supplier, materialized.keySerde(), materialized.valueSerde());
    if (materialized.loggingEnabled()) {
        builder.withLoggingEnabled(materialized.logConfig());
    } else {
        builder.withLoggingDisabled();
    }
    if (materialized.cachingEnabled()) {
        builder.withCachingEnabled();
    }
    return builder;
}
Also used : WindowBytesStoreSupplier(org.apache.kafka.streams.state.WindowBytesStoreSupplier) TimestampedWindowStore(org.apache.kafka.streams.state.TimestampedWindowStore)

Example 2 with TimestampedWindowStore

use of org.apache.kafka.streams.state.TimestampedWindowStore in project kafka by apache.

the class SlidingWindowedCogroupedKStreamImpl method materialize.

private StoreBuilder<TimestampedWindowStore<K, V>> materialize(final MaterializedInternal<K, V, WindowStore<Bytes, byte[]>> materialized) {
    WindowBytesStoreSupplier supplier = (WindowBytesStoreSupplier) materialized.storeSupplier();
    if (supplier == null) {
        final long retentionPeriod = materialized.retention() != null ? materialized.retention().toMillis() : windows.gracePeriodMs() + 2 * windows.timeDifferenceMs();
        if ((windows.timeDifferenceMs() * 2 + windows.gracePeriodMs()) > retentionPeriod) {
            throw new IllegalArgumentException("The retention period of the window store " + name + " must be no smaller than 2 * time difference plus the grace period." + " Got time difference=[" + windows.timeDifferenceMs() + "]," + " grace=[" + windows.gracePeriodMs() + "]," + " retention=[" + retentionPeriod + "]");
        }
        supplier = Stores.persistentTimestampedWindowStore(materialized.storeName(), Duration.ofMillis(retentionPeriod), Duration.ofMillis(windows.timeDifferenceMs()), false);
    }
    final StoreBuilder<TimestampedWindowStore<K, V>> builder = Stores.timestampedWindowStoreBuilder(supplier, materialized.keySerde(), materialized.valueSerde());
    if (materialized.loggingEnabled()) {
        builder.withLoggingEnabled(materialized.logConfig());
    } else {
        builder.withLoggingDisabled();
    }
    if (materialized.cachingEnabled()) {
        builder.withCachingEnabled();
    } else {
        builder.withCachingDisabled();
    }
    return builder;
}
Also used : WindowBytesStoreSupplier(org.apache.kafka.streams.state.WindowBytesStoreSupplier) TimestampedWindowStore(org.apache.kafka.streams.state.TimestampedWindowStore)

Example 3 with TimestampedWindowStore

use of org.apache.kafka.streams.state.TimestampedWindowStore in project kafka by apache.

the class SlidingWindowedKStreamImpl method materialize.

private <VR> StoreBuilder<TimestampedWindowStore<K, VR>> materialize(final MaterializedInternal<K, VR, WindowStore<Bytes, byte[]>> materialized) {
    WindowBytesStoreSupplier supplier = (WindowBytesStoreSupplier) materialized.storeSupplier();
    if (supplier == null) {
        final long retentionPeriod = materialized.retention() != null ? materialized.retention().toMillis() : windows.gracePeriodMs() + 2 * windows.timeDifferenceMs();
        // earliest window start time we could need to create corresponding right window would be recordTime - 2 * timeDifference
        if ((windows.timeDifferenceMs() * 2 + windows.gracePeriodMs()) > retentionPeriod) {
            throw new IllegalArgumentException("The retention period of the window store " + name + " must be no smaller than 2 * time difference plus the grace period." + " Got time difference=[" + windows.timeDifferenceMs() + "]," + " grace=[" + windows.gracePeriodMs() + "]," + " retention=[" + retentionPeriod + "]");
        }
        supplier = Stores.persistentTimestampedWindowStore(materialized.storeName(), Duration.ofMillis(retentionPeriod), Duration.ofMillis(windows.timeDifferenceMs()), false);
    }
    final StoreBuilder<TimestampedWindowStore<K, VR>> builder = Stores.timestampedWindowStoreBuilder(supplier, materialized.keySerde(), materialized.valueSerde());
    if (materialized.loggingEnabled()) {
        builder.withLoggingEnabled(materialized.logConfig());
    } else {
        builder.withLoggingDisabled();
    }
    if (materialized.cachingEnabled()) {
        builder.withCachingEnabled();
    } else {
        builder.withCachingDisabled();
    }
    return builder;
}
Also used : WindowBytesStoreSupplier(org.apache.kafka.streams.state.WindowBytesStoreSupplier) TimestampedWindowStore(org.apache.kafka.streams.state.TimestampedWindowStore)

Example 4 with TimestampedWindowStore

use of org.apache.kafka.streams.state.TimestampedWindowStore in project kafka by apache.

the class TimeWindowedCogroupedKStreamImpl method materialize.

private StoreBuilder<TimestampedWindowStore<K, V>> materialize(final MaterializedInternal<K, V, WindowStore<Bytes, byte[]>> materialized) {
    WindowBytesStoreSupplier supplier = (WindowBytesStoreSupplier) materialized.storeSupplier();
    if (supplier == null) {
        final long retentionPeriod = materialized.retention() != null ? materialized.retention().toMillis() : windows.size() + windows.gracePeriodMs();
        if ((windows.size() + windows.gracePeriodMs()) > retentionPeriod) {
            throw new IllegalArgumentException("The retention period of the window store " + name + " must be no smaller than its window size plus the grace period." + " Got size=[" + windows.size() + "]," + " grace=[" + windows.gracePeriodMs() + "]," + " retention=[" + retentionPeriod + "]");
        }
        supplier = Stores.persistentTimestampedWindowStore(materialized.storeName(), Duration.ofMillis(retentionPeriod), Duration.ofMillis(windows.size()), false);
    }
    final StoreBuilder<TimestampedWindowStore<K, V>> builder = Stores.timestampedWindowStoreBuilder(supplier, materialized.keySerde(), materialized.valueSerde());
    if (materialized.loggingEnabled()) {
        builder.withLoggingEnabled(materialized.logConfig());
    } else {
        builder.withLoggingDisabled();
    }
    if (materialized.cachingEnabled()) {
        builder.withCachingEnabled();
    }
    return builder;
}
Also used : WindowBytesStoreSupplier(org.apache.kafka.streams.state.WindowBytesStoreSupplier) TimestampedWindowStore(org.apache.kafka.streams.state.TimestampedWindowStore)

Aggregations

TimestampedWindowStore (org.apache.kafka.streams.state.TimestampedWindowStore)4 WindowBytesStoreSupplier (org.apache.kafka.streams.state.WindowBytesStoreSupplier)4