Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kv): implement KeysWithFilters and ListKeysWithFilters with tests #1711

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

somratdutta
Copy link

@somratdutta somratdutta commented Sep 4, 2024

  • Added KeysWithFilters to filter and return a list of matching keys.
  • Added ListKeysWithFilters to filter keys and return them as an iterable lister.
  • Included test cases for both methods to validate filtering logic and key retrieval.

Resolves: #1655

- Added `KeysWithFilters` to filter and return a list of matching keys.
- Added `ListKeysWithFilters` to filter keys and return them as an iterable lister.
- Included test cases for both methods to validate filtering logic and key retrieval.
@Jarema Jarema requested a review from piotrpio November 13, 2024 12:27
Copy link
Collaborator

@piotrpio piotrpio left a comment

Choose a reason for hiding this comment

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

Hello @somratdutta, thank you for the contribution and sorry it took so long to review this. There are a few issues with this PR and it'll be easier to list them in a single comment rather than commenting on individual lines:

  1. The filtering should not be done client-side, for a few reasons. Firstly, it is not efficient as you're fetching all keys from the server, even if you're interested in 1% of them based on the provided filter. Secondly, the filter you apply will not work with wildcards, which users should be able to provide. For filtering, we should leverage the FilterSubjects field on ConsumerConfig and let the server do the work and simply return results to the user.
    That presents another issue unfortunately. While you can add a single filter to Watch() and use it to filter the keys (instead of WatchAll()), there currently is no version of Watch() which accepts multiple filters.

  2. We agreed internally that we don't really want to bloat the API with too many new methods, so we settled on adding a single one: ListKeysFiltered(ctx context.Context, filters ...string) (KeyLister, error). This will allow us to add 0 or more keys easily and iterate over results in efficient way (not having to allocate memory for all keys at once if there are many of them). Also in this new method WatchOpt can be dropped as it does not really contribute to the result.

I understand that this was not properly outlined in the related issue, apologies for that. Here's my proposal - I'll work on adding a watcher which can accept multiple filters (it should not take longer than 1-2 days I hope) and after it's done you'll be able to rework this PR to use this new API - obviously if you're still willing to.

@somratdutta
Copy link
Author

somratdutta commented Nov 14, 2024

Thanks, @piotrpio for the detailed feedback on the PR.
I now get the approach and it makes a lot of sense.
I would love to still work on it as I have previously worked on many NATS-related PRs.
FYI : I am currently working on adding Jetstream support to Nats-Flink connector 😄

@piotrpio
Copy link
Collaborator

Hello @somratdutta! We've merged the PR for WatchFiltered (#1739) so you can continue with this PR now :)

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.

Add KeysWithFilter methods to KV interface
2 participants