From 68485f344ee2c05de62068df847921f032622e61 Mon Sep 17 00:00:00 2001 From: Rynco Maekawa Date: Thu, 7 Oct 2021 15:33:53 +0800 Subject: [PATCH 1/3] fix: disallow job polling when no space is available --- judger/src/client/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/judger/src/client/mod.rs b/judger/src/client/mod.rs index f72ac541..fe624659 100644 --- a/judger/src/client/mod.rs +++ b/judger/src/client/mod.rs @@ -721,6 +721,11 @@ async fn poll_jobs( let request_for_new_task = client_config.cfg().max_concurrent_tasks as u32 - active_task_count; + if request_for_new_task == 0 { + tracing::debug!("No new job is needed."); + continue; + } + tracing::debug!( "Polling jobs from server. Asking for {} new jobs.", request_for_new_task From 6bfa618824c661d34b232c7c97cc6ae8fa2239a9 Mon Sep 17 00:00:00 2001 From: Rynco Maekawa Date: Thu, 7 Oct 2021 15:57:00 +0800 Subject: [PATCH 2/3] fix: add tags for multi-job dispatcher --- .../Services/JudgerCoordinatorService.cs | 37 +++---------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/coordinator/Services/JudgerCoordinatorService.cs b/coordinator/Services/JudgerCoordinatorService.cs index 09ac9c3c..61fa05e1 100644 --- a/coordinator/Services/JudgerCoordinatorService.cs +++ b/coordinator/Services/JudgerCoordinatorService.cs @@ -452,8 +452,7 @@ await judger.Socket.SendMessage(new MultipleNewJobServerMsg() { static readonly TimeSpan DISPATH_TIMEOUT = TimeSpan.FromMinutes(30); - protected async Task GetLastUndispatchedJobFromDatabase(RurikawaDb db, List? tags, bool allowUntagged) { - IQueryable res = QueuedCriteria(db.Jobs); + protected IQueryable ApplyTagCriteria(IQueryable res, RurikawaDb db, List? tags, bool allowUntagged) { if (tags != null) { // join the test suites for suite tags var query = res.Join(db.TestSuites, j => j.TestSuite, t => t.Id, (job, suite) => new { job, suite }); @@ -467,12 +466,12 @@ await judger.Socket.SendMessage(new MultipleNewJobServerMsg() { // but still return a job res = query.Select(x => x.job); } - return await res - .OrderBy(j => j.Id).FirstOrDefaultAsync(); + return res + ; } - protected async Task> GetUndispatchedJobsFromDatabase(RurikawaDb db, int count) { - var res = await QueuedCriteria(db.Jobs) + protected async Task> GetUndispatchedJobsFromDatabase(RurikawaDb db, int count, List? tags, bool allowUntagged) { + var res = await ApplyTagCriteria(QueuedCriteria(db.Jobs), db, tags, allowUntagged) .OrderBy(j => j.Id) .Take(count) .ToListAsync(); @@ -499,30 +498,6 @@ public static IQueryable QueuedCriteria(IQueryable jobs) { ); } - /// - /// Dispatch ONE job from database. - /// - /// The judger to dispatch from - /// - protected async ValueTask TryDispatchJobFromDatabase(Judger judger) { - using var scope = scopeProvider.CreateScope(); - var db = GetDb(scope); - using var tx = await db.Database.BeginTransactionAsync(System.Data.IsolationLevel.Serializable); - var job = await GetLastUndispatchedJobFromDatabase( - db, judger.DbJudgerEntry.Tags, judger.DbJudgerEntry.AcceptUntaggedJobs); - if (job == null) return false; - - try { - var res = await DispatchJob(judger, job); - await db.SaveChangesAsync(); - await tx.CommitAsync(); - return res; - } catch { - await tx.RollbackAsync(); - return false; - } - } - /// /// Dispatch MANY job from database. This method should be favored over /// TryDispatchJobFromDatabase(Judger) @@ -538,7 +513,7 @@ protected async ValueTask TryDispatchJobFromDatabase( using var scope = scopeProvider.CreateScope(); var db = GetDb(scope); using var tx = await db.Database.BeginTransactionAsync(System.Data.IsolationLevel.Serializable); - var jobs = await GetUndispatchedJobsFromDatabase(db, count); + var jobs = await GetUndispatchedJobsFromDatabase(db, count, judger.DbJudgerEntry.Tags, judger.DbJudgerEntry.AcceptUntaggedJobs); try { var res = await DispatchJobs(judger, jobs, replyTo); From de9ce9c1db1e5788b88a0a1e6b2d6eaafcc2758b Mon Sep 17 00:00:00 2001 From: Rynco Maekawa Date: Sun, 10 Oct 2021 10:16:53 +0800 Subject: [PATCH 3/3] fix: add context to internal errors --- judger/src/tester/exec/mod.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/judger/src/tester/exec/mod.rs b/judger/src/tester/exec/mod.rs index 38a2dd76..98771d4d 100644 --- a/judger/src/tester/exec/mod.rs +++ b/judger/src/tester/exec/mod.rs @@ -409,7 +409,9 @@ impl Image { // Freeze `path` as a tar archive. Some(hyper::Body::wrap_stream(tar_stream)), ) - .map_err(|e| BuildError::Internal(e.to_string())) + .map_err(|e| { + BuildError::Internal(format!("Internal error when building image: {:?}", e)) + }) .try_for_each(|info| async { if let Some(e) = info.error { return Err(BuildError::BuildError { @@ -428,7 +430,12 @@ impl Image { archiving .await - .map_err(|e| BuildError::Internal(e.to_string()))? + .map_err(|e| { + BuildError::Internal(format!( + "Internal error when joining file transfer task: {}", + e + )) + })? .map_err(|e: io::Error| BuildError::FileTransferError(e.to_string()))?; Ok(())