From e49b43ece326b8bb0e7e6ab78b175ce060ef2042 Mon Sep 17 00:00:00 2001 From: dl239 Date: Tue, 31 Mar 2026 10:40:11 +0800 Subject: [PATCH 1/2] rm bind Signed-off-by: dl239 --- src/nameserver/cluster_info.cc | 6 ++++-- src/nameserver/name_server_impl.cc | 4 +++- src/tablet/tablet_impl.cc | 4 ++-- src/tablet/tablet_impl_keep_alive_test.cc | 3 +-- src/zk/zk_client.h | 7 +++---- src/zk/zk_client_test.cc | 4 +--- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/nameserver/cluster_info.cc b/src/nameserver/cluster_info.cc index ec685ce8b3f..77194dfafba 100644 --- a/src/nameserver/cluster_info.cc +++ b/src/nameserver/cluster_info.cc @@ -143,12 +143,14 @@ int ClusterInfo::Init(std::string& msg) { PDLOG(WARNING, "connect ns failed, replica cluster ns"); return 403; } - zk_client_->WatchNodes(boost::bind(&ClusterInfo::UpdateNSClient, this, _1)); + zk_client_->WatchNodes([this](const std::vector& endpoints) { + this->UpdateNSClient(endpoints); + }); zk_client_->WatchNodes(); if (FLAGS_use_name) { UpdateRemoteRealEpMap(); bool ok = zk_client_->WatchItem(cluster_add_.zk_path() + "/nodes", - boost::bind(&ClusterInfo::UpdateRemoteRealEpMap, this)); + [this]() { this->UpdateRemoteRealEpMap(); }); if (!ok) { zk_client_->CloseZK(); msg = "zk watch nodes failed"; diff --git a/src/nameserver/name_server_impl.cc b/src/nameserver/name_server_impl.cc index a53c0dddf0e..a59233d481e 100644 --- a/src/nameserver/name_server_impl.cc +++ b/src/nameserver/name_server_impl.cc @@ -1509,7 +1509,9 @@ bool NameServerImpl::Init(const std::string& zk_cluster, const std::string& zk_p } else { UpdateTablets(endpoints); } - zk_client_->WatchNodes(boost::bind(&NameServerImpl::UpdateTabletsLocked, this, _1)); + zk_client_->WatchNodes([this](const std::vector& endpoints) { + this->UpdateTabletsLocked(endpoints); + }); bool ok = zk_client_->WatchNodes(); if (!ok) { PDLOG(WARNING, "fail to watch nodes"); diff --git a/src/tablet/tablet_impl.cc b/src/tablet/tablet_impl.cc index 778bbadb95e..5a99b7b23e7 100644 --- a/src/tablet/tablet_impl.cc +++ b/src/tablet/tablet_impl.cc @@ -405,11 +405,11 @@ bool TabletImpl::RegisterZK() { zk_client_->CreateNode(globalvar_changed_notify_path_, "1"); } if (!zk_client_->WatchItem(globalvar_changed_notify_path_, - boost::bind(&TabletImpl::UpdateGlobalVarTable, this))) { + [this]() { this->UpdateGlobalVarTable(); })) { LOG(WARNING) << "add global var changed watcher failed"; return false; } - if (!zk_client_->WatchItem(notify_path_, boost::bind(&TabletImpl::RefreshTableInfo, this))) { + if (!zk_client_->WatchItem(notify_path_, [this]() { this->RefreshTableInfo(); })) { LOG(WARNING) << "add notify watcher failed"; return false; } diff --git a/src/tablet/tablet_impl_keep_alive_test.cc b/src/tablet/tablet_impl_keep_alive_test.cc index a6e0fd1f5ec..872b9e63bd2 100644 --- a/src/tablet/tablet_impl_keep_alive_test.cc +++ b/src/tablet/tablet_impl_keep_alive_test.cc @@ -18,7 +18,6 @@ #include #include -#include "boost/bind.hpp" #include "gflags/gflags.h" #include "gtest/gtest.h" #include "tablet/tablet_impl.h" @@ -71,7 +70,7 @@ TEST_F(TabletImplTest, KeepAlive) { ASSERT_TRUE(ok); ok = zk_client.Mkdir("/rtidb2/nodes"); ASSERT_TRUE(ok); - zk_client.WatchNodes(boost::bind(&WatchCallback, _1)); + zk_client.WatchNodes(&WatchCallback); ok = zk_client.WatchNodes(); ASSERT_TRUE(ok); TabletImpl tablet; diff --git a/src/zk/zk_client.h b/src/zk/zk_client.h index 7062e7dd99e..55fc9129c87 100644 --- a/src/zk/zk_client.h +++ b/src/zk/zk_client.h @@ -20,13 +20,12 @@ #include #include // NOLINT #include +#include #include #include // NOLINT #include #include -#include "boost/function.hpp" - extern "C" { #include "zookeeper/zookeeper.h" } @@ -34,9 +33,9 @@ extern "C" { namespace openmldb { namespace zk { -typedef boost::function& endpoint)> NodesChangedCallback; +typedef std::function& endpoint)> NodesChangedCallback; -typedef boost::function ItemChangedCallback; +typedef std::function ItemChangedCallback; const uint32_t ZK_MAX_BUFFER_SIZE = 1024 * 1024; diff --git a/src/zk/zk_client_test.cc b/src/zk/zk_client_test.cc index 04879c74359..1810ba529fc 100644 --- a/src/zk/zk_client_test.cc +++ b/src/zk/zk_client_test.cc @@ -20,8 +20,6 @@ #include #include -#include - #include "base/glog_wrapper.h" // NOLINT extern "C" { #include "zookeeper/zookeeper.h" @@ -66,7 +64,7 @@ TEST_F(ZkClientTest, Init) { uint32_t size = 1; ASSERT_EQ(size, endpoints.size()); ASSERT_EQ("127.0.0.1:9527", endpoints[0]); - client.WatchNodes(boost::bind(&WatchCallback, _1)); + client.WatchNodes(&WatchCallback); // trigger watch ok = client.WatchNodes(); ASSERT_TRUE(ok); From c9ce1afd6830ea71c81005b187be3fe32596831b Mon Sep 17 00:00:00 2001 From: dl239 Date: Tue, 31 Mar 2026 11:01:55 +0800 Subject: [PATCH 2/2] feat: update dist lock Signed-off-by: dl239 --- src/zk/dist_lock.cc | 11 ++++++----- src/zk/dist_lock.h | 4 ++-- src/zk/dist_lock_test.cc | 10 ++++------ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/zk/dist_lock.cc b/src/zk/dist_lock.cc index bf0d44d81fe..339edf6742d 100644 --- a/src/zk/dist_lock.cc +++ b/src/zk/dist_lock.cc @@ -16,9 +16,8 @@ #include "zk/dist_lock.h" +#include "absl/strings/str_join.h" #include "base/glog_wrapper.h" -#include "boost/algorithm/string/join.hpp" -#include "boost/bind.hpp" extern "C" { #include "zookeeper/zookeeper.h" } @@ -43,7 +42,7 @@ DistLock::DistLock(const std::string& root_path, ZkClient* zk_client, NotifyCall DistLock::~DistLock() {} -void DistLock::Lock() { pool_.AddTask(boost::bind(&DistLock::InternalLock, this)); } +void DistLock::Lock() { pool_.AddTask([this]() { this->InternalLock(); }); } void DistLock::Stop() { running_.store(false, std::memory_order_relaxed); @@ -74,7 +73,9 @@ void DistLock::InternalLock() { lock_state_.store(kTryLock, std::memory_order_relaxed); client_session_term_ = cur_session_term; HandleChildrenChanged(children); - zk_client_->WatchChildren(root_path_, boost::bind(&DistLock::HandleChildrenChangedLocked, this, _1)); + zk_client_->WatchChildren(root_path_, [this](const std::vector& children) { + this->HandleChildrenChangedLocked(children); + }); } } } @@ -117,7 +118,7 @@ void DistLock::HandleChildrenChanged(const std::vector& children) { } PDLOG(INFO, "my path %s , first child %s , lock value %s", assigned_path_.c_str(), current_lock_node_.c_str(), current_lock_value_.c_str()); - PDLOG(INFO, "all child: %s", boost::algorithm::join(children, ", ").c_str()); + PDLOG(INFO, "all child: %s", absl::StrJoin(children, ",").c_str()); } void DistLock::HandleChildrenChangedLocked(const std::vector& children) { diff --git a/src/zk/dist_lock.h b/src/zk/dist_lock.h index 71984d1f5c1..98a6893ca46 100644 --- a/src/zk/dist_lock.h +++ b/src/zk/dist_lock.h @@ -18,11 +18,11 @@ #define SRC_ZK_DIST_LOCK_H_ #include +#include #include // NOLINT #include #include -#include "boost/function.hpp" #include "common/thread_pool.h" #include "zk/zk_client.h" @@ -32,7 +32,7 @@ using ::baidu::common::ThreadPool; enum LockState { kLocked, kLostLock, kTryLock }; -typedef boost::function NotifyCallback; +typedef std::function NotifyCallback; class DistLock { public: DistLock(const std::string& root_path, ZkClient* zk_client, NotifyCallback on_locked_cl, diff --git a/src/zk/dist_lock_test.cc b/src/zk/dist_lock_test.cc index 0bf33604bf0..727b2968fb7 100644 --- a/src/zk/dist_lock_test.cc +++ b/src/zk/dist_lock_test.cc @@ -20,8 +20,6 @@ #include #include -#include - #include "zk/zk_client.h" extern "C" { #include "zookeeper/zookeeper.h" @@ -46,8 +44,8 @@ TEST_F(DistLockTest, Lock) { ZkClient client("127.0.0.1:6181", "", 10000, "127.0.0.1:9527", "/openmldb_lock", "", ""); bool ok = client.Init(); ASSERT_TRUE(ok); - DistLock lock("/openmldb_lock/nameserver_lock", &client, boost::bind(&OnLockedCallback), - boost::bind(&OnLostCallback), "endpoint1"); + DistLock lock("/openmldb_lock/nameserver_lock", &client, &OnLockedCallback, + &OnLostCallback, "endpoint1"); lock.Lock(); sleep(5); if (!call_invoked) { @@ -65,8 +63,8 @@ TEST_F(DistLockTest, Lock) { lock.Stop(); ASSERT_TRUE(false); } - DistLock lock2("/openmldb_lock/nameserver_lock", &client2, boost::bind(&OnLockedCallback), - boost::bind(&OnLostCallback), "endpoint2"); + DistLock lock2("/openmldb_lock/nameserver_lock", &client2, &OnLockedCallback, + &OnLostCallback, "endpoint2"); lock2.Lock(); sleep(5); ASSERT_FALSE(call_invoked);