diff --git a/mindspore/ccsrc/ps/core/communicator/http_communicator.cc b/mindspore/ccsrc/ps/core/communicator/http_communicator.cc index c8f06de5606..fe8f23a88ec 100644 --- a/mindspore/ccsrc/ps/core/communicator/http_communicator.cc +++ b/mindspore/ccsrc/ps/core/communicator/http_communicator.cc @@ -53,7 +53,7 @@ bool HttpCommunicator::Stop() { void HttpCommunicator::RegisterMsgCallBack(const std::string &msg_type, const MessageCallback &cb) { MS_LOG(INFO) << "msg_type is: " << msg_type; msg_callbacks_[msg_type] = cb; - http_msg_callbacks_[msg_type] = [&](std::shared_ptr http_msg) -> void { + http_msg_callbacks_[msg_type] = [this, msg_type](std::shared_ptr http_msg) -> void { MS_EXCEPTION_IF_NULL(http_msg); try { size_t len = 0; diff --git a/mindspore/ccsrc/ps/core/communicator/http_message_handler.cc b/mindspore/ccsrc/ps/core/communicator/http_message_handler.cc index 209da4fcdf1..8314a6455a2 100644 --- a/mindspore/ccsrc/ps/core/communicator/http_message_handler.cc +++ b/mindspore/ccsrc/ps/core/communicator/http_message_handler.cc @@ -209,7 +209,7 @@ bool HttpMessageHandler::GetPostMsg(size_t *len, uint8_t **buffer) { return false; } *len = evbuffer_get_length(event_request_->input_buffer); - constexpr size_t max_http_bytes_len = UINT32_MAX; // 4GB + const size_t max_http_bytes_len = UINT32_MAX; // 4GB if (*len == 0 || *len > max_http_bytes_len) { MS_LOG(ERROR) << "The post message length " << max_http_bytes_len << " is invalid!"; return false; diff --git a/mindspore/ccsrc/ps/core/communicator/http_msg_handler.cc b/mindspore/ccsrc/ps/core/communicator/http_msg_handler.cc index 9cc61ee873a..849a3b18d39 100644 --- a/mindspore/ccsrc/ps/core/communicator/http_msg_handler.cc +++ b/mindspore/ccsrc/ps/core/communicator/http_msg_handler.cc @@ -20,7 +20,7 @@ namespace mindspore { namespace ps { namespace core { -HttpMsgHandler::HttpMsgHandler(const std::shared_ptr &http_msg, uint8_t *data, size_t len) +HttpMsgHandler::HttpMsgHandler(const std::shared_ptr &http_msg, uint8_t *const data, size_t len) : http_msg_(http_msg), data_(data), len_(len) {} void *HttpMsgHandler::data() const { diff --git a/mindspore/ccsrc/ps/core/communicator/http_msg_handler.h b/mindspore/ccsrc/ps/core/communicator/http_msg_handler.h index 75f977a1ce8..98dd842fa91 100644 --- a/mindspore/ccsrc/ps/core/communicator/http_msg_handler.h +++ b/mindspore/ccsrc/ps/core/communicator/http_msg_handler.h @@ -36,7 +36,7 @@ class HttpMsgHandler : public MessageHandler { private: std::shared_ptr http_msg_; - unsigned char *data_; + uint8_t *data_; size_t len_; }; } // namespace core diff --git a/mindspore/ccsrc/ps/core/communicator/tcp_client.cc b/mindspore/ccsrc/ps/core/communicator/tcp_client.cc index a4975f7a995..78eb9c01358 100644 --- a/mindspore/ccsrc/ps/core/communicator/tcp_client.cc +++ b/mindspore/ccsrc/ps/core/communicator/tcp_client.cc @@ -165,7 +165,7 @@ void TcpClient::SetTcpNoDelay(const evutil_socket_t &fd) { } } -void TcpClient::TimeoutCallback(evutil_socket_t, std::int16_t, void *arg) { +void TcpClient::TimeoutCallback(evutil_socket_t, std::int16_t, void *const arg) { try { TimeoutCallbackInner(arg); } catch (const std::exception &e) { @@ -173,13 +173,13 @@ void TcpClient::TimeoutCallback(evutil_socket_t, std::int16_t, void *arg) { } } -void TcpClient::TimeoutCallbackInner(void *arg) { +void TcpClient::TimeoutCallbackInner(void *const arg) { MS_EXCEPTION_IF_NULL(arg); auto tcp_client = reinterpret_cast(arg); tcp_client->Init(); } -void TcpClient::ReadCallback(struct bufferevent *bev, void *ctx) { +void TcpClient::ReadCallback(struct bufferevent *bev, void *const ctx) { try { ReadCallbackInner(bev, ctx); } catch (const std::exception &e) { @@ -187,7 +187,7 @@ void TcpClient::ReadCallback(struct bufferevent *bev, void *ctx) { } } -void TcpClient::ReadCallbackInner(struct bufferevent *bev, void *ctx) { +void TcpClient::ReadCallbackInner(struct bufferevent *bev, void *const ctx) { MS_EXCEPTION_IF_NULL(bev); MS_EXCEPTION_IF_NULL(ctx); auto tcp_client = reinterpret_cast(ctx); @@ -234,7 +234,7 @@ bool TcpClient::EstablishSSL() { return true; } -void TcpClient::EventCallback(struct bufferevent *bev, std::int16_t events, void *ptr) { +void TcpClient::EventCallback(struct bufferevent *bev, std::int16_t events, void *const ptr) { try { EventCallbackInner(bev, events, ptr); } catch (const std::exception &e) { @@ -242,7 +242,7 @@ void TcpClient::EventCallback(struct bufferevent *bev, std::int16_t events, void } } -void TcpClient::EventCallbackInner(struct bufferevent *bev, std::int16_t events, void *ptr) { +void TcpClient::EventCallbackInner(struct bufferevent *bev, std::int16_t events, void *const ptr) { MS_EXCEPTION_IF_NULL(bev); MS_EXCEPTION_IF_NULL(ptr); auto tcp_client = reinterpret_cast(ptr); diff --git a/mindspore/ccsrc/ps/core/communicator/tcp_server.cc b/mindspore/ccsrc/ps/core/communicator/tcp_server.cc index 13cc675e26b..65c72f9f827 100644 --- a/mindspore/ccsrc/ps/core/communicator/tcp_server.cc +++ b/mindspore/ccsrc/ps/core/communicator/tcp_server.cc @@ -245,7 +245,7 @@ void TcpServer::RemoveConnection(const evutil_socket_t &fd) { std::shared_ptr TcpServer::GetConnectionByFd(const evutil_socket_t &fd) { return connections_[fd]; } void TcpServer::ListenerCallback(struct evconnlistener *, evutil_socket_t fd, struct sockaddr *sockaddr, int, - void *data) { + void *const data) { try { ListenerCallbackInner(fd, sockaddr, data); } catch (const std::exception &e) { @@ -253,7 +253,7 @@ void TcpServer::ListenerCallback(struct evconnlistener *, evutil_socket_t fd, st } } -void TcpServer::ListenerCallbackInner(evutil_socket_t fd, struct sockaddr *sockaddr, void *data) { +void TcpServer::ListenerCallbackInner(evutil_socket_t fd, struct sockaddr *sockaddr, void *const data) { auto server = reinterpret_cast(data); MS_EXCEPTION_IF_NULL(server); auto base = reinterpret_cast(server->base_); @@ -320,7 +320,7 @@ std::shared_ptr TcpServer::onCreateConnection(struct bufferevent OnServerReceiveMessage TcpServer::GetServerReceive() const { return message_callback_; } -void TcpServer::SignalCallback(evutil_socket_t, std::int16_t, void *data) { +void TcpServer::SignalCallback(evutil_socket_t, std::int16_t, void *const data) { try { SignalCallbackInner(data); } catch (const std::exception &e) { @@ -328,7 +328,7 @@ void TcpServer::SignalCallback(evutil_socket_t, std::int16_t, void *data) { } } -void TcpServer::SignalCallbackInner(void *data) { +void TcpServer::SignalCallbackInner(void *const data) { MS_EXCEPTION_IF_NULL(data); auto server = reinterpret_cast(data); struct event_base *base = server->base_; @@ -340,7 +340,7 @@ void TcpServer::SignalCallbackInner(void *data) { } } -void TcpServer::ReadCallback(struct bufferevent *bev, void *connection) { +void TcpServer::ReadCallback(struct bufferevent *bev, void *const connection) { try { ReadCallbackInner(bev, connection); } catch (const std::exception &e) { @@ -348,7 +348,7 @@ void TcpServer::ReadCallback(struct bufferevent *bev, void *connection) { } } -void TcpServer::ReadCallbackInner(struct bufferevent *bev, void *connection) { +void TcpServer::ReadCallbackInner(struct bufferevent *bev, void *const connection) { MS_EXCEPTION_IF_NULL(bev); MS_EXCEPTION_IF_NULL(connection); @@ -365,7 +365,7 @@ void TcpServer::ReadCallbackInner(struct bufferevent *bev, void *connection) { } } -void TcpServer::EventCallback(struct bufferevent *bev, std::int16_t events, void *data) { +void TcpServer::EventCallback(struct bufferevent *bev, std::int16_t events, void *const data) { try { EventCallbackInner(bev, events, data); } catch (const std::exception &e) { @@ -373,7 +373,7 @@ void TcpServer::EventCallback(struct bufferevent *bev, std::int16_t events, void } } -void TcpServer::EventCallbackInner(struct bufferevent *bev, std::int16_t events, void *data) { +void TcpServer::EventCallbackInner(struct bufferevent *bev, std::int16_t events, void *const data) { MS_EXCEPTION_IF_NULL(bev); MS_EXCEPTION_IF_NULL(data); struct evbuffer *output = bufferevent_get_output(bev); diff --git a/mindspore/ccsrc/ps/core/scheduler_node.cc b/mindspore/ccsrc/ps/core/scheduler_node.cc index 92bb6873ace..e27f0792048 100644 --- a/mindspore/ccsrc/ps/core/scheduler_node.cc +++ b/mindspore/ccsrc/ps/core/scheduler_node.cc @@ -92,8 +92,10 @@ void SchedulerNode::RunRecovery() { node_manager_.set_next_server_rank_id(clusterConfig.initial_next_server_rank_id); node_manager_.set_total_node_num(clusterConfig.initial_total_node_num); - for (const auto kvs : initial_node_infos) { - auto client = std::make_shared(kvs.second.ip_, kvs.second.port_, config_.get()); + for (const auto &kvs : initial_node_infos) { + auto &node_id = kvs.first; + auto &node_info = kvs.second; + auto client = std::make_shared(node_info.ip_, node_info.port_, config_.get()); client->SetMessageCallback( [&](const std::shared_ptr &meta, const Protos &protos, const void *data, size_t size) { MS_LOG(INFO) << "received the response. "; @@ -106,20 +108,20 @@ void SchedulerNode::RunRecovery() { MS_EXCEPTION_IF_NULL(message_meta); message_meta->set_cmd(NodeCommand::SCHEDULER_RECOVERY); - int rank_id = kvs.second.rank_id_; + auto rank_id = node_info.rank_id_; SendMetadataMessage scheduler_recovery_message; scheduler_recovery_message.set_worker_num(worker_num); scheduler_recovery_message.set_server_num(server_num); scheduler_recovery_message.set_rank_id(rank_id); if (!SendMessageSync(client, message_meta, Protos::PROTOBUF, scheduler_recovery_message.SerializeAsString().data(), scheduler_recovery_message.ByteSizeLong())) { - if (kvs.second.node_role_ == NodeRole::WORKER) { + if (node_info.node_role_ == NodeRole::WORKER) { is_worker_timeout_ = true; break; } - MS_LOG(WARNING) << "Scheduler send recovery msg to " << kvs.first << " timeout!"; + MS_LOG(WARNING) << "Scheduler send recovery msg to " << node_id << " timeout!"; } else { - MS_LOG(INFO) << "Scheduler send recovery msg to " << kvs.first << " successful."; + MS_LOG(INFO) << "Scheduler send recovery msg to " << node_id << " successful."; } } MS_LOG(INFO) << "Scheduler recovery finish."; @@ -1348,7 +1350,7 @@ void SchedulerNode::BroadcastTimeoutEvent() { auto initial_node_infos = clusterConfig.initial_registered_nodes_infos; const uint32_t event = static_cast(ps::UserDefineEvent::kNodeTimeout); MS_LOG(INFO) << "Broad timeout event:" << event; - for (const auto kvs : initial_node_infos) { + for (const auto &kvs : initial_node_infos) { auto client = GetOrCreateClient(kvs.second); SendEvent(client, event); }