Open marshall-lee opened 3 years ago
It's worth to mention @fspmarshall
While something like this could definitely be added, there is a fairly simple workaround that should achieve this behavior:
So long as there is at least one key that always exists when the data is set, you can "expect" that key as the empty string (which we treat as expecting the key to not exist). If there is not one key that always exists, then a sentinel key can be used for this purpose.
Description
What happened:
I started to use
SetPluginData
extensively and realized that it's impossible to callSetPluginData
atomically in a "create-if-empty" manner.The reason is that I cannot pass empty
Expect
parameter. When serializing, protobuf doesn't make a difference between empty map andnil
map. Given that Teleport treatsnil
expectation as an ignore of compare-and-swap semantics, I don't get a desired result — compare-with-empty-and-swap.What you expected to happen:
I expect this code not to be prone to race conditions:
Wonder what a solution here would be. Maybe add some new parameter like
IfEmpty: true
or do some magic with serialization ofExpect
.