Adding Producer-Consumer Semantics to Watch API?
the watch api now support Pub-Sub Semantics, as any client can sub whatever data they interested in and sync all the data in client's local memory.
That's cool. Still, when client is not only want to read the data, but also want to consume it, problem appears.
The origin problem comes from scheduler of k8s. When there is just one scheduler consume unscheduled pods, and schedule it, that's all right, but if there are many scheduler processes want to consume unscheduled pods, it is not possible. Because:
Scheduler A ---watch----> pod(unscheduled)
Scheduler B ---watch----> pod(unscheduled)
then
Scheduler A get pod 1, pod 2 ...
Scheduler B get pod 1, pod 2 ....
So, is there any possible to make Scheduler A &B watch the same pipe, and get pod alternately?
Scheduler A get pod 1, pod 3 ...
Scheduler B get pod 2, pod 4 ....
the responding api may look like this
curl http://127.0.0.1:2379/v2/keys/foo?wait=true&channel=1
@alfred-huangjian @kevin-wangzefeng @magicwang-cn
@xiang90 We are thinking whether Etcd can support such Producer-Consumer Mode in Watch API. Above is an example for scheduler. However we also meet some requirements for processing the object changes in multiple clients as currently we can only use active-standby mode for such applications. Can you help to take a look at this?
This sounds unreliable-- what happens if B receives an event on a channel shared with A but crashes before it can process it?
@heyitsanthony It can come back and get the event again. We should not keep any reliable state for watchers. Also we only guarantees that the "new" event will deliver to one of the watchers that share same channelID. This is just an optimization, application still needs to de-dup if they start to watch on old revision.
Also they need to expect crash recovery... it might take long, since it needs to wait for the old server to come back to grab the event again. Or the event will be lost.
@xiang90 sure, I wasn't suggesting adding state to the watchers. It seems to me that this style of watcher (at the etcd level) would be very difficult to coordinate among distributed clients on the application side if you don't want to lose events. High potential for bugs for what appears to be a somewhat minor optimization.
High potential for bugs for what appears to be a somewhat minor optimization.
I agree. If the the number of watchers on the same channel is small, it does not worth it. Probably simple client side filtering would be easier. Client's need to do de-dup, failure recovery even if we add the feature. If the fan out is huge (like 1000s of workers), then it would worth the effort if users do not want implement their client/server mode.
@HardySimpson Can you answer questions @heyitsanthony and I have?
OK, as it is a produce-consume model. the recovery of client should not be considered by etcd server. client must guarantee the message process idempotency.
Think another way for crash recovery.
etcd server -watch-> clientA , obj1, obj3
then server should create another TTL key, like
obj1_done(ttl =5), obj2_done(ttl=5)
if clientA will not update obj1 and obj3 in 5 seconds, then server can send obj1 and obj3 to any other client
maybe it is a little wordy, but can guarantee obj send to other client
another idea, can use consistent hashing to distribute object among clients
Closing since this seems unreliable in general and can probably be done client-side through application logic so it doesn't need explicit etcd support.