Expand description
Rust client SDK for Oxia, a scalable metadata store and coordination system.
The entry point is OxiaClient. Every operation returns a request builder:
chain options onto it and .await it directly.
use oxia::{ComparisonType, OxiaClient};
let client = OxiaClient::connect("localhost:6648").await?;
// Plain put/get.
let res = client.put("greeting", "hello").await?;
let rec = client.get("greeting").await?;
assert_eq!(rec.value.as_deref(), Some(b"hello".as_ref()));
// Options chain onto the builder.
client
.put("config/a", "1")
.expected_version_id(res.version.version_id)
.await?;
client.put("locks/w1", "").ephemeral().await?;
let floor = client.get("config/z").comparison(ComparisonType::Floor).await?;
// Range operations, as a whole result or as an ordered stream.
let keys = client.list("config/", "config/~").await?;
let mut scan = client.range_scan("config/", "config/~").stream().await?;
client.close().await?;§Concepts
- Records are key/value pairs with a
Versioncarrying the record’s version id and timestamps; conditional operations (expected_version_id) implement compare-and-swap. - Ephemeral records (
PutBuilder::ephemeral) live as long as the client’s session and are removed automatically when it closes or expires. - Partition keys (
PutBuilder::partition_key) co-locate related records on one shard, enabling atomic multi-record batches and server-generated sequential keys (PutBuilder::sequence_key_deltas,OxiaClient::sequence_updates). - Secondary indexes (
PutBuilder::secondary_index) provide alternate query paths for gets, lists and scans (GetBuilder::use_index,ListBuilder::use_index). - Notifications (
OxiaClient::notifications) stream every change applied to the database.
Keys are sorted with Oxia’s slash-aware order (/-separated path segments),
not plain lexicographic order; range boundaries follow it.
§Error handling
Every operation returns OxiaError. Semantic outcomes callers commonly
match on are dedicated variants (OxiaError::KeyNotFound,
OxiaError::UnexpectedVersionId, …); transient infrastructure failures
answer true to OxiaError::is_retryable and are safe to retry —
idempotent operations unconditionally, non-idempotent ones (puts without a
version condition) with application-level judgment. Each operation on
OxiaClient documents the errors it can produce.
The client retries retryable failures internally — re-routing via the leader hints the server attaches to routing errors, re-hashing operations onto the new shard when a shard is split or merged, with exponential backoff, bounded by the request timeout — so the errors you observe are post-retry. One consequence, shared with the reference clients: a write whose batch failed after reaching the wire may be retried even though the server already applied it, so unconditional writes have at-least-once semantics under retries; version-conditioned writes are exactly-once.
§Cancellation
Dropping an operation’s future stops waiting but does not recall an
operation already submitted to a batch; it may still execute on the
server. The recv methods on Notifications and SequenceUpdates
are cancel-safe.
Structs§
- Bytes
- A cheaply cloneable and sliceable chunk of contiguous memory.
- Delete
Builder - A pending
delete, created withOxiaClient::delete. Chain options and.awaitit. - Delete
Range Builder - A pending
delete_range, created withOxiaClient::delete_range. Chain options and.awaitit. - GetBuilder
- A pending
get, created withOxiaClient::get. Chain options and.awaitit. - GetResult
- A record returned by
getorrange_scan. - List
Builder - A pending
list, created withOxiaClient::list. - List
Stream - An ordered stream of keys produced by
ListBuilder::stream. - Notifications
- A subscription to database change notifications, created with
OxiaClient::notifications. - Notifications
Builder - A pending notifications subscription, created with
OxiaClient::notifications..awaitit to obtain theNotificationsstream. - Oxia
Client - The Oxia client.
- Oxia
Client Builder - Configures and creates an
OxiaClient. - PutBuilder
- A pending
put, created withOxiaClient::put. Chain options and.awaitit. - PutResult
- The result of a successful
put. - Range
Scan Builder - A pending
range_scan, created withOxiaClient::range_scan. - Range
Scan Stream - An ordered stream of records produced by
RangeScanBuilder::stream. - Sequence
Updates - A subscription to sequence advances, created with
OxiaClient::sequence_updates. - Sequence
Updates Builder - A pending sequence-updates subscription, created with
OxiaClient::sequence_updates..awaitit to obtain theSequenceUpdatesstream. - Version
- Metadata about the state of a record.
Enums§
- Comparison
Type - The key comparison applied by a
getoperation. - Notification
- A change notification streamed from
OxiaClient::notifications. - Oxia
Error - Errors returned by the Oxia client.