Skip to content

ETCD 接口暴露#47

Closed
yousongyang wants to merge 1 commit into
owent:mainfrom
yousongyang:main
Closed

ETCD 接口暴露#47
yousongyang wants to merge 1 commit into
owent:mainfrom
yousongyang:main

Conversation

@yousongyang
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR focuses on exposing and refactoring parts of the ETCD module/watchers API, including moving watcher callback wrapper types into the public header and centralizing watcher configuration wiring.

Changes:

  • Refactored etcd_module::init() startup keepalive validation into a new helper (check_keepalive_actor_start_failed).
  • Added etcd_watcher::fill_conf_from_protobuf(...) to consolidate watcher configuration setup from protobuf config.
  • Exposed additional ETCD-related helper APIs (path generation, wrapper factories, callback list accessors) from etcd_module.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
src/atframe/modules/etcd_module.cpp Refactors init keepalive startup checking; switches watcher setup to fill_conf_from_protobuf; adds new exported helper accessors/factories.
include/atframe/modules/etcd_module.h Moves callback wrapper structs into the header and adds new exported APIs for wrapper creation and callback list access.
src/atframe/etcdcli/etcd_watcher.cpp Implements fill_conf_from_protobuf and adds protobuf includes/util for duration conversion.
include/atframe/etcdcli/etcd_watcher.h Forward-declares watcher protobuf config type and declares fill_conf_from_protobuf.

Comment thread src/atframe/modules/etcd_module.cpp Outdated
Comment thread src/atframe/modules/etcd_module.cpp Outdated
Comment on lines 275 to 285
bool etcd_module::check_keepalive_actor_start_failed(const std::list<etcd_keepalive::ptr_t> &keepalives) {
// setup timer for timeout
uv_timer_t tick_timer;
init_timer_data_type tick_timer_data;
uv_timer_init(get_app()->get_bus_node()->get_evloop(), &tick_timer);
tick_timer_data.cluster = &etcd_ctx_;
tick_timer_data.timeout = std::chrono::system_clock::now();
tick_timer_data.timeout += std::chrono::seconds(conf.init().timeout().seconds());
tick_timer_data.timeout += std::chrono::seconds(get_configure().init().timeout().seconds());
tick_timer_data.timeout += std::chrono::duration_cast<std::chrono::system_clock::duration>(
std::chrono::nanoseconds(conf.init().timeout().nanos()));
std::chrono::nanoseconds(get_configure().init().timeout().nanos()));
tick_timer.data = &tick_timer_data;
Comment thread include/atframe/modules/etcd_module.h Outdated
Comment thread include/atframe/modules/etcd_module.h Outdated
Comment thread include/atframe/modules/etcd_module.h Outdated
Comment thread include/atframe/modules/etcd_module.h Outdated
using topology_info_event_callback_list_t = std::list<topology_info_event_callback_t>;
using topology_info_event_callback_handle_t = topology_info_event_callback_list_t::iterator;

