Add logging to PVF and other related parts (#3596)

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Sergei Shulepov
2021-08-08 19:39:16 +02:00
committed by GitHub
parent 968132155a
commit 9d6ed7ecae
10 changed files with 211 additions and 58 deletions
@@ -194,6 +194,7 @@ fn handle_to_pool(
) {
match to_pool {
ToPool::Spawn => {
tracing::debug!(target: LOG_TARGET, "spawning a new prepare worker");
mux.push(spawn_worker_task(program_path.to_owned(), spawn_timeout).boxed());
},
ToPool::StartWork { worker, code, artifact_path, background_priority } => {
@@ -224,6 +225,7 @@ fn handle_to_pool(
}
},
ToPool::Kill(worker) => {
tracing::debug!(target: LOG_TARGET, ?worker, "killing prepare worker");
// It may be absent if it were previously already removed by `purge_dead`.
let _ = spawned.remove(worker);
},
+24 -2
View File
@@ -212,6 +212,13 @@ async fn handle_to_queue(queue: &mut Queue, to_queue: ToQueue) -> Result<(), Fat
}
async fn handle_enqueue(queue: &mut Queue, priority: Priority, pvf: Pvf) -> Result<(), Fatal> {
tracing::debug!(
target: LOG_TARGET,
validation_code_hash = ?pvf.code_hash,
?priority,
"PVF is enqueued for preparation.",
);
let artifact_id = pvf.as_artifact_id();
if never!(
queue.artifact_id_to_job.contains_key(&artifact_id),
@@ -254,8 +261,14 @@ async fn handle_amend(
artifact_id: ArtifactId,
) -> Result<(), Fatal> {
if let Some(&job) = queue.artifact_id_to_job.get(&artifact_id) {
let mut job_data: &mut JobData = &mut queue.jobs[job];
tracing::debug!(
target: LOG_TARGET,
validation_code_hash = ?artifact_id.code_hash,
?priority,
"amending preparation priority.",
);
let mut job_data: &mut JobData = &mut queue.jobs[job];
if job_data.priority < priority {
// The new priority is higher. We should do two things:
// - if the worker was already spawned with the background prio and the new one is not
@@ -349,6 +362,14 @@ async fn handle_worker_concluded(
queue.artifact_id_to_job.remove(&artifact_id);
tracing::debug!(
target: LOG_TARGET,
validation_code_hash = ?artifact_id.code_hash,
?worker,
?rip,
"prepare worker concluded",
);
reply(&mut queue.from_queue_tx, FromQueue::Prepared(artifact_id))?;
// Figure out what to do with the worker.
@@ -380,8 +401,9 @@ async fn handle_worker_concluded(
}
async fn handle_worker_rip(queue: &mut Queue, worker: Worker) -> Result<(), Fatal> {
let worker_data = queue.workers.remove(worker);
tracing::debug!(target: LOG_TARGET, ?worker, "prepare worker ripped");
let worker_data = queue.workers.remove(worker);
if let Some(WorkerData { job: Some(job), .. }) = worker_data {
// This is an edge case where the worker ripped after we sent assignment but before it
// was received by the pool.
+10 -1
View File
@@ -103,6 +103,7 @@ pub async fn start_work(
// We may potentially overwrite the artifact in rare cases where the worker didn't make
// it to report back the result.
#[derive(Debug)]
enum Selected {
Done,
IoErr,
@@ -170,7 +171,15 @@ pub async fn start_work(
Selected::IoErr | Selected::Deadline => {
let bytes = Artifact::DidntMakeIt.serialize();
// best effort: there is nothing we can do here if the write fails.
let _ = async_std::fs::write(&artifact_path, &bytes).await;
if let Err(err) = async_std::fs::write(&artifact_path, &bytes).await {
tracing::warn!(
target: LOG_TARGET,
worker_pid = %pid,
"preparation didn't make it, because of `{:?}`: {:?}",
selected,
err,
);
}
Outcome::DidntMakeIt
},
}