-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Node service plugins #5072
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
Open
bart-linera
wants to merge
16
commits into
linera-io:main
Choose a base branch
from
bart-linera:node-service-plugins
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Node service plugins #5072
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f0f4660
Node service operator plugins.
afck 0079ce2
Add a test.
afck 6fa868d
Add an example app to test the task processor.
afck 62c4f15
Avoid using sleep.
afck 6fcbd8d
Make info log more user friendly.
afck 6d4d267
Test cleanup.
afck a952dbc
Port the controller part of the PM demo
bart-linera bcc8395
Fix some CI issues
bart-linera 54a6828
Fix CLI.md
bart-linera 79bfd77
Really fix CLI.md
bart-linera e208f0a
Allow the controller to start/stop listening to chains
bart-linera 25a8096
Fix controller dependencies
bart-linera 3146095
Fix web build
bart-linera 63e1476
Fix the select! in chain listener
bart-linera 3ace93f
Use a different fix for the select! in chain listener
bart-linera 94d99ff
Fix the notification stream test
bart-linera 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,25 @@ | ||
| [package] | ||
| name = "controller" | ||
| version = "0.1.0" | ||
| authors = ["Linera <[email protected]>"] | ||
| edition = "2021" | ||
|
|
||
| [dependencies] | ||
| async-graphql = { workspace = true, default-features = false } | ||
| bcs.workspace = true | ||
| futures.workspace = true | ||
| linera-sdk.workspace = true | ||
| serde = { workspace = true, features = ["derive"] } | ||
| serde_json = { workspace = true } | ||
|
|
||
| [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] | ||
| linera-sdk = { workspace = true, features = ["test", "wasmer"] } | ||
| tokio = { workspace = true, features = ["rt", "sync"] } | ||
|
|
||
| [[bin]] | ||
| name = "controller_contract" | ||
| path = "src/contract.rs" | ||
|
|
||
| [[bin]] | ||
| name = "controller_service" | ||
| path = "src/service.rs" |
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,162 @@ | ||
| # Controller | ||
|
|
||
| The Controller is a Linera application that manages the orchestration of distributed | ||
| services across multiple worker nodes. It provides a centralized registry for workers and | ||
| services, enabling dynamic assignment and coordination. | ||
|
|
||
| ## Concepts | ||
|
|
||
| ### Workers | ||
|
|
||
| A **Worker** is a node that can run services. Each worker: | ||
| - Runs on its own chain | ||
| - Registers itself with the controller, declaring its capabilities | ||
| - Receives commands from the controller to start/stop services | ||
| - Can follow additional chains as needed | ||
|
|
||
| ### Services | ||
|
|
||
| A **Service** is a task or application component that runs on one or more workers. Services are identified by a `ServiceId` (a blob hash of their description). A service can be assigned to multiple workers for redundancy or load distribution. | ||
|
|
||
| ### Controller Chain | ||
|
|
||
| The **Controller Chain** is the chain where the controller application was originally deployed. It serves as the central authority that: | ||
| - Maintains the registry of all workers | ||
| - Tracks which services run on which workers | ||
| - Processes admin commands to update service assignments | ||
|
|
||
| ### Admin | ||
|
|
||
| **Admins** are authorized account owners who can execute controller commands to manage services. If no admin list is set, operations are permissive but remote commands are rejected for safety. | ||
|
|
||
| ## Architecture | ||
|
|
||
| Workers register with the controller and receive Start/Stop messages for services. | ||
|
|
||
| ```mermaid | ||
| graph TB | ||
| subgraph "Controller Chain" | ||
| CC[Controller Contract] | ||
| WR[(Workers Registry)] | ||
| SR[(Services Registry)] | ||
| CC --> WR | ||
| CC --> SR | ||
| end | ||
| subgraph "Worker Chain A" | ||
| WA[Worker A] | ||
| LSA[(Local Services)] | ||
| WA --> LSA | ||
| end | ||
| subgraph "Worker Chain B" | ||
| WB[Worker B] | ||
| LSB[(Local Services)] | ||
| WB --> LSB | ||
| end | ||
| subgraph "Worker Chain C" | ||
| WC[Worker C] | ||
| LSC[(Local Services)] | ||
| WC --> LSC | ||
| end | ||
| WA -->|RegisterWorker| CC | ||
| WB -->|RegisterWorker| CC | ||
| WC -->|RegisterWorker| CC | ||
| CC -->|Start/Stop| WA | ||
| CC -->|Start/Stop| WB | ||
| CC -->|Start/Stop| WC | ||
| ``` | ||
|
|
||
| ## Message Flow | ||
|
|
||
| ### Worker Registration | ||
|
|
||
| When a worker wants to join the network: | ||
|
|
||
| ```mermaid | ||
| sequenceDiagram | ||
| participant W as Worker Chain | ||
| participant C as Controller Chain | ||
| W->>W: prepare_worker_command_locally<br/>(set local_worker) | ||
| W->>C: Message::ExecuteWorkerCommand<br/>{RegisterWorker} | ||
| C->>C: execute_worker_command_locally<br/>(add to workers registry) | ||
| ``` | ||
|
|
||
| ### Service Assignment | ||
|
|
||
| When an admin assigns a service to workers: | ||
|
|
||
| ```mermaid | ||
| sequenceDiagram | ||
| participant A as Admin | ||
| participant C as Controller Chain | ||
| participant W1 as Worker 1 | ||
| participant W2 as Worker 2 | ||
| A->>C: ExecuteControllerCommand<br/>{UpdateService} | ||
| C->>C: Update services registry | ||
| C->>W1: Message::Start{service_id} | ||
| C->>W2: Message::Start{service_id} | ||
| W1->>W1: Add to local_services | ||
| W2->>W2: Add to local_services | ||
| ``` | ||
|
|
||
| ### Service Removal | ||
|
|
||
| ```mermaid | ||
| sequenceDiagram | ||
| participant A as Admin | ||
| participant C as Controller Chain | ||
| participant W1 as Worker 1 | ||
| participant W2 as Worker 2 | ||
| A->>C: ExecuteControllerCommand<br/>{RemoveService} | ||
| C->>C: Remove from services registry | ||
| C->>W1: Message::Stop{service_id} | ||
| C->>W2: Message::Stop{service_id} | ||
| W1->>W1: Remove from local_services | ||
| W2->>W2: Remove from local_services | ||
| ``` | ||
|
|
||
| ## Operations | ||
|
|
||
| ### Worker Commands | ||
|
|
||
| | Command | Description | | ||
| |---------|-------------| | ||
| | `RegisterWorker { capabilities }` | Register a worker with its capabilities | | ||
| | `DeregisterWorker` | Remove the worker from the network | | ||
|
|
||
| ### Controller Commands (Admin Only) | ||
|
|
||
| | Command | Description | | ||
| |---------|-------------| | ||
| | `SetAdmins { admins }` | Set the list of authorized admin accounts | | ||
| | `RemoveWorker { worker_id }` | Force-remove a worker and clean up its assignments | | ||
| | `UpdateService { service_id, workers }` | Assign a service to specific workers | | ||
| | `RemoveService { service_id }` | Remove a service from all workers | | ||
| | `UpdateAllServices { services }` | Bulk update all service assignments | | ||
|
|
||
| ## State | ||
|
|
||
| ### Controller Chain State | ||
|
|
||
| - `admins`: Set of authorized admin accounts | ||
| - `workers`: Map of ChainId to Worker (all registered workers) | ||
| - `services`: Map of ServiceId to Set of ChainIds (service assignments) | ||
|
|
||
| ### Worker Chain State | ||
|
|
||
| - `local_worker`: This worker's registration info | ||
| - `local_services`: Set of services running on this worker | ||
| - `local_chains`: Additional chains this worker is following | ||
|
|
||
| ## Messages | ||
|
|
||
| Messages are sent between chains to coordinate state: | ||
|
|
||
| | Message | Direction | Purpose | | ||
| |---------|-----------|---------| | ||
| | `ExecuteWorkerCommand` | Worker -> Controller | Register/deregister worker | | ||
| | `ExecuteControllerCommand` | Any -> Controller | Admin commands | | ||
| | `Reset` | Controller -> Worker | Clear worker state | | ||
| | `Start { service_id }` | Controller -> Worker | Start a service | | ||
| | `Stop { service_id }` | Controller -> Worker | Stop a service | | ||
| | `FollowChain { chain_id }` | Controller -> Worker | Follow a chain | | ||
| | `ForgetChain { chain_id }` | Controller -> Worker | Stop following a chain | |
Oops, something went wrong.
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.
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.
"operator application" is not quite right because some of these applications may not use an "operator" at all. Let's do a round of brainstorming