Skip to content

Commit

Permalink
refactor: debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
aneojgurhem committed Nov 28, 2024
1 parent 2e55acc commit b52d4ff
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
53 changes: 46 additions & 7 deletions Common/src/Pollster/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public sealed class Agent : IAgent
private readonly IObjectStorage objectStorage_;
private readonly IPushQueueStorage pushQueueStorage_;
private readonly IResultTable resultTable_;
private readonly SemaphoreSlim sem_;
private readonly Dictionary<string, long> sentResults_;
private readonly SessionData sessionData_;
private readonly ISubmitter submitter_;
Expand Down Expand Up @@ -87,11 +88,13 @@ public Agent(ISubmitter submitter,
taskTable_ = taskTable;
logger_ = logger;
createdTasks_ = new List<TaskCreationRequest>();
sentResults_ = new Dictionary<string, long>();
sessionData_ = sessionData;
taskData_ = taskData;
Folder = folder;
Token = token;
sem_ = new SemaphoreSlim(1,
1);
sentResults_ = new Dictionary<string, long>();
sessionData_ = sessionData;
taskData_ = taskData;
Folder = folder;
Token = token;
}

/// <inheritdoc />
Expand All @@ -113,6 +116,9 @@ public async Task FinalizeTaskCreation(CancellationToken cancellationToken)
("sessionId", sessionData_.SessionId));

logger_.LogDebug("Finalize child task creation");
logger_.LogDebug("created {results} and {tasks}",
sentResults_.Count,
createdTasks_.Count);

await submitter_.FinalizeTaskCreation(createdTasks_,
sessionData_,
Expand All @@ -137,12 +143,14 @@ await TaskLifeCycleHelper.ResolveDependencies(taskTable_,
logger_,
cancellationToken)
.ConfigureAwait(false);
logger_.LogDebug("created {results} and {tasks}",
sentResults_.Count,
createdTasks_.Count);
}

/// <inheritdoc />
public void Dispose()
{
}
=> sem_.Dispose();

/// <inheritdoc />
public async Task<string> GetResourceData(string token,
Expand Down Expand Up @@ -248,6 +256,16 @@ await TaskLifeCycleHelper.CreateTasks(taskTable_,
cancellationToken)
.ConfigureAwait(false);

await using var def = new Deferrer(() =>
{
sem_.Release(1);
});
if (!sem_.Wait(0))
{
logger_.LogError("Concurrency issue when submitting tasks");
def.Reset();
}

createdTasks_.AddRange(createdTasks);

return createdTasks;
Expand Down Expand Up @@ -293,6 +311,16 @@ await resultTable_.Create(results,

foreach (var result in results)
{
await using var def = new Deferrer(() =>
{
sem_.Release(1);
});
if (!sem_.Wait(0))
{
logger_.LogError("Concurrency issue when creating results");
def.Reset();
}

sentResults_.Add(result.ResultId,
result.Size);
}
Expand Down Expand Up @@ -340,6 +368,17 @@ await channel.Writer.WriteAsync(buffer.AsMemory(0,
channel.Writer.Complete();

await add.ConfigureAwait(false);

await using var def = new Deferrer(() =>
{
sem_.Release(1);
});
if (!sem_.Wait(0))
{
logger_.LogError("Concurrency issue when notifying results");
def.Reset();
}

sentResults_.Add(result,
size);
}
Expand Down
3 changes: 3 additions & 0 deletions Common/src/Pollster/AgentHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,8 @@ await app_.DisposeAsync()
{
File.Delete(computePlaneOptions_.AgentChannel.Address);
}

logger_.LogDebug("Socket {file} deleted",
computePlaneOptions_.AgentChannel.Address);
}
}

0 comments on commit b52d4ff

Please sign in to comment.