liangyepianzhou commented on PR #21271:
URL: https://github.com/apache/pulsar/pull/21271#issuecomment-1751941749
>
> I think the main concern is that `get` might be blocking while Pulsar uses
the `future.xxxAsync` everywhere and it's dangerous to call a blocking method
in the callback of `xxxAsync`. For the sake of this reason, I'm +1 to add a
method to read messages to latest at a certain time point.
>
> However, I think the `refreshAsync` design is not good. Considering the
following case:
>
> ```java
> view.refreshAsync().thenAccept(__ -> {
> // Now, the TableView is the latest snapshot of the compacted topic
> if (view.containsKey(key)) { // T1
> process(view.get(key)); // T2
> }
> });
> ```
>
> Assume at `T1`, the internal data is `{ key => value1 }`. Since the
`TableView` keeps fetching the latest message at the background, if a new
message `(key, value2)` is written after `T1` and before `T2`, at `T2`,
`view.get(key)` will be `value2`.
>
> The root cause is that `TableView` is not immutable.
`TableViewImpl#readTailMessages` fetches the messages at the background. So I
suggest returning an immutable map like:
>
> ```java
> /**
> * Get the latest snapshot for a set of keys at the current time point.
> *
> * @param keys
> * @return a future of the map that represents the snapshot of the
table view. The keys must be a subset of the
> * `keys` parameter and the value is guaranteed to be the latest
value before the future is completed.
> */
> CompletableFuture<Map<String, T>> getLatestSnapshotAsync(Set<String>
keys);
>
> /**
> * Get the latest snapshot at the current time point.
> * @return a future of map that represents the snapshot of the table
view.
> */
> CompletableFuture<Map<String, T>> getLatestSnapshotAsync();
> ```
The current use case is that when reads and writes for a key do not occur at
the same time, we can refresh the TableView next time to get the latest value
of this key.
As for the `getLatestSnapshotAsync` method, I don't quite understand its use
case. Could you give an example to illustrate under what circumstances we would
use this guarantee?
--
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]