use of org.apache.kafka.streams.errors.InvalidStateStoreException in project apache-kafka-on-k8s by banzaicloud.
the class QueryableStateIntegrationTest method shouldNotMakeStoreAvailableUntilAllStoresAvailable.
@Test
public void shouldNotMakeStoreAvailableUntilAllStoresAvailable() throws Exception {
final StreamsBuilder builder = new StreamsBuilder();
final KStream<String, String> stream = builder.stream(streamThree);
final String storeName = "count-by-key";
stream.groupByKey().count(Materialized.<String, Long, KeyValueStore<Bytes, byte[]>>as(storeName));
kafkaStreams = new KafkaStreams(builder.build(), streamsConfiguration);
kafkaStreams.start();
final KeyValue<String, String> hello = KeyValue.pair("hello", "hello");
IntegrationTestUtils.produceKeyValuesSynchronously(streamThree, Arrays.asList(hello, hello, hello, hello, hello, hello, hello, hello), TestUtils.producerConfig(CLUSTER.bootstrapServers(), StringSerializer.class, StringSerializer.class, new Properties()), mockTime);
final int maxWaitMs = 30000;
TestUtils.waitForCondition(new WaitForStore(storeName), maxWaitMs, "waiting for store " + storeName);
final ReadOnlyKeyValueStore<String, Long> store = kafkaStreams.store(storeName, QueryableStoreTypes.<String, Long>keyValueStore());
TestUtils.waitForCondition(new TestCondition() {
@Override
public boolean conditionMet() {
return new Long(8).equals(store.get("hello"));
}
}, maxWaitMs, "wait for count to be 8");
// close stream
kafkaStreams.close();
// start again
kafkaStreams = new KafkaStreams(builder.build(), streamsConfiguration);
kafkaStreams.start();
// make sure we never get any value other than 8 for hello
TestUtils.waitForCondition(new TestCondition() {
@Override
public boolean conditionMet() {
try {
assertEquals(Long.valueOf(8L), kafkaStreams.store(storeName, QueryableStoreTypes.<String, Long>keyValueStore()).get("hello"));
return true;
} catch (final InvalidStateStoreException ise) {
return false;
}
}
}, maxWaitMs, "waiting for store " + storeName);
}
use of org.apache.kafka.streams.errors.InvalidStateStoreException in project apache-kafka-on-k8s by banzaicloud.
the class CompositeReadOnlyWindowStore method fetch.
@Override
public WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long 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();
}
use of org.apache.kafka.streams.errors.InvalidStateStoreException 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();
}
use of org.apache.kafka.streams.errors.InvalidStateStoreException in project apache-kafka-on-k8s by banzaicloud.
the class ReadOnlyWindowStoreStub method fetch.
@Override
public KeyValueIterator<Windowed<K>, V> fetch(K from, K to, long timeFrom, long timeTo) {
if (!open) {
throw new InvalidStateStoreException("Store is not open");
}
final List<KeyValue<Windowed<K>, V>> results = new ArrayList<>();
for (long now = timeFrom; now <= timeTo; now++) {
final NavigableMap<K, V> kvMap = data.get(now);
if (kvMap != null) {
for (Entry<K, V> entry : kvMap.subMap(from, true, to, true).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();
}
@Override
public void remove() {
throw new UnsupportedOperationException("remove() not supported in " + getClass().getName());
}
};
}
use of org.apache.kafka.streams.errors.InvalidStateStoreException in project apache-kafka-on-k8s by banzaicloud.
the class ReadOnlyWindowStoreStub method fetchAll.
@Override
public KeyValueIterator<Windowed<K>, V> fetchAll(long timeFrom, long timeTo) {
if (!open) {
throw new InvalidStateStoreException("Store is not open");
}
final List<KeyValue<Windowed<K>, V>> results = new ArrayList<>();
for (long now : data.keySet()) {
if (!(now >= timeFrom && now <= timeTo))
continue;
final NavigableMap<K, V> kvMap = data.get(now);
if (kvMap != null) {
for (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();
}
@Override
public void remove() {
throw new UnsupportedOperationException("remove() not supported in " + getClass().getName());
}
};
}
Aggregations