-
Notifications
You must be signed in to change notification settings - Fork 7.1k
[Core Worker] implement ObjectInterface and add test framework #4899
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
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
121b24f
Initial high-level code structure of CoreWorker.
raulchen bca82ed
Rename buffer.h and add const
raulchen ac1bdc2
shared_ptr and more comments
raulchen 0964b32
prototype for task submission
zhijunfu e481ec5
update
zhijunfu 8259d9f
fixes
raulchen 35ce1a3
fix typo
raulchen a9b4f12
use reference
raulchen ea75b8d
format
raulchen dc58275
add override keyword and rename length to size
raulchen cd35803
rename Arg to TaskArg
raulchen f1ed0da
Refine TaskArg
raulchen 81c0ff4
Change CoreWorker pointer to reference
raulchen 2de7c9b
comment
raulchen 490e90e
implement task execution
zhijunfu a53daba
merge
zhijunfu c7dba57
add object interface
zhijunfu db4eae7
update
zhijunfu d92ffe3
fix compile
zhijunfu 8516658
add test for ObjectInterface
zhijunfu e6ca92b
add test script
zhijunfu 2c2dda3
merge and remove other interfaces except ObjectInterface
zhijunfu 8f86942
typo
zhijunfu 1f8151c
resolve comments
zhijunfu 0e5b217
update for comments
zhijunfu 31b9169
new line
zhijunfu cca5b57
add core work test to ci
zhijunfu c8c89b9
add missing file
zhijunfu eb2d621
fix WorkerContext task id
zhijunfu 8d08d4c
Update src/ray/core_worker/core_worker_test.cc
zhijunfu 87a4860
Update src/ray/core_worker/core_worker_test.cc
zhijunfu 26347e5
update
zhijunfu dd5ba36
Merge remote-tracking branch 'origin/object_interface' into object_in…
zhijunfu 0f23c5b
Merge branch 'master' of https://github.com/ray-project/ray into obje…
zhijunfu 632a80f
update for IDs
zhijunfu d0e91f7
format
zhijunfu 55e3ff5
update
zhijunfu 4430b5f
fix ci
zhijunfu 3dfe1c4
format
zhijunfu 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
|
|
||
| #include "context.h" | ||
|
|
||
| namespace ray { | ||
|
|
||
| /// per-thread context for core worker. | ||
| struct WorkerThreadContext { | ||
| WorkerThreadContext() | ||
| : current_task_id(TaskID::FromRandom()), task_index(0), put_index(0) {} | ||
|
|
||
| int GetNextTaskIndex() { return ++task_index; } | ||
|
|
||
| int GetNextPutIndex() { return ++put_index; } | ||
|
|
||
| const TaskID &GetCurrentTaskID() const { return current_task_id; } | ||
|
|
||
| void SetCurrentTask(const TaskID &task_id) { | ||
| current_task_id = task_id; | ||
| task_index = 0; | ||
| put_index = 0; | ||
| } | ||
|
|
||
| void SetCurrentTask(const raylet::TaskSpecification &spec) { | ||
| SetCurrentTask(spec.TaskId()); | ||
| } | ||
|
|
||
| private: | ||
| /// The task ID for current task. | ||
| TaskID current_task_id; | ||
zhijunfu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// Number of tasks that have been submitted from current task. | ||
| int task_index; | ||
|
Contributor
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. int -> size_t |
||
|
|
||
| /// Number of objects that have been put from current task. | ||
| int put_index; | ||
| }; | ||
|
|
||
| thread_local std::unique_ptr<WorkerThreadContext> WorkerContext::thread_context_ = | ||
| nullptr; | ||
|
|
||
| WorkerContext::WorkerContext(WorkerType worker_type, const DriverID &driver_id) | ||
| : worker_type(worker_type), | ||
| worker_id(worker_type == WorkerType::DRIVER | ||
| ? ClientID::FromBinary(driver_id.Binary()) | ||
| : ClientID::FromRandom()), | ||
| current_driver_id(worker_type == WorkerType::DRIVER ? driver_id : DriverID::Nil()) { | ||
| // For worker main thread which initializes the WorkerContext, | ||
| // set task_id according to whether current worker is a driver. | ||
| // (For other threads it's set to randmom ID via GetThreadContext). | ||
| GetThreadContext().SetCurrentTask( | ||
| (worker_type == WorkerType::DRIVER) ? TaskID::FromRandom() : TaskID::Nil()); | ||
| } | ||
|
|
||
| const WorkerType WorkerContext::GetWorkerType() const { return worker_type; } | ||
|
|
||
| const ClientID &WorkerContext::GetWorkerID() const { return worker_id; } | ||
|
|
||
| int WorkerContext::GetNextTaskIndex() { return GetThreadContext().GetNextTaskIndex(); } | ||
|
|
||
| int WorkerContext::GetNextPutIndex() { return GetThreadContext().GetNextPutIndex(); } | ||
|
|
||
| const DriverID &WorkerContext::GetCurrentDriverID() const { return current_driver_id; } | ||
|
|
||
| const TaskID &WorkerContext::GetCurrentTaskID() const { | ||
| return GetThreadContext().GetCurrentTaskID(); | ||
| } | ||
|
|
||
| void WorkerContext::SetCurrentTask(const raylet::TaskSpecification &spec) { | ||
| current_driver_id = spec.DriverId(); | ||
| GetThreadContext().SetCurrentTask(spec); | ||
| } | ||
|
|
||
| WorkerThreadContext &WorkerContext::GetThreadContext() { | ||
| if (thread_context_ == nullptr) { | ||
| thread_context_ = std::unique_ptr<WorkerThreadContext>(new WorkerThreadContext()); | ||
| } | ||
|
|
||
| return *thread_context_; | ||
| } | ||
|
|
||
| } // namespace ray | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #ifndef RAY_CORE_WORKER_CONTEXT_H | ||
| #define RAY_CORE_WORKER_CONTEXT_H | ||
|
|
||
| #include "common.h" | ||
| #include "ray/raylet/task_spec.h" | ||
|
|
||
| namespace ray { | ||
|
|
||
| struct WorkerThreadContext; | ||
|
|
||
| class WorkerContext { | ||
| public: | ||
| WorkerContext(WorkerType worker_type, const DriverID &driver_id); | ||
|
|
||
| const WorkerType GetWorkerType() const; | ||
|
|
||
| const ClientID &GetWorkerID() const; | ||
|
|
||
| const DriverID &GetCurrentDriverID() const; | ||
|
|
||
| const TaskID &GetCurrentTaskID() const; | ||
|
|
||
| void SetCurrentTask(const raylet::TaskSpecification &spec); | ||
|
|
||
| int GetNextTaskIndex(); | ||
|
|
||
| int GetNextPutIndex(); | ||
|
|
||
| private: | ||
| /// Type of the worker. | ||
| const WorkerType worker_type; | ||
|
|
||
| /// ID for this worker. | ||
| const ClientID worker_id; | ||
|
|
||
| /// Driver ID for this worker. | ||
| DriverID current_driver_id; | ||
zhijunfu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private: | ||
| static WorkerThreadContext &GetThreadContext(); | ||
|
|
||
| /// Per-thread worker context. | ||
| static thread_local std::unique_ptr<WorkerThreadContext> thread_context_; | ||
| }; | ||
|
|
||
| } // namespace ray | ||
|
|
||
| #endif // RAY_CORE_WORKER_CONTEXT_H | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #include "core_worker.h" | ||
| #include "context.h" | ||
|
|
||
| namespace ray { | ||
|
|
||
| CoreWorker::CoreWorker(const enum WorkerType worker_type, const enum Language language, | ||
| const std::string &store_socket, const std::string &raylet_socket, | ||
| DriverID driver_id) | ||
| : worker_type_(worker_type), | ||
| language_(language), | ||
| worker_context_(worker_type, driver_id), | ||
| store_socket_(store_socket), | ||
| raylet_socket_(raylet_socket), | ||
| task_interface_(*this), | ||
| object_interface_(*this), | ||
| task_execution_interface_(*this) {} | ||
|
|
||
| Status CoreWorker::Connect() { | ||
| // connect to plasma. | ||
| RAY_ARROW_RETURN_NOT_OK(store_client_.Connect(store_socket_)); | ||
|
|
||
| // connect to raylet. | ||
| ::Language lang = ::Language::PYTHON; | ||
| if (language_ == ray::Language::JAVA) { | ||
| lang = ::Language::JAVA; | ||
| } | ||
zhijunfu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // TODO: currently RayletClient would crash in its constructor if it cannot | ||
| // connect to Raylet after a number of retries, this needs to be changed | ||
| // so that the worker (java/python .etc) can retrieve and handle the error | ||
| // instead of crashing. | ||
| raylet_client_ = std::unique_ptr<RayletClient>( | ||
| new RayletClient(raylet_socket_, worker_context_.GetWorkerID(), | ||
| (worker_type_ == ray::WorkerType::WORKER), | ||
| worker_context_.GetCurrentDriverID(), lang)); | ||
| return Status::OK(); | ||
| } | ||
|
|
||
| } // namespace ray | ||
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.