Skip to main content

query_runtime/observability/
task_identity.rs

1//! Identity of one runtime task attempt.
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
6#[serde(transparent)]
7/// Compiled task identity scoped to one native plan invocation.
8pub struct RuntimeTaskId(String);
9
10impl RuntimeTaskId {
11    /// Creates a task identity from its scope-local label without validating the text.
12    pub fn new(value: impl Into<String>) -> Self {
13        Self(value.into())
14    }
15
16    /// Returns the original scope-local task label.
17    pub fn as_str(&self) -> &str {
18        &self.0
19    }
20}
21
22impl From<String> for RuntimeTaskId {
23    fn from(value: String) -> Self {
24        Self::new(value)
25    }
26}
27
28impl From<&str> for RuntimeTaskId {
29    fn from(value: &str) -> Self {
30        Self::new(value)
31    }
32}
33
34impl std::fmt::Display for RuntimeTaskId {
35    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36        formatter.write_str(self.as_str())
37    }
38}
39
40#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
41#[serde(transparent)]
42/// Execution attempt number for one compiled task, independent of the query attempt identity.
43pub struct RuntimeAttemptId(u32);
44
45impl RuntimeAttemptId {
46    /// Creates a task execution attempt number from a caller-provided value.
47    pub const fn new(value: u32) -> Self {
48        Self(value)
49    }
50}
51
52#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
53/// Compiled task identity paired with its execution attempt number.
54pub struct TaskAttemptId {
55    /// Compiled task whose execution attempt this value identifies.
56    pub task_id: RuntimeTaskId,
57    pub(crate) attempt: RuntimeAttemptId,
58}
59
60impl TaskAttemptId {
61    /// Pairs a compiled task identity with its execution attempt number.
62    pub const fn new(task_id: RuntimeTaskId, attempt: RuntimeAttemptId) -> Self {
63        Self { task_id, attempt }
64    }
65}