Skip to content

Commit 96bbfcc

Browse files
authored
docs: add doc comments, fix visibility, and polish API (#11)
- Add doc comments to all public option enums, result types, and notification types with descriptions of each variant - Add doc comment with code example to OxiaClientBuilder - Fix DeleteRangeOperation visibility to pub(crate) - Fix ephemeral example: use separate variable after shutdown - Total: 48 tests passing (12 unit + 35 integration + 1 doctest) Signed-off-by: mattisonchao <mattisonchao@gmail.com>
1 parent c831d35 commit 96bbfcc

File tree

4 files changed

+73
-10
lines changed

4 files changed

+73
-10
lines changed

liboxia-native/examples/metadata_ephemeral.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ async fn main() {
1414
.with_target(false)
1515
.init();
1616

17-
let mut client = OxiaClientBuilder::new().build().await.unwrap();
17+
let client = OxiaClientBuilder::new().build().await.unwrap();
1818
let key = String::from("key1");
1919
let payload = "payload".to_string().into_bytes();
2020

@@ -27,13 +27,13 @@ async fn main() {
2727
"put the ephemeral record. key {:?} value {:?} version {:?}",
2828
put_result.key, payload, put_result.version
2929
);
30-
// close the client
30+
// close the client (this closes the session, which should delete ephemeral records)
3131
client.shutdown().await.unwrap();
3232

33-
// create a new client
34-
client = OxiaClientBuilder::new().build().await.unwrap();
35-
let result = client.get(key.clone()).await;
33+
// create a new client and verify the ephemeral record is gone
34+
let client2 = OxiaClientBuilder::new().build().await.unwrap();
35+
let result = client2.get(key.clone()).await;
3636
info!("get the value again. error: {:?}", result.unwrap_err());
3737

38-
client.shutdown().await.unwrap();
38+
client2.shutdown().await.unwrap();
3939
}

liboxia-native/src/client.rs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,45 +28,70 @@ use tokio::task::JoinSet;
2828
use tonic::codegen::tokio_stream::StreamExt;
2929
use tonic::{async_trait, Request};
3030

31+
/// Options for put operations.
3132
pub enum PutOption {
32-
/// Only succeed if the record does not already exist (equivalent to ExpectVersionId(-1))
33+
/// Only succeed if the record does not already exist (equivalent to ExpectVersionId(-1)).
3334
ExpectedRecordNotExists(),
34-
/// Only succeed if the current version matches
35+
/// Only succeed if the current version matches the specified version ID (CAS operation).
3536
ExpectVersionId(i64),
37+
/// Override partition routing. Records with the same partition key are co-located on the same shard.
3638
PartitionKey(String),
39+
/// Server-assigned atomic sequential keys. The key will get added suffixes based on
40+
/// adding the delta to the current highest key with the same prefix.
3741
SequenceKeyDelta(Vec<u64>),
42+
/// Associate secondary indexes with the record for alternative query paths.
3843
SecondaryIndexes(Vec<SecondaryIndex>),
44+
/// Create an ephemeral record that is automatically deleted when the client's session
45+
/// is closed or expires.
3946
Ephemeral(),
4047
}
4148

49+
/// The result of a put operation.
4250
#[derive(Clone, Debug, PartialEq)]
4351
pub struct PutResult {
52+
/// The key of the stored record. May differ from the requested key when using sequence deltas.
4453
pub key: String,
54+
/// The version metadata of the stored record.
4555
pub version: Version,
4656
}
4757

58+
/// Options for delete operations.
4859
pub enum DeleteOption {
60+
/// Override partition routing.
4961
PartitionKey(String),
62+
/// Only delete if the current version matches (conditional delete).
5063
ExpectVersionId(i64),
64+
/// Only delete if the record does not exist (no-op check).
5165
RecordDoesNotExist(),
5266
}
5367

68+
/// Options for delete range operations.
5469
pub enum DeleteRangeOption {
70+
/// Override partition routing.
5571
PartitionKey(String),
5672
}
5773

74+
/// Options for get operations.
5875
pub enum GetOption {
76+
/// Key comparison type: Equal (default), Floor, Ceiling, Lower, Higher.
5977
ComparisonType(KeyComparisonType),
78+
/// Override partition routing.
6079
PartitionKey(String),
61-
/// Include the value in the response (default: true)
80+
/// Whether to include the value in the response (default: true).
81+
/// Set to false for metadata-only queries.
6282
IncludeValue(bool),
83+
/// Query a secondary index instead of the primary key space.
6384
UseIndex(String),
6485
}
6586

87+
/// The result of a get operation.
6688
#[derive(Clone, Debug, PartialEq)]
6789
pub struct GetResult {
90+
/// The key of the record. May differ from the requested key when using comparison queries.
6891
pub key: String,
92+
/// The value of the record. None if the value was not requested or the record has no value.
6993
pub value: Option<Vec<u8>>,
94+
/// The version metadata of the record.
7095
pub version: Version,
7196
}
7297
impl Eq for GetResult {}
@@ -83,32 +108,47 @@ impl Ord for GetResult {
83108
}
84109
}
85110

