This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dubbo-rust.git
The following commit(s) were added to refs/heads/main by this push:
new 15b2ac2 skip NodeExist error when create_path_with_parent_check (#170)
15b2ac2 is described below
commit 15b2ac2bd9cbfe71ecf67619c2a64f5f9fb9e1eb
Author: Xin Luo <[email protected]>
AuthorDate: Mon Jan 8 11:46:36 2024 +0800
skip NodeExist error when create_path_with_parent_check (#170)
---
registry/zookeeper/src/lib.rs | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/registry/zookeeper/src/lib.rs b/registry/zookeeper/src/lib.rs
index bcccdc4..6a6e94b 100644
--- a/registry/zookeeper/src/lib.rs
+++ b/registry/zookeeper/src/lib.rs
@@ -31,7 +31,7 @@ use dubbo_base::{
use dubbo_logger::tracing::{debug, error, info};
use serde::{Deserialize, Serialize};
#[allow(unused_imports)]
-use zookeeper::{Acl, CreateMode, WatchedEvent, WatchedEventType, Watcher,
ZooKeeper};
+use zookeeper::{Acl, CreateMode, WatchedEvent, WatchedEventType, Watcher,
ZkError, ZooKeeper};
use dubbo::{
registry::{
@@ -153,7 +153,7 @@ impl ZookeeperRegistry {
match zk_result {
Ok(_) => Ok(()),
Err(err) => {
- error!("zk path {} parent not exists.", path);
+ error!("create path {} to zookeeper error {}", path, err);
Err(Box::try_from(err).unwrap())
}
}
@@ -184,8 +184,20 @@ impl ZookeeperRegistry {
true => data,
false => "",
};
- self.create_path(current.as_str(), new_data, new_create_mode)
- .unwrap();
+
+ //Skip ZkError::NodeExists
+ let res = self.create_path(current.as_str(), new_data,
new_create_mode);
+ let mut node_exist = false;
+ if let Err(e) = &res {
+ if let Some(zk_err) = e.downcast_ref::<ZkError>() {
+ if ZkError::NodeExists == *zk_err {
+ node_exist = true;
+ }
+ }
+ }
+ if !node_exist {
+ return res;
+ }
}
}
Ok(())