From dfed384741819e88237a1f5f9dfbaa51ead3fe30 Mon Sep 17 00:00:00 2001 From: gulu-goolu Date: Mon, 18 Dec 2023 16:41:25 +0800 Subject: [PATCH] feat: replace the type of PeerId::addr from butil::EndPoint to string --- src/braft/cli.cpp | 26 +++++++++--------- src/braft/cli_service.cpp | 6 ++--- src/braft/configuration.h | 44 +++++++++++++++++-------------- src/braft/file_system_adaptor.cpp | 4 +-- src/braft/fsm_caller.cpp | 4 +-- src/braft/log_entry.cpp | 4 +-- src/braft/log_manager.cpp | 4 +-- src/braft/node.cpp | 14 +++++----- src/braft/node_manager.cpp | 11 ++++---- src/braft/node_manager.h | 8 +++--- src/braft/raft.cpp | 14 ++-------- src/braft/raft.h | 5 ++-- src/braft/raft_service.h | 4 +-- src/braft/replicator.cpp | 2 +- src/braft/route_table.cpp | 2 +- src/braft/snapshot.cpp | 12 ++++----- src/braft/snapshot.h | 10 +++---- src/braft/snapshot_executor.cpp | 2 +- src/braft/snapshot_executor.h | 2 +- 19 files changed, 85 insertions(+), 93 deletions(-) diff --git a/src/braft/cli.cpp b/src/braft/cli.cpp index c0447812..a7421abc 100644 --- a/src/braft/cli.cpp +++ b/src/braft/cli.cpp @@ -35,7 +35,7 @@ static butil::Status get_leader(const GroupId& group_id, const Configuration& co for (Configuration::const_iterator iter = conf.begin(); iter != conf.end(); ++iter) { brpc::Channel channel; - if (channel.Init(iter->addr, NULL) != 0) { + if (channel.Init(iter->addr.c_str(), NULL) != 0) { return butil::Status(-1, "Fail to init channel to %s", iter->to_string().c_str()); } @@ -73,7 +73,7 @@ butil::Status add_peer(const GroupId& group_id, const Configuration& conf, butil::Status st = get_leader(group_id, conf, &leader_id); BRAFT_RETURN_IF(!st.ok(), st); brpc::Channel channel; - if (channel.Init(leader_id.addr, NULL) != 0) { + if (channel.Init(leader_id.addr.c_str(), NULL) != 0) { return butil::Status(-1, "Fail to init channel to %s", leader_id.to_string().c_str()); } @@ -93,11 +93,11 @@ butil::Status add_peer(const GroupId& group_id, const Configuration& conf, } Configuration old_conf; for (int i = 0; i < response.old_peers_size(); ++i) { - old_conf.add_peer(response.old_peers(i)); + old_conf.add_peer(PeerId::from_string(response.old_peers(i))); } Configuration new_conf; for (int i = 0; i < response.new_peers_size(); ++i) { - new_conf.add_peer(response.new_peers(i)); + new_conf.add_peer(PeerId::from_string(response.new_peers(i))); } LOG(INFO) << "Configuration of replication group `" << group_id << "' changed from " << old_conf @@ -111,7 +111,7 @@ butil::Status remove_peer(const GroupId& group_id, const Configuration& conf, butil::Status st = get_leader(group_id, conf, &leader_id); BRAFT_RETURN_IF(!st.ok(), st); brpc::Channel channel; - if (channel.Init(leader_id.addr, NULL) != 0) { + if (channel.Init(leader_id.addr.c_str(), NULL) != 0) { return butil::Status(-1, "Fail to init channel to %s", leader_id.to_string().c_str()); } @@ -131,11 +131,11 @@ butil::Status remove_peer(const GroupId& group_id, const Configuration& conf, } Configuration old_conf; for (int i = 0; i < response.old_peers_size(); ++i) { - old_conf.add_peer(response.old_peers(i)); + old_conf.add_peer(PeerId::from_string(response.old_peers(i))); } Configuration new_conf; for (int i = 0; i < response.new_peers_size(); ++i) { - new_conf.add_peer(response.new_peers(i)); + new_conf.add_peer(PeerId::from_string(response.new_peers(i))); } LOG(INFO) << "Configuration of replication group `" << group_id << "' changed from " << old_conf @@ -150,7 +150,7 @@ butil::Status reset_peer(const GroupId& group_id, const PeerId& peer_id, return butil::Status(EINVAL, "new_conf is empty"); } brpc::Channel channel; - if (channel.Init(peer_id.addr, NULL) != 0) { + if (channel.Init(peer_id.addr.c_str(), NULL) != 0) { return butil::Status(-1, "Fail to init channel to %s", peer_id.to_string().c_str()); } @@ -176,7 +176,7 @@ butil::Status reset_peer(const GroupId& group_id, const PeerId& peer_id, butil::Status snapshot(const GroupId& group_id, const PeerId& peer_id, const CliOptions& options) { brpc::Channel channel; - if (channel.Init(peer_id.addr, NULL) != 0) { + if (channel.Init(peer_id.addr.c_str(), NULL) != 0) { return butil::Status(-1, "Fail to init channel to %s", peer_id.to_string().c_str()); } @@ -204,7 +204,7 @@ butil::Status change_peers(const GroupId& group_id, const Configuration& conf, LOG(INFO) << "conf=" << conf << " leader=" << leader_id << " new_peers=" << new_peers; brpc::Channel channel; - if (channel.Init(leader_id.addr, NULL) != 0) { + if (channel.Init(leader_id.addr.c_str(), NULL) != 0) { return butil::Status(-1, "Fail to init channel to %s", leader_id.to_string().c_str()); } @@ -228,11 +228,11 @@ butil::Status change_peers(const GroupId& group_id, const Configuration& conf, } Configuration old_conf; for (int i = 0; i < response.old_peers_size(); ++i) { - old_conf.add_peer(response.old_peers(i)); + old_conf.add_peer(PeerId::from_string(response.old_peers(i))); } Configuration new_conf; for (int i = 0; i < response.new_peers_size(); ++i) { - new_conf.add_peer(response.new_peers(i)); + new_conf.add_peer(PeerId::from_string(response.new_peers(i))); } LOG(INFO) << "Configuration of replication group `" << group_id << "' changed from " << old_conf @@ -250,7 +250,7 @@ butil::Status transfer_leader(const GroupId& group_id, const Configuration& conf return butil::Status::OK(); } brpc::Channel channel; - if (channel.Init(leader_id.addr, NULL) != 0) { + if (channel.Init(leader_id.addr.c_str(), NULL) != 0) { return butil::Status(-1, "Fail to init channel to %s", leader_id.to_string().c_str()); } diff --git a/src/braft/cli_service.cpp b/src/braft/cli_service.cpp index 5f84079d..fb024d46 100644 --- a/src/braft/cli_service.cpp +++ b/src/braft/cli_service.cpp @@ -38,7 +38,7 @@ static void add_peer_returned(brpc::Controller* cntl, for (size_t i = 0; i < old_peers.size(); ++i) { response->add_old_peers(old_peers[i].to_string()); response->add_new_peers(old_peers[i].to_string()); - if (old_peers[i] == request->peer_id()) { + if (old_peers[i] == PeerId::from_string(request->peer_id())) { already_exists = true; } } @@ -94,7 +94,7 @@ static void remove_peer_returned(brpc::Controller* cntl, } for (size_t i = 0; i < old_peers.size(); ++i) { response->add_old_peers(old_peers[i].to_string()); - if (old_peers[i] != request->peer_id()) { + if (old_peers[i] != PeerId::from_string(request->peer_id())) { response->add_new_peers(old_peers[i].to_string()); } } @@ -233,7 +233,7 @@ butil::Status CliServiceImpl::get_node(scoped_refptr* node, const GroupId& group_id, const std::string& peer_id) { if (!peer_id.empty()) { - *node = global_node_manager->get(group_id, peer_id); + *node = global_node_manager->get(group_id, PeerId::from_string(peer_id)); if (!(*node)) { return butil::Status(ENOENT, "Fail to find node %s in group %s", peer_id.c_str(), diff --git a/src/braft/configuration.h b/src/braft/configuration.h index 310539ae..fb3ef40f 100644 --- a/src/braft/configuration.h +++ b/src/braft/configuration.h @@ -23,7 +23,7 @@ #include #include #include -#include +#include "butil/string_printf.h" #include #include #include @@ -41,41 +41,41 @@ enum Role { // Represent a participant in a replicating group. struct PeerId { - butil::EndPoint addr; // ip+port. - int idx; // idx in same addr, default 0 + std::string addr; // ip+port. + int idx = 0; // idx in same addr, default 0 Role role = REPLICA; PeerId() : idx(0), role(REPLICA) {} - explicit PeerId(butil::EndPoint addr_) : addr(addr_), idx(0), role(REPLICA) {} - PeerId(butil::EndPoint addr_, int idx_) : addr(addr_), idx(idx_), role(REPLICA) {} - PeerId(butil::EndPoint addr_, int idx_, bool witness) : addr(addr_), idx(idx_) { + + PeerId(std::string addr_, int idx_) : addr(addr_), idx(idx_), role(REPLICA) {} + PeerId(std::string addr_, int idx_, bool witness) : addr(addr_), idx(idx_) { if (witness) { this->role = WITNESS; } } - /*intended implicit*/PeerId(const std::string& str) - { CHECK_EQ(0, parse(str)); } PeerId(const PeerId& id) : addr(id.addr), idx(id.idx), role(id.role) {} void reset() { - addr.ip = butil::IP_ANY; - addr.port = 0; + addr.clear(); idx = 0; role = REPLICA; } bool is_empty() const { - return (addr.ip == butil::IP_ANY && addr.port == 0 && idx == 0); + return (addr.empty() && idx == 0); } + bool is_witness() const { return role == WITNESS; } + int parse(const std::string& str) { reset(); - char ip_str[64]; + char ip_str[1024]; + int32_t port; int value = REPLICA; - if (2 > sscanf(str.c_str(), "%[^:]%*[:]%d%*[:]%d%*[:]%d", ip_str, &addr.port, &idx, &value)) { + if (2 > sscanf(str.c_str(), "%[^:]%*[:]%d%*[:]%d%*[:]%d", ip_str, &port, &idx, &value)) { reset(); return -1; } @@ -84,20 +84,24 @@ struct PeerId { reset(); return -1; } - if (0 != butil::str2ip(ip_str, &addr.ip)) { - reset(); - return -1; - } + + addr = butil::string_printf("%s:%d", ip_str, port); + return 0; } std::string to_string() const { - char str[128]; - snprintf(str, sizeof(str), "%s:%d:%d", butil::endpoint2str(addr).c_str(), idx, int(role)); - return std::string(str); + return butil::string_printf("%s:%d:%d", addr.c_str(), idx, int(role)); } PeerId& operator=(const PeerId& rhs) = default; + + static PeerId from_string(const std::string&s) { + PeerId p; + CHECK_EQ(0,p.parse(s)); + + return p; + } }; inline bool operator<(const PeerId& id1, const PeerId& id2) { diff --git a/src/braft/file_system_adaptor.cpp b/src/braft/file_system_adaptor.cpp index 8509544e..1cdcf6af 100644 --- a/src/braft/file_system_adaptor.cpp +++ b/src/braft/file_system_adaptor.cpp @@ -122,7 +122,7 @@ ssize_t BufferedSequentialWriteFileAdaptor::write(const butil::IOBuf& data, off_ BRAFT_VLOG << "begin write offset " << offset << ", data_size " << data.size() << ", buffer_offset " << _buffer_offset << ", buffer_size " << _buffer_size; - if (offset < _buffer_offset + _buffer_size) { + if (offset < _buffer_offset + static_cast(_buffer_size)) { LOG(WARNING) << "Fail to write into buffered file adaptor with invalid range" << ", offset: " << offset << ", data_size: " << data.size() @@ -130,7 +130,7 @@ ssize_t BufferedSequentialWriteFileAdaptor::write(const butil::IOBuf& data, off_ << ", buffer_size: " << _buffer_size; errno = EINVAL; return -1; - } else if (offset > _buffer_offset + _buffer_size) { + } else if (offset > _buffer_offset + static_cast(_buffer_size)) { // passby hole CHECK(_buffer_size == 0); BRAFT_VLOG << "seek to new offset " << offset << " as there is hole"; diff --git a/src/braft/fsm_caller.cpp b/src/braft/fsm_caller.cpp index 98913eea..a35615b4 100644 --- a/src/braft/fsm_caller.cpp +++ b/src/braft/fsm_caller.cpp @@ -64,7 +64,7 @@ int FSMCaller::run(void* meta, bthread::TaskIterator& iter) { } int64_t max_committed_index = -1; int64_t counter = 0; - size_t batch_size = FLAGS_raft_fsm_caller_commit_batch; + int64_t batch_size = FLAGS_raft_fsm_caller_commit_batch; for (; iter; ++iter) { if (iter->type == COMMITTED && counter < batch_size) { if (iter->committed_index > max_committed_index) { @@ -417,7 +417,7 @@ void FSMCaller::do_snapshot_load(LoadSnapshotClosure* done) { // Joint stage is not supposed to be noticeable by end users. Configuration conf; for (int i = 0; i < meta.peers_size(); ++i) { - conf.add_peer(meta.peers(i)); + conf.add_peer(PeerId::from_string(meta.peers(i))); } _fsm->on_configuration_committed(conf, meta.last_included_index()); } diff --git a/src/braft/log_entry.cpp b/src/braft/log_entry.cpp index 540ac17a..ee9ddae2 100644 --- a/src/braft/log_entry.cpp +++ b/src/braft/log_entry.cpp @@ -41,12 +41,12 @@ butil::Status parse_configuration_meta(const butil::IOBuf& data, LogEntry* entry } entry->peers = new std::vector; for (int j = 0; j < meta.peers_size(); ++j) { - entry->peers->push_back(PeerId(meta.peers(j))); + entry->peers->push_back(PeerId::from_string(meta.peers(j))); } if (meta.old_peers_size() > 0) { entry->old_peers = new std::vector; for (int i = 0; i < meta.old_peers_size(); i++) { - entry->old_peers->push_back(PeerId(meta.old_peers(i))); + entry->old_peers->push_back(PeerId::from_string(meta.old_peers(i))); } } return status; diff --git a/src/braft/log_manager.cpp b/src/braft/log_manager.cpp index cf077751..7efa1e35 100644 --- a/src/braft/log_manager.cpp +++ b/src/braft/log_manager.cpp @@ -629,11 +629,11 @@ void LogManager::set_snapshot(const SnapshotMeta* meta) { } Configuration conf; for (int i = 0; i < meta->peers_size(); ++i) { - conf.add_peer(meta->peers(i)); + conf.add_peer(PeerId::from_string(meta->peers(i))); } Configuration old_conf; for (int i = 0; i < meta->old_peers_size(); ++i) { - old_conf.add_peer(meta->old_peers(i)); + old_conf.add_peer(PeerId::from_string(meta->old_peers(i))); } ConfigurationEntry entry; entry.id = LogId(meta->last_included_index(), meta->last_included_term()); diff --git a/src/braft/node.cpp b/src/braft/node.cpp index b5ba39eb..de4e2cf3 100644 --- a/src/braft/node.cpp +++ b/src/braft/node.cpp @@ -493,7 +493,7 @@ int NodeImpl::init(const NodeOptions& options) { _options = options; // check _server_id - if (butil::IP_ANY == _server_id.addr.ip) { + if ( _server_id.addr.empty()) { LOG(ERROR) << "Group " << _group_id << " Node can't started from IP_ANY"; return -1; @@ -972,8 +972,8 @@ void NodeImpl::snapshot(Closure* done) { } void NodeImpl::do_snapshot(Closure* done) { - LOG(INFO) << "node " << _group_id << ":" << _server_id - << " starts to do snapshot"; + VLOG(1) << "node " << _group_id << ":" << _server_id + << " starts to do snapshot"; if (_snapshot_executor) { _snapshot_executor->do_snapshot(done); } else { @@ -1654,7 +1654,7 @@ void NodeImpl::pre_vote(std::unique_lock* lck, bool triggered) { options.max_retry = 0; options.connect_timeout_ms = FLAGS_raft_rpc_channel_connect_timeout_ms; brpc::Channel channel; - if (0 != channel.Init(iter->addr, &options)) { + if (0 != channel.Init(iter->addr.c_str(), &options)) { LOG(WARNING) << "node " << _group_id << ":" << _server_id << " channel init failed, addr " << iter->addr; continue; @@ -1760,7 +1760,7 @@ void NodeImpl::request_peers_to_vote(const std::set& peers, options.connect_timeout_ms = FLAGS_raft_rpc_channel_connect_timeout_ms; options.max_retry = 0; brpc::Channel channel; - if (0 != channel.Init(iter->addr, &options)) { + if (0 != channel.Init(iter->addr.c_str(), &options)) { LOG(WARNING) << "node " << _group_id << ":" << _server_id << " channel init failed, addr " << iter->addr; continue; @@ -2539,13 +2539,13 @@ void NodeImpl::handle_append_entries_request(brpc::Controller* cntl, if (entry.peers_size() > 0) { log_entry->peers = new std::vector; for (int i = 0; i < entry.peers_size(); i++) { - log_entry->peers->push_back(entry.peers(i)); + log_entry->peers->push_back(PeerId::from_string(entry.peers(i))); } CHECK_EQ(log_entry->type, ENTRY_TYPE_CONFIGURATION); if (entry.old_peers_size() > 0) { log_entry->old_peers = new std::vector; for (int i = 0; i < entry.old_peers_size(); i++) { - log_entry->old_peers->push_back(entry.old_peers(i)); + log_entry->old_peers->push_back(PeerId::from_string(entry.old_peers(i))); } } } else { diff --git a/src/braft/node_manager.cpp b/src/braft/node_manager.cpp index 84bf940e..a22d1b5c 100644 --- a/src/braft/node_manager.cpp +++ b/src/braft/node_manager.cpp @@ -26,24 +26,23 @@ NodeManager::NodeManager() {} NodeManager::~NodeManager() {} -bool NodeManager::server_exists(butil::EndPoint addr) { +bool NodeManager::server_exists(const std::string& addr) { BAIDU_SCOPED_LOCK(_mutex); - if (addr.ip != butil::IP_ANY) { - butil::EndPoint any_addr(butil::IP_ANY, addr.port); - if (_addr_set.find(any_addr) != _addr_set.end()) { + if (addr!= std::string()) { + if (_addr_set.find(addr) != _addr_set.end()) { return true; } } return _addr_set.find(addr) != _addr_set.end(); } -void NodeManager::remove_address(butil::EndPoint addr) { +void NodeManager::remove_address(const std::string& addr) { BAIDU_SCOPED_LOCK(_mutex); _addr_set.erase(addr); } int NodeManager::add_service(brpc::Server* server, - const butil::EndPoint& listen_address) { + const std::string& listen_address) { if (server == NULL) { LOG(ERROR) << "server is NULL"; return -1; diff --git a/src/braft/node_manager.h b/src/braft/node_manager.h index 5d443995..d2bf9111 100644 --- a/src/braft/node_manager.h +++ b/src/braft/node_manager.h @@ -49,13 +49,13 @@ class NodeManager { // Add service to |server| at |listen_addr| int add_service(brpc::Server* server, - const butil::EndPoint& listen_addr); + const std::string& listen_addr); // Return true if |addr| is reachable by a RPC Server - bool server_exists(butil::EndPoint addr); + bool server_exists(const std::string& addr); // Remove the addr from _addr_set when the backing service is destroyed - void remove_address(butil::EndPoint addr); + void remove_address(const std::string& addr); private: NodeManager(); @@ -79,7 +79,7 @@ class NodeManager { butil::DoublyBufferedData _nodes; raft_mutex_t _mutex; - std::set _addr_set; + std::set _addr_set; }; #define global_node_manager NodeManager::GetInstance() diff --git a/src/braft/raft.cpp b/src/braft/raft.cpp index 6069f706..f239112f 100644 --- a/src/braft/raft.cpp +++ b/src/braft/raft.cpp @@ -86,23 +86,13 @@ void global_init_once_or_die() { } } -int add_service(brpc::Server* server, const butil::EndPoint& listen_addr) { +int add_service(brpc::Server* server, const std::string& listen_addr) { global_init_once_or_die(); return global_node_manager->add_service(server, listen_addr); } int add_service(brpc::Server* server, int port) { - butil::EndPoint addr(butil::IP_ANY, port); - return add_service(server, addr); -} - -int add_service(brpc::Server* server, const char* listen_ip_and_port) { - butil::EndPoint addr; - if (butil::str2endpoint(listen_ip_and_port, &addr) != 0) { - LOG(ERROR) << "Fail to parse `" << listen_ip_and_port << "'"; - return -1; - } - return add_service(server, addr); + return add_service(server, butil::string_printf("%s:%d", butil::ip2str(butil::IP_ANY).c_str(),port)); } // GC diff --git a/src/braft/raft.h b/src/braft/raft.h index 8a7f5d8e..f9084953 100644 --- a/src/braft/raft.h +++ b/src/braft/raft.h @@ -46,7 +46,7 @@ class FileSystemAdaptor; class SnapshotThrottle; class LogStorage; -const PeerId ANY_PEER(butil::EndPoint(butil::IP_ANY, 0), 0); +const PeerId ANY_PEER(std::string(), 0); // Raft-specific closure which encloses a butil::Status to report if the // operation was successful. @@ -843,9 +843,8 @@ int bootstrap(const BootstrapOptions& options); // listen address, if the Server is going to be started from a range of ports, // the behavior is undefined. // Returns 0 on success, -1 otherwise. -int add_service(brpc::Server* server, const butil::EndPoint& listen_addr); +int add_service(brpc::Server* server, const std::string& listen_addr); int add_service(brpc::Server* server, int port); -int add_service(brpc::Server* server, const char* listen_ip_and_port); // GC struct GCOptions { diff --git a/src/braft/raft_service.h b/src/braft/raft_service.h index 954f923d..6a88e3f7 100644 --- a/src/braft/raft_service.h +++ b/src/braft/raft_service.h @@ -23,7 +23,7 @@ namespace braft { class RaftServiceImpl : public RaftService { public: - explicit RaftServiceImpl(butil::EndPoint addr) + explicit RaftServiceImpl(const std::string& addr) : _addr(addr) {} ~RaftServiceImpl(); @@ -51,7 +51,7 @@ class RaftServiceImpl : public RaftService { ::braft::TimeoutNowResponse* response, ::google::protobuf::Closure* done); private: - butil::EndPoint _addr; + std::string _addr; }; } diff --git a/src/braft/replicator.cpp b/src/braft/replicator.cpp index 65aea0df..0c205e12 100644 --- a/src/braft/replicator.cpp +++ b/src/braft/replicator.cpp @@ -116,7 +116,7 @@ int Replicator::start(const ReplicatorOptions& options, ReplicatorId *id) { brpc::ChannelOptions channel_opt; channel_opt.connect_timeout_ms = FLAGS_raft_rpc_channel_connect_timeout_ms; channel_opt.timeout_ms = -1; // We don't need RPC timeout - if (r->_sending_channel.Init(options.peer_id.addr, &channel_opt) != 0) { + if (r->_sending_channel.Init(options.peer_id.addr.c_str(), &channel_opt) != 0) { LOG(ERROR) << "Fail to init sending channel" << ", group " << options.group_id; delete r; diff --git a/src/braft/route_table.cpp b/src/braft/route_table.cpp index 000abd55..4e78e628 100644 --- a/src/braft/route_table.cpp +++ b/src/braft/route_table.cpp @@ -174,7 +174,7 @@ butil::Status refresh_leader(const GroupId& group, int timeout_ms) { for (Configuration::const_iterator iter = conf.begin(); iter != conf.end(); ++iter) { brpc::Channel channel; - if (channel.Init(iter->addr, NULL) != 0) { + if (channel.Init(iter->addr.c_str(), NULL) != 0) { if (error.ok()) { error.set_error(-1, "Fail to init channel to %s", iter->to_string().c_str()); diff --git a/src/braft/snapshot.cpp b/src/braft/snapshot.cpp index 7a97132a..f89eca21 100644 --- a/src/braft/snapshot.cpp +++ b/src/braft/snapshot.cpp @@ -280,7 +280,7 @@ int LocalSnapshotWriter::sync() { } LocalSnapshotReader::LocalSnapshotReader(const std::string& path, - butil::EndPoint server_addr, + const std::string& server_addr, FileSystemAdaptor* fs, SnapshotThrottle* snapshot_throttle) : _path(path) @@ -407,7 +407,7 @@ class SnapshotFileReader : public LocalDirReader { }; std::string LocalSnapshotReader::generate_uri_for_copy() { - if (_addr == butil::EndPoint()) { + if (_addr.empty()) { LOG(ERROR) << "Address is not specified, path:" << _path; return std::string(); } @@ -783,9 +783,9 @@ void LocalSnapshotCopier::copy() { } while (0); if (!ok() && _writer && _writer->ok()) { LOG(WARNING) << "Fail to copy, error_code " << error_code() - << " error_msg " << error_cstr() + << " error_msg " << error_str() << " writer path " << _writer->get_path(); - _writer->set_error(error_code(), error_cstr()); + _writer->set_error(error_code(), error_str()); } if (_writer) { // set_error for copier only when failed to close writer and copier was @@ -818,7 +818,7 @@ void LocalSnapshotCopier::load_meta_table() { lck.unlock(); if (!session->status().ok()) { LOG(WARNING) << "Fail to copy meta file : " << session->status(); - set_error(session->status().error_code(), session->status().error_cstr()); + set_error(session->status().error_code(), session->status().error_str()); return; } if (_remote_snapshot._meta_table.load_from_iobuf_as_remote(meta_buf) != 0) { @@ -997,7 +997,7 @@ void LocalSnapshotCopier::copy_file(const std::string& filename) { _cur_session = NULL; lck.unlock(); if (!session->status().ok()) { - set_error(session->status().error_code(), session->status().error_cstr()); + set_error(session->status().error_code(), session->status().error_str()); return; } if (_writer->add_file(filename, &meta) != 0) { diff --git a/src/braft/snapshot.h b/src/braft/snapshot.h index 8d617d92..473eb4b8 100644 --- a/src/braft/snapshot.h +++ b/src/braft/snapshot.h @@ -113,7 +113,7 @@ friend class LocalSnapshotStorage; private: // Users shouldn't create LocalSnapshotReader Directly LocalSnapshotReader(const std::string& path, - butil::EndPoint server_addr, + const std::string& server_addr, FileSystemAdaptor* fs, SnapshotThrottle* snapshot_throttle); virtual ~LocalSnapshotReader(); @@ -121,7 +121,7 @@ friend class LocalSnapshotStorage; std::string _path; LocalSnapshotMetaTable _meta_table; - butil::EndPoint _addr; + std::string _addr; int64_t _reader_id; scoped_refptr _fs; scoped_refptr _snapshot_throttle; @@ -204,8 +204,8 @@ friend class LocalSnapshotCopier; SnapshotStorage* new_instance(const std::string& uri) const; butil::Status gc_instance(const std::string& uri) const; - void set_server_addr(butil::EndPoint server_addr) { _addr = server_addr; } - bool has_server_addr() { return _addr != butil::EndPoint(); } + void set_server_addr(const std::string& server_addr) { _addr = server_addr; } + bool has_server_addr() { return !_addr.empty(); } void set_copy_file(bool copy_file) { _copy_file = copy_file; } private: SnapshotWriter* create(bool from_empty) WARN_UNUSED_RESULT; @@ -219,7 +219,7 @@ friend class LocalSnapshotCopier; bool _filter_before_copy_remote; int64_t _last_snapshot_index; std::map _ref_map; - butil::EndPoint _addr; + std::string _addr; bool _copy_file = true; scoped_refptr _fs; scoped_refptr _snapshot_throttle; diff --git a/src/braft/snapshot_executor.cpp b/src/braft/snapshot_executor.cpp index e33ece86..04894207 100644 --- a/src/braft/snapshot_executor.cpp +++ b/src/braft/snapshot_executor.cpp @@ -151,7 +151,7 @@ void SnapshotExecutor::do_snapshot(Closure* done) { lck.unlock(); _log_manager->clear_bufferred_logs(); - LOG_IF(INFO, _node != NULL) << "node " << _node->node_id() + VLOG_IF(1, _node != NULL) << "node " << _node->node_id() << " the gap between fsm applied index " << saved_fsm_applied_index << " and last_snapshot_index " << saved_last_snapshot_index << " is less than " << FLAGS_raft_do_snapshot_min_index_gap diff --git a/src/braft/snapshot_executor.h b/src/braft/snapshot_executor.h index d5879505..1ebbfd04 100644 --- a/src/braft/snapshot_executor.h +++ b/src/braft/snapshot_executor.h @@ -41,7 +41,7 @@ struct SnapshotExecutorOptions { NodeImpl* node; LogManager* log_manager; int64_t init_term; - butil::EndPoint addr; + std::string addr; bool filter_before_copy_remote; bool usercode_in_pthread; bool copy_file = true;