etcd icon indicating copy to clipboard operation
etcd copied to clipboard

Adding Producer-Consumer Semantics to Watch API?

Open HardySimpson opened this issue 10 years ago • 12 comments

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

HardySimpson avatar Jul 14 '16 07:07 HardySimpson

@alfred-huangjian @kevin-wangzefeng @magicwang-cn

HardySimpson avatar Jul 14 '16 07:07 HardySimpson

@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?

alfred-huangjian avatar Jul 14 '16 07:07 alfred-huangjian

This sounds unreliable-- what happens if B receives an event on a channel shared with A but crashes before it can process it?

heyitsanthony avatar Jul 14 '16 16:07 heyitsanthony

@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.

xiang90 avatar Jul 14 '16 16:07 xiang90

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 avatar Jul 14 '16 16:07 xiang90

@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.

heyitsanthony avatar Jul 14 '16 17:07 heyitsanthony

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.

xiang90 avatar Jul 14 '16 17:07 xiang90

@HardySimpson Can you answer questions @heyitsanthony and I have?

xiang90 avatar Jul 27 '16 22:07 xiang90

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.

HardySimpson avatar Jul 28 '16 04:07 HardySimpson

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

HardySimpson avatar Jul 28 '16 05:07 HardySimpson

another idea, can use consistent hashing to distribute object among clients

HardySimpson avatar Aug 12 '16 08:08 HardySimpson

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.

heyitsanthony avatar May 26 '17 17:05 heyitsanthony