struct LIBATAPP_MACRO_API_HEAD_ONLY topology_watcher_callback_list_wrapper_t {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

不要对外暴露细节,如果需要包一层类型。导出类型要显式声明导出 拷贝构造、移动构造、拷贝复制、移动复制。

Comment thread src/atframe/etcdcli/etcd_watcher.cpp Outdated
LIBATAPP_MACRO_NAMESPACE_BEGIN

namespace {
static std::chrono::system_clock::duration convert_to_chrono(const ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Duration &in,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

已有类似接口,不要重复代码。

Comment thread include/atframe/modules/etcd_module.h Outdated
LIBATAPP_MACRO_API topology_watcher_callback_list_wrapper_t
create_topology_watcher_callback_list_wrapper(std::list<topology_watcher_list_callback_t> &cbks);

LIBATAPP_MACRO_API std::list<topology_watcher_list_callback_t> &get_topology_watcher_callbacks() noexcept;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

禁止暴露底层存储结构,必须通过handle操作,handle必须考虑容器失效或迭代器无效。

Comment thread src/atframe/modules/etcd_module.cpp Outdated

// Setup for first, we must check if all resource available.
bool is_failed = false;
bool is_failed = check_keepalive_actor_start_failed(internal_discovery_keepalive_actors_) ||
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

同外层模块内不应该区分keepalive的业务功能,应该是并发的。

Comment thread include/atframe/etcdcli/etcd_watcher.h Outdated
return rpc_.startup_random_delay_max;
}

LIBATAPP_MACRO_API void fill_conf_from_protobuf(
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

统一命名 set_conf_XXX

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Comment thread src/atframe/etcdcli/etcd_watcher.cpp Outdated
Comment on lines 398 to 403
// close timer for timeout
uv_timer_stop(&tick_timer);
uv_close(reinterpret_cast<uv_handle_t *>(&tick_timer), init_timer_closed_callback);
while (tick_timer.data != nullptr) {
uv_run(get_app()->get_bus_node()->get_evloop(), UV_RUN_ONCE);
}
Comment thread include/atframe/modules/etcd_module.h Outdated
Comment thread src/atframe/modules/etcd_module.cpp
Comment thread src/atframe/modules/etcd_module.cpp Outdated
Comment thread include/atframe/etcdcli/etcd_watcher.h
Comment thread src/atframe/modules/etcd_module.cpp Outdated
tick_timer_data.cluster = &etcd_ctx_;
tick_timer_data.timeout = std::chrono::system_clock::now();
tick_timer_data.timeout += std::chrono::seconds(conf.init().timeout().seconds());
tick_timer_data.timeout += std::chrono::seconds(get_configure().init().timeout().seconds());
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

用转换接口

Comment thread include/atframe/atapp_conf.h Outdated

LIBATAPP_MACRO_API void parse_timepoint(gsl::string_view in, ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Timestamp &out);
LIBATAPP_MACRO_API void parse_duration(gsl::string_view in, ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Duration &out);
LIBATAPP_MACRO_API std::chrono::system_clock::duration convert_to_chrono(
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

全局接口名称要包含模块信息,按下面通用接口一样使用模板适配更多类型。
补全单元测试。

Comment thread include/atframe/modules/etcd_module.h Outdated
LIBATAPP_MACRO_API void set_maybe_update_keepalive_discovery_metadata();

// Return True If Failed
LIBATAPP_MACRO_API bool check_keepalive_actor_start_failed(
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

算法接口使用static函数或包装一层组件。尽量不允许被外层误用

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Comment on lines 409 to 412
uv_close(reinterpret_cast<uv_handle_t *>(&tick_timer), init_timer_closed_callback);
while (tick_timer.data != nullptr) {
uv_run(get_app()->get_bus_node()->get_evloop(), UV_RUN_ONCE);
}
Comment thread include/atframe/modules/etcd_module.h Outdated
Comment on lines +160 to +163
// Return True If Failed
LIBATAPP_MACRO_API bool check_keepalive_actor_start_failed(
const std::vector<const std::list<etcd_keepalive::ptr_t> *> &keepalive_actors);

Comment on lines 186 to 189
LIBATAPP_MACRO_API const atapp::protocol::atapp_etcd &get_configure() const;
LIBATAPP_MACRO_API const std::string &get_configure_path() const;
LIBATAPP_MACRO_API std::string gen_etcd_path(const std::string &path) const;

Comment on lines +19 to +20
#include <memory/rc_ptr.h>

Comment thread include/atframe/modules/etcd_module.h Outdated
Comment thread include/atframe/modules/etcd_module.h Outdated
Comment thread include/atframe/atapp_conf.h Outdated
Comment thread src/atframe/modules/etcd_module.cpp Outdated
Comment thread src/atframe/modules/etcd_module.cpp Outdated
Comment thread src/atframe/modules/etcd_module.cpp Outdated
Comment thread src/atframe/modules/etcd_module.cpp Outdated
@yousongyang yousongyang force-pushed the main branch 4 times, most recently from 4dfb592 to 005050b Compare May 8, 2026 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants