Skip to content

Commit 5b9b548

Browse files
committed
Update CAS interface to remove current and add new-with-read
Signed-off-by: Darwin Boersma <[email protected]>
1 parent da58d54 commit 5b9b548

File tree

5 files changed

+47
-33
lines changed

5 files changed

+47
-33
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ This proposal was inspired by Dapr's [State API]
120120
[State API](https://docs.dapr.io/developing-applications/building-blocks/state-management/)
121121

122122
### Change log
123-
123+
- 2025-03-29:
124+
- Modified `atomics` interface signature
124125
- 2024-03-29:
125126
- Simplified interfaces to 3 key pieces of functionality: store, atomics, and batch. Also removed
126127
the use of streams to simplify the starting point of the API

imports.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ Components targeting this world will be able to do:</p>
99
<ul>
1010
<li>Imports:
1111
<ul>
12-
<li>interface <a href="#wasi_keyvalue_store_0_2_0_draft2"><code>wasi:keyvalue/[email protected]draft2</code></a></li>
13-
<li>interface <a href="#wasi_keyvalue_atomics_0_2_0_draft2"><code>wasi:keyvalue/[email protected]draft2</code></a></li>
14-
<li>interface <a href="#wasi_keyvalue_batch_0_2_0_draft2"><code>wasi:keyvalue/[email protected]draft2</code></a></li>
12+
<li>interface <a href="#wasi_keyvalue_store_0_2_0_draft3"><code>wasi:keyvalue/[email protected]draft3</code></a></li>
13+
<li>interface <a href="#wasi_keyvalue_atomics_0_2_0_draft3"><code>wasi:keyvalue/[email protected]draft3</code></a></li>
14+
<li>interface <a href="#wasi_keyvalue_batch_0_2_0_draft3"><code>wasi:keyvalue/[email protected]draft3</code></a></li>
1515
</ul>
1616
</li>
1717
</ul>
18-
<h2><a id="wasi_keyvalue_store_0_2_0_draft2"></a>Import interface wasi:keyvalue/[email protected]draft2</h2>
18+
<h2><a id="wasi_keyvalue_store_0_2_0_draft3"></a>Import interface wasi:keyvalue/[email protected]draft3</h2>
1919
<p>A keyvalue interface that provides eventually consistent key-value operations.</p>
2020
<p>Each of these operations acts on a single key-value pair.</p>
2121
<p>The value in the key-value pair is defined as a <code>u8</code> byte array and the intention is that it is
@@ -178,7 +178,7 @@ for more information.</p>
178178
<ul>
179179
<li><a id="method_bucket_list_keys.0"></a> result&lt;<a href="#key_response"><a href="#key_response"><code>key-response</code></a></a>, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
180180
</ul>
181-
<h2><a id="wasi_keyvalue_atomics_0_2_0_draft2"></a>Import interface wasi:keyvalue/[email protected]draft2</h2>
181+
<h2><a id="wasi_keyvalue_atomics_0_2_0_draft3"></a>Import interface wasi:keyvalue/[email protected]draft3</h2>
182182
<p>A keyvalue interface that provides atomic operations.</p>
183183
<p>Atomic operations are single, indivisible operations. When a fault causes an atomic operation to
184184
fail, it will appear to the invoker of the atomic operation that the action either completed
@@ -226,16 +226,17 @@ latest version or transaction.
226226
<ul>
227227
<li><a id="static_cas_new.0"></a> result&lt;own&lt;<a href="#cas"><a href="#cas"><code>cas</code></a></a>&gt;, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
228228
</ul>
229-
<h4><a id="method_cas_current"></a><code>[method]cas.current: func</code></h4>
230-
<p>Get the current value of the key (if it exists). This allows for avoiding reads if all
231-
that is needed to ensure the atomicity of the operation</p>
229+
<h4><a id="static_cas_new_with_read"></a><code>[static]cas.new_with_read: func</code></h4>
230+
<p>Construct a new CAS operation returning the current value. Implementors can map the underlying functionality
231+
(transactions, versions, etc) as desired.</p>
232232
<h5>Params</h5>
233233
<ul>
234-
<li><a id="method_cas_current.self"></a><code>self</code>: borrow&lt;<a href="#cas"><a href="#cas"><code>cas</code></a></a>&gt;</li>
234+
<li><a id="static_cas_new_with_read.bucket"></a><a href="#bucket"><code>bucket</code></a>: borrow&lt;<a href="#bucket"><a href="#bucket"><code>bucket</code></a></a>&gt;</li>
235+
<li><a id="static_cas_new_with_read.key"></a><code>key</code>: <code>string</code></li>
235236
</ul>
236237
<h5>Return values</h5>
237238
<ul>
238-
<li><a id="method_cas_current.0"></a> result&lt;option&lt;list&lt;<code>u8</code>&gt;&gt;, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
239+
<li><a id="static_cas_new_with_read.0"></a> result&lt;own&lt;<a href="#cas"><a href="#cas"><code>cas</code></a></a>&gt;, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
239240
</ul>
240241
<h4><a id="increment"></a><code>increment: func</code></h4>
241242
<p>Atomically increment the value associated with the key in the store by the given delta. It
@@ -265,7 +266,7 @@ the CAS operation failed.</p>
265266
<ul>
266267
<li><a id="swap.0"></a> result&lt;_, <a href="#cas_error"><a href="#cas_error"><code>cas-error</code></a></a>&gt;</li>
267268
</ul>
268-
<h2><a id="wasi_keyvalue_batch_0_2_0_draft2"></a>Import interface wasi:keyvalue/[email protected]draft2</h2>
269+
<h2><a id="wasi_keyvalue_batch_0_2_0_draft3"></a>Import interface wasi:keyvalue/[email protected]draft3</h2>
269270
<p>A keyvalue interface that provides batch operations.</p>
270271
<p>A batch operation is an operation that operates on multiple keys at once.</p>
271272
<p>Batch operations are useful for reducing network round-trip time. For example, if you want to

watch-service.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
<ul>
33
<li>Imports:
44
<ul>
5-
<li>interface <a href="#wasi_keyvalue_store_0_2_0_draft2"><code>wasi:keyvalue/[email protected]draft2</code></a></li>
6-
<li>interface <a href="#wasi_keyvalue_atomics_0_2_0_draft2"><code>wasi:keyvalue/[email protected]draft2</code></a></li>
7-
<li>interface <a href="#wasi_keyvalue_batch_0_2_0_draft2"><code>wasi:keyvalue/[email protected]draft2</code></a></li>
5+
<li>interface <a href="#wasi_keyvalue_store_0_2_0_draft3"><code>wasi:keyvalue/[email protected]draft3</code></a></li>
6+
<li>interface <a href="#wasi_keyvalue_atomics_0_2_0_draft3"><code>wasi:keyvalue/[email protected]draft3</code></a></li>
7+
<li>interface <a href="#wasi_keyvalue_batch_0_2_0_draft3"><code>wasi:keyvalue/[email protected]draft3</code></a></li>
88
</ul>
99
</li>
1010
<li>Exports:
1111
<ul>
12-
<li>interface <a href="#wasi_keyvalue_watcher_0_2_0_draft2"><code>wasi:keyvalue/[email protected]draft2</code></a></li>
12+
<li>interface <a href="#wasi_keyvalue_watcher_0_2_0_draft3"><code>wasi:keyvalue/[email protected]draft3</code></a></li>
1313
</ul>
1414
</li>
1515
</ul>
16-
<h2><a id="wasi_keyvalue_store_0_2_0_draft2"></a>Import interface wasi:keyvalue/[email protected]draft2</h2>
16+
<h2><a id="wasi_keyvalue_store_0_2_0_draft3"></a>Import interface wasi:keyvalue/[email protected]draft3</h2>
1717
<p>A keyvalue interface that provides eventually consistent key-value operations.</p>
1818
<p>Each of these operations acts on a single key-value pair.</p>
1919
<p>The value in the key-value pair is defined as a <code>u8</code> byte array and the intention is that it is
@@ -176,7 +176,7 @@ for more information.</p>
176176
<ul>
177177
<li><a id="method_bucket_list_keys.0"></a> result&lt;<a href="#key_response"><a href="#key_response"><code>key-response</code></a></a>, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
178178
</ul>
179-
<h2><a id="wasi_keyvalue_atomics_0_2_0_draft2"></a>Import interface wasi:keyvalue/[email protected]draft2</h2>
179+
<h2><a id="wasi_keyvalue_atomics_0_2_0_draft3"></a>Import interface wasi:keyvalue/[email protected]draft3</h2>
180180
<p>A keyvalue interface that provides atomic operations.</p>
181181
<p>Atomic operations are single, indivisible operations. When a fault causes an atomic operation to
182182
fail, it will appear to the invoker of the atomic operation that the action either completed
@@ -224,16 +224,17 @@ latest version or transaction.
224224
<ul>
225225
<li><a id="static_cas_new.0"></a> result&lt;own&lt;<a href="#cas"><a href="#cas"><code>cas</code></a></a>&gt;, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
226226
</ul>
227-
<h4><a id="method_cas_current"></a><code>[method]cas.current: func</code></h4>
228-
<p>Get the current value of the key (if it exists). This allows for avoiding reads if all
229-
that is needed to ensure the atomicity of the operation</p>
227+
<h4><a id="static_cas_new_with_read"></a><code>[static]cas.new_with_read: func</code></h4>
228+
<p>Construct a new CAS operation returning the current value. Implementors can map the underlying functionality
229+
(transactions, versions, etc) as desired.</p>
230230
<h5>Params</h5>
231231
<ul>
232-
<li><a id="method_cas_current.self"></a><code>self</code>: borrow&lt;<a href="#cas"><a href="#cas"><code>cas</code></a></a>&gt;</li>
232+
<li><a id="static_cas_new_with_read.bucket"></a><a href="#bucket"><code>bucket</code></a>: borrow&lt;<a href="#bucket"><a href="#bucket"><code>bucket</code></a></a>&gt;</li>
233+
<li><a id="static_cas_new_with_read.key"></a><code>key</code>: <code>string</code></li>
233234
</ul>
234235
<h5>Return values</h5>
235236
<ul>
236-
<li><a id="method_cas_current.0"></a> result&lt;option&lt;list&lt;<code>u8</code>&gt;&gt;, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
237+
<li><a id="static_cas_new_with_read.0"></a> result&lt;own&lt;<a href="#cas"><a href="#cas"><code>cas</code></a></a>&gt;, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
237238
</ul>
238239
<h4><a id="increment"></a><code>increment: func</code></h4>
239240
<p>Atomically increment the value associated with the key in the store by the given delta. It
@@ -263,7 +264,7 @@ the CAS operation failed.</p>
263264
<ul>
264265
<li><a id="swap.0"></a> result&lt;_, <a href="#cas_error"><a href="#cas_error"><code>cas-error</code></a></a>&gt;</li>
265266
</ul>
266-
<h2><a id="wasi_keyvalue_batch_0_2_0_draft2"></a>Import interface wasi:keyvalue/[email protected]draft2</h2>
267+
<h2><a id="wasi_keyvalue_batch_0_2_0_draft3"></a>Import interface wasi:keyvalue/[email protected]draft3</h2>
267268
<p>A keyvalue interface that provides batch operations.</p>
268269
<p>A batch operation is an operation that operates on multiple keys at once.</p>
269270
<p>Batch operations are useful for reducing network round-trip time. For example, if you want to
@@ -342,7 +343,7 @@ fail.</p>
342343
<ul>
343344
<li><a id="delete_many.0"></a> result&lt;_, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
344345
</ul>
345-
<h2><a id="wasi_keyvalue_watcher_0_2_0_draft2"></a>Export interface wasi:keyvalue/[email protected]draft2</h2>
346+
<h2><a id="wasi_keyvalue_watcher_0_2_0_draft3"></a>Export interface wasi:keyvalue/[email protected]draft3</h2>
346347
<hr />
347348
<h3>Types</h3>
348349
<h4><a id="bucket"></a><code>type bucket</code></h4>

wit/atomic.wit

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,30 @@ interface atomics {
1616
/// A store error occurred when performing the operation
1717
store-error(error),
1818
/// The CAS operation failed because the value was too old. This returns a new CAS handle
19-
/// for easy retries. Implementors MUST return a CAS handle that has been updated to the
19+
/// for easy retries, as well as the current value for comparison. Implementors MUST return a CAS handle that has been updated to the
2020
/// latest version or transaction.
21-
cas-failed(cas),
21+
cas-failed(tuple<cas,option<list<u8>>>),
2222
}
2323

2424
/// A handle to a CAS (compare-and-swap) operation.
2525
resource cas {
26-
/// Construct a new CAS operation. Implementors can map the underlying functionality
27-
/// (transactions, versions, etc) as desired.
26+
/// Construct a new CAS handle for `key`.
27+
///
28+
/// This handle should guarantee that a subsequent `swap` operation will operate on data that has
29+
/// not been modified since this call. If that condition is not met, `swap` should return `error`.
30+
///
31+
/// Note that this handle does not necessarily guarantee that no other operations occur on the key
32+
/// after the handle is created, only that `error` is returned when calling `swap` if other operations did occur.
2833
new: static func(bucket: borrow<bucket>, key: string) -> result<cas, error>;
29-
/// Get the current value of the key (if it exists). This allows for avoiding reads if all
30-
/// that is needed to ensure the atomicity of the operation
31-
current: func() -> result<option<list<u8>>, error>;
34+
35+
/// Construct a new CAS handle returning the current value of `key`.
36+
///
37+
/// This handle should guarantee that a subsequent `swap` operation will operate on data that has
38+
/// not been modified since this call. If that condition is not met, `swap` should return `error`.
39+
///
40+
/// Note that this handle does not necessarily guarantee that no other operations occur on the key
41+
/// after the handle is created, only that `error` is returned when calling `swap` if other operations did occur.
42+
new-with-read: static func(bucket: borrow<bucket>, key: string) -> result<tuple<cas, option<list<u8>>>, error>;
3243
}
3344

3445
/// Atomically increment the value associated with the key in the store by the given delta. It

wit/world.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package wasi:keyvalue@0.2.0-draft2;
1+
package wasi:keyvalue@0.2.0-draft3;
22

33
/// The `wasi:keyvalue/imports` world provides common APIs for interacting with key-value stores.
44
/// Components targeting this world will be able to do:

0 commit comments

Comments
 (0)