Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion .github/workflows/slo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ jobs:
matrix:
workload:
- AdoNet
- EF
- Dapper
# - EF

concurrency:
group: slo-${{ github.ref }}-${{ matrix.workload }}
Expand Down
4 changes: 1 addition & 3 deletions slo/src/AdoNet/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// See https://aka.ms/new-console-template for more information

using AdoNet;
using AdoNet;
using Internal;

await Cli.Run(new SloTableContext(), args);
11 changes: 6 additions & 5 deletions slo/src/AdoNet/SloTableContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace AdoNet;

public class SloTableContext : SloTableContext<YdbDataSource>
{
private readonly AsyncPolicy _policy = Policy.Handle<YdbException>(exception => exception.IsTransient)
private static readonly AsyncPolicy Policy = Polly.Policy.Handle<YdbException>(exception => exception.IsTransient)
.WaitAndRetryAsync(10, attempt => TimeSpan.FromMilliseconds(attempt * 10),
(e, _, _, _) => { Logger.LogWarning(e, "Failed read / write operation"); });

Expand Down Expand Up @@ -45,8 +45,10 @@ PRIMARY KEY (Guid, Id)
int writeTimeout
)
{
var policyResult = await _policy.ExecuteAndCaptureAsync(async _ =>
var attempts = 0;
var policyResult = await Policy.ExecuteAndCaptureAsync(async _ =>
{
attempts++;
await using var ydbConnection = await client.OpenConnectionAsync();

var ydbCommand = new YdbCommand(ydbConnection)
Expand Down Expand Up @@ -95,8 +97,7 @@ int writeTimeout
}, new Context());


return (policyResult.Context.TryGetValue("RetryCount", out var countAttempts) ? (int)countAttempts : 1,
((YdbException)policyResult.FinalException)?.Code ?? StatusCode.Success);
return (attempts, ((YdbException)policyResult.FinalException)?.Code ?? StatusCode.Success);
}

protected override async Task<(int, StatusCode, object?)> Select(
Expand All @@ -106,7 +107,7 @@ int readTimeout
)
{
var attempts = 0;
var policyResult = await _policy.ExecuteAndCaptureAsync(async _ =>
var policyResult = await Policy.ExecuteAndCaptureAsync(async _ =>
{
attempts++;
await using var ydbConnection = await client.OpenConnectionAsync();
Expand Down
19 changes: 19 additions & 0 deletions slo/src/Dapper/AdoNet.Dapper.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>AdoNet.Dapper</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Internal\Internal.csproj"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Polly" Version="8.4.1"/>
<PackageReference Include="Dapper" Version="2.1.66"/>
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions slo/src/Dapper/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using AdoNet.Dapper;
using Internal;

await Cli.Run(new SloTableContext(), args);
81 changes: 81 additions & 0 deletions slo/src/Dapper/SloTableContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using Dapper;
using Internal;
using Microsoft.Extensions.Logging;
using Polly;
using Ydb.Sdk;
using Ydb.Sdk.Ado;

namespace AdoNet.Dapper;

public class SloTableContext : SloTableContext<YdbDataSource>
{
private static readonly AsyncPolicy Policy = Polly.Policy.Handle<YdbException>(exception => exception.IsTransient)
.WaitAndRetryAsync(10, attempt => TimeSpan.FromMilliseconds(attempt * 10),
(e, _, _, _) => { Logger.LogWarning(e, "Failed read / write operation"); });

protected override string Job => "Dapper";

protected override YdbDataSource CreateClient(Config config) => new(
new YdbConnectionStringBuilder(config.ConnectionString) { LoggerFactory = ISloContext.Factory }
);

protected override async Task Create(YdbDataSource client, int operationTimeout)
{
await using var connection = await client.OpenConnectionAsync();
await connection.ExecuteAsync($"""
CREATE TABLE `{SloTable.Name}` (
Guid Uuid,
Id Int32,
PayloadStr Text,
PayloadDouble Double,
PayloadTimestamp Timestamp,
PRIMARY KEY (Guid, Id)
);
{SloTable.Options}
""");
}

protected override async Task<(int, StatusCode)> Save(YdbDataSource client, SloTable sloTable, int writeTimeout)
{
var attempt = 0;
var policyResult = await Policy.ExecuteAndCaptureAsync(async _ =>
{
attempt++;
await using var connection = await client.OpenConnectionAsync();
await connection.ExecuteAsync($"""
UPSERT INTO `{SloTable.Name}` (Guid, Id, PayloadStr, PayloadDouble, PayloadTimestamp)
VALUES (@Guid, @Id, @PayloadStr, @PayloadDouble, @PayloadTimestamp)
""", sloTable);
}, new Context()
);

return (attempt, ((YdbException)policyResult.FinalException)?.Code ?? StatusCode.Success);
}

protected override async Task<(int, StatusCode, object?)> Select(YdbDataSource client, (Guid Guid, int Id) select,
int readTimeout)
{
var attempts = 0;
var policyResult = await Policy.ExecuteAndCaptureAsync(async _ =>
{
attempts++;
await using var connection = await client.OpenConnectionAsync();

return await connection.QueryFirstOrDefaultAsync<SloTable>(
$"""
SELECT Guid, Id, PayloadStr, PayloadDouble, PayloadTimestamp
FROM `{SloTable.Name}` WHERE Guid = @Guid AND Id = @Id;
""",
new { select.Guid, select.Id }
);
}, new Context());

return (attempts, ((YdbException)policyResult.FinalException)?.Code ?? StatusCode.Success, policyResult.Result);
}

protected override async Task<int> SelectCount(YdbDataSource client)
{
await using var connection = await client.OpenConnectionAsync();
return await connection.ExecuteScalarAsync<int>($"SELECT MAX(Id) FROM {SloTable.Name}");
}
}
4 changes: 1 addition & 3 deletions slo/src/EF/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// See https://aka.ms/new-console-template for more information

using EF;
using EF;
using Internal;

await Cli.Run(new SloTableContext(), args);
6 changes: 6 additions & 0 deletions slo/src/src.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TopicService", "TopicServic
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EF", "EF\EF.csproj", "{291A2C64-8A20-40AA-B68A-B9E2A730B66C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdoNet.Dapper", "Dapper\AdoNet.Dapper.csproj", "{A6B9B4F1-4C7C-42C1-A212-B71A9B0D67F7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -33,6 +35,10 @@ Global
{291A2C64-8A20-40AA-B68A-B9E2A730B66C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{291A2C64-8A20-40AA-B68A-B9E2A730B66C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{291A2C64-8A20-40AA-B68A-B9E2A730B66C}.Release|Any CPU.Build.0 = Release|Any CPU
{A6B9B4F1-4C7C-42C1-A212-B71A9B0D67F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A6B9B4F1-4C7C-42C1-A212-B71A9B0D67F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A6B9B4F1-4C7C-42C1-A212-B71A9B0D67F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A6B9B4F1-4C7C-42C1-A212-B71A9B0D67F7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading