Skip to content

Commit f857b78

Browse files
committed
feat: support versioning
1 parent 35b2843 commit f857b78

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"1.3.0","languages":{"en":{"hash":"en_ab77e913d5","wasm":"en","page_count":13}}}
1+
{"version":"1.3.0","languages":{"en":{"hash":"en_7f1b21347c","wasm":"en","page_count":19}}}

public/features/versioning.png

175 KB
Loading
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import {Tabs} from 'nextra/components'
2+
3+
# Versioning
4+
5+
![versioning](/features/versioning.png)
6+
7+
Oxia will assign a version to all mutable operations, excluding those using put with`SequenceKeysDeltas.`
8+
9+
Therefore, you can use this assigned version as the expected value for subsequent mutable operations to support `CompareThenSet-like` atomic operations.
10+
11+
## Use cases
12+
13+
The versioning is usually used for **Optimistic Concurrency Control (OCC)**. Instead of locking resources, each item has a version number. When you read an item, you get its version. When you try to update it, you send back the version you read. If the version on the server doesn't match, it means someone else updated the item in the interim, and your `put` fails. You then typically retry the operation by re-reading the latest version.
14+
15+
16+
## Using Versioning
17+
18+
<Tabs items={['Go', 'Java']}>
19+
<Tabs.Tab>
20+
```go
21+
// read version
22+
key, value, version, err := client.Get(context.Background(), "/my-key")
23+
if err != nil {
24+
log.Fatal(err)
25+
}
26+
// case-1: expect not exists
27+
_, res1, err := client.Put(context.Background(), "/my-key", []byte("value-1"), ExpectedRecordNotExists())
28+
if err != nil {
29+
log.Fatal(err)
30+
}
31+
// case-2: expect by version
32+
_, _, err = client.Put(context.Background(), "/my-key", []byte("value-2"), ExpectedVersionId(version))
33+
if err != nil {
34+
log.Fatal(err)
35+
}
36+
```
37+
</Tabs.Tab>
38+
<Tabs.Tab>
39+
```java
40+
// read version
41+
var result = client.get("a");
42+
43+
// case-1: expect not exist
44+
var result = client.put("a", "a2".getBytes(UTF_8), Set.of(IfRecordDoesNotExist);
45+
46+
// case-2: expect by version
47+
var result = client.put("a", "a2".getBytes(UTF_8), Set.of(IfVersionIdEquals(version)));
48+
```
49+
</Tabs.Tab>
50+
</Tabs>

0 commit comments

Comments
 (0)