|
| 1 | +/// A keyvalue interface that provides eventually consistent batch operations. |
| 2 | +/// |
| 3 | +/// A batch operation is an operation that operates on multiple keys at once. |
| 4 | +/// |
| 5 | +/// Batch operations are useful for reducing network round-trip time. For example, |
| 6 | +/// if you want to get the values associated with 100 keys, you can either do 100 get |
| 7 | +/// operations or you can do 1 batch get operation. The batch operation is |
| 8 | +/// faster because it only needs to make 1 network call instead of 100. |
| 9 | +/// |
| 10 | +/// A batch operation does not guarantee atomicity, meaning that if the batch |
| 11 | +/// operation fails, some of the keys may have been modified and some may not. |
| 12 | +/// Transactional operations are being worked on and will be added in the future to |
| 13 | +/// provide atomicity. |
| 14 | +/// |
| 15 | +/// Data consistency in a key value store refers to the gaurantee that once a |
| 16 | +/// write operation completes, all subsequent read operations will return the |
| 17 | +/// value that was written. |
| 18 | +/// |
| 19 | +/// The level of consistency in batch operations is **eventual consistency**, the same |
| 20 | +/// with the readwrite interface. This interface does not guarantee strong consistency, |
| 21 | +/// meaning that if a write operation completes, subsequent read operations may not return |
| 22 | +/// the value that was written. |
| 23 | +interface eventual-batch { |
| 24 | + /// A keyvalue interface that provides batch get operations. |
| 25 | + use types.{bucket, error, key, incoming-value, outgoing-value}; |
| 26 | + |
| 27 | + /// Get the values associated with the keys in the bucket. It returns a list of |
| 28 | + /// incoming-value that can be consumed to get the value associated with the key. |
| 29 | + /// |
| 30 | + /// If any of the keys do not exist in the bucket, it returns a `none` value for |
| 31 | + /// that key in the list. |
| 32 | + /// |
| 33 | + /// Note that the key-value pairs are guaranteed to be returned in the same order |
| 34 | + /// |
| 35 | + /// MAY show an out-of-date value if there are concurrent writes to the bucket. |
| 36 | + /// |
| 37 | + /// If any other error occurs, it returns an `Err(error)`. |
| 38 | + get-many: func(bucket: borrow<bucket>, keys: list<key>) -> result<list<option<incoming-value>>, error>; |
| 39 | + |
| 40 | + /// Get all the keys in the bucket. It returns a list of keys. |
| 41 | + /// |
| 42 | + /// Note that the keys are not guaranteed to be returned in any particular order. |
| 43 | + /// |
| 44 | + /// If the bucket is empty, it returns an empty list. |
| 45 | + /// |
| 46 | + /// MAY show an out-of-date list of keys if there are concurrent writes to the bucket. |
| 47 | + /// |
| 48 | + /// If any error occurs, it returns an `Err(error)`. |
| 49 | + keys: func(bucket: borrow<bucket>) -> result<list<key>, error>; |
| 50 | + |
| 51 | + /// Set the values associated with the keys in the bucket. If the key already |
| 52 | + /// exists in the bucket, it overwrites the value. |
| 53 | + /// |
| 54 | + /// Note that the key-value pairs are not guaranteed to be set in the order |
| 55 | + /// they are provided. |
| 56 | + /// |
| 57 | + /// If any of the keys do not exist in the bucket, it creates a new key-value pair. |
| 58 | + /// |
| 59 | + /// If any other error occurs, it returns an `Err(error)`. When an error occurs, it |
| 60 | + /// does not rollback the key-value pairs that were already set. Thus, this batch operation |
| 61 | + /// does not guarantee atomicity, implying that some key-value pairs could be |
| 62 | + /// set while others might fail. |
| 63 | + /// |
| 64 | + /// Other concurrent operations may also be able to see the partial results. |
| 65 | + set-many: func(bucket: borrow<bucket>, key-values: list<tuple<key, borrow<outgoing-value>>>) -> result<_, error>; |
| 66 | + |
| 67 | + /// Delete the key-value pairs associated with the keys in the bucket. |
| 68 | + /// |
| 69 | + /// Note that the key-value pairs are not guaranteed to be deleted in the order |
| 70 | + /// they are provided. |
| 71 | + /// |
| 72 | + /// If any of the keys do not exist in the bucket, it skips the key. |
| 73 | + /// |
| 74 | + /// If any other error occurs, it returns an `Err(error)`. When an error occurs, it |
| 75 | + /// does not rollback the key-value pairs that were already deleted. Thus, this batch operation |
| 76 | + /// does not guarantee atomicity, implying that some key-value pairs could be |
| 77 | + /// deleted while others might fail. |
| 78 | + /// |
| 79 | + /// Other concurrent operations may also be able to see the partial results. |
| 80 | + delete-many: func(bucket: borrow<bucket>, keys: list<key>) -> result<_, error>; |
| 81 | +} |
0 commit comments