Skip to content

Commit

Permalink
fix: add keep alive logic for xlinectl lock command
Browse files Browse the repository at this point in the history
Closes: #664
Signed-off-by: Phoeniix Zhao <[email protected]>
  • Loading branch information
Phoenix500526 committed Jun 26, 2024
1 parent bf5140a commit 0295eb2
Show file tree
Hide file tree
Showing 18 changed files with 474 additions and 631 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
26 changes: 16 additions & 10 deletions crates/xline-client/examples/lock.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Result;
use xline_client::{
types::lock::{LockRequest, UnlockRequest},
clients::Xutex,
types::kv::{Compare, CompareResult, PutRequest, TxnOp},
Client, ClientOptions,
};

Expand All @@ -9,19 +10,24 @@ async fn main() -> Result<()> {
// the name and address of all curp members
let curp_members = ["10.0.0.1:2379", "10.0.0.2:2379", "10.0.0.3:2379"];

let client = Client::connect(curp_members, ClientOptions::default())
.await?
.lock_client();
let client = Client::connect(curp_members, ClientOptions::default()).await?;

// acquire a lock
let resp = client.lock(LockRequest::new("lock-test")).await?;
let lock_client = client.lock_client();
let kv_client = client.kv_client();

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

println!("lock key: {:?}", String::from_utf8_lossy(&key));
let txn_req = xutex_guard
.txn_check_locked_key()
.when([Compare::value("key2", CompareResult::Equal, "value2")])
.and_then([TxnOp::put(
PutRequest::new("key2", "value3").with_prev_kv(true),
)])
.or_else(&[]);

// release the lock
client.unlock(UnlockRequest::new(key)).await?;
let _resp = kv_client.txn(txn_req).await?;

Ok(())
}
Loading

0 comments on commit 0295eb2

Please sign in to comment.