Skip to content

[Release] prepare for next development iteration #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "obkv-table-client-rs"
version = "0.1.0"
version = "0.2.0"
authors = ["OceanBase OBKV Developers", "CeresDB Authors <[email protected]>"]
edition = "2021"

[workspace.package]
version = "0.1.0"
version = "0.2.0"
authors = ["OceanBase OBKV Developers", "CeresDB Authors <[email protected]>"]
edition = "2021"

Expand Down Expand Up @@ -54,6 +54,7 @@ serde = "1.0"
serde_bytes = "0.11"
serde_derive = "1.0"
serde_json = "1.0"
socket2 = "0.5"
spin = "0.9"
tokio = { workspace = true }
tokio-util = "0.7"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

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.

## Examples
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).

## Acknowledgment
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).

Expand Down
20 changes: 12 additions & 8 deletions benches/concurrent_insert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

extern crate obkv;

use std::{sync::Arc, thread, time};
use std::{sync::Arc, time};

use obkv::{serde_obkv::value::Value, Builder, ObTableClient, RunningMode, Table};
use obkv::{serde_obkv::value::Value, Builder, ObTableClient, RunningMode};
use tokio::task;

// TODO: use test conf to control which environments to test.
const TEST_FULL_USER_NAME: &str = "test";
Expand Down Expand Up @@ -54,11 +55,11 @@ const TABLE_NAME: &str = "series_key_to_id_0";
// PRIMARY KEY(series_key),
// KEY index_id(series_id)
// );
fn concurrent_insert(client: Arc<ObTableClient>) {
async fn concurrent_insert(client: Arc<ObTableClient>) {
let mut thds = Vec::with_capacity(20);
for i in 0..50 {
let client = client.clone();
let thd = thread::spawn(move || {
let thd = task::spawn(async move {
for j in i * 100..(i * 100 + 50) {
let series_key = format!("series_key_test_padding_padding_{j}");
let series_id = j * j;
Expand All @@ -69,6 +70,7 @@ fn concurrent_insert(client: Arc<ObTableClient>) {
vec!["series_id".to_owned()],
vec![Value::from(series_id as i64)],
)
.await
.unwrap_or_else(|err| {
panic!("fail to insert row:{series_key} {series_id}, err:{err}")
});
Expand All @@ -78,18 +80,20 @@ fn concurrent_insert(client: Arc<ObTableClient>) {
}

for (i, thd) in thds.into_iter().enumerate() {
thd.join()
thd.await
.unwrap_or_else(|_| panic!("thread#{i} fail to join"));
}
}

fn main() {
let client = build_client(RunningMode::Normal);
#[tokio::main]
async fn main() {
let client_handle = task::spawn_blocking(|| build_client(RunningMode::Normal));
let client = client_handle.await.unwrap();
client
.truncate_table(TABLE_NAME)
.expect("fail to truncate the table");
let start = time::Instant::now();
concurrent_insert(Arc::new(client));
concurrent_insert(Arc::new(client)).await;
let elapsed = time::Instant::now() - start;
println!("Benches::concurrent_insert cost time:{elapsed:?}");
}
56 changes: 26 additions & 30 deletions docs/simple_demo/simple_operation/demo.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Demo for obkv-table-client-rs
Edited by OBKV developers on March 3, 2023.
Edited by OBKV developers on June 6, 2023.

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

```rust Table and ObTableClient
impl Table for ObTableClient {
// implement operation in Table
// ...
}

pub trait Table {
fn insert(
impl ObTableClient {
// implement operation
#[inline]
pub async fn insert(
&self,
table_name: &str,
row_keys: Vec<Value>,
columns: Vec<String>,
properties: Vec<Value>,
) -> Result<i64>;
) -> Result<i64> {}

fn update(
#[inline]
pub async fn update(
&self,
table_name: &str,
row_keys: Vec<Value>,
columns: Vec<String>,
properties: Vec<Value>,
) -> Result<i64>;
) -> Result<i64> {}
// ...
}
```

A simple operation example is shown below:
```rust simple operation example
fn simple_operation() {
let client = build_normal_client();
async fn simple_operation() {
let client_handle = task::spawn_blocking(utils::common::build_normal_client);
let client = client_handle.await.unwrap();

let result = client.insert(
"your_table_name",
vec![Value::from("foo")],
vec!["c2".to_owned()],
vec![Value::from("baz")],
);
).await;

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

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

// execute
let result = client.execute_batch("your_table_name", batch_op);
let result = client.execute_batch("your_table_name", batch_op).await;
assert!(result.is_ok());
}
```
Expand All @@ -97,30 +97,26 @@ More [demos](https://github.com/oceanbase/obkv-table-client-rs/blob/main/tests/t
Query is different from get, it allows the user to get a range of data.
A **Query** could get from **ObTableClient** by calling ```query()``` method, then you could customize your query by calling methods in **ObTableClientQueryImpl** and **TableQuery**.
```rust ObTableClientQueryImpll
impl TableQuery for ObTableClientQueryImpl {
// implement methods from TableQuery
// ...
}

pub trait TableQuery {
fn execute(&self) -> Result<QueryResultSet>;
fn select(self, columns: Vec<String>) -> Self;
impl ObTableClientQueryImpl {
pub async fn execute(&self) -> Result<QueryResultSet> {}
pub fn select(self, columns: Vec<String>) -> Self {}
// ...
fn clear(&mut self);
pub fn clear(&mut self) {}
}
```
A simple query example is shown below:
```rust query example
fn query() {
let client = utils::common::build_normal_client();
async fn query() {
let client_handle = task::spawn_blocking(utils::common::build_normal_client);
let client = client_handle.await.unwrap();

let query = client
.query("your_table_name")
.select(vec!["c1".to_owned()])
.scan_order(false)
.add_scan_range(vec![Value::from("123")], true, vec![Value::from("567")], true)
.add_scan_range(vec![Value::from("123")], true, vec![Value::from("567")], true);

let result = query.execute();
let result = query.execute().await;
assert!(result.is_ok());
}
```
Expand Down
Loading