-
Notifications
You must be signed in to change notification settings - Fork 43
Introduce sled-agent-config-reconciler skeleton #8063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jgallagher
wants to merge
9
commits into
main
Choose a base branch
from
john/sled-agent-config-reconciler-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
69b74a3
Introduce sled-agent-config-reconciler skeleton
jgallagher 319465e
hakari
jgallagher 01ebe83
add clarifying comments
jgallagher 608905a
be less clever about internal disk sorting (explicit ID type)
jgallagher 80918e1
Merge branch 'main' into john/sled-agent-config-reconciler-1
jgallagher a41323a
typo
jgallagher 3f84a04
rework call-once-ness of spawn_reconciliation_task
jgallagher 996a102
typo
jgallagher 16a4c56
make trait futures Send
jgallagher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
[package] | ||
name = "sled-agent-config-reconciler" | ||
version = "0.1.0" | ||
edition = "2021" | ||
license = "MPL-2.0" | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[dependencies] | ||
anyhow.workspace = true | ||
async-trait.workspace = true | ||
camino.workspace = true | ||
camino-tempfile.workspace = true | ||
chrono.workspace = true | ||
derive_more.workspace = true | ||
dropshot.workspace = true | ||
glob.workspace = true | ||
id-map.workspace = true | ||
illumos-utils.workspace = true | ||
key-manager.workspace = true | ||
nexus-sled-agent-shared.workspace = true | ||
omicron-common.workspace = true | ||
omicron-uuid-kinds.workspace = true | ||
sled-agent-api.workspace = true | ||
sled-agent-types.workspace = true | ||
sled-hardware.workspace = true | ||
sled-storage.workspace = true | ||
slog.workspace = true | ||
slog-error-chain.workspace = true | ||
thiserror.workspace = true | ||
tokio.workspace = true | ||
tufaceous-artifact.workspace = true | ||
zone.workspace = true | ||
omicron-workspace-hack.workspace = true | ||
|
||
[dev-dependencies] | ||
omicron-test-utils.workspace = true | ||
proptest.workspace = true | ||
test-strategy.workspace = true | ||
|
||
[features] | ||
testing = [] |
162 changes: 162 additions & 0 deletions
162
sled-agent/config-reconciler/src/dataset_serialization_task.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! Many of the ZFS operations sled-agent performs are not atomic, because they | ||
//! involve multiple lower-level ZFS operations. This module implements a tokio | ||
//! task that serializes a set of operations to ensure no two operations could | ||
//! be executing concurrently. | ||
//! | ||
//! It uses the common pattern of "a task with a mpsc channel to send requests, | ||
//! using oneshot channels to send responses". | ||
|
||
use camino::Utf8PathBuf; | ||
use id_map::IdMap; | ||
use id_map::IdMappable; | ||
use nexus_sled_agent_shared::inventory::InventoryDataset; | ||
use omicron_common::disk::DatasetConfig; | ||
use omicron_common::zpool_name::ZpoolName; | ||
use omicron_uuid_kinds::DatasetUuid; | ||
use sled_storage::config::MountConfig; | ||
use sled_storage::manager::NestedDatasetConfig; | ||
use sled_storage::manager::NestedDatasetListOptions; | ||
use sled_storage::manager::NestedDatasetLocation; | ||
use slog::Logger; | ||
use slog::warn; | ||
use std::collections::BTreeSet; | ||
use std::sync::Arc; | ||
use tokio::sync::mpsc; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum DatasetTaskError { | ||
#[error("cannot perform dataset operations: waiting for key manager")] | ||
WaitingForKeyManager, | ||
#[error("dataset task busy; cannot service new requests")] | ||
Busy, | ||
#[error("internal error: dataset task exited!")] | ||
Exited, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub(crate) struct DatasetEnsureResult(IdMap<SingleDatasetEnsureResult>); | ||
|
||
#[derive(Debug, Clone)] | ||
struct SingleDatasetEnsureResult { | ||
config: DatasetConfig, | ||
state: DatasetState, | ||
} | ||
|
||
impl IdMappable for SingleDatasetEnsureResult { | ||
type Id = DatasetUuid; | ||
|
||
fn id(&self) -> Self::Id { | ||
self.config.id | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
enum DatasetState { | ||
Mounted, | ||
FailedToMount, // TODO add error | ||
UuidMismatch(DatasetUuid), | ||
ZpoolNotFound, | ||
ParentMissingFromConfig, | ||
ParentFailedToMount, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub(crate) struct DatasetTaskHandle(mpsc::Sender<DatasetTaskRequest>); | ||
|
||
impl DatasetTaskHandle { | ||
pub fn spawn_dataset_task( | ||
mount_config: Arc<MountConfig>, | ||
base_log: &Logger, | ||
) -> Self { | ||
// We don't expect too many concurrent requests to this task, and want | ||
// to detect "the task is wedged" pretty quickly. Common operations: | ||
// | ||
// 1. Reconciler wants to ensure datasets (at most 1 at a time) | ||
// 2. Inventory requests from Nexus (likely at most 3 at a time) | ||
// 3. Support bundle operations (unlikely to be multiple concurrently) | ||
// | ||
// so we'll pick a number that allows all of those plus a little | ||
// overhead. | ||
let (request_tx, request_rx) = mpsc::channel(16); | ||
|
||
tokio::spawn( | ||
DatasetTask { | ||
mount_config, | ||
request_rx, | ||
log: base_log.new(slog::o!("component" => "DatasetTask")), | ||
} | ||
.run(), | ||
); | ||
|
||
Self(request_tx) | ||
} | ||
|
||
pub async fn datasets_ensure( | ||
&self, | ||
_dataset_configs: IdMap<DatasetConfig>, | ||
_zpools: BTreeSet<ZpoolName>, | ||
) -> Result<DatasetEnsureResult, DatasetTaskError> { | ||
unimplemented!() | ||
} | ||
|
||
pub async fn inventory( | ||
&self, | ||
_zpools: BTreeSet<ZpoolName>, | ||
) -> Result<Vec<InventoryDataset>, DatasetTaskError> { | ||
unimplemented!() | ||
} | ||
|
||
pub async fn nested_dataset_ensure_mounted( | ||
&self, | ||
_dataset: NestedDatasetLocation, | ||
) -> Result<Utf8PathBuf, DatasetTaskError> { | ||
unimplemented!() | ||
} | ||
|
||
pub async fn nested_dataset_ensure( | ||
&self, | ||
_config: NestedDatasetConfig, | ||
) -> Result<(), DatasetTaskError> { | ||
unimplemented!() | ||
} | ||
|
||
pub async fn nested_dataset_destroy( | ||
&self, | ||
_name: NestedDatasetLocation, | ||
) -> Result<(), DatasetTaskError> { | ||
unimplemented!() | ||
} | ||
|
||
pub async fn nested_dataset_list( | ||
&self, | ||
_name: NestedDatasetLocation, | ||
_options: NestedDatasetListOptions, | ||
) -> Result<Vec<NestedDatasetConfig>, DatasetTaskError> { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
struct DatasetTask { | ||
mount_config: Arc<MountConfig>, | ||
request_rx: mpsc::Receiver<DatasetTaskRequest>, | ||
log: Logger, | ||
} | ||
|
||
impl DatasetTask { | ||
async fn run(mut self) { | ||
while let Some(req) = self.request_rx.recv().await { | ||
self.handle_request(req).await; | ||
} | ||
warn!(self.log, "all request handles closed; exiting dataset task"); | ||
} | ||
|
||
async fn handle_request(&mut self, _req: DatasetTaskRequest) { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
enum DatasetTaskRequest {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can punt on this question if it's answered in a follow-up PR, but with no rustdocs on a pub method, I figured I'd ask: why is the
zpools
argument being passed here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is a little messy. It's because the implementation of this is basically
omicron/sled-storage/src/manager.rs
Lines 1165 to 1181 in bac3385
FWIW, I think this method isn't really
pub
, because the type it's on isn't directly exposed outside the crate. But it's still a good question! Once the rest of the work starts to land I wonder if there's a way to not need to pass this argument.