This repository has been archived by the owner on Aug 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* example: a new example 'simple_crud' has been added to briefly introduce basic operations * feat(examples): add `mvcc` and `scan_read` to demonstrate scan and transaction functions respectively * docs: version up * style: code format * style: `partial_cmp` code format
- Loading branch information
Showing
11 changed files
with
137 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "kip_db" | ||
version = "0.1.1-alpha.0" | ||
version = "0.1.2-alpha.0" | ||
edition = "2021" | ||
authors = ["Kould <[email protected]>"] | ||
description = "轻量级、异步 基于LSM Leveled Compaction K-V数据库" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use bytes::Bytes; | ||
use kip_db::kernel::lsm::storage::{Config, KipStorage}; | ||
use kip_db::kernel::Storage; | ||
use kip_db::KernelError; | ||
use tempfile::TempDir; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), KernelError> { | ||
let temp_dir = TempDir::new().expect("unable to create temporary working directory"); | ||
let config = Config::new(temp_dir.into_path()).enable_level_0_memorization(); | ||
let kip_storage = KipStorage::open_with_config(config).await?; | ||
|
||
println!("New Transaction"); | ||
let mut tx = kip_storage.new_transaction().await; | ||
|
||
println!("Set KeyValue after the transaction -> (key_1, value_1)"); | ||
kip_storage | ||
.set(b"key_1", Bytes::copy_from_slice(b"value_1")) | ||
.await?; | ||
|
||
println!("Read key_1 on the transaction: {:?}", tx.get(b"key_1")?); | ||
|
||
println!("Set KeyValue on the transaction -> (key_2, value_2)"); | ||
tx.set(b"key_2", Bytes::copy_from_slice(b"value_2")); | ||
|
||
println!("Read key_2 on the transaction: {:?}", tx.get(b"key_2")?); | ||
|
||
println!( | ||
"Read key_2 on the storage: {:?}", | ||
kip_storage.get(b"key_2").await? | ||
); | ||
|
||
println!("Commit this transaction"); | ||
tx.commit().await?; | ||
|
||
println!( | ||
"Read key_2 on the storage again!: {:?}", | ||
kip_storage.get(b"key_2").await? | ||
); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use bytes::Bytes; | ||
use kip_db::kernel::lsm::storage::{Config, KipStorage}; | ||
use kip_db::kernel::Storage; | ||
use kip_db::KernelError; | ||
use std::collections::Bound; | ||
use tempfile::TempDir; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), KernelError> { | ||
let temp_dir = TempDir::new().expect("unable to create temporary working directory"); | ||
let config = Config::new(temp_dir.into_path()).enable_level_0_memorization(); | ||
let kip_storage = KipStorage::open_with_config(config).await?; | ||
|
||
println!("Set KeyValue -> (key_1, value_1)"); | ||
kip_storage | ||
.set(b"key_1", Bytes::copy_from_slice(b"value_1")) | ||
.await?; | ||
println!("Set KeyValue -> (key_2, value_2)"); | ||
kip_storage | ||
.set(b"key_2", Bytes::copy_from_slice(b"value_2")) | ||
.await?; | ||
println!("Set KeyValue -> (key_3, value_3)"); | ||
kip_storage | ||
.set(b"key_3", Bytes::copy_from_slice(b"value_3")) | ||
.await?; | ||
|
||
println!("New Transaction"); | ||
let tx = kip_storage.new_transaction().await; | ||
|
||
println!( | ||
"RangeScan without key_3 By Transaction: {:?}", | ||
tx.range_scan(Bound::Unbounded, Bound::Excluded(b"key_3"))? | ||
); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use bytes::Bytes; | ||
use kip_db::kernel::lsm::storage::{Config, KipStorage}; | ||
use kip_db::kernel::{CommandData, Storage}; | ||
use kip_db::KernelError; | ||
use tempfile::TempDir; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), KernelError> { | ||
let temp_dir = TempDir::new().expect("unable to create temporary working directory"); | ||
let config = Config::new(temp_dir.into_path()).enable_level_0_memorization(); | ||
let kip_storage = KipStorage::open_with_config(config).await?; | ||
|
||
println!("Set KeyValue -> (apple, banana)"); | ||
kip_storage | ||
.set(b"apple", Bytes::copy_from_slice(b"banana")) | ||
.await?; | ||
|
||
println!( | ||
"Get Key: apple -> Value: {:?}", | ||
kip_storage.get(b"apple").await? | ||
); | ||
println!("SizeOfDisk: {}", kip_storage.size_of_disk().await?); | ||
println!("Len: {}", kip_storage.len().await?); | ||
println!("IsEmpty: {}", kip_storage.is_empty().await); | ||
|
||
kip_storage.flush().await?; | ||
|
||
let join_cmd_1 = vec![ | ||
CommandData::set(b"moon".to_vec(), b"star".to_vec()), | ||
// CommandData::remove(b"apple".to_vec()), | ||
]; | ||
println!( | ||
"Join 1: {:?} -> {:?}", | ||
join_cmd_1.clone(), | ||
kip_storage.join(join_cmd_1).await? | ||
); | ||
let join_cmd_2 = vec![ | ||
CommandData::get(b"moon".to_vec()), | ||
CommandData::get(b"apple".to_vec()), | ||
]; | ||
println!( | ||
"Join 2: {:?} -> {:?}", | ||
join_cmd_2.clone(), | ||
kip_storage.join(join_cmd_2).await? | ||
); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters