Skip to content

Commit

Permalink
spinloop: remove suite locks
Browse files Browse the repository at this point in the history
CMK-15137
  • Loading branch information
SoloJacobs committed Dec 5, 2023
1 parent e478c45 commit 53300ef
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 51 deletions.
4 changes: 0 additions & 4 deletions v2/robotmk/src/bin/scheduler/internal_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use robotmk::{
};

use camino::Utf8PathBuf;
use std::sync::Arc;
use std::sync::Mutex;
use tokio_util::sync::CancellationToken;

pub struct GlobalConfig {
Expand All @@ -33,7 +31,6 @@ pub struct Suite {
pub session: Session,
pub working_directory_cleanup_config: WorkingDirectoryCleanupConfig,
pub cancellation_token: CancellationToken,
pub parallelism_protection: Arc<Mutex<usize>>,
pub host: Host,
pub results_directory_locker: Locker,
}
Expand Down Expand Up @@ -70,7 +67,6 @@ pub fn from_external_config(
session: Session::new(&suite_config.session_config),
working_directory_cleanup_config: suite_config.working_directory_cleanup_config,
cancellation_token: cancellation_token.clone(),
parallelism_protection: Arc::new(Mutex::new(0)),
host: suite_config.host,
results_directory_locker: results_directory_locker.clone(),
})
Expand Down
8 changes: 1 addition & 7 deletions v2/robotmk/src/bin/scheduler/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub enum EnvironmentBuildStatusError {
#[derive(Serialize)]
pub struct SuiteExecutionReport {
pub suite_id: String,
pub outcome: ExecutionReport,
pub outcome: AttemptsOutcome,
}

impl WritePiggybackSection for SuiteExecutionReport {
Expand All @@ -108,12 +108,6 @@ impl WritePiggybackSection for SuiteExecutionReport {
}
}

#[derive(Serialize)]
pub enum ExecutionReport {
Executed(AttemptsOutcome),
AlreadyRunning,
}

#[derive(Serialize)]
pub struct AttemptsOutcome {
pub attempts: Vec<AttemptOutcome>,
Expand Down
42 changes: 2 additions & 40 deletions v2/robotmk/src/bin/scheduler/scheduling/suites.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::environment::ResultCode;
use crate::internal_config::Suite;
use crate::results::{
AttemptOutcome, AttemptsConfig, AttemptsOutcome, ExecutionReport, SuiteExecutionReport,
};
use crate::results::{AttemptOutcome, AttemptsConfig, AttemptsOutcome, SuiteExecutionReport};
use crate::rf::{rebot::Rebot, robot::Attempt};
use crate::sessions::session::{RunOutcome, RunSpec};

Expand All @@ -12,30 +10,12 @@ use chrono::Utc;
use log::{debug, error};
use robotmk::section::WritePiggybackSection;
use std::fs::create_dir_all;
use std::sync::{MutexGuard, TryLockError};

pub fn run_suite(suite: &Suite) -> Result<()> {
// We hold the lock as long as `_non_parallel_guard` is in scope
let _non_parallel_guard = try_acquire_suite_lock(suite).map_err(|err| {
let report = SuiteExecutionReport {
suite_id: suite.id.clone(),
outcome: ExecutionReport::AlreadyRunning,
};
report
.write(
&suite.results_file,
suite.host.clone(),
&suite.results_directory_locker,
)
.context("Reporting failure to acquire suite lock failed")
.err()
.unwrap_or(err)
})?;

debug!("Running suite {}", &suite.id);
let report = SuiteExecutionReport {
suite_id: suite.id.clone(),
outcome: ExecutionReport::Executed(produce_suite_results(suite)?),
outcome: produce_suite_results(suite)?,
};
report
.write(
Expand All @@ -49,24 +29,6 @@ pub fn run_suite(suite: &Suite) -> Result<()> {
Ok(())
}

fn try_acquire_suite_lock(suite: &Suite) -> Result<MutexGuard<usize>> {
match suite.parallelism_protection.try_lock() {
Ok(non_parallel_guard) => Ok(non_parallel_guard),
Err(try_lock_error) => match try_lock_error {
TryLockError::WouldBlock => {
bail!(
"Failed to acquire lock for suite {}, skipping this run",
suite.id
);
}
TryLockError::Poisoned(poison_error) => {
error!("Lock for suite {} poisoned, unpoisoning", suite.id);
Ok(poison_error.into_inner())
}
},
}
}

fn produce_suite_results(suite: &Suite) -> Result<AttemptsOutcome> {
let output_directory = suite
.working_directory
Expand Down

0 comments on commit 53300ef

Please sign in to comment.