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

Watch a path, including the current content #7362

Closed
derekchiang opened this issue Feb 21, 2017 · 4 comments
Closed

Watch a path, including the current content #7362

derekchiang opened this issue Feb 21, 2017 · 4 comments

Comments

@derekchiang
Copy link
Contributor

What is the best way to watch a particular prefix p, while having the stream include the current objects that match the prefix?

I have come up with two approaches so far, neither of which seems ideal:

Approach 1

In this approach, you use the WithRev(0) option with Watch. That way, all events since the beginning of time get returned (other than those already GC-ed).

The downside is that you also get really old events that you don't care about anymore. For instance, if an object was added but subsequently removed, you don't really want to receive the PUT and DELETE events. It'd be ideal if the stream was smart enough to just not tell you about that object at all.

Approach 2

In this approach, you use a Get to get all the current objects first. Then, you issue the Watch with the option WithRev(t) where t is the revision time stamp you got from the Get.

The downside of this approach is that it's cumbersome. You have to use a Get and a Watch.


So I guess my question is, is there a better approach that I'm not aware of, and if not, would it be a good idea to have something like a WithCurrent option built into etcd that would include the current objects in the watch stream?

@heyitsanthony
Copy link
Contributor

heyitsanthony commented Feb 21, 2017

In this approach, you use the WithRev(0) option with Watch. That way, all events since the beginning of time get returned (other than those already GC-ed).

It doesn't work like this. Rev=0 is treated like the current revision + 1-- it will block until the next update.

Approach 2 is the way to do it. It's a little clunky but it better respects the stream semantics of grouping events together as revision updates. This is essentially what Syncer in clientv3/mirror does.

@derekchiang
Copy link
Contributor Author

derekchiang commented Feb 21, 2017

@heyitsanthony oh yeah I think you are right about Rev=0. I seem to remember that when I tried rev=0 it didn't do what I expected, then I tried rev=1 and it worked (i.e. giving me all historical updates). For posterity, could you confirm that using rev=1 would indeed give you all historical updates (barring GC)?

@heyitsanthony
Copy link
Contributor

@derekchiang yes, it will stream all the updates since rev=1. However, using only rev=1 isn't totally reliable since if the store's been compacted, then the watch will fail and return a CompactRevision in the watch response with the earliest available historical revision.

@derekchiang
Copy link
Contributor Author

@heyitsanthony thanks for the clarification. I will close this issue since the clientv3/mirror package (which I wasn't aware of) seems to be a nice solution to this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants