Skip to content

Conversation

@sobychacko
Copy link
Contributor

Fixes: #2942

This is an initial iteration for providing a basic API around interactive query service in Kafka Streams. In this iteration, we introduce a single API for retrieving the queryable state store from the Kafka Streams topology, namely, retrieveQueryableStore.

@sobychacko sobychacko requested a review from artembilan February 8, 2024 23:42
Fixes: spring-projects#2942

This is an initial iteration for providing a basic API around interactive query service in Kafka Streams.
In this iteration, we introduce a single API for retrieving the queryable state store from the Kafka Streams topology, namely, retrieveQueryableStore.
Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checkstyle violation:

 Error: eckstyle] [ERROR] /home/runner/work/spring-kafka/spring-kafka/spring-kafka/src/main/java/org/springframework/kafka/streams/KafkaStreamsInteractiveQueryService.java:96:25: Reference to instance variable 'retryTemplate' needs "this.". [RequireThis]
Error: eckstyle] [ERROR] /home/runner/work/spring-kafka/spring-kafka/spring-kafka/src/main/java/org/springframework/kafka/streams/KafkaStreamsInteractiveQueryService.java:98:25: Reference to instance variable 'retryTemplate' needs "this.". [RequireThis]

* {@link KafkaStreams} under consideration.
*
* @author Soby Chacko
* @since 3.2.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just 3.2 for consistency with the rest of styles.

private KafkaStreams kafkaStreams;

/**
* Constructs an instance for querying state stores from the KafkaStreams in the {@link StreamsBuilderFactoryBean}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method Javadocs must be imperative: https://github.com/spring-projects/spring-framework/wiki/Code-Style#javadoc-formatting

Plus no blank lines in the method Javadocs.

/**
* Underlying {@link KafkaStreams} from {@link StreamsBuilderFactoryBean}.
*/
private KafkaStreams kafkaStreams;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this has to be volatile since you initialize this property in lazy manner on demand.

}
Assert.notNull(this.kafkaStreams, "KafkaStreams cannot be null");
StoreQueryParameters<T> storeQueryParams = StoreQueryParameters.fromNameAndType(storeName, storeType);
AtomicReference<StoreQueryParameters<T>> storeQueryParametersReference = new AtomicReference<>(storeQueryParams);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure in this extra reference: that storeQueryParams is effectively already final.

QueryableStoreTypes.keyValueStore());

assertThat(objectObjectReadOnlyKeyValueStore.get(123)).isNotNull();
assertThat((Long) objectObjectReadOnlyKeyValueStore.get(123) >= 1L).isTrue();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to call get() for the same value twice.
There is also isGreaterThanOrEqualTo() instead of that isTrue() for more precise reporting (if that).

.retrieveQueryableStore(NON_EXISTENT_STORE, QueryableStoreTypes.keyValueStore());
}
catch (Exception e) {
exc = e;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to use assertThatException() instead of try..catch: must better reporting.

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are good so far.
We can turn this into a normal PR and go ahead with docs.

Thanks

@sobychacko sobychacko changed the title [REVIEW-ONLY-DO-NOT-MERGE] GH-2942: Kafka Streams queryable stores GH-2942: Kafka Streams queryable stores Feb 12, 2024
Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the whats-new.adoc has to mention this new feature as well.

Thanks

if (this.kafkaStreams == null) {
this.kafkaStreams = this.streamsBuilderFactoryBean.getKafkaStreams();
}
Assert.notNull(this.kafkaStreams, "KafkaStreams cannot be null");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's improve this assert with something like ". Was provided StreamsBuilderFactoryBean been started?"!


/**
* Retrieve and return a queryable store by name created in the application.
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blank line.

A new API `KafkaStreamsInteractiveQuerySupport` for accessing queryable stores used in Kafka Streams interactive queries.
See xref:streams.adoc#kafka-streams-iq-support[Kafka Streams Interactive Support] for more details.

A new `TransactionIdSuffixStrategy` interface was introduced to manage `transactional.id` suffix.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this paragraph is a copy/paste artifact.
Will fix it shortly from GH GUI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. Sorry.

@artembilan artembilan enabled auto-merge (squash) February 12, 2024 21:56
@artembilan artembilan merged commit f2e77e6 into spring-projects:main Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider providing an API for Kafka Streams Interactive Queries

2 participants