I'm using Consul for service discovery and the KV store, with more than 10 nodes. Let's say that each of these nodes has to increment a counter on the same KV, but has to do it atomically. The way I think this should work is the following (using 2 nodes to keep it simple):
- Node A acquires a lock on KV1
- Node B tries to get a lock on KV1 but is blocked
- Node A gets the value, increments it and writes it to the KV
- Node A releases the lock
- Node B is unblocked, can get the value, update it and then write it
Is this possible using Hashicorp Consul? I think it can be achieved using sessions, but I didn't find a lot of resources on it.