Skip to content

Commit 146590b

Browse files
authored
[core] Cover cpplint for ray/tree/master/src/ray/gcs (#51407)
Signed-off-by: Ziy1-Tan <ajb459684460@gmail.com>
1 parent 2c45a71 commit 146590b

34 files changed

+169
-65
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ repos:
4747
hooks:
4848
- id: cpplint
4949
args: ["--filter=-whitespace/braces,-whitespace/line_length,-build/c++11,-build/c++14,-build/c++17,-readability/braces,-whitespace/indent_namespace,-runtime/int,-runtime/references,-build/include_order"]
50-
files: ^src/ray/(util|raylet_client|internal|scheduling|pubsub|object_manager|gcs/gcs_server|rpc(?:/.*)?)/.*\.(h|cc)$
50+
files: ^src/ray/(util|raylet_client|internal|scheduling|pubsub|object_manager|gcs|rpc(?:/.*)?)/.*\.(h|cc)$
5151

5252
- repo: https://github.com/keith/pre-commit-buildifier
5353
rev: 8.0.1

src/ray/gcs/gcs_client/accessor.cc

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
#include "ray/gcs/gcs_client/accessor.h"
1616

1717
#include <future>
18+
#include <memory>
19+
#include <string>
20+
#include <unordered_map>
21+
#include <utility>
22+
#include <vector>
1823

1924
#include "ray/common/asio/instrumented_io_context.h"
2025
#include "ray/common/common_protocol.h"
@@ -24,16 +29,14 @@
2429
namespace ray {
2530
namespace gcs {
2631

27-
using namespace ray::rpc;
28-
2932
int64_t GetGcsTimeoutMs() {
3033
return absl::ToInt64Milliseconds(
3134
absl::Seconds(RayConfig::instance().gcs_server_request_timeout_seconds()));
3235
}
3336

3437
JobInfoAccessor::JobInfoAccessor(GcsClient *client_impl) : client_impl_(client_impl) {}
3538

36-
Status JobInfoAccessor::AsyncAdd(const std::shared_ptr<JobTableData> &data_ptr,
39+
Status JobInfoAccessor::AsyncAdd(const std::shared_ptr<rpc::JobTableData> &data_ptr,
3740
const StatusCallback &callback) {
3841
JobID job_id = JobID::FromBinary(data_ptr->job_id());
3942
RAY_LOG(DEBUG).WithField(job_id)
@@ -70,7 +73,8 @@ Status JobInfoAccessor::AsyncMarkFinished(const JobID &job_id,
7073
}
7174

7275
Status JobInfoAccessor::AsyncSubscribeAll(
73-
const SubscribeCallback<JobID, JobTableData> &subscribe, const StatusCallback &done) {
76+
const SubscribeCallback<JobID, rpc::JobTableData> &subscribe,
77+
const StatusCallback &done) {
7478
RAY_CHECK(subscribe != nullptr);
7579
fetch_all_data_operation_ = [this, subscribe](const StatusCallback &done) {
7680
auto callback = [subscribe, done](const Status &status,
@@ -474,13 +478,13 @@ bool ActorInfoAccessor::IsActorUnsubscribed(const ActorID &actor_id) {
474478

475479
NodeInfoAccessor::NodeInfoAccessor(GcsClient *client_impl) : client_impl_(client_impl) {}
476480

477-
Status NodeInfoAccessor::RegisterSelf(const GcsNodeInfo &local_node_info,
481+
Status NodeInfoAccessor::RegisterSelf(const rpc::GcsNodeInfo &local_node_info,
478482
const StatusCallback &callback) {
479483
auto node_id = NodeID::FromBinary(local_node_info.node_id());
480484
RAY_LOG(DEBUG).WithField(node_id)
481485
<< "Registering node info, address is = " << local_node_info.node_manager_address();
482486
RAY_CHECK(local_node_id_.IsNil()) << "This node is already connected.";
483-
RAY_CHECK(local_node_info.state() == GcsNodeInfo::ALIVE);
487+
RAY_CHECK(local_node_info.state() == rpc::GcsNodeInfo::ALIVE);
484488
rpc::RegisterNodeRequest request;
485489
request.mutable_node_info()->CopyFrom(local_node_info);
486490
client_impl_->GetGcsRpcClient().RegisterNode(
@@ -518,7 +522,7 @@ void NodeInfoAccessor::UnregisterSelf(const rpc::NodeDeathInfo &node_death_info,
518522
[this, node_id, unregister_done_callback](const Status &status,
519523
rpc::UnregisterNodeReply &&reply) {
520524
if (status.ok()) {
521-
local_node_info_.set_state(GcsNodeInfo::DEAD);
525+
local_node_info_.set_state(rpc::GcsNodeInfo::DEAD);
522526
local_node_id_ = NodeID::Nil();
523527
}
524528
RAY_LOG(INFO).WithField(node_id)
@@ -529,7 +533,7 @@ void NodeInfoAccessor::UnregisterSelf(const rpc::NodeDeathInfo &node_death_info,
529533

530534
const NodeID &NodeInfoAccessor::GetSelfId() const { return local_node_id_; }
531535

532-
const GcsNodeInfo &NodeInfoAccessor::GetSelfInfo() const { return local_node_info_; }
536+
const rpc::GcsNodeInfo &NodeInfoAccessor::GetSelfInfo() const { return local_node_info_; }
533537

534538
Status NodeInfoAccessor::AsyncRegister(const rpc::GcsNodeInfo &node_info,
535539
const StatusCallback &callback) {
@@ -614,7 +618,7 @@ Status NodeInfoAccessor::DrainNodes(const std::vector<NodeID> &node_ids,
614618
return Status::OK();
615619
}
616620

617-
Status NodeInfoAccessor::AsyncGetAll(const MultiItemCallback<GcsNodeInfo> &callback,
621+
Status NodeInfoAccessor::AsyncGetAll(const MultiItemCallback<rpc::GcsNodeInfo> &callback,
618622
int64_t timeout_ms,
619623
std::optional<NodeID> node_id) {
620624
RAY_LOG(DEBUG) << "Getting information of all nodes.";
@@ -625,7 +629,7 @@ Status NodeInfoAccessor::AsyncGetAll(const MultiItemCallback<GcsNodeInfo> &callb
625629
client_impl_->GetGcsRpcClient().GetAllNodeInfo(
626630
request,
627631
[callback](const Status &status, rpc::GetAllNodeInfoReply &&reply) {
628-
std::vector<GcsNodeInfo> result;
632+
std::vector<rpc::GcsNodeInfo> result;
629633
result.reserve((reply.node_info_list_size()));
630634
for (int index = 0; index < reply.node_info_list_size(); ++index) {
631635
result.emplace_back(reply.node_info_list(index));
@@ -639,14 +643,15 @@ Status NodeInfoAccessor::AsyncGetAll(const MultiItemCallback<GcsNodeInfo> &callb
639643
}
640644

641645
Status NodeInfoAccessor::AsyncSubscribeToNodeChange(
642-
const SubscribeCallback<NodeID, GcsNodeInfo> &subscribe, const StatusCallback &done) {
646+
const SubscribeCallback<NodeID, rpc::GcsNodeInfo> &subscribe,
647+
const StatusCallback &done) {
643648
RAY_CHECK(subscribe != nullptr);
644649
RAY_CHECK(node_change_callback_ == nullptr);
645650
node_change_callback_ = subscribe;
646651

647652
fetch_node_data_operation_ = [this](const StatusCallback &done) {
648653
auto callback = [this, done](const Status &status,
649-
std::vector<GcsNodeInfo> &&node_info_list) {
654+
std::vector<rpc::GcsNodeInfo> &&node_info_list) {
650655
for (auto &node_info : node_info_list) {
651656
HandleNotification(std::move(node_info));
652657
}
@@ -658,7 +663,7 @@ Status NodeInfoAccessor::AsyncSubscribeToNodeChange(
658663
};
659664

660665
subscribe_node_operation_ = [this](const StatusCallback &done) {
661-
auto on_subscribe = [this](GcsNodeInfo &&data) {
666+
auto on_subscribe = [this](rpc::GcsNodeInfo &&data) {
662667
HandleNotification(std::move(data));
663668
};
664669
return client_impl_->GetGcsSubscriber().SubscribeAllNodeInfo(on_subscribe, done);
@@ -669,8 +674,8 @@ Status NodeInfoAccessor::AsyncSubscribeToNodeChange(
669674
});
670675
}
671676

672-
const GcsNodeInfo *NodeInfoAccessor::Get(const NodeID &node_id,
673-
bool filter_dead_nodes) const {
677+
const rpc::GcsNodeInfo *NodeInfoAccessor::Get(const NodeID &node_id,
678+
bool filter_dead_nodes) const {
674679
RAY_CHECK(!node_id.IsNil());
675680
auto entry = node_cache_.find(node_id);
676681
if (entry != node_cache_.end()) {
@@ -682,7 +687,7 @@ const GcsNodeInfo *NodeInfoAccessor::Get(const NodeID &node_id,
682687
return nullptr;
683688
}
684689

685-
const absl::flat_hash_map<NodeID, GcsNodeInfo> &NodeInfoAccessor::GetAll() const {
690+
const absl::flat_hash_map<NodeID, rpc::GcsNodeInfo> &NodeInfoAccessor::GetAll() const {
686691
return node_cache_;
687692
}
688693

@@ -725,9 +730,9 @@ bool NodeInfoAccessor::IsRemoved(const NodeID &node_id) const {
725730
return removed_nodes_.count(node_id) == 1;
726731
}
727732

728-
void NodeInfoAccessor::HandleNotification(GcsNodeInfo &&node_info) {
733+
void NodeInfoAccessor::HandleNotification(rpc::GcsNodeInfo &&node_info) {
729734
NodeID node_id = NodeID::FromBinary(node_info.node_id());
730-
bool is_alive = (node_info.state() == GcsNodeInfo::ALIVE);
735+
bool is_alive = (node_info.state() == rpc::GcsNodeInfo::ALIVE);
731736
auto entry = node_cache_.find(node_id);
732737
bool is_notif_new;
733738
if (entry == node_cache_.end()) {
@@ -736,7 +741,7 @@ void NodeInfoAccessor::HandleNotification(GcsNodeInfo &&node_info) {
736741
} else {
737742
// If the entry is in the cache, then the notification is new if the node
738743
// was alive and is now dead or resources have been updated.
739-
bool was_alive = (entry->second.state() == GcsNodeInfo::ALIVE);
744+
bool was_alive = (entry->second.state() == rpc::GcsNodeInfo::ALIVE);
740745
is_notif_new = was_alive && !is_alive;
741746

742747
// Once a node with a given ID has been removed, it should never be added
@@ -778,7 +783,7 @@ void NodeInfoAccessor::HandleNotification(GcsNodeInfo &&node_info) {
778783
}
779784
if (node_change_callback_) {
780785
// Copy happens!
781-
GcsNodeInfo cache_data_copied = node_cache_[node_id];
786+
rpc::GcsNodeInfo cache_data_copied = node_cache_[node_id];
782787
node_change_callback_(node_id, std::move(cache_data_copied));
783788
}
784789
}
@@ -1160,7 +1165,7 @@ Status InternalKVAccessor::AsyncInternalKVGet(
11601165
client_impl_->GetGcsRpcClient().InternalKVGet(
11611166
req,
11621167
[callback](const Status &status, rpc::InternalKVGetReply &&reply) {
1163-
if (reply.status().code() == (int)StatusCode::NotFound) {
1168+
if (reply.status().code() == static_cast<int>(StatusCode::NotFound)) {
11641169
callback(status, std::nullopt);
11651170
} else {
11661171
callback(status, reply.value());

src/ray/gcs/gcs_client/accessor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
// limitations under the License.
1414

1515
#pragma once
16+
#include <memory>
17+
#include <string>
18+
#include <unordered_map>
19+
#include <unordered_set>
20+
#include <vector>
1621

1722
#include "absl/types/optional.h"
1823
#include "ray/common/id.h"

src/ray/gcs/gcs_client/gcs_client.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
#include "ray/gcs/gcs_client/gcs_client.h"
1616

1717
#include <chrono>
18+
#include <memory>
19+
#include <string>
1820
#include <thread>
21+
#include <unordered_map>
1922
#include <utility>
23+
#include <vector>
2024

2125
#include "ray/common/asio/asio_util.h"
2226
#include "ray/common/ray_config.h"

src/ray/gcs/gcs_client/gcs_client.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
#include <boost/asio.hpp>
2020
#include <memory>
2121
#include <string>
22+
#include <unordered_map>
23+
#include <utility>
2224
#include <vector>
2325

2426
#include "absl/strings/str_split.h"
25-
#include "gtest/gtest_prod.h"
2627
#include "ray/common/asio/instrumented_io_context.h"
2728
#include "ray/common/asio/periodical_runner.h"
2829
#include "ray/common/id.h"

src/ray/gcs/gcs_client/global_state_accessor.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414

1515
#include "ray/gcs/gcs_client/global_state_accessor.h"
1616

17+
#include <algorithm>
1718
#include <boost/algorithm/string.hpp>
19+
#include <memory>
20+
#include <string>
21+
#include <unordered_map>
22+
#include <utility>
23+
#include <vector>
1824

1925
#include "ray/common/asio/instrumented_io_context.h"
2026

src/ray/gcs/gcs_client/global_state_accessor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
#pragma once
1616

17+
#include <algorithm>
18+
#include <memory>
19+
#include <string>
20+
#include <unordered_map>
21+
#include <vector>
22+
1723
#include "absl/base/thread_annotations.h"
1824
#include "absl/synchronization/mutex.h"
1925
#include "ray/common/asio/instrumented_io_context.h"

src/ray/gcs/gcs_client/python_callbacks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <Python.h>
1818

1919
#include <string>
20+
#include <utility>
2021
#include <vector>
2122

2223
#include "ray/util/logging.h"

src/ray/gcs/gcs_client/test/accessor_test.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414

1515
#include "ray/gcs/gcs_client/accessor.h"
1616

17+
#include <utility>
18+
1719
#include "gtest/gtest.h"
1820
#include "src/ray/protobuf/gcs.pb.h"
1921

2022
namespace ray {
21-
using namespace ray::gcs;
22-
using namespace ray::rpc;
23+
using namespace ray::gcs; // NOLINT
24+
using namespace ray::rpc; // NOLINT
2325

2426
TEST(NodeInfoAccessorTest, TestHandleNotification) {
2527
NodeInfoAccessor accessor;

src/ray/gcs/gcs_client/test/gcs_client_reconnection_test.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#include <boost/asio/ip/tcp.hpp>
1616
#include <chrono>
1717
#include <future>
18+
#include <memory>
19+
#include <string>
20+
#include <vector>
1821

1922
#include "absl/strings/substitute.h"
2023
#include "gtest/gtest.h"
@@ -27,9 +30,9 @@
2730
#include "ray/rpc/gcs_server/gcs_rpc_client.h"
2831
#include "ray/util/util.h"
2932

30-
using namespace std::chrono_literals;
31-
using namespace ray;
32-
using namespace std::chrono;
33+
using namespace std::chrono_literals; // NOLINT
34+
using namespace ray; // NOLINT
35+
using namespace std::chrono; // NOLINT
3336

3437
class GcsClientReconnectionTest : public ::testing::Test {
3538
public:
@@ -127,7 +130,7 @@ class GcsClientReconnectionTest : public ::testing::Test {
127130

128131
protected:
129132
unsigned short GetFreePort() {
130-
using namespace boost::asio;
133+
using namespace boost::asio; // NOLINT
131134
io_service service;
132135
ip::tcp::acceptor acceptor(service, ip::tcp::endpoint(ip::tcp::v4(), 0));
133136
unsigned short port = acceptor.local_endpoint().port();

0 commit comments

Comments
 (0)