Skip to content

Commit 35b2843

Browse files
committed
Ephemerals
1 parent 9ee8184 commit 35b2843

File tree

2 files changed

+112
-2
lines changed

2 files changed

+112
-2
lines changed

src/content/clients/go.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ Available client options include:
7676
```go
7777
// Write a record to Oxia with the specified key and value, and with the expectation
7878
// that the record does not already exist.
79-
insertedKey1, res1, err := client.Put(context.Background(), "/my-key", []byte("value-1"), ExpectedRecordNotExists())
79+
insertedKey1, res1, err := client.Put(context.Background(), "my-key", []byte("value-1"), oxia.ExpectedRecordNotExists())
8080

8181
// Write a record with the expectation that it has not changed since the previous write.
8282
// If there was any change, the operation will fail
83-
insertedKey2, res2, err := client.Put(context.Background(), "/my-key", []byte("value-2"), ExpectedVersionId(res1.VersionId))
83+
insertedKey2, res2, err := client.Put(context.Background(), "my-key", []byte("value-2"), oxia.ExpectedVersionId(res1.VersionId))
8484
```
8585
</Tabs.Tab>
8686
<Tabs.Tab>
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
sidebarTitle: Ephemerals
3+
---
4+
5+
import {Tabs} from 'nextra/components'
6+
7+
# Ephemeral records
8+
9+
Oxia records can be optionally marked as *ephemerals*.
10+
11+
Ephemeral records have their lifecycle tied to a particular client instance, and they
12+
are automatically deleted when the client instance is closed.
13+
These records are also deleted if the client cannot communicate with the Oxia
14+
service for some extended amount of time, and the session between the client and
15+
the service "expires".
16+
17+
Application can control the session behavior by setting the session timeout
18+
appropriately with [WithSessionTimeout] option when creating the client instance.
19+
20+
Oxia can partition the data in different namespaces. Application can use namespaces to isolate different use cases
21+
and also have more visibility in the metrics, which are going to be labeled with the namespace as well.
22+
23+
Each namespace has its own independent key-space and set of shards.
24+
25+
## Use cases
26+
27+
Ephemeral records can be used to implement many system coordination tasks, such as:
28+
29+
1. Service discovery
30+
2. Leader election
31+
3. Distributed resource locks
32+
33+
## Using ephemeral records
34+
35+
When creating/modifying a record, applications can specify the "ephemeral" option:
36+
37+
<Tabs items={['Go', 'Java']}>
38+
<Tabs.Tab>
39+
```go
40+
insertedKey, res, err := client.Put(context.Background(),
41+
"my-key", []byte("my-value"),
42+
oxia.Ephemeral())
43+
```
44+
</Tabs.Tab>
45+
<Tabs.Tab>
46+
```java
47+
PutResult pr = client.put("my-key", "my-value".getBytes(),
48+
Set.of(PutOption.AsEphemeralRecord));
49+
```
50+
</Tabs.Tab>
51+
</Tabs>
52+
53+
54+
## Oxia session management
55+
56+
An ephemeral record is tied to a particular session. Oxia client SDK will automatically
57+
create a session the first time there is an attempt to write ephemeral records.
58+
59+
The session is internally managed by the client SDK, which will also take care of the
60+
heartbeat communications with the server.
61+
62+
A session is deleted when:
63+
64+
1. Client instance is gracefully closed, deleting the session
65+
2. Client crashed, causing the Oxia server to expire the session
66+
3. Client is partitioned from Oxia, causing the Oxia server to expire the session
67+
68+
When a session is deleted or expired, all the ephemeral records tied to that session
69+
are automatically deleted.
70+
71+
If a client is subscribed to the notifications, it will receive the corresponding events.
72+
73+
In case of network partitioning, the client SDK is internally proceeding to create a
74+
new session.
75+
76+
### Session ID and client identity
77+
78+
A client can optionally specify a client identifier that will be tied to the session.
79+
80+
<Tabs items={['Go', 'Java']}>
81+
<Tabs.Tab>
82+
```go
83+
client, err := oxia.NewClient("localhost:6648", oxia.WithIdentity("my-client-identity"))
84+
```
85+
</Tabs.Tab>
86+
<Tabs.Tab>
87+
```java
88+
SyncOxiaClient client = OxiaClientBuilder.create("localhost:6648")
89+
.clientIdentifier("my-client-identifier")
90+
.syncClient();
91+
```
92+
</Tabs.Tab>
93+
</Tabs>
94+
95+
The client identity is stored as part of the version object, for ephemeral records, and will
96+
allow applications to detect ephemeral records that were written by the same logical client
97+
instance before a crash.
98+
99+
```json
100+
{
101+
"key": "my-key",
102+
"version_id": 2145,
103+
"created_timestamp": "2025-06-22T10:21:00.107-07:00",
104+
"modified_timestamp": "2025-06-22T10:21:00.107-07:00",
105+
"modifications_count": 0,
106+
"ephemeral": true,
107+
"session_id": 1677,
108+
"client_identity": "my-client-identity"
109+
}
110+
```

0 commit comments

Comments
 (0)