-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Semantics of atomic.increment
with other methods; value type system
#51
Comments
I like the idea of a value type system you brought up in this issue, which obviously adds more complexity to the implementation. I am also curious to hear what implementors thoughts on this. |
Recently, I have been implementing For example, we do not separate key space between I'm also not sure we need to use For example, if we were to wrap all values with a metadata wrapper like the following I agree there is a problem. Let's figure out the best way to solve it. |
My current approach to this is that you shouldn't do So my opinion is that this is something we should try to document, but not to solve |
dIn all operations on a keyvalue store, the type of a value is given by
list<u8>
.atomic.increment
is the one exception where the value is passed in as ans64
and returned as ans64
. Withincrement
I can create a news64
value for a key not in the store, modify by adding ans64
, and retrieve the currents64
if I pass in a delta of0
.The spec for
atomic.increment
needs to describe how the value associated with this key interacts with all of the other operations on the store. This is tricky because many underlying implementations of a store have a more complicated type system than representing every value as just a binary bloblist<u8>
, and only make operations like atomic addition available on types that were stored as numbers, rather than as blobs.One possible path for the spec is, if the value in
bucket.set
to a byte sequence which, as ascii, parses to a base 10 integer value (optional leading-
, then up to some limit of digits in0-9
) and contains no trailing symbols, the value is considered an numeric value instead of a binary blob. Abucket.get
of the value gives the bytes of the ascii base-10 integer. (If you dont like ascii base 10, you could pick some other encoding of integers here, be it a sequence of 8 bytes with a little-endian 2s complement integer, or EB128 used in the wasm binary format, or whatever else you can dream up - its a big open ended problem). And nowatomic.increment
works on that value, because its a number value, right? You probably want an error variant now for when you useincrement
on a non-number value too.This general path for solving the problem has introduced a phantom datatype system for values - it exists in the semantics of the interface, but it doesn't show up in the syntax.
So then say we introduce some common denominator datatype system that many of these underlying store implementations already have at the keyvalue interface. For example, we could define
variant value { string(string), blob(list<u8>), number(s64) }
and use that in place of all thelist<u8>
s in the set/get methods. This has a lot of advantages - now its very obvious what values are numbers versus which are binary blobs, and it means numbers get to be passed across the interface in an encoding defined by the component model, rather than being solved specifically for this proposal. It also puts this spec in a position where we have to choose our datatype system very carefully to have consistent semantics on the wide range of possible underlying common stores - we already have to do that for at least numbers in order to support increment properly, but now we have the opportunity to support storing other types as well, strings being the most obvious.I think this is a pretty major design problem in the current spec of keyvalue. I'd like to hear what other implementors have done in order to implement
atomic.increment
so far, and what sort of discussion, if any, there has been to date about introducing a value datatype system.The text was updated successfully, but these errors were encountered: