Clarification on watch

The wiki page has a good explanation on watch: https://github.com/apple/foundationdb/wiki/An-Overview-how-Watches-Work [1].

I still have some questions to clarify:

  1. Say DB has k1=v1; Client registers a watch on key k1; Later when the key is updated with the same value, say set(k1,v1), will the watch be triggered?
    (It seems the watch will be triggered based on https://github.com/apple/foundationdb/blob/master/fdbserver/storageserver.actor.cpp#L1891)

  2. If a shard is moved, will the watch inside the shared be triggered?
    I think so because the key will be removed from the storage server as a part of shard movement. This will change the StorageServer->watches;

  3. In the wiki page, it says

Watches are subjected to the ABA-problem: if a value changes twice and after the second update it has the same value as before, the client might not be notified of that update.

Question: This only happens when a watch is registered after the second update. If the watch registration happens before B is applied, the watch will be triggered. Right?

  1. The value of the watch will be checked after that trigger, and if it hasn’t changed the watch won’t fire.

  2. I think this gets bounced out to the client and probably automatically sent to the new location.

  3. I believe this can happen even if the watch is registered before any update, or at least it is allowed by contract.

1 Like

Yeah, you are right. I checked the code again. :slight_smile:

About 2., the watch will be triggered and try to register in the SS, which will throw the wrong_shard_server() error. The error is bounced back to the client (in NativeAPI.actor.cpp) and register the watch from the client.

About 3., because of the reason in 1, if the checking happens later after ABA is executed, then the watch will not be triggered.