Skip to content

Commit

Permalink
fix Uint64 -> Int32
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillKurdyukov committed Aug 15, 2024
1 parent bedbca4 commit b2af5e0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
2 changes: 2 additions & 0 deletions slo/src/AdoNet/SloContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Internal;
using Microsoft.Extensions.Logging;
using Polly;
using Prometheus;
using Ydb.Sdk;
Expand All @@ -15,6 +16,7 @@ public class SloContext : SloContext<YdbDataSource>
{
var errorsGauge = (Gauge)context["errorsGauge"];
Logger.LogWarning(e, "Failed read / write operation");
errorsGauge?.WithLabels(((YdbException)e).Code.StatusName(), "retried").Inc();
});

Expand Down
37 changes: 17 additions & 20 deletions slo/src/Internal/SloContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ namespace Internal;

public abstract class SloContext<T> where T : IDisposable
{
protected readonly ILoggerFactory Factory;
private readonly ILogger _logger;
// ReSharper disable once StaticMemberInGenericType
protected static readonly ILoggerFactory Factory =
LoggerFactory.Create(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Information));

private volatile int _maxId;
protected static readonly ILogger Logger = Factory.CreateLogger<SloContext<T>>();

protected SloContext()
{
Factory = LoggerFactory.Create(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Information));
_logger = Factory.CreateLogger<SloContext<T>>();
}
private volatile int _maxId;

protected abstract string Job { get; }

Expand All @@ -29,7 +26,7 @@ public async Task Create(CreateConfig config)
using var client = await CreateClient(config);
for (var attempt = 0; attempt < maxCreateAttempts; attempt++)
{
_logger.LogInformation("Creating table {TableName}..", config.TableName);
Logger.LogInformation("Creating table {TableName}..", config.TableName);
try
{
var createTableSql = $"""
Expand All @@ -49,17 +46,17 @@ PRIMARY KEY (hash, id)
AUTO_PARTITIONING_MAX_PARTITIONS_COUNT = {config.MaxPartitionsCount}
);
""";
_logger.LogInformation("YQL script: {sql}", createTableSql);
Logger.LogInformation("YQL script: {sql}", createTableSql);

await Create(client, createTableSql, config.WriteTimeout);

_logger.LogInformation("Created table {TableName}", config.TableName);
Logger.LogInformation("Created table {TableName}", config.TableName);

break;
}
catch (Exception e)
{
_logger.LogError(e, "Fail created table");
Logger.LogError(e, "Fail created table");

if (attempt == maxCreateAttempts - 1)
{
Expand All @@ -82,11 +79,11 @@ PRIMARY KEY (hash, id)
}
catch (Exception e)
{
_logger.LogError(e, "Init failed when all tasks, continue..");
Logger.LogError(e, "Init failed when all tasks, continue..");
}
finally
{
_logger.LogInformation("Created task is finished");
Logger.LogInformation("Created task is finished");
}
}

Expand All @@ -103,7 +100,7 @@ public async Task Run(RunConfig runConfig)
new Dictionary<string, YdbValue>(), runConfig.ReadTimeout);
_maxId = (int)maxId!;

_logger.LogInformation("Init row count: {MaxId}", _maxId);
Logger.LogInformation("Init row count: {MaxId}", _maxId);

var writeLimiter = new FixedWindowRateLimiter(new FixedWindowRateLimiterOptions
{
Expand All @@ -120,21 +117,21 @@ public async Task Run(RunConfig runConfig)
var writeTask = ShootingTask(writeLimiter, "write", Upsert);
var readTask = ShootingTask(readLimiter, "read", Select);

_logger.LogInformation("Started write / read shooting..");
Logger.LogInformation("Started write / read shooting..");

try
{
await Task.WhenAll(readTask, writeTask);
}
catch (Exception e)
{
_logger.LogInformation(e, "Cancel shooting");
Logger.LogInformation(e, "Cancel shooting");
}

await prometheus.StopAsync();
await MetricReset(promPgwEndpoint);

_logger.LogInformation("Run task is finished");
Logger.LogInformation("Run task is finished");
return;

Task ShootingTask(RateLimiter rateLimitPolicy, string jobName,
Expand Down Expand Up @@ -203,7 +200,7 @@ Task ShootingTask(RateLimiter rateLimitPolicy, string jobName,
// ReSharper disable once MethodSupportsCancellation
await Task.Delay(TimeSpan.FromSeconds(runConfig.ShutdownTime));
_logger.LogInformation("{ShootingName} shooting is stopped", jobName);
Logger.LogInformation("{ShootingName} shooting is stopped", jobName);
});
}
}
Expand Down Expand Up @@ -254,7 +251,7 @@ Task ShootingTask(RateLimiter rateLimitPolicy, string jobName,
""",
new Dictionary<string, YdbValue>
{
{ "$id", YdbValue.MakeUint64((ulong)Random.Shared.Next(_maxId)) }
{ "$id", YdbValue.MakeInt32(Random.Shared.Next(_maxId)) }
}, config.ReadTimeout, errorsGauge);

return (attempts, code);
Expand Down
4 changes: 4 additions & 0 deletions slo/src/TableService/SloContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Internal;
using Microsoft.Extensions.Logging;
using Prometheus;
using Ydb.Sdk;
using Ydb.Sdk.Services.Table;
Expand Down Expand Up @@ -38,6 +39,7 @@ protected override async Task Create(TableClient client, string createTableSql,
return response;
}
errorsGauge?.WithLabels(response.Status.StatusCode.ToString(), "retried").Inc();
return response;
Expand All @@ -64,6 +66,8 @@ protected override async Task Create(TableClient client, string createTableSql,
return response;
}
Logger.LogWarning("{}", response.Status.ToString());
errorsGauge?.WithLabels(response.Status.StatusCode.StatusName(), "retried").Inc();
return response;
Expand Down

0 comments on commit b2af5e0

Please sign in to comment.