0

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.

1 Answer 1

1

Consider using Consul's check-and-set operation over locks. Assuming all of the apps writing to this KV path are written to use CAS, it will provide protections you're looking for without the added complexity of managing locks.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.