Fix resource_ids_ data race (#8253)

This commit is contained in:
Edward Oakes
2020-04-30 18:55:54 -05:00
committed by GitHub
parent 43be73e4cf
commit 484f68765c
2 changed files with 10 additions and 6 deletions
+8 -4
View File
@@ -1352,6 +1352,11 @@ Status CoreWorker::GetActorHandle(const ActorID &actor_id,
return Status::OK();
}
const ResourceMappingType CoreWorker::GetResourceIDs() const {
absl::MutexLock lock(&mutex_);
return *resource_ids_;
}
std::unique_ptr<worker::ProfileEvent> CoreWorker::CreateProfileEvent(
const std::string &event_type) {
return std::unique_ptr<worker::ProfileEvent>(
@@ -1413,10 +1418,6 @@ Status CoreWorker::ExecuteTask(const TaskSpecification &task_spec,
task_queue_length_ -= 1;
num_executed_tasks_ += 1;
if (resource_ids != nullptr) {
resource_ids_ = resource_ids;
}
if (!options_.is_local_mode) {
worker_context_.SetCurrentTask(task_spec);
SetCurrentTaskId(task_spec.TaskId());
@@ -1424,6 +1425,9 @@ Status CoreWorker::ExecuteTask(const TaskSpecification &task_spec,
{
absl::MutexLock lock(&mutex_);
current_task_ = task_spec;
if (resource_ids) {
resource_ids_ = resource_ids;
}
}
RayFunction func{task_spec.GetLanguage(), task_spec.FunctionDescriptor()};
+2 -2
View File
@@ -634,7 +634,7 @@ class CoreWorker : public rpc::CoreWorkerServiceHandler {
const ActorID &GetActorId() const { return actor_id_; }
// Get the resource IDs available to this worker (as assigned by the raylet).
const ResourceMappingType GetResourceIDs() const { return *resource_ids_; }
const ResourceMappingType GetResourceIDs() const;
/// Create a profile event with a reference to the core worker's profiler.
std::unique_ptr<worker::ProfileEvent> CreateProfileEvent(const std::string &event_type);
@@ -1028,7 +1028,7 @@ class CoreWorker : public rpc::CoreWorkerServiceHandler {
/// A map from resource name to the resource IDs that are currently reserved
/// for this worker. Each pair consists of the resource ID and the fraction
/// of that resource allocated for this worker. This is set on task assignment.
std::shared_ptr<ResourceMappingType> resource_ids_;
std::shared_ptr<ResourceMappingType> resource_ids_ GUARDED_BY(mutex_);
// Interface that receives tasks from the raylet.
std::unique_ptr<CoreWorkerRayletTaskReceiver> raylet_task_receiver_;