hashicorp / hashicorp/consul

KV put should return ModifyIndex to allow for optimistic locking

Open
#14,258 0 comments 7 reactions 0 assignees View on GitHub
theme/kv type/enhancement
Dominant language
Go
Stars
30.1k
Forks
4.6k
Avg merge
1d 18h
Merged PRs (30d)
39

Description

Consul KVs seem like a good fit for counters that need to be sequential cluster wide. This can be implemented using PUT with the "cas" option set to the last known values ModifyIndex when updating the counter value. Unfortunately this seems to always require re-fetching the current value to get access to the current ModifyIndex, even if no other updates have occurred, as there is apparently no way for the successful PUT operation to return the new ModifyIndex and it's not reliably predictable either.

If the PUT operation were to return the new ModifyIndex, either as JSON or as an additional header, it would be possible to optimistically update the value without refetching, in cases where concurrent updates are rare. I doubt you'll be eager to change the return value of PUT, as it would break existing code, but adding an additional "X-Consul-ModifyIndex" should not be disruptive. This header could also be added for GETs, then the "raw" option could be used in this case and Base64+JSON coding of the value could be avoided. (You may want to add the other fields from the JSON response as headers as well for consistency.)

Contributor guide

Open the contributing guide

Research direction

Start by locating the Consul KV PUT and GET API entry points and reviewing how ModifyIndex is currently exposed in the JSON response. Determine the compatible response or header behavior for successful writes and raw reads, then add coverage for the returned index and confirm existing clients remain unaffected.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, distributed-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.