use of org.apache.kafka.streams.errors.InvalidStateStoreException in project apache-kafka-on-k8s by banzaicloud.
the class CompositeReadOnlyKeyValueStore method range.
@Override
public KeyValueIterator<K, V> range(final K from, final K to) {
Objects.requireNonNull(from);
Objects.requireNonNull(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 (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));
}
use of org.apache.kafka.streams.errors.InvalidStateStoreException in project apache-kafka-on-k8s by banzaicloud.
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 (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));
}
use of org.apache.kafka.streams.errors.InvalidStateStoreException in project apache-kafka-on-k8s by banzaicloud.
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 (long now : data.keySet()) {
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());
}
};
}
use of org.apache.kafka.streams.errors.InvalidStateStoreException in project apache-kafka-on-k8s by banzaicloud.
the class GlobalKTableIntegrationTest method shouldRestoreTransactionalMessages.
@Test
public void shouldRestoreTransactionalMessages() throws Exception {
produceInitialGlobalTableValues(true);
startStreams();
final Map<Long, String> expected = new HashMap<>();
expected.put(1L, "A");
expected.put(2L, "B");
expected.put(3L, "C");
expected.put(4L, "D");
TestUtils.waitForCondition(new TestCondition() {
@Override
public boolean conditionMet() {
ReadOnlyKeyValueStore<Long, String> store = null;
try {
store = kafkaStreams.store(globalStore, QueryableStoreTypes.<Long, String>keyValueStore());
} catch (InvalidStateStoreException ex) {
return false;
}
Map<Long, String> result = new HashMap<>();
Iterator<KeyValue<Long, String>> it = store.all();
while (it.hasNext()) {
KeyValue<Long, String> kv = it.next();
result.put(kv.key, kv.value);
}
return result.equals(expected);
}
}, 30000L, "waiting for initial values");
System.out.println("no failed test");
}
use of org.apache.kafka.streams.errors.InvalidStateStoreException in project kafka by apache.
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.as(storeName));
kafkaStreams = new KafkaStreams(builder.build(), streamsConfiguration);
startKafkaStreamsAndWaitForRunningState(kafkaStreams);
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;
final ReadOnlyKeyValueStore<String, Long> store = IntegrationTestUtils.getStore(storeName, kafkaStreams, keyValueStore());
TestUtils.waitForCondition(() -> Long.valueOf(8).equals(store.get("hello")), maxWaitMs, "wait for count to be 8");
// close stream
kafkaStreams.close();
// start again, and since it may take time to restore we wait for it to transit to RUNNING a bit longer
kafkaStreams = new KafkaStreams(builder.build(), streamsConfiguration);
startKafkaStreamsAndWaitForRunningState(kafkaStreams, maxWaitMs);
// make sure we never get any value other than 8 for hello
TestUtils.waitForCondition(() -> {
try {
assertEquals(8L, IntegrationTestUtils.getStore(storeName, kafkaStreams, keyValueStore()).get("hello"));
return true;
} catch (final InvalidStateStoreException ise) {
return false;
}
}, maxWaitMs, "waiting for store " + storeName);
}
Aggregations