Search in sources :

Example 1 with MeteredSessionStore

use of org.apache.kafka.streams.state.internals.MeteredSessionStore in project ksql by confluentinc.

the class SessionStoreCacheBypass method getInnermostStore.

@SuppressWarnings("unchecked")
private static SessionStore<Bytes, byte[]> getInnermostStore(final ReadOnlySessionStore<GenericKey, GenericRow> sessionStore) {
    SessionStore<Bytes, byte[]> wrapped = ((MeteredSessionStore<GenericKey, GenericRow>) sessionStore).wrapped();
    // layer.
    while (wrapped instanceof WrappedStateStore) {
        final StateStore store = ((WrappedStateStore<?, ?, ?>) wrapped).wrapped();
        // we just store there.
        if (!(store instanceof SessionStore)) {
            break;
        }
        wrapped = (SessionStore<Bytes, byte[]>) store;
    }
    // now we have the innermost layer of the store.
    return wrapped;
}
Also used : CompositeReadOnlySessionStore(org.apache.kafka.streams.state.internals.CompositeReadOnlySessionStore) SessionStore(org.apache.kafka.streams.state.SessionStore) ReadOnlySessionStore(org.apache.kafka.streams.state.ReadOnlySessionStore) MeteredSessionStore(org.apache.kafka.streams.state.internals.MeteredSessionStore) Bytes(org.apache.kafka.common.utils.Bytes) MeteredSessionStore(org.apache.kafka.streams.state.internals.MeteredSessionStore) WrappedStateStore(org.apache.kafka.streams.state.internals.WrappedStateStore) WrappedStateStore(org.apache.kafka.streams.state.internals.WrappedStateStore) StateStore(org.apache.kafka.streams.processor.StateStore)

Example 2 with MeteredSessionStore

use of org.apache.kafka.streams.state.internals.MeteredSessionStore in project ksql by confluentinc.

the class SessionStoreCacheBypass method fetchRangeUncached.

/*
  This method is used for range queries. It is invoked by the fetchRange method
   */
private static KeyValueIterator<Windowed<GenericKey>, GenericRow> fetchRangeUncached(final ReadOnlySessionStore<GenericKey, GenericRow> sessionStore, final GenericKey keyFrom, final GenericKey keyTo) {
    if (!(sessionStore instanceof MeteredSessionStore)) {
        throw new IllegalStateException("Expecting a MeteredSessionStore");
    } else {
        final StateSerdes<GenericKey, GenericRow> serdes = getSerdes(sessionStore);
        final Bytes rawKeyFrom = Bytes.wrap(serdes.rawKey(keyFrom));
        final Bytes rawKeyTo = Bytes.wrap(serdes.rawKey(keyTo));
        final SessionStore<Bytes, byte[]> wrapped = getInnermostStore(sessionStore);
        final KeyValueIterator<Windowed<Bytes>, byte[]> fetch = wrapped.fetch(rawKeyFrom, rawKeyTo);
        return new DeserializingIterator(fetch, serdes);
    }
}
Also used : GenericRow(io.confluent.ksql.GenericRow) Windowed(org.apache.kafka.streams.kstream.Windowed) MeteredSessionStore(org.apache.kafka.streams.state.internals.MeteredSessionStore) Bytes(org.apache.kafka.common.utils.Bytes) GenericKey(io.confluent.ksql.GenericKey)

Example 3 with MeteredSessionStore

use of org.apache.kafka.streams.state.internals.MeteredSessionStore in project ksql by confluentinc.

the class SessionStoreCacheBypass method fetchUncached.

/*
  This method is used for single key lookups. It is invoked by the fetch method
   */
private static KeyValueIterator<Windowed<GenericKey>, GenericRow> fetchUncached(final ReadOnlySessionStore<GenericKey, GenericRow> sessionStore, final GenericKey key) {
    if (!(sessionStore instanceof MeteredSessionStore)) {
        throw new IllegalStateException("Expecting a MeteredSessionStore");
    } else {
        final StateSerdes<GenericKey, GenericRow> serdes = getSerdes(sessionStore);
        final Bytes rawKey = Bytes.wrap(serdes.rawKey(key));
        final SessionStore<Bytes, byte[]> wrapped = getInnermostStore(sessionStore);
        final KeyValueIterator<Windowed<Bytes>, byte[]> fetch = wrapped.fetch(rawKey);
        return new DeserializingIterator(fetch, serdes);
    }
}
Also used : GenericRow(io.confluent.ksql.GenericRow) Windowed(org.apache.kafka.streams.kstream.Windowed) MeteredSessionStore(org.apache.kafka.streams.state.internals.MeteredSessionStore) Bytes(org.apache.kafka.common.utils.Bytes) GenericKey(io.confluent.ksql.GenericKey)

Aggregations

Bytes (org.apache.kafka.common.utils.Bytes)3 MeteredSessionStore (org.apache.kafka.streams.state.internals.MeteredSessionStore)3 GenericKey (io.confluent.ksql.GenericKey)2 GenericRow (io.confluent.ksql.GenericRow)2 Windowed (org.apache.kafka.streams.kstream.Windowed)2 StateStore (org.apache.kafka.streams.processor.StateStore)1 ReadOnlySessionStore (org.apache.kafka.streams.state.ReadOnlySessionStore)1 SessionStore (org.apache.kafka.streams.state.SessionStore)1 CompositeReadOnlySessionStore (org.apache.kafka.streams.state.internals.CompositeReadOnlySessionStore)1 WrappedStateStore (org.apache.kafka.streams.state.internals.WrappedStateStore)1