Search in sources :

Example 6 with InvalidStateStoreException

use of org.apache.kafka.streams.errors.InvalidStateStoreException 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 7 with InvalidStateStoreException

use of org.apache.kafka.streams.errors.InvalidStateStoreException 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 8 with InvalidStateStoreException

use of org.apache.kafka.streams.errors.InvalidStateStoreException 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 9 with InvalidStateStoreException

use of org.apache.kafka.streams.errors.InvalidStateStoreException in project kafka by apache.

the class CompositeReadOnlyKeyValueStore method get.

@Override
public V get(final K key) {
    Objects.requireNonNull(key);
    final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType);
    for (final ReadOnlyKeyValueStore<K, V> store : stores) {
        try {
            final V result = store.get(key);
            if (result != null) {
                return result;
            }
        } catch (final InvalidStateStoreException e) {
            throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata.");
        }
    }
    return null;
}
Also used : InvalidStateStoreException(org.apache.kafka.streams.errors.InvalidStateStoreException) ReadOnlyKeyValueStore(org.apache.kafka.streams.state.ReadOnlyKeyValueStore)

Example 10 with InvalidStateStoreException

use of org.apache.kafka.streams.errors.InvalidStateStoreException in project kafka by apache.

the class CompositeReadOnlyKeyValueStore method reverseRange.

@Override
public KeyValueIterator<K, V> reverseRange(final K from, final K to) {
    final NextIteratorFunction<K, V, ReadOnlyKeyValueStore<K, V>> nextIteratorFunction = new NextIteratorFunction<K, V, ReadOnlyKeyValueStore<K, V>>() {

        @Override
        public KeyValueIterator<K, V> apply(final ReadOnlyKeyValueStore<K, V> store) {
            try {
                return store.reverseRange(from, to);
            } catch (final InvalidStateStoreException e) {
                throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata.");
            }
        }
    };
    final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType);
    return new DelegatingPeekingKeyValueIterator<>(storeName, new CompositeKeyValueIterator<>(stores.iterator(), nextIteratorFunction));
}
Also used : InvalidStateStoreException(org.apache.kafka.streams.errors.InvalidStateStoreException) ReadOnlyKeyValueStore(org.apache.kafka.streams.state.ReadOnlyKeyValueStore)

Aggregations

InvalidStateStoreException (org.apache.kafka.streams.errors.InvalidStateStoreException)46 Windowed (org.apache.kafka.streams.kstream.Windowed)14 Test (org.junit.Test)14 ReadOnlyKeyValueStore (org.apache.kafka.streams.state.ReadOnlyKeyValueStore)13 ArrayList (java.util.ArrayList)12 KeyValue (org.apache.kafka.streams.KeyValue)10 TimeWindow (org.apache.kafka.streams.kstream.internals.TimeWindow)9 KeyValueIterator (org.apache.kafka.streams.state.KeyValueIterator)9 KafkaStreams (org.apache.kafka.streams.KafkaStreams)8 IntegrationTest (org.apache.kafka.test.IntegrationTest)7 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)6 ReadOnlySessionStore (org.apache.kafka.streams.state.ReadOnlySessionStore)6 Properties (java.util.Properties)4 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)4 KeyQueryMetadata (org.apache.kafka.streams.KeyQueryMetadata)4 ReadOnlyWindowStore (org.apache.kafka.streams.state.ReadOnlyWindowStore)4 Semaphore (java.util.concurrent.Semaphore)3 KafkaStreamsTest (org.apache.kafka.streams.KafkaStreamsTest)3 IOException (java.io.IOException)2 TreeMap (java.util.TreeMap)2