Unable to connect to local ZooKeeper instance using `zookeeper_client`
MrCh1ppy opened this issue · 5 comments
I am using the zookeeper_client
library in my Rust application to connect to a local ZooKeeper instance running on localhost:2181
. However, when I try to create a node using the create
method, I get an error: "called Result::unwrap()
on an Err
value: Unimplemented".
Here is my code snippet:
use anyhow::Error;
type AnyResult<T> = Result<T,Error>;
#[tokio::main]
async fn main() ->AnyResult<()>{
use zookeeper_client as zk;
let data = "path_data".as_bytes().to_vec();
let create_options = zk::CreateMode::Persistent.with_acls(zk::Acls::anyone_all());
let cluster = "localhost:2181";
let client = zk::Client::connect(cluster).await.unwrap();
let (stat, _) = client.create("/test1", &data, &create_options).await.unwrap();
Ok(())
}
Environment:
rust:1.7.4
zookeeper:3.4.1
zookeeper-client:0.6.1
err message is:
thread 'main' panicked at src/main.rs:21:75:
called `Result::unwrap()` on an `Err` value: Unimplemented
stack backtrace:
0: rust_begin_unwind
at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panicking.rs:597:5
1: core::panicking::panic_fmt
at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/panicking.rs:72:14
2: core::result::unwrap_failed
at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/result.rs:1652:5
3: core::result::Result<T,E>::unwrap
at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/result.rs:1077:23
4: zk_smaple::main::{{closure}}
at ./src/main.rs:21:21
5: tokio::runtime::park::CachedParkThread::block_on::{{closure}}
at /home/ch1ppy/.cargo/registry/src/mirrors.ustc.edu.cn-12df342d903acd47/tokio-1.35.0/src/runtime/park.rs:282:63
6: tokio::runtime::coop::with_budget
at /home/ch1ppy/.cargo/registry/src/mirrors.ustc.edu.cn-12df342d903acd47/tokio-1.35.0/src/runtime/coop.rs:107:5
7: tokio::runtime::coop::budget
at /home/ch1ppy/.cargo/registry/src/mirrors.ustc.edu.cn-12df342d903acd47/tokio-1.35.0/src/runtime/coop.rs:73:5
8: tokio::runtime::park::CachedParkThread::block_on
i just try to get err message,but only msg is Unimplemented,even when i use anyhow to print msg
my toml
[package]
name = "zk_smaple"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = {version = "1.34.0",features = ["full"]}
zookeeper-client = "0.6.1"
anyhow = "1.0.75"
as I use following code:
use anyhow::Error;
type AnyResult<T> = Result<T,Error>;
#[tokio::main]
async fn main() ->AnyResult<()>{
use zookeeper_client as zk;
let data = "path_data".as_bytes().to_vec();
let create_options = zk::CreateMode::Persistent.with_acls(zk::Acls::anyone_all());
let cluster = "localhost:2181";
let client = zk::Client::connect(cluster).await.unwrap();
let (stat, _) = match client.create("/test1", &data, &create_options).await {
Ok(data) => {
data
}
Err(err) => {
println!("{}", err);
return Ok(())
}
};
Ok(())
}
I get
warning: `zk_smaple` (bin "zk_smaple") generated 1 warning (run `cargo fix --bin "zk_smaple"` to apply 1 suggestion)
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/zk_smaple`
unimplemented operation
does it not support zookeeper 3.4.1?
Client::create uses OpCode::create2 to get Stat
for created node. OpCode::create2
was added in ZOOKEEPER-1297 which is shipped in 3.5.0. So, yes, Client::create
does not support ZooKeeper 3.4.x.
I am not sure how to shape client side API for server compatibility issues for now. Maybe a comment in doc just like MultiWriter::add_create or a customizable client side version, or even auto server side version detection. See also ZOOKEEPER-1381 and ZOOKEEPER-3762.