Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Improve slow Task queries #3594

Merged
merged 8 commits into from
Oct 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Restore some back-compat
  • Loading branch information
Porges authored Oct 24, 2023
commit 7780715732ccddba68d2be8813ee3584557977ee
7 changes: 6 additions & 1 deletion src/ApiService/ApiService/Functions/AgentCanSchedule.cs
Original file line number Diff line number Diff line change
@@ -40,7 +40,12 @@ public async Async.Task<HttpResponseData> Run(
var allowed = canProcessNewWork.IsAllowed;
var reason = canProcessNewWork.Reason;

var task = await _context.TaskOperations.GetByJobIdAndTaskId(canScheduleRequest.JobId, canScheduleRequest.TaskId);
var task = await
(canScheduleRequest.JobId.HasValue
? _context.TaskOperations.GetByJobIdAndTaskId(canScheduleRequest.JobId.Value, canScheduleRequest.TaskId)
// old agent, fall back
: _context.TaskOperations.GetByTaskIdSlow(canScheduleRequest.TaskId));

var workStopped = task == null || task.State.ShuttingDown();
if (!allowed) {
_log.LogInformation("Node cannot process new work {PoolName} {ScalesetId} - {MachineId} ", node.PoolName, node.ScalesetId, node.MachineId);
11 changes: 9 additions & 2 deletions src/ApiService/ApiService/Functions/AgentEvents.cs
Original file line number Diff line number Diff line change
@@ -184,7 +184,10 @@ public async Async.Task<HttpResponseData> Run(

private async Async.Task<Error?> OnWorkerEventRunning(Guid machineId, WorkerRunningEvent running) {
var (task, node) = await (
_context.TaskOperations.GetByJobIdAndTaskId(running.JobId, running.TaskId),
(running.JobId.HasValue
? _context.TaskOperations.GetByJobIdAndTaskId(running.JobId.Value, running.TaskId)
// old agent, fallback
: _context.TaskOperations.GetByTaskIdSlow(running.TaskId)),
_context.NodeOperations.GetByMachineId(machineId));

if (task is null) {
@@ -233,8 +236,12 @@ public async Async.Task<HttpResponseData> Run(
}

private async Async.Task<Error?> OnWorkerEventDone(Guid machineId, WorkerDoneEvent done) {

var (task, node) = await (
_context.TaskOperations.GetByJobIdAndTaskId(done.JobId, done.TaskId),
(done.JobId.HasValue
? _context.TaskOperations.GetByJobIdAndTaskId(done.JobId.Value, done.TaskId)
// old agent, fall back
: _context.TaskOperations.GetByTaskIdSlow(done.TaskId)),
_context.NodeOperations.GetByMachineId(machineId));

if (task is null) {
6 changes: 3 additions & 3 deletions src/ApiService/ApiService/OneFuzzTypes/Requests.cs
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ public record BaseRequest {

public record CanScheduleRequest(
[property: Required] Guid MachineId,
[property: Required] Guid JobId,
Guid? JobId,
[property: Required] Guid TaskId
) : BaseRequest;

@@ -64,11 +64,11 @@ public record WorkerEvent(
) : NodeEventBase;

public record WorkerRunningEvent(
[property: Required] Guid JobId,
Guid? JobId,
[property: Required] Guid TaskId);

public record WorkerDoneEvent(
[property: Required] Guid JobId,
Guid? JobId,
[property: Required] Guid TaskId,
[property: Required] ExitStatus ExitStatus,
[property: Required] string Stderr,