Add POC for discussion around CAS method on backends #5356
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is more of a POC than a PR, but I find it easiest to discuss in code.
One of the challenges with initialization currently is that if two Vault servers simultaneously try to initialize the same storage backend, there's a race and they might both initialize, overwriting the other one. Then you have Vault servers with in-memory keys that they think are correct, but have actually been overwritten by another Vault server that tried to initialize at the same time.
As such, I propose added a
PutCAS
method on physical.Backend (in the form of an optionally implemented interface). If implemented, operations like init would use this CAS operation instead of the regular put operation. This would prevent overwriting and would at least return an error (that we could retry on).While the init function does first check if the backend is initialized before proceeding, it's possible that another backend initializes between that check and when the actual initialization call is made a few lines down. Adding a CAS method that backends could implement would make some backends safer to start a collection of Vault servers in parallel.
/cc @jefferai @chrishoffman