Skip to content
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

feat(services/zookeeper): Add zookeeper backend #2735

Closed
wants to merge 46 commits into from

Conversation

Murphy-OrangeMud
Copy link

Add Zookeeper backend skeleton.

An issue to be discussed is that Zookeeper supports plugin Acl. In this implementation the authentication is similar to redis using username+password digest and the access control is consistent throughout the session. Maybe we could apply acl at a finer grain in the future.

.env.example Outdated Show resolved Hide resolved
core/src/services/zookeeper/backend.rs Show resolved Hide resolved
core/src/services/zookeeper/backend.rs Outdated Show resolved Hide resolved
core/src/services/zookeeper/backend.rs Outdated Show resolved Hide resolved
core/src/services/zookeeper/backend.rs Outdated Show resolved Hide resolved
core/src/services/zookeeper/backend.rs Show resolved Hide resolved
core/src/services/zookeeper/backend.rs Outdated Show resolved Hide resolved
core/src/services/zookeeper/backend.rs Show resolved Hide resolved
core/src/services/zookeeper/backend.rs Outdated Show resolved Hide resolved
Cargo.lock Outdated Show resolved Hide resolved
@Murphy-OrangeMud Murphy-OrangeMud marked this pull request as ready for review August 25, 2023 00:38
@Murphy-OrangeMud
Copy link
Author

Hi, so sorry for the delay😔. Currently I've fixed the bugs and the tests has passed. Thecargo clippy test failed due to weird reason because I think the suggestions themselves correspond to the original code. About the multi cluster endpoints issue currently I didn't find a neat way to implement it but personally I think according to the zookeeper characteristics it might be better to directly open more than one session for more than one endpoints (each session/endpoint has its own auths).

@Xuanwo
Copy link
Member

Xuanwo commented Aug 25, 2023

Currently I've fixed the bugs and the tests has passed.

Thanks a lot for your effort!

Thecargo clippy test failed due to weird reason because I think the suggestions themselves correspond to the original code.

Don't worry about this. Rust 1.72 released! So part of our code didn't pass the clippy.

About the multi cluster endpoints issue currently I didn't find a neat way to implement it but personally

That's ok to implement in the future.

@Xuanwo
Copy link
Member

Xuanwo commented Aug 25, 2023

Don't worry about this. Rust 1.72 released!

Addressed in #2927. Please merge with main and try again!

core/src/services/zookeeper/backend.rs Outdated Show resolved Hide resolved
core/src/services/zookeeper/backend.rs Outdated Show resolved Hide resolved
}
}

fn create_nested_node<'a>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can use async fn create_nested_node() directly instead of playing with BoxFuture?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is this form cause of recursion. I have a similar version using loop. Hope it could help @Murphy-OrangeMud .

PS: I think I should port some convenient methods from java world.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have release version 0.6.0 which has mkdir to create nodes up to given path, just like mkdir -p in filesystem. Hope it could help. @Murphy-OrangeMud

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So nice!

if path.as_bytes()[0] != b'/' {
path = "/".to_string() + path.strip_suffix('/').unwrap_or(&path);
}
match self.create_nested_node(&path, value).await {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's required to create parent node first for zookeepr, I perfer to check if parent exist first instead handling error.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, create_nested_node() is a recursive function that creates parent node recursively till a node exists. So when we find that the parent node doesn't exit (the NoNode error in zookeeper-client indicates this) we call this function to create the parent nodes till all the parent nodes on the path in the tree has created. Also it's because the fact that the function is both recursive and async that we use BoxFuture.

core/src/services/zookeeper/backend.rs Outdated Show resolved Hide resolved
@Murphy-OrangeMud
Copy link
Author

kezhuw/zookeeper-client-rust#13

It seems that a test has newly been added and this pr failed the test. Tested with the sdk and has opened an issue here.

Copy link
Member

@kezhuw kezhuw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments related to this pr are inlined.

Beside above, thanks for the adoption of kezhuw/zookeeper-client-rust. I have created issues for some missing features. I think it is better to move forward without them for now to keep passion.

Anyway, have fun!

core/src/services/zookeeper/backend.rs Show resolved Hide resolved
core/src/services/zookeeper/backend.rs Outdated Show resolved Hide resolved
core/src/services/zookeeper/backend.rs Show resolved Hide resolved
}
}

fn create_nested_node<'a>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is this form cause of recursion. I have a similar version using loop. Hope it could help @Murphy-OrangeMud .

PS: I think I should port some convenient methods from java world.

match self.create_nested_node(&path, value).await {
Ok(()) => {}
Err(e) => {
return Err(Error::new(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw Error::set_temporary. I think it is a natural fit for zk::Error::ConnectionLoss.

Besides this, is it better to enrich the error a bit ?

@Xuanwo Is it better to shape Error::new to accept message: impl Into<String> ? I saw Error::new(_, &format!("")).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a good idea.

core/src/services/zookeeper/backend.rs Show resolved Hide resolved
core/src/services/zookeeper/backend.rs Show resolved Hide resolved
core/src/services/zookeeper/backend.rs Show resolved Hide resolved
/// currently we do not support sasl authentication
const ZOOKEEPER_AUTH_SCHEME: &str = "digest";

/// Zookeeper backend builder
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we document the limitations of this backend ?

ZooKeeper, as an aged CP system, does not work well as file backend though its node hierarchy is shaped like a tree. I list some of notables here for what I know.

  1. Data node size limitation is 1MiB.
  2. Does not work well when list directory with large number of children.

The first might be crucial.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we will record the first limitation by adding a new capability with a maximum file size.

.env.example Outdated Show resolved Hide resolved
.github/workflows/bindings_cpp.yml Outdated Show resolved Hide resolved
@Xuanwo
Copy link
Member

Xuanwo commented Oct 4, 2023

Running cargo clippy --features services-zookeeper to make clippy happy.

@Murphy-OrangeMud
Copy link
Author

image It seems that this test (`test_copy_file_with_non_ascii_name`) will always fail. This is the screenshot using zookeeper commandline client with local zookeeper clusters.

@Xuanwo
Copy link
Member

Xuanwo commented Oct 5, 2023

test_copy_file_with_non_ascii_name

You can skip this test for now like what we do for supabase.

@Xuanwo
Copy link
Member

Xuanwo commented Dec 19, 2023

Hi @Murphy-OrangeMud, are you still on this? This PR has been open for a while, and I believe we can resolve conflicts and workaround some issue so that we can merge it first.

@Xuanwo
Copy link
Member

Xuanwo commented Apr 9, 2024

Hi, @Murphy-OrangeMud, thanks for your contribution first. We've made numerous updates to our Rust core, rendering this PR quite outdated. I'll be closing it but feel free to open a new one. I'm here to offer any help you might need.

@Xuanwo Xuanwo closed this Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants