Skip to content

Commit 0090b29

Browse files
authored
[Release] prepare for next development iteration (#55)
* [Release] prepare for next development iteration
1 parent f7c7a2c commit 0090b29

32 files changed

+2061
-1913
lines changed

Cargo.lock

+14-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
22
name = "obkv-table-client-rs"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
authors = ["OceanBase OBKV Developers", "CeresDB Authors <[email protected]>"]
55
edition = "2021"
66

77
[workspace.package]
8-
version = "0.1.0"
8+
version = "0.2.0"
99
authors = ["OceanBase OBKV Developers", "CeresDB Authors <[email protected]>"]
1010
edition = "2021"
1111

@@ -54,6 +54,7 @@ serde = "1.0"
5454
serde_bytes = "0.11"
5555
serde_derive = "1.0"
5656
serde_json = "1.0"
57+
socket2 = "0.5"
5758
spin = "0.9"
5859
tokio = { workspace = true }
5960
tokio-util = "0.7"

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
OBKV Table Client is Rust Library that can be used to access table data from [OceanBase](https://github.com/oceanbase/oceanbase) storage layer. Its access method is different from JDBC, it skips the SQL parsing layer, so it has significant performance advantage.
44

5+
## Examples
6+
A simple example could be found in [Demo](https://github.com/oceanbase/obkv-table-client-rs/blob/main/docs/simple_demo/simple_operation/demo.md).
7+
58
## Acknowledgment
69
The CeresDB team implemented this rust client from scratch. Thanks to the [CeresDB](https://github.com/CeresDB/ceresdb) team (CeresDB is a high-performance, distributed, cloud native time-series database).
710

benches/concurrent_insert/mod.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818
extern crate obkv;
1919

20-
use std::{sync::Arc, thread, time};
20+
use std::{sync::Arc, time};
2121

22-
use obkv::{serde_obkv::value::Value, Builder, ObTableClient, RunningMode, Table};
22+
use obkv::{serde_obkv::value::Value, Builder, ObTableClient, RunningMode};
23+
use tokio::task;
2324

2425
// TODO: use test conf to control which environments to test.
2526
const TEST_FULL_USER_NAME: &str = "test";
@@ -54,11 +55,11 @@ const TABLE_NAME: &str = "series_key_to_id_0";
5455
// PRIMARY KEY(series_key),
5556
// KEY index_id(series_id)
5657
// );
57-
fn concurrent_insert(client: Arc<ObTableClient>) {
58+
async fn concurrent_insert(client: Arc<ObTableClient>) {
5859
let mut thds = Vec::with_capacity(20);
5960
for i in 0..50 {
6061
let client = client.clone();
61-
let thd = thread::spawn(move || {
62+
let thd = task::spawn(async move {
6263
for j in i * 100..(i * 100 + 50) {
6364
let series_key = format!("series_key_test_padding_padding_{j}");
6465
let series_id = j * j;
@@ -69,6 +70,7 @@ fn concurrent_insert(client: Arc<ObTableClient>) {
6970
vec!["series_id".to_owned()],
7071
vec![Value::from(series_id as i64)],
7172
)
73+
.await
7274
.unwrap_or_else(|err| {
7375
panic!("fail to insert row:{series_key} {series_id}, err:{err}")
7476
});
@@ -78,18 +80,20 @@ fn concurrent_insert(client: Arc<ObTableClient>) {
7880
}
7981

8082
for (i, thd) in thds.into_iter().enumerate() {
81-
thd.join()
83+
thd.await
8284
.unwrap_or_else(|_| panic!("thread#{i} fail to join"));
8385
}
8486
}
8587

86-
fn main() {
87-
let client = build_client(RunningMode::Normal);
88+
#[tokio::main]
89+
async fn main() {
90+
let client_handle = task::spawn_blocking(|| build_client(RunningMode::Normal));
91+
let client = client_handle.await.unwrap();
8892
client
8993
.truncate_table(TABLE_NAME)
9094
.expect("fail to truncate the table");
9195
let start = time::Instant::now();
92-
concurrent_insert(Arc::new(client));
96+
concurrent_insert(Arc::new(client)).await;
9397
let elapsed = time::Instant::now() - start;
9498
println!("Benches::concurrent_insert cost time:{elapsed:?}");
9599
}

docs/simple_demo/simple_operation/demo.md

+26-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Demo for obkv-table-client-rs
2-
Edited by OBKV developers on March 3, 2023.
2+
Edited by OBKV developers on June 6, 2023.
33

44
## Introduction
55
obkv-table-client-rs is Rust Library that can access table data from OceanBase storage layer.
@@ -13,42 +13,41 @@ Now we provide an interface to access data from OceanBase, which we will introdu
1313
obkv-table-client-rs support several simple operations, such as get, insert, update, insert_or_update, replace, append, increment, delete.
1414

1515
```rust Table and ObTableClient
16-
impl Table for ObTableClient {
17-
// implement operation in Table
18-
// ...
19-
}
20-
21-
pub trait Table {
22-
fn insert(
16+
impl ObTableClient {
17+
// implement operation
18+
#[inline]
19+
pub async fn insert(
2320
&self,
2421
table_name: &str,
2522
row_keys: Vec<Value>,
2623
columns: Vec<String>,
2724
properties: Vec<Value>,
28-
) -> Result<i64>;
25+
) -> Result<i64> {}
2926

30-
fn update(
27+
#[inline]
28+
pub async fn update(
3129
&self,
3230
table_name: &str,
3331
row_keys: Vec<Value>,
3432
columns: Vec<String>,
3533
properties: Vec<Value>,
36-
) -> Result<i64>;
34+
) -> Result<i64> {}
3735
// ...
3836
}
3937
```
4038

4139
A simple operation example is shown below:
4240
```rust simple operation example
43-
fn simple_operation() {
44-
let client = build_normal_client();
41+
async fn simple_operation() {
42+
let client_handle = task::spawn_blocking(utils::common::build_normal_client);
43+
let client = client_handle.await.unwrap();
4544

4645
let result = client.insert(
4746
"your_table_name",
4847
vec![Value::from("foo")],
4948
vec!["c2".to_owned()],
5049
vec![Value::from("baz")],
51-
);
50+
).await;
5251

5352
assert!(result.is_ok());
5453
}
@@ -72,8 +71,9 @@ impl ObTableBatchOperation {
7271
```
7372
A simple batch operation example is shown below:
7473
```rust batch operation example
75-
fn batch_operation() {
76-
let client = utils::common::build_normal_client();
74+
async fn batch_operation() {
75+
let client_handle = task::spawn_blocking(utils::common::build_normal_client);
76+
let client = client_handle.await.unwrap();
7777

7878
// set number of operations in batch_op
7979
let mut batch_op = client.batch_operation(2);
@@ -87,7 +87,7 @@ fn batch_operation() {
8787
);
8888

8989
// execute
90-
let result = client.execute_batch("your_table_name", batch_op);
90+
let result = client.execute_batch("your_table_name", batch_op).await;
9191
assert!(result.is_ok());
9292
}
9393
```
@@ -97,30 +97,26 @@ More [demos](https://github.com/oceanbase/obkv-table-client-rs/blob/main/tests/t
9797
Query is different from get, it allows the user to get a range of data.
9898
A **Query** could get from **ObTableClient** by calling ```query()``` method, then you could customize your query by calling methods in **ObTableClientQueryImpl** and **TableQuery**.
9999
```rust ObTableClientQueryImpll
100-
impl TableQuery for ObTableClientQueryImpl {
101-
// implement methods from TableQuery
102-
// ...
103-
}
104-
105-
pub trait TableQuery {
106-
fn execute(&self) -> Result<QueryResultSet>;
107-
fn select(self, columns: Vec<String>) -> Self;
100+
impl ObTableClientQueryImpl {
101+
pub async fn execute(&self) -> Result<QueryResultSet> {}
102+
pub fn select(self, columns: Vec<String>) -> Self {}
108103
// ...
109-
fn clear(&mut self);
104+
pub fn clear(&mut self) {}
110105
}
111106
```
112107
A simple query example is shown below:
113108
```rust query example
114-
fn query() {
115-
let client = utils::common::build_normal_client();
109+
async fn query() {
110+
let client_handle = task::spawn_blocking(utils::common::build_normal_client);
111+
let client = client_handle.await.unwrap();
116112

117113
let query = client
118114
.query("your_table_name")
119115
.select(vec!["c1".to_owned()])
120116
.scan_order(false)
121-
.add_scan_range(vec![Value::from("123")], true, vec![Value::from("567")], true)
117+
.add_scan_range(vec![Value::from("123")], true, vec![Value::from("567")], true);
122118

123-
let result = query.execute();
119+
let result = query.execute().await;
124120
assert!(result.is_ok());
125121
}
126122
```

0 commit comments

Comments
 (0)