mjsax commented on code in PR #23842:
URL: https://github.com/apache/kafka/pull/23842#discussion_r4396969924
##########
docs/streams/developer-guide/interactive-queries.md:
##########
Review Comment:
```suggestion
KTable<String, Integer> oddCounts = regionCounts.filter((region, count)
-> (count % 2 != 0),
```
##########
docs/streams/developer-guide/interactive-queries.md:
##########
Review Comment:
```suggestion
Materialized.<String, Integer, KeyValueStore<Bytes,
byte[]>>as("queryableStoreName"));
```
##########
docs/streams/developer-guide/interactive-queries.md:
##########
Review Comment:
```suggestion
KTable<String, Integer> evenCounts = numberLines.filter((region, count)
-> (count % 2 == 0));
```
##########
docs/streams/developer-guide/interactive-queries.md:
##########
@@ -549,7 +549,7 @@ Here is how to implement `QueryableStoreType`:
A wrapper class is required because each instance of a Kafka Streams
application may run multiple stream tasks and manage multiple local instances
of a particular state store. The wrapper class hides this complexity and lets
you query a "logical" state store by name without having to know about all of
the underlying local instances of that state store.
-When implementing your wrapper class you must use the
[StateStoreProvider](https://github.com/apache/kafka/blob/4.4/streams/src/main/java/org/apache/kafka/streams/state/internals/StateStoreProvider.java)
interface to get access to the underlying instances of your store.
`StateStoreProvider#stores(String storeName, QueryableStoreType<T>
queryableStoreType)` returns a `List` of state stores with the given storeName
and of the type as defined by `queryableStoreType`.
+When implementing your wrapper class you must use the
[StateStoreProvider](https://github.com/apache/kafka/blob/trunk/streams/src/main/java/org/apache/kafka/streams/state/internals/StateStoreProvider.java)
interface to get access to the underlying instances of your store.
`StateStoreProvider#stores(String storeName, QueryableStoreType<T>
queryableStoreType)` returns a `List` of state stores with the given storeName
and of the type as defined by `queryableStoreType`.
Review Comment:
We should not point to changing stuff... `trunk` is moving.
We have a script IIRC, which updates these links per release to match the
right number.
##########
docs/streams/developer-guide/interactive-queries.md:
##########
@@ -889,45 +889,48 @@ This example shows how to configure and run a Kafka
Streams application that sup
## Discovering and accessing application instances and their local state stores
-The following methods return
[StreamsMetadata](/{version}/javadoc/org/apache/kafka/streams/state/StreamsMetadata.html)
objects, which provide meta-information about application instances such as
their RPC endpoint and locally available state stores.
+The following methods return
[StreamsMetadata](/{version}/javadoc/org/apache/kafka/streams/StreamsMetadata.html)
objects, which provide meta-information about application instances such as
their RPC endpoint and locally available state stores.
- * `KafkaStreams#allMetadata()`: find all instances of this application
- * `KafkaStreams#allMetadataForStore(String storeName)`: find those
applications instances that manage local instances of the state store
"storeName"
- * `KafkaStreams#metadataForKey(String storeName, K key, Serializer<K>
keySerializer)`: using the default stream partitioning strategy, find the one
application instance that holds the data for the given key in the given state
store
- * `KafkaStreams#metadataForKey(String storeName, K key, StreamPartitioner<K,
?> partitioner)`: using `partitioner`, find the one application instance that
holds the data for the given key in the given state store
+ * `KafkaStreams#metadataForAllStreamsClients()`: find all instances of this
application
+ * `KafkaStreams#streamsMetadataForStore(String storeName)`: find those
applications instances that manage local instances of the state store
"storeName"
Review Comment:
```suggestion
* `KafkaStreams#streamsMetadataForStore(String storeName)`: find those
application instances that manage local instances of the state store "storeName"
```
##########
docs/streams/developer-guide/interactive-queries.md:
##########
@@ -889,45 +889,48 @@ This example shows how to configure and run a Kafka
Streams application that sup
## Discovering and accessing application instances and their local state stores
-The following methods return
[StreamsMetadata](/{version}/javadoc/org/apache/kafka/streams/state/StreamsMetadata.html)
objects, which provide meta-information about application instances such as
their RPC endpoint and locally available state stores.
+The following methods return
[StreamsMetadata](/{version}/javadoc/org/apache/kafka/streams/StreamsMetadata.html)
objects, which provide meta-information about application instances such as
their RPC endpoint and locally available state stores.
- * `KafkaStreams#allMetadata()`: find all instances of this application
- * `KafkaStreams#allMetadataForStore(String storeName)`: find those
applications instances that manage local instances of the state store
"storeName"
- * `KafkaStreams#metadataForKey(String storeName, K key, Serializer<K>
keySerializer)`: using the default stream partitioning strategy, find the one
application instance that holds the data for the given key in the given state
store
- * `KafkaStreams#metadataForKey(String storeName, K key, StreamPartitioner<K,
?> partitioner)`: using `partitioner`, find the one application instance that
holds the data for the given key in the given state store
+ * `KafkaStreams#metadataForAllStreamsClients()`: find all instances of this
application
+ * `KafkaStreams#streamsMetadataForStore(String storeName)`: find those
applications instances that manage local instances of the state store
"storeName"
+
+The following methods return
[KeyQueryMetadata](/{version}/javadoc/org/apache/kafka/streams/KeyQueryMetadata.html),
which provides the active and standby application instances for a key.
+
+ * `KafkaStreams#queryMetadataForKey(String storeName, K key, Serializer<K>
keySerializer)`: using the default stream partitioning strategy, find the one
application instance that holds the data for the given key in the given state
store
+ * `KafkaStreams#queryMetadataForKey(String storeName, K key,
StreamPartitioner<K, ?> partitioner)`: using `partitioner`, find the one
application instance that holds the data for the given key in the given state
store
Attention
-If `application.server` is not configured for an application instance, then
the above methods will not find any
[StreamsMetadata](/{version}/javadoc/org/apache/kafka/streams/state/StreamsMetadata.html)
for it.
+If `application.server` is not configured for an application instance, then
`metadataForAllStreamsClients()` and `streamsMetadataForStore()` will not find
any
[StreamsMetadata](/{version}/javadoc/org/apache/kafka/streams/StreamsMetadata.html)
for it. `queryMetadataForKey()` cannot provide a usable host for a key
assigned to that instance.
For example, we can now find the `StreamsMetadata` for the state store named
"word-count" that we defined in the code example shown in the previous section:
KafkaStreams streams = ...;
// Find all the locations of local instances of the state store named
"word-count"
- Collection<StreamsMetadata> wordCountHosts =
streams.allMetadataForStore("word-count");
+ Collection<StreamsMetadata> wordCountHosts =
streams.streamsMetadataForStore("word-count");
// For illustrative purposes, we assume using an HTTP client to talk to
remote app instances.
HttpClient http = ...;
// Get the word count for word (aka key) 'alice': Approach 1
//
// We first find the one app instance that manages the count for 'alice'
in its local state stores.
- StreamsMetadata metadata = streams.metadataForKey("word-count", "alice",
Serdes.String().serializer());
+ KeyQueryMetadata metadata = streams.queryMetadataForKey("word-count",
"alice", Serdes.String().serializer());
// Then, we query only that single app instance for the latest count of
'alice'.
// Note: The RPC URL shown below is fictitious and only serves to
illustrate the idea. Ultimately,
// the URL (or, in general, the method of communication) will depend on
the RPC layer you opted to
// implement. Again, we provide end-to-end demo applications (such as
KafkaMusicExample) that showcase
// how to implement such an RPC layer.
- Long result = http.getLong("http://" + metadata.host() + ":" +
metadata.port() + "/word-count/alice");
+ Long result = http.getLong("http://" + metadata.activeHost().host() + ":"
+ metadata.activeHost().port() + "/word-count/alice");
// Get the word count for word (aka key) 'alice': Approach 2
//
// Alternatively, we could also choose (say) a brute-force approach where
we query every app instance
// until we find the one that happens to know about 'alice'.
- Optional<Long> result = streams.allMetadataForStore("word-count")
+ Optional<Long> result = streams.streamsMetadataForStore("word-count")
.stream()
.map(streamsMetadata -> {
// Construct the (fictituous) full endpoint URL to query the
current remote application instance
Review Comment:
```suggestion
// Construct the (fictitious) full endpoint URL to query the
current remote application instance
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]