|
| 1 | +//! The scheduler's view of the storage layer, abstracting inbound polling and placement-time reads. |
| 2 | +
|
| 3 | +use std::time::Duration; |
| 4 | + |
| 5 | +use async_trait::async_trait; |
| 6 | +use spider_core::{ |
| 7 | + job::JobState, |
| 8 | + types::id::{JobId, SessionId}, |
| 9 | +}; |
| 10 | + |
| 11 | +use crate::{error::StorageClientError, types::InboundEntry}; |
| 12 | + |
| 13 | +/// The scheduler's view of the storage layer. |
| 14 | +/// |
| 15 | +/// Abstracts the storage-owned inbound queue and the read-only queries a scheduling algorithm |
| 16 | +/// needs to make placement decisions. Modeled as a trait so the scheduler runtime can be driven by |
| 17 | +/// a real storage client in production or a mock in tests. |
| 18 | +#[async_trait] |
| 19 | +pub trait SchedulerStorageClient: Send + Sync + Clone { |
| 20 | + /// Polls the regular-task lane of the storage-owned inbound queue for ready tasks. |
| 21 | + /// |
| 22 | + /// # Parameters |
| 23 | + /// |
| 24 | + /// * `max_items` - The maximum number of entries to return from a single poll. |
| 25 | + /// * `wait` - The maximum duration to block waiting for ready entries on the storage side. |
| 26 | + /// |
| 27 | + /// # Returns |
| 28 | + /// |
| 29 | + /// A tuple on success, containing: |
| 30 | + /// |
| 31 | + /// * The storage session the poll was served under. |
| 32 | + /// * The ready regular tasks drained from the lane. |
| 33 | + /// |
| 34 | + /// # Errors |
| 35 | + /// |
| 36 | + /// Returns an error if: |
| 37 | + /// |
| 38 | + /// * [`StorageClientError::InboundClosed`] if the regular-task lane is closed and can no longer |
| 39 | + /// yield entries. |
| 40 | + async fn poll_ready( |
| 41 | + &self, |
| 42 | + max_items: usize, |
| 43 | + wait: Duration, |
| 44 | + ) -> Result<(SessionId, Vec<InboundEntry>), StorageClientError>; |
| 45 | + |
| 46 | + /// Polls the commit-task lane of the storage-owned inbound queue for ready tasks. |
| 47 | + /// |
| 48 | + /// # Parameters |
| 49 | + /// |
| 50 | + /// * `max_items` - The maximum number of entries to return from a single poll. |
| 51 | + /// * `wait` - The maximum duration to block waiting for ready entries on the storage side. |
| 52 | + /// |
| 53 | + /// # Returns |
| 54 | + /// |
| 55 | + /// A tuple on success, containing: |
| 56 | + /// |
| 57 | + /// * The storage session the poll was served under. |
| 58 | + /// * The ready commit tasks drained from the lane. |
| 59 | + /// |
| 60 | + /// # Errors |
| 61 | + /// |
| 62 | + /// Returns an error if: |
| 63 | + /// |
| 64 | + /// * [`StorageClientError::InboundClosed`] if the commit-task lane is closed and can no longer |
| 65 | + /// yield entries. |
| 66 | + async fn poll_commit_ready( |
| 67 | + &self, |
| 68 | + max_items: usize, |
| 69 | + wait: Duration, |
| 70 | + ) -> Result<(SessionId, Vec<InboundEntry>), StorageClientError>; |
| 71 | + |
| 72 | + /// Polls the cleanup-task lane of the storage-owned inbound queue for ready tasks. |
| 73 | + /// |
| 74 | + /// # Parameters |
| 75 | + /// |
| 76 | + /// * `max_items` - The maximum number of entries to return from a single poll. |
| 77 | + /// * `wait` - The maximum duration to block waiting for ready entries on the storage side. |
| 78 | + /// |
| 79 | + /// # Returns |
| 80 | + /// |
| 81 | + /// A tuple on success, containing: |
| 82 | + /// |
| 83 | + /// * The storage session the poll was served under. |
| 84 | + /// * The ready cleanup tasks drained from the lane. |
| 85 | + /// |
| 86 | + /// # Errors |
| 87 | + /// |
| 88 | + /// Returns an error if: |
| 89 | + /// |
| 90 | + /// * [`StorageClientError::InboundClosed`] if the cleanup-task lane is closed and can no longer |
| 91 | + /// yield entries. |
| 92 | + async fn poll_cleanup_ready( |
| 93 | + &self, |
| 94 | + max_items: usize, |
| 95 | + wait: Duration, |
| 96 | + ) -> Result<(SessionId, Vec<InboundEntry>), StorageClientError>; |
| 97 | + |
| 98 | + /// Reads the current state of a job. |
| 99 | + /// |
| 100 | + /// # Parameters |
| 101 | + /// |
| 102 | + /// * `job_id` - The identifier of the job to query. |
| 103 | + /// |
| 104 | + /// # Returns |
| 105 | + /// |
| 106 | + /// The job's current [`JobState`] on success. |
| 107 | + /// |
| 108 | + /// # Errors |
| 109 | + /// |
| 110 | + /// Returns an error if: |
| 111 | + /// |
| 112 | + /// * [`StorageClientError::JobNotFound`] if no job with the given identifier exists. |
| 113 | + async fn job_state(&self, job_id: JobId) -> Result<JobState, StorageClientError>; |
| 114 | +} |
0 commit comments