Skip to content
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][Core-worker] fix the initialization/destruction order between reference_counter_ and node change subscription. #29108

Merged
merged 4 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions src/ray/core_worker/core_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,6 @@ CoreWorker::CoreWorker(const CoreWorkerOptions &options, const WorkerID &worker_
RAY_CHECK_OK(gcs_client_->Connect(io_service_));
RegisterToGcs();

// Register a callback to monitor removed nodes.
auto on_node_change = [this](const NodeID &node_id, const rpc::GcsNodeInfo &data) {
if (data.state() == rpc::GcsNodeInfo::DEAD) {
OnNodeRemoved(node_id);
}
};
RAY_CHECK_OK(gcs_client_->Nodes().AsyncSubscribeToNodeChange(on_node_change, nullptr));

// Initialize profiler.
profiler_ = std::make_shared<worker::Profiler>(
worker_context_, options_.node_ip_address, io_service_, gcs_client_);
Expand Down Expand Up @@ -272,6 +264,20 @@ CoreWorker::CoreWorker(const CoreWorkerOptions &options, const WorkerID &worker_
new rpc::CoreWorkerClient(addr, *client_call_manager_));
});

// Register a callback to monitor removed nodes.
// Note we capture a shared ownership of reference_counter_
// here to avoid destruction order fiasco between gcs_client and reference_counter_.
auto on_node_change = [reference_counter = this->reference_counter_](
const NodeID &node_id, const rpc::GcsNodeInfo &data) {
if (data.state() == rpc::GcsNodeInfo::DEAD) {
RAY_LOG(INFO) << "Node failure from " << node_id
<< ". All objects pinned on that node will be lost if object "
"reconstruction is not enabled.";
reference_counter->ResetObjectsOnRemovedNode(node_id);
}
};
RAY_CHECK_OK(gcs_client_->Nodes().AsyncSubscribeToNodeChange(on_node_change, nullptr));

plasma_store_provider_.reset(new CoreWorkerPlasmaStoreProvider(
options_.store_socket,
local_raylet_client_,
Expand Down Expand Up @@ -722,16 +728,6 @@ void CoreWorker::RunIOService() {
RAY_LOG(INFO) << "Core worker main io service stopped.";
}

void CoreWorker::OnNodeRemoved(const NodeID &node_id) {
// if (node_id == GetCurrentNodeId()) {
// RAY_LOG(FATAL) << "The raylet for this worker has died. Killing itself...";
// }
RAY_LOG(INFO) << "Node failure from " << node_id
<< ". All objects pinned on that node will be lost if object "
"reconstruction is not enabled.";
reference_counter_->ResetObjectsOnRemovedNode(node_id);
}

const WorkerID &CoreWorker::GetWorkerID() const { return worker_context_.GetWorkerID(); }

void CoreWorker::SetCurrentTaskId(const TaskID &task_id,
Expand Down
3 changes: 0 additions & 3 deletions src/ray/core_worker/core_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -1216,9 +1216,6 @@ class CoreWorker : public rpc::CoreWorkerServiceHandler {
}
}

/// Handler if a raylet node is removed from the cluster.
void OnNodeRemoved(const NodeID &node_id);

/// Request the spillage of an object that we own from the primary that hosts
/// the primary copy to spill.
void SpillOwnedObject(const ObjectID &object_id,
Expand Down