Search in sources :

Example 11 with InvalidStateStoreException

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

the class CompositeReadOnlyKeyValueStore method range.

@Override
public KeyValueIterator<K, V> range(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.range(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)

Example 12 with InvalidStateStoreException

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

the class CompositeReadOnlyKeyValueStore method all.

@Override
public KeyValueIterator<K, V> all() {
    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.all();
            } 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)

Example 13 with InvalidStateStoreException

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

the class CompositeReadOnlyWindowStore method backwardFetch.

@Override
public WindowStoreIterator<V> backwardFetch(final K key, final Instant timeFrom, final Instant timeTo) throws IllegalArgumentException {
    Objects.requireNonNull(key, "key can't be null");
    final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType);
    for (final ReadOnlyWindowStore<K, V> windowStore : stores) {
        try {
            final WindowStoreIterator<V> result = windowStore.backwardFetch(key, timeFrom, timeTo);
            if (!result.hasNext()) {
                result.close();
            } else {
                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 KeyValueIterators.emptyWindowStoreIterator();
}
Also used : InvalidStateStoreException(org.apache.kafka.streams.errors.InvalidStateStoreException) ReadOnlyWindowStore(org.apache.kafka.streams.state.ReadOnlyWindowStore)

Example 14 with InvalidStateStoreException

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

the class CompositeReadOnlyWindowStore method fetch.

@Override
public WindowStoreIterator<V> fetch(final K key, final Instant timeFrom, final Instant timeTo) {
    Objects.requireNonNull(key, "key can't be null");
    final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType);
    for (final ReadOnlyWindowStore<K, V> windowStore : stores) {
        try {
            final WindowStoreIterator<V> result = windowStore.fetch(key, timeFrom, timeTo);
            if (!result.hasNext()) {
                result.close();
            } else {
                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 KeyValueIterators.emptyWindowStoreIterator();
}
Also used : InvalidStateStoreException(org.apache.kafka.streams.errors.InvalidStateStoreException) ReadOnlyWindowStore(org.apache.kafka.streams.state.ReadOnlyWindowStore)

Example 15 with InvalidStateStoreException

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

the class ReadOnlyWindowStoreStub method all.

@Override
public KeyValueIterator<Windowed<K>, V> all() {
    if (!open) {
        throw new InvalidStateStoreException("Store is not open");
    }
    final List<KeyValue<Windowed<K>, V>> results = new ArrayList<>();
    for (final long now : data.keySet()) {
        final NavigableMap<K, V> kvMap = data.get(now);
        if (kvMap != null) {
            for (final Entry<K, V> entry : kvMap.entrySet()) {
                results.add(new KeyValue<>(new Windowed<>(entry.getKey(), new TimeWindow(now, now + windowSize)), entry.getValue()));
            }
        }
    }
    final Iterator<KeyValue<Windowed<K>, V>> iterator = results.iterator();
    return new KeyValueIterator<Windowed<K>, V>() {

        @Override
        public void close() {
        }

        @Override
        public Windowed<K> peekNextKey() {
            throw new UnsupportedOperationException("peekNextKey() not supported in " + getClass().getName());
        }

        @Override
        public boolean hasNext() {
            return iterator.hasNext();
        }

        @Override
        public KeyValue<Windowed<K>, V> next() {
            return iterator.next();
        }
    };
}
Also used : KeyValue(org.apache.kafka.streams.KeyValue) ArrayList(java.util.ArrayList) TimeWindow(org.apache.kafka.streams.kstream.internals.TimeWindow) Windowed(org.apache.kafka.streams.kstream.Windowed) InvalidStateStoreException(org.apache.kafka.streams.errors.InvalidStateStoreException) KeyValueIterator(org.apache.kafka.streams.state.KeyValueIterator)

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