Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ suspicious_op_assign_impl = "allow"
[workspace.dependencies]
anyhow = { version = "1.0.99", default-features = false }
arbitrary = "1.4.1"
async-task = "4.7.1"
aws-config = "1.8.12"
aws-lc-rs = "1.15.2"
aws-sdk-ec2 = "1.200.0"
Expand Down
1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ workspace = true

[dependencies]
arbitrary = { workspace = true, optional = true }
async-task.workspace = true
bytes.workspace = true
cfg-if.workspace = true
commonware-codec.workspace = true
Expand Down
54 changes: 54 additions & 0 deletions runtime/src/deterministic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,18 @@ impl Tasks {
type Network = MeteredNetwork<AuditedNetwork<DeterministicNetwork>>;
type Storage = MeteredStorage<AuditedStorage<FaultyStorage<MemStorage>>>;

/// Marks a dedicated subtree as closed before the parent task's result is made
/// observable through its handle.
struct DedicatedGuard {
tree: Arc<Tree>,
}

impl Drop for DedicatedGuard {
fn drop(&mut self) {
self.tree.abort();
}
}

/// Implementation of [crate::Spawner], [crate::Clock],
/// [crate::Network], and [crate::Storage] for the `deterministic`
/// runtime.
Expand All @@ -900,6 +912,7 @@ pub struct Context {
tree: Arc<Tree>,
execution: Execution,
traced: bool,
dedicated: Option<Arc<Tree>>,
}

impl Clone for Context {
Expand All @@ -918,6 +931,7 @@ impl Clone for Context {
tree: child,
execution: Execution::default(),
traced: false,
dedicated: self.dedicated.clone(),
}
}
}
Expand Down Expand Up @@ -999,6 +1013,7 @@ impl Context {
tree: Tree::root(),
execution: Execution::default(),
traced: false,
dedicated: None,
},
executor,
panicked,
Expand Down Expand Up @@ -1071,6 +1086,7 @@ impl Context {
tree: Tree::root(),
execution: Execution::default(),
traced: false,
dedicated: None,
},
executor,
panicked,
Expand Down Expand Up @@ -1138,6 +1154,11 @@ impl crate::Spawner for Context {
self
}

fn colocated(mut self) -> Self {
self.execution = Execution::Colocated;
self
}

fn shared(mut self, blocking: bool) -> Self {
self.execution = Execution::Shared(blocking);
self
Expand All @@ -1154,14 +1175,38 @@ impl crate::Spawner for Context {

// Track supervision before resetting configuration
let parent = Arc::clone(&self.tree);
let past = self.execution;
let traced = self.traced;
let inherited_dedicated = self.dedicated.clone();
self.execution = Execution::default();
self.traced = false;
if matches!(past, Execution::Colocated) {
let dedicated = inherited_dedicated
.as_ref()
.expect("`colocated()` requires a running dedicated ancestor");
assert!(
!dedicated.is_aborted(),
"`colocated()` requires a running dedicated ancestor"
);
}
let (child, aborted) = Tree::child(&parent);
if aborted {
return Handle::closed(metric);
}
let child_dedicated = match past {
// Dedicated creates a new execution domain for the spawned child.
// In the deterministic runtime, the child context node itself is
// sufficient to model that domain because the supervision tree
// already tracks whether the dedicated root task is still alive.
Execution::Dedicated => Some(child.clone()),
// Colocated reuses the nearest dedicated ancestor, which must
// already have been validated before creating the child node.
Execution::Colocated => inherited_dedicated,
// Shared clears the dedicated branch assignment.
Execution::Shared(_) => None,
};
self.tree = child;
self.dedicated = child_dedicated.clone();

// Spawn the task (we don't care about Model)
let executor = self.executor();
Expand All @@ -1174,6 +1219,15 @@ impl crate::Spawner for Context {
} else {
Either::Right(f(self))
};
let future = if matches!(past, Execution::Dedicated) {
let dedicated = child_dedicated.expect("dedicated tree missing");
Either::Left(async move {
let _guard = DedicatedGuard { tree: dedicated };
future.await
})
} else {
Either::Right(future)
};
let (f, handle) = Handle::init(
future,
metric,
Expand Down
Loading
Loading