111+
/// Options for list operations.
86112
pub enum ListOption {
113+
/// Override partition routing.
87114
PartitionKey(String),
115+
/// Query a secondary index instead of the primary key space.
88116
UseIndex(String),
89117
}
90118

119+
/// The result of a list operation.
91120
#[derive(Clone, Debug, PartialEq)]
92121
pub struct ListResult {
122+
/// The keys found within the specified range.
93123
pub keys: Vec<String>,
94124
}
95125

126+
/// Options for range scan operations.
96127
pub enum RangeScanOption {
128+
/// Override partition routing.
97129
PartitionKey(String),
130+
/// Query a secondary index instead of the primary key space.
98131
UseIndex(String),
99132
}
100133

134+
/// The result of a range scan operation.
101135
#[derive(Clone, Debug, PartialEq)]
102136
pub struct RangeScanResult {
137+
/// The records found within the specified range, including keys, values, and versions.
103138
pub records: Vec<GetResult>,
104139
}
105140

141+
/// Options for notification subscriptions.
106142
pub enum GetNotificationOption {
143+
/// Buffer size for the notification channel (default: 100).
107144
BufferSize(usize),
108145
}
109146

147+
/// Options for sequence update subscriptions.
110148
pub enum GetSequenceUpdatesOption {
149+
/// Required: the partition key for the sequence. Must be specified.
111150
PartitionKey(String),
151+
/// Buffer size for the sequence updates channel (default: 100).
112152
BufferSize(usize),
113153
}
114154

@@ -135,12 +175,18 @@ pub struct KeyRangeDeleted {
135175
pub key_range_last: Option<String>,
136176
}
137177

178+
/// A change notification received from Oxia.
138179
#[derive(Clone, Debug, PartialEq)]
139180
pub enum Notification {
181+
/// A new key was created.
140182
KeyCreated(KeyCreated),
183+
/// A key was deleted.
141184
KeyDeleted(KeyDeleted),
185+
/// An existing key was modified.
142186
KeyModified(KeyModified),
187+
/// A range of keys was deleted.
143188
KeyRangeDeleted(KeyRangeDeleted),
189+
/// An unknown notification type was received.
144190
Unknown(),
145191
}
146192

liboxia-native/src/client_builder.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@ use crate::client_options::OxiaClientOptions;
44
use crate::errors::OxiaError;
55
use std::time::Duration;
66

7+
/// Builder for creating an [`OxiaClient`] with custom configuration.
8+
///
9+
/// # Example
10+
/// ```no_run
11+
/// # async fn example() {
12+
/// use liboxia::client_builder::OxiaClientBuilder;
13+
/// use std::time::Duration;
14+
///
15+
/// let client = OxiaClientBuilder::new()
16+
/// .service_address("localhost:6648".to_string())
17+
/// .namespace("my-namespace".to_string())
18+
/// .session_timeout(Duration::from_secs(30))
19+
/// .build()
20+
/// .await
21+
/// .unwrap();
22+
/// # }
23+
/// ```
724
#[derive(Debug, Clone, Default)]
825
pub struct OxiaClientBuilder {
926
service_address: Option<String>,

liboxia-native/src/operations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl CompletableOperation<DeleteResponse> for DeleteOperation {
170170
}
171171

172172
#[derive(Default)]
173-
pub struct DeleteRangeOperation {
173+
pub(crate) struct DeleteRangeOperation {
174174
pub(crate) callback: Option<Sender<Result<DeleteRangeResponse, OxiaError>>>,
175175
pub(crate) partition_key: Option<String>,
176176
pub(crate) start_inclusive: String,

0 commit comments

Comments
 (0)