Skip to content

Commit

Permalink
refactor: add session in lock implement and remove LockRequest types
Browse files Browse the repository at this point in the history
Closes: 664,684
Signed-off-by: Phoeniix Zhao <Phoenix500526@163.com>
  • Loading branch information
Phoenix500526 committed Jun 18, 2024
1 parent 22b62ad commit e078327
Show file tree
Hide file tree
Showing 18 changed files with 421 additions and 702 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ jobs:
-e ACTIONS_CACHE_URL=${ACTIONS_CACHE_URL} \
-e ACTIONS_RUNTIME_TOKEN=${ACTIONS_RUNTIME_TOKEN} \
ghcr.io/xline-kv/build-env:latest \
cargo build --release --bin xline --bin benchmark --bin validation_lock_client
cargo build --release --bin xline --bin benchmark
sudo apt-get install -y --force-yes expect
cd scripts
cp ../target/release/{xline,benchmark,validation_lock_client} .
cp ../target/release/{xline,benchmark} .
ldd ./xline
ldd ./benchmark
cp ../fixtures/{private,public}.pem .
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ jobs:
cp ../fixtures/{private,public}.pem .
docker build . -t ghcr.io/xline-kv/xline:latest
docker pull gcr.io/etcd-development/etcd:v3.5.5
binaries: 'xline,benchmark,validation_lock_client'
binaries: 'xline,benchmark'
script_name: 'validation_test.sh'
uploadLogs: true
69 changes: 67 additions & 2 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions crates/xline-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ keywords = ["Client", "Xline", "RPC"]

[dependencies]
anyhow = "1.0.83"
async-dropper = { version = "0.3.1", features = ["tokio", "simple"] }
async-trait = "0.1.80"
clippy-utilities = "0.2.0"
curp = { path = "../curp" }
futures = "0.3.25"
Expand Down
20 changes: 8 additions & 12 deletions crates/xline-client/examples/lock.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use anyhow::Result;
use xline_client::{
types::lock::{LockRequest, UnlockRequest},
Client, ClientOptions,
};
use xline_client::{clients::Xutex, Client, ClientOptions};

#[tokio::main]
async fn main() -> Result<()> {
Expand All @@ -13,15 +10,14 @@ async fn main() -> Result<()> {
.await?
.lock_client();

// acquire a lock
let resp = client.lock(LockRequest::new("lock-test")).await?;
let mut xutex = Xutex::new(client, "lock-test", None, None).await?;
// when the `xutex_guard` drop, the lock will be unlocked.
let xutex_guard = xutex.lock().await?;

let key = resp.key;

println!("lock key: {:?}", String::from_utf8_lossy(&key));

// release the lock
client.unlock(UnlockRequest::new(key)).await?;
println!(
"lock key: {:?}",
String::from_utf8_lossy(xutex_guard.key().as_bytes())
);

Ok(())
}
Loading

0 comments on commit e078327

Please sign in to comment.