Search in sources :

Example 1 with ReadOnlySessionStore

use of org.apache.kafka.streams.state.ReadOnlySessionStore in project apache-kafka-on-k8s by banzaicloud.

the class CompositeReadOnlySessionStore method fetch.

@Override
public KeyValueIterator<Windowed<K>, V> fetch(final K key) {
    Objects.requireNonNull(key, "key can't be null");
    final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType);
    for (final ReadOnlySessionStore<K, V> store : stores) {
        try {
            final KeyValueIterator<Windowed<K>, V> result = store.fetch(key);
            if (!result.hasNext()) {
                result.close();
            } else {
                return result;
            }
        } catch (final InvalidStateStoreException ise) {
            throw new InvalidStateStoreException("State store  [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata.");
        }
    }
    return KeyValueIterators.emptyIterator();
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) InvalidStateStoreException(org.apache.kafka.streams.errors.InvalidStateStoreException) ReadOnlySessionStore(org.apache.kafka.streams.state.ReadOnlySessionStore)

Example 2 with ReadOnlySessionStore

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

the class CompositeReadOnlySessionStore method fetch.

@Override
public KeyValueIterator<Windowed<K>, V> fetch(final K key) {
    Objects.requireNonNull(key, "key can't be null");
    final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType);
    for (final ReadOnlySessionStore<K, V> store : stores) {
        try {
            final KeyValueIterator<Windowed<K>, V> result = store.fetch(key);
            if (!result.hasNext()) {
                result.close();
            } else {
                return result;
            }
        } catch (final InvalidStateStoreException ise) {
            throw new InvalidStateStoreException("State store  [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata. " + "Original error message: " + ise.toString());
        }
    }
    return KeyValueIterators.emptyIterator();
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) InvalidStateStoreException(org.apache.kafka.streams.errors.InvalidStateStoreException) ReadOnlySessionStore(org.apache.kafka.streams.state.ReadOnlySessionStore)

Example 3 with ReadOnlySessionStore

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

the class CompositeReadOnlySessionStore method findSessions.

@Override
public KeyValueIterator<Windowed<K>, V> findSessions(final K key, final long earliestSessionEndTime, final long latestSessionStartTime) {
    Objects.requireNonNull(key, "key can't be null");
    final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType);
    for (final ReadOnlySessionStore<K, V> store : stores) {
        try {
            final KeyValueIterator<Windowed<K>, V> result = store.findSessions(key, earliestSessionEndTime, latestSessionStartTime);
            if (!result.hasNext()) {
                result.close();
            } else {
                return result;
            }
        } catch (final InvalidStateStoreException ise) {
            throw new InvalidStateStoreException("State store  [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata.", ise);
        }
    }
    return KeyValueIterators.emptyIterator();
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) InvalidStateStoreException(org.apache.kafka.streams.errors.InvalidStateStoreException) ReadOnlySessionStore(org.apache.kafka.streams.state.ReadOnlySessionStore)

Example 4 with ReadOnlySessionStore

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

the class CompositeReadOnlySessionStore method backwardFetch.

@Override
public KeyValueIterator<Windowed<K>, V> backwardFetch(final K key) {
    Objects.requireNonNull(key, "key can't be null");
    final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType);
    for (final ReadOnlySessionStore<K, V> store : stores) {
        try {
            final KeyValueIterator<Windowed<K>, V> result = store.backwardFetch(key);
            if (!result.hasNext()) {
                result.close();
            } else {
                return result;
            }
        } catch (final InvalidStateStoreException ise) {
            throw new InvalidStateStoreException("State store  [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata.", ise);
        }
    }
    return KeyValueIterators.emptyIterator();
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) InvalidStateStoreException(org.apache.kafka.streams.errors.InvalidStateStoreException) ReadOnlySessionStore(org.apache.kafka.streams.state.ReadOnlySessionStore)

Example 5 with ReadOnlySessionStore

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

the class CompositeReadOnlySessionStore method backwardFindSessions.

@Override
public KeyValueIterator<Windowed<K>, V> backwardFindSessions(final K key, final long earliestSessionEndTime, final long latestSessionStartTime) {
    Objects.requireNonNull(key, "key can't be null");
    final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType);
    for (final ReadOnlySessionStore<K, V> store : stores) {
        try {
            final KeyValueIterator<Windowed<K>, V> result = store.backwardFindSessions(key, earliestSessionEndTime, latestSessionStartTime);
            if (!result.hasNext()) {
                result.close();
            } else {
                return result;
            }
        } catch (final InvalidStateStoreException ise) {
            throw new InvalidStateStoreException("State store  [" + storeName + "] is not available anymore" + " and may have been migrated to another instance; " + "please re-discover its location from the state metadata.", ise);
        }
    }
    return KeyValueIterators.emptyIterator();
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) InvalidStateStoreException(org.apache.kafka.streams.errors.InvalidStateStoreException) ReadOnlySessionStore(org.apache.kafka.streams.state.ReadOnlySessionStore)

Aggregations

ReadOnlySessionStore (org.apache.kafka.streams.state.ReadOnlySessionStore)7 InvalidStateStoreException (org.apache.kafka.streams.errors.InvalidStateStoreException)6 Windowed (org.apache.kafka.streams.kstream.Windowed)5 StateStoreProviderStub (org.apache.kafka.test.StateStoreProviderStub)1 Test (org.junit.Test)1