Watch WithPrefix equivalent when replacing etcd with fdb

What is the equivalent to calling Watch with the WithPrefix option argument when using fdb instead of etcd?

The fdb Watch function takes a single KeyConvertible.

I there a way the watch any key that has a particular prefix?

Regards,
Richard

AFAIK, there isn’t a way to do this. What I have done in the past to implement behavior like this is to update another key, using an atomic increment, that represents the prefix whenever a transaction updates something with that prefix and then watch that other key. You would have to do something like this in a layer rather than a direct mapping from the etcd API to FDB api calls.

Until and unless range watches are implemented, the easiest approach is usually what Sam said: have a key at each “level” that you are interested in watching, and ensure that it is updated when anything “inside” is updated.

Other approaches are possible; for example, you could actually keep a table of range watches in an appropriate data structure in the database, check it on every potentially relevant write, and erase any range watch entries that are affected by a write. Then a watcher inserts an entry and watches for it to be removed.

2 Likes