mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-03 13:11:31 +00:00
feat: oci concurrency improvements (#95)
* feat: implement improved and detailed oci progress indication * feat: implement on-disk indexes of images * oci: utilize rw-lock for increased cache performance
This commit is contained in:
@ -372,7 +372,7 @@ impl ControlService for DaemonControlService {
|
||||
|
||||
let output = try_stream! {
|
||||
let mut task = tokio::task::spawn(async move {
|
||||
our_packer.request(name, format, context).await
|
||||
our_packer.request(name, format, request.overwrite_cache, context).await
|
||||
});
|
||||
let abort_handle = task.abort_handle();
|
||||
let _task_cancel_guard = scopeguard::guard(abort_handle, |handle| {
|
||||
@ -381,26 +381,14 @@ impl ControlService for DaemonControlService {
|
||||
|
||||
loop {
|
||||
let what = select! {
|
||||
x = receiver.recv() => PullImageSelect::Progress(x.ok()),
|
||||
x = receiver.changed() => match x {
|
||||
Ok(_) => PullImageSelect::Progress(Some(receiver.borrow_and_update().clone())),
|
||||
Err(_) => PullImageSelect::Progress(None),
|
||||
},
|
||||
x = &mut task => PullImageSelect::Completed(x),
|
||||
};
|
||||
match what {
|
||||
PullImageSelect::Progress(Some(mut progress)) => {
|
||||
let mut drain = 0;
|
||||
loop {
|
||||
if drain >= 10 {
|
||||
break;
|
||||
}
|
||||
|
||||
if let Ok(latest) = receiver.try_recv() {
|
||||
progress = latest;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
drain += 1;
|
||||
}
|
||||
|
||||
PullImageSelect::Progress(Some(progress)) => {
|
||||
let reply = PullImageReply {
|
||||
progress: Some(convert_oci_progress(progress)),
|
||||
digest: String::new(),
|
||||
|
@ -51,7 +51,7 @@ impl Daemon {
|
||||
image_cache_dir.push("image");
|
||||
fs::create_dir_all(&image_cache_dir).await?;
|
||||
|
||||
let packer = OciPackerService::new(None, &image_cache_dir, OciPlatform::current())?;
|
||||
let packer = OciPackerService::new(None, &image_cache_dir, OciPlatform::current()).await?;
|
||||
|
||||
let runtime = Runtime::new(store.clone()).await?;
|
||||
let guests_db_path = format!("{}/guests.db", store);
|
||||
|
@ -1,33 +1,72 @@
|
||||
use krata::v1::control::{
|
||||
PullImageProgress, PullImageProgressLayer, PullImageProgressLayerPhase, PullImageProgressPhase,
|
||||
image_progress_indication::Indication, ImageProgress, ImageProgressIndication,
|
||||
ImageProgressIndicationBar, ImageProgressIndicationCompleted, ImageProgressIndicationHidden,
|
||||
ImageProgressIndicationSpinner, ImageProgressLayer, ImageProgressLayerPhase,
|
||||
ImageProgressPhase,
|
||||
};
|
||||
use krataoci::progress::{
|
||||
OciProgress, OciProgressIndication, OciProgressLayer, OciProgressLayerPhase, OciProgressPhase,
|
||||
};
|
||||
use krataoci::progress::{OciProgress, OciProgressLayer, OciProgressLayerPhase, OciProgressPhase};
|
||||
|
||||
fn convert_oci_layer_progress(layer: OciProgressLayer) -> PullImageProgressLayer {
|
||||
PullImageProgressLayer {
|
||||
id: layer.id,
|
||||
phase: match layer.phase {
|
||||
OciProgressLayerPhase::Waiting => PullImageProgressLayerPhase::Waiting,
|
||||
OciProgressLayerPhase::Downloading => PullImageProgressLayerPhase::Downloading,
|
||||
OciProgressLayerPhase::Downloaded => PullImageProgressLayerPhase::Downloaded,
|
||||
OciProgressLayerPhase::Extracting => PullImageProgressLayerPhase::Extracting,
|
||||
OciProgressLayerPhase::Extracted => PullImageProgressLayerPhase::Extracted,
|
||||
}
|
||||
.into(),
|
||||
value: layer.value,
|
||||
total: layer.total,
|
||||
fn convert_oci_progress_indication(indication: OciProgressIndication) -> ImageProgressIndication {
|
||||
ImageProgressIndication {
|
||||
indication: Some(match indication {
|
||||
OciProgressIndication::Hidden => Indication::Hidden(ImageProgressIndicationHidden {}),
|
||||
OciProgressIndication::ProgressBar {
|
||||
message,
|
||||
current,
|
||||
total,
|
||||
bytes,
|
||||
} => Indication::Bar(ImageProgressIndicationBar {
|
||||
message: message.unwrap_or_default(),
|
||||
current,
|
||||
total,
|
||||
is_bytes: bytes,
|
||||
}),
|
||||
OciProgressIndication::Spinner { message } => {
|
||||
Indication::Spinner(ImageProgressIndicationSpinner {
|
||||
message: message.unwrap_or_default(),
|
||||
})
|
||||
}
|
||||
OciProgressIndication::Completed {
|
||||
message,
|
||||
total,
|
||||
bytes,
|
||||
} => Indication::Completed(ImageProgressIndicationCompleted {
|
||||
message: message.unwrap_or_default(),
|
||||
total: total.unwrap_or(0),
|
||||
is_bytes: bytes,
|
||||
}),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn convert_oci_progress(oci: OciProgress) -> PullImageProgress {
|
||||
PullImageProgress {
|
||||
fn convert_oci_layer_progress(layer: OciProgressLayer) -> ImageProgressLayer {
|
||||
ImageProgressLayer {
|
||||
id: layer.id,
|
||||
phase: match layer.phase {
|
||||
OciProgressLayerPhase::Waiting => ImageProgressLayerPhase::Waiting,
|
||||
OciProgressLayerPhase::Downloading => ImageProgressLayerPhase::Downloading,
|
||||
OciProgressLayerPhase::Downloaded => ImageProgressLayerPhase::Downloaded,
|
||||
OciProgressLayerPhase::Extracting => ImageProgressLayerPhase::Extracting,
|
||||
OciProgressLayerPhase::Extracted => ImageProgressLayerPhase::Extracted,
|
||||
}
|
||||
.into(),
|
||||
indication: Some(convert_oci_progress_indication(layer.indication)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn convert_oci_progress(oci: OciProgress) -> ImageProgress {
|
||||
ImageProgress {
|
||||
phase: match oci.phase {
|
||||
OciProgressPhase::Resolving => PullImageProgressPhase::Resolving,
|
||||
OciProgressPhase::Resolved => PullImageProgressPhase::Resolved,
|
||||
OciProgressPhase::ConfigAcquire => PullImageProgressPhase::ConfigAcquire,
|
||||
OciProgressPhase::LayerAcquire => PullImageProgressPhase::LayerAcquire,
|
||||
OciProgressPhase::Packing => PullImageProgressPhase::Packing,
|
||||
OciProgressPhase::Complete => PullImageProgressPhase::Complete,
|
||||
OciProgressPhase::Started => ImageProgressPhase::Started,
|
||||
OciProgressPhase::Resolving => ImageProgressPhase::Resolving,
|
||||
OciProgressPhase::Resolved => ImageProgressPhase::Resolved,
|
||||
OciProgressPhase::ConfigDownload => ImageProgressPhase::ConfigDownload,
|
||||
OciProgressPhase::LayerDownload => ImageProgressPhase::LayerDownload,
|
||||
OciProgressPhase::Assemble => ImageProgressPhase::Assemble,
|
||||
OciProgressPhase::Pack => ImageProgressPhase::Pack,
|
||||
OciProgressPhase::Complete => ImageProgressPhase::Complete,
|
||||
}
|
||||
.into(),
|
||||
layers: oci
|
||||
@ -35,7 +74,6 @@ pub fn convert_oci_progress(oci: OciProgress) -> PullImageProgress {
|
||||
.into_values()
|
||||
.map(convert_oci_layer_progress)
|
||||
.collect::<Vec<_>>(),
|
||||
value: oci.value,
|
||||
total: oci.total,
|
||||
indication: Some(convert_oci_progress_indication(oci.indication)),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user