|
ndmspc v1.2.0-0.1.rc7
|
Manages task lifecycle: pending → running → done/failed. More...
#include <NTaskStateManager.h>
Public Types | |
| using | TaskId = size_t |
| using | WorkerId = std::string |
| using | TaskPayload = std::vector<int> |
Public Member Functions | |
| void | AddPending (TaskId id, const TaskPayload &payload) |
| Add a new task to the pending queue. | |
| bool | AssignToWorker (const WorkerId &worker, TaskId id) |
| Assign a pending task to a worker (transitions to running) | |
| bool | ClaimNextPendingForWorker (const WorkerId &worker, TaskId &id, TaskPayload &payload) |
| Atomically pop the next pending task and assign it to a worker. | |
| bool | MarkDone (TaskId id) |
| Mark a running task as completed. | |
| bool | MarkFailed (TaskId id) |
| Mark a running task as failed (returns to pending for redistribution) | |
| bool | RequeueTask (TaskId id) |
| Requeue a task to pending state from running or done state. | |
| std::set< TaskId > | GetWorkerTasks (const WorkerId &worker) const |
| Get all tasks currently assigned to a worker. | |
| std::pair< TaskId, TaskPayload > | GetNextPending () |
| Get the next pending task for dispatch. | |
| bool | HasPending () const |
| Check if there are pending tasks. | |
| std::vector< std::pair< TaskId, TaskPayload > > | RecoverWorkerTasks (const WorkerId &worker) |
| Recover all tasks from a failed worker. | |
| bool | RemoveTaskFromWorker (const WorkerId &worker, TaskId id) |
| Remove a specific task ID from a worker (e.g., after ACK but worker later fails) | |
| WorkerId | GetTaskWorker (TaskId id) const |
| Get the worker currently executing a task. | |
| bool | IsDone (TaskId id) const |
| Check if a task has been completed. | |
| size_t | PendingCount () const |
| Get number of pending tasks. | |
| size_t | RunningCount () const |
| Get number of running tasks. | |
| size_t | DoneCount () const |
| Get number of completed tasks. | |
| size_t | TotalCount () const |
| Get total tasks tracked (pending + running + done) | |
| void | Clear () |
| Clear all state (for reuse or cleanup) | |
Private Member Functions | |
| bool | TaskExists (TaskId id) const |
| Check if task exists in any state. | |
| void | EnqueuePending (TaskId id, const TaskPayload &payload) |
| Push task into pending queue and pending-id index. | |
Private Attributes | |
| std::queue< std::pair< TaskId, TaskPayload > > | fPending |
| std::unordered_set< TaskId > | fPendingIds |
| std::unordered_map< TaskId, TaskPayload > | fRunning |
| std::set< TaskId > | fDone |
| std::unordered_map< WorkerId, std::set< TaskId > > | fWorkerToTasks |
| std::unordered_map< TaskId, WorkerId > | fTaskToWorker |
| std::unordered_map< TaskId, TaskPayload > | fTaskPayloads |
Manages task lifecycle: pending → running → done/failed.
Separates task state management from IPC/worker concerns. Tracks which tasks are assigned to which workers and handles redistribution.
Definition at line 22 of file NTaskStateManager.h.
| using Ndmspc::NTaskStateManager::TaskId = size_t |
Definition at line 24 of file NTaskStateManager.h.
| using Ndmspc::NTaskStateManager::TaskPayload = std::vector<int> |
Definition at line 26 of file NTaskStateManager.h.
| using Ndmspc::NTaskStateManager::WorkerId = std::string |
Definition at line 25 of file NTaskStateManager.h.
| void Ndmspc::NTaskStateManager::AddPending | ( | TaskId | id, |
| const TaskPayload & | payload ) |
Add a new task to the pending queue.
| id | Unique task identifier |
| payload | Task data (typically coordinates) |
Definition at line 6 of file NTaskStateManager.cxx.
References EnqueuePending(), and TaskExists().
| bool Ndmspc::NTaskStateManager::AssignToWorker | ( | const WorkerId & | worker, |
| TaskId | id ) |
Assign a pending task to a worker (transitions to running)
| worker | Worker identifier |
| id | Task ID to assign |
Definition at line 15 of file NTaskStateManager.cxx.
| bool Ndmspc::NTaskStateManager::ClaimNextPendingForWorker | ( | const WorkerId & | worker, |
| TaskId & | id, | ||
| TaskPayload & | payload ) |
Atomically pop the next pending task and assign it to a worker.
| worker | Worker identifier |
| id | Output task ID |
| payload | Output task payload |
Definition at line 45 of file NTaskStateManager.cxx.
| void Ndmspc::NTaskStateManager::Clear | ( | ) |
Clear all state (for reuse or cleanup)
Definition at line 239 of file NTaskStateManager.cxx.
|
inline |
Get number of completed tasks.
Definition at line 133 of file NTaskStateManager.h.
Referenced by TotalCount().
|
private |
Push task into pending queue and pending-id index.
Definition at line 258 of file NTaskStateManager.cxx.
Referenced by AddPending(), MarkFailed(), RecoverWorkerTasks(), and RequeueTask().
| std::pair< NTaskStateManager::TaskId, NTaskStateManager::TaskPayload > Ndmspc::NTaskStateManager::GetNextPending | ( | ) |
Get the next pending task for dispatch.
Definition at line 164 of file NTaskStateManager.cxx.
| NTaskStateManager::WorkerId Ndmspc::NTaskStateManager::GetTaskWorker | ( | TaskId | id | ) | const |
Get the worker currently executing a task.
| id | Task ID |
Definition at line 225 of file NTaskStateManager.cxx.
| std::set< NTaskStateManager::TaskId > Ndmspc::NTaskStateManager::GetWorkerTasks | ( | const WorkerId & | worker | ) | const |
Get all tasks currently assigned to a worker.
| worker | Worker identifier |
Definition at line 155 of file NTaskStateManager.cxx.
| bool Ndmspc::NTaskStateManager::HasPending | ( | ) | const |
Check if there are pending tasks.
Definition at line 174 of file NTaskStateManager.cxx.
| bool Ndmspc::NTaskStateManager::IsDone | ( | TaskId | id | ) | const |
Check if a task has been completed.
| id | Task ID |
Definition at line 234 of file NTaskStateManager.cxx.
| bool Ndmspc::NTaskStateManager::MarkDone | ( | TaskId | id | ) |
Mark a running task as completed.
| id | Task ID to mark done |
Definition at line 64 of file NTaskStateManager.cxx.
| bool Ndmspc::NTaskStateManager::MarkFailed | ( | TaskId | id | ) |
Mark a running task as failed (returns to pending for redistribution)
| id | Task ID that failed |
Definition at line 89 of file NTaskStateManager.cxx.
References EnqueuePending().
|
inline |
Get number of pending tasks.
Definition at line 127 of file NTaskStateManager.h.
Referenced by TotalCount().
| std::vector< std::pair< NTaskStateManager::TaskId, NTaskStateManager::TaskPayload > > Ndmspc::NTaskStateManager::RecoverWorkerTasks | ( | const WorkerId & | worker | ) |
Recover all tasks from a failed worker.
| worker | Worker identifier |
Definition at line 180 of file NTaskStateManager.cxx.
References EnqueuePending().
| bool Ndmspc::NTaskStateManager::RemoveTaskFromWorker | ( | const WorkerId & | worker, |
| TaskId | id ) |
Remove a specific task ID from a worker (e.g., after ACK but worker later fails)
| worker | Worker identifier |
| id | Task ID to remove |
Definition at line 206 of file NTaskStateManager.cxx.
| bool Ndmspc::NTaskStateManager::RequeueTask | ( | TaskId | id | ) |
Requeue a task to pending state from running or done state.
| id | Task ID to requeue |
Definition at line 115 of file NTaskStateManager.cxx.
References EnqueuePending().
|
inline |
Get number of running tasks.
Definition at line 130 of file NTaskStateManager.h.
Referenced by TotalCount().
|
private |
Check if task exists in any state.
Definition at line 250 of file NTaskStateManager.cxx.
Referenced by AddPending().
|
inline |
Get total tasks tracked (pending + running + done)
Definition at line 136 of file NTaskStateManager.h.
References DoneCount(), PendingCount(), and RunningCount().
|
private |
Definition at line 146 of file NTaskStateManager.h.
|
private |
Definition at line 143 of file NTaskStateManager.h.
|
private |
Definition at line 144 of file NTaskStateManager.h.
|
private |
Definition at line 145 of file NTaskStateManager.h.
|
private |
Definition at line 151 of file NTaskStateManager.h.
|
private |
Definition at line 150 of file NTaskStateManager.h.
|
private |
Definition at line 149 of file NTaskStateManager.h.