Skip to main content

query_runtime/runtime/
execution_policy.rs

1//! Runtime memory-resource and source-scheduling policies.
2
3use query_planning::error::{QueryError, QueryErrorCode, Result};
4
5#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
6pub enum MemoryResourcePolicy {
7    #[default]
8    DefaultCuda,
9    Pool {
10        initial_pool_size: usize,
11        maximum_pool_size: Option<usize>,
12    },
13    ExternalRuntime,
14}
15
16/// Native source scheduling controls.
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18pub struct SourceSchedulerPolicy {
19    max_source_reads_in_flight: usize,
20}
21
22impl SourceSchedulerPolicy {
23    /// Creates a source scheduler with one read at a time and no prefetch.
24    pub const fn serialized() -> Self {
25        Self { max_source_reads_in_flight: 1 }
26    }
27
28    /// Sets the maximum concurrent source reads. Zero is rejected by
29    /// [`Self::validate`]; the default permits two reads.
30    pub const fn new(max_source_reads_in_flight: usize) -> Self {
31        Self { max_source_reads_in_flight }
32    }
33
34    /// Returns the configured concurrent source-read bound.
35    pub const fn max_source_reads_in_flight(self) -> usize {
36        self.max_source_reads_in_flight
37    }
38
39    /// Returns whether the policy permits more than one concurrent source read.
40    pub const fn enables_prefetch(self) -> bool {
41        self.max_source_reads_in_flight > 1
42    }
43
44    /// Rejects zero concurrent source reads with `InvalidConfiguration`.
45    pub fn validate(self) -> Result<()> {
46        if self.max_source_reads_in_flight == 0 {
47            return Err(QueryError::new(
48                QueryErrorCode::InvalidConfiguration,
49                "query_engine.source_scheduler_policy.validate",
50                "source scheduler max_source_reads_in_flight must be greater than zero",
51            )
52            .with_fact("field", "max_source_reads_in_flight")
53            .with_fact("reason", "zero"));
54        }
55        Ok(())
56    }
57}
58
59impl Default for SourceSchedulerPolicy {
60    fn default() -> Self {
61        Self { max_source_reads_in_flight: 2 }
62    }
63}