-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core] Fix gcs healthch manager crash when node is removed by node manager. #31917
Merged
+90
−59
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d360389
potential fix
fishbone 71b91f3
fix
fishbone 407a8f0
checking
fishbone 10a6afc
fix
fishbone 5b265da
up
fishbone 9344a27
fix
fishbone b78ef88
fix
fishbone ee370a3
format
fishbone 5231a41
fix
fishbone ca37f6c
fix win
fishbone e75a2b6
format
fishbone 84b9f8e
skip tsan for stress test
fishbone a07e1fc
fix
fishbone 70bc03b
up
fishbone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,13 @@ | |
#include <boost/date_time/posix_time/posix_time.hpp> | ||
#include <boost/optional.hpp> | ||
#include <boost/thread.hpp> | ||
#include <cstdlib> | ||
#include <unordered_map> | ||
|
||
using namespace boost; | ||
using namespace boost::asio; | ||
using namespace boost::asio::ip; | ||
|
||
#include <ray/rpc/grpc_server.h> | ||
|
||
#include <chrono> | ||
|
@@ -30,6 +34,20 @@ using namespace boost; | |
#include "gtest/gtest.h" | ||
#include "ray/gcs/gcs_server/gcs_health_check_manager.h" | ||
|
||
int GetFreePort() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fun fact: it's generated by chatgpt |
||
io_service io_service; | ||
tcp::acceptor acceptor(io_service); | ||
tcp::endpoint endpoint; | ||
|
||
// try to bind to port 0 to find a free port | ||
acceptor.open(tcp::v4()); | ||
acceptor.bind(tcp::endpoint(tcp::v4(), 0)); | ||
endpoint = acceptor.local_endpoint(); | ||
auto port = endpoint.port(); | ||
acceptor.close(); | ||
return port; | ||
} | ||
|
||
using namespace ray; | ||
using namespace std::literals::chrono_literals; | ||
|
||
|
@@ -46,7 +64,6 @@ class GcsHealthCheckManagerTest : public ::testing::Test { | |
timeout_ms, | ||
period_ms, | ||
failure_threshold); | ||
port = 10000; | ||
} | ||
|
||
void TearDown() override { | ||
|
@@ -65,7 +82,8 @@ class GcsHealthCheckManagerTest : public ::testing::Test { | |
NodeID AddServer(bool alive = true) { | ||
std::promise<int> port_promise; | ||
auto node_id = NodeID::FromRandom(); | ||
|
||
auto port = GetFreePort(); | ||
RAY_LOG(INFO) << "Get port " << port; | ||
auto server = std::make_shared<rpc::GrpcServer>(node_id.Hex(), port, true); | ||
|
||
auto channel = grpc::CreateChannel("localhost:" + std::to_string(port), | ||
|
@@ -76,7 +94,6 @@ class GcsHealthCheckManagerTest : public ::testing::Test { | |
} | ||
servers.emplace(node_id, server); | ||
health_check->AddNode(node_id, channel); | ||
++port; | ||
return node_id; | ||
} | ||
|
||
|
@@ -115,14 +132,13 @@ class GcsHealthCheckManagerTest : public ::testing::Test { | |
} | ||
} | ||
|
||
int port; | ||
instrumented_io_context io_service; | ||
std::unique_ptr<gcs::GcsHealthCheckManager> health_check; | ||
std::unordered_map<NodeID, std::shared_ptr<rpc::GrpcServer>> servers; | ||
std::unordered_set<NodeID> dead_nodes; | ||
const int64_t initial_delay_ms = 1000; | ||
const int64_t timeout_ms = 1000; | ||
const int64_t period_ms = 1000; | ||
const int64_t initial_delay_ms = 100; | ||
const int64_t timeout_ms = 10; | ||
const int64_t period_ms = 10; | ||
const int64_t failure_threshold = 5; | ||
}; | ||
|
||
|
@@ -143,8 +159,6 @@ TEST_F(GcsHealthCheckManagerTest, TestBasic) { | |
Run(2); // One for starting RPC and one for the RPC callback. | ||
} | ||
|
||
Run(); // For failure callback. | ||
|
||
ASSERT_EQ(1, dead_nodes.size()); | ||
ASSERT_TRUE(dead_nodes.count(node_id)); | ||
} | ||
|
@@ -169,8 +183,6 @@ TEST_F(GcsHealthCheckManagerTest, StoppedAndResume) { | |
} | ||
} | ||
|
||
Run(); // For failure callback. | ||
|
||
ASSERT_EQ(0, dead_nodes.size()); | ||
} | ||
|
||
|
@@ -196,8 +208,6 @@ TEST_F(GcsHealthCheckManagerTest, Crashed) { | |
Run(2); // One for starting RPC and one for the RPC callback. | ||
} | ||
|
||
Run(); // For failure callback. | ||
|
||
ASSERT_EQ(1, dead_nodes.size()); | ||
ASSERT_TRUE(dead_nodes.count(node_id)); | ||
} | ||
|
@@ -230,12 +240,49 @@ TEST_F(GcsHealthCheckManagerTest, NoRegister) { | |
Run(2); // One for starting RPC and one for the RPC callback. | ||
} | ||
|
||
Run(2); | ||
Run(1); | ||
ASSERT_EQ(1, dead_nodes.size()); | ||
ASSERT_TRUE(dead_nodes.count(node_id)); | ||
} | ||
|
||
TEST_F(GcsHealthCheckManagerTest, StressTest) { | ||
#ifdef _RAY_TSAN_BUILD | ||
GTEST_SKIP() << "Disabled in tsan because of performance"; | ||
#endif | ||
boost::asio::io_service::work work(io_service); | ||
std::srand(std::time(nullptr)); | ||
auto t = std::make_unique<std::thread>([this]() { this->io_service.run(); }); | ||
|
||
std::vector<NodeID> alive_nodes; | ||
|
||
for (int i = 0; i < 200; ++i) { | ||
alive_nodes.emplace_back(AddServer(true)); | ||
std::this_thread::sleep_for(10ms); | ||
} | ||
|
||
for (size_t i = 0; i < 20000UL; ++i) { | ||
RAY_LOG(INFO) << "Progress: " << i << "/20000"; | ||
auto iter = alive_nodes.begin() + std::rand() % alive_nodes.size(); | ||
health_check->RemoveNode(*iter); | ||
DeleteServer(*iter); | ||
alive_nodes.erase(iter); | ||
alive_nodes.emplace_back(AddServer(true)); | ||
} | ||
RAY_LOG(INFO) << "Finished!"; | ||
io_service.stop(); | ||
t->join(); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
InitShutdownRAII ray_log_shutdown_raii(ray::RayLog::StartRayLog, | ||
ray::RayLog::ShutDownRayLog, | ||
argv[0], | ||
ray::RayLogLevel::INFO, | ||
/*log_dir=*/""); | ||
|
||
ray::RayLog::InstallFailureSignalHandler(argv[0]); | ||
ray::RayLog::InstallTerminateHandler(); | ||
|
||
::testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we make context_ an pointer or unique_ptr, would it make it more nature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It actually doesn't matter any difference I think since at the same time, only one in-flight request will be there per node.
I did this just following what gRPC did (https://sourcegraph.com/github.com/grpc/grpc/-/blob/test/cpp/qps/client_sync.cc?L189:26) and I think this is for performance (allocate on stack vs allocate on heap)(perf is not very important here, so I think no big difference.)