Fix resource_ids_ data race (#8253)

This commit is contained in:
Edward Oakes
2020-05-01 00:26:39 -07:00
committed by SangBin Cho
parent c2ef9fee74
commit 9c022975c4
2 changed files with 10 additions and 6 deletions
+8 -4
View File
@@ -1346,6 +1346,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>(
@@ -1407,10 +1412,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());
@@ -1418,6 +1419,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_;