Skip to content

Commit 231f0db

Browse files
fixes
1 parent 719fefd commit 231f0db

File tree

9 files changed

+95
-67
lines changed

9 files changed

+95
-67
lines changed

.github/workflows/slo.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
matrix:
3232
workload:
3333
- AdoNet
34+
- EF
3435

3536
concurrency:
3637
group: slo-${{ github.ref }}-${{ matrix.workload }}
@@ -56,12 +57,12 @@ jobs:
5657
- name: Prepare SLO Database
5758
run: |
5859
cd slo/src/${{ matrix.workload }}
59-
dotnet run create grpc://localhost:2135 /Root/testdb
60+
dotnet run create "Host=localhost;Port=2135;Database=/Root/testdb"
6061
6162
- name: Run SLO Tests
6263
run: |
6364
cd slo/src/${{ matrix.workload }}
64-
dotnet run run grpc://localhost:2135 /Root/testdb \
65+
dotnet run run "Host=localhost;Port=2135;Database=/Root/testdb" \
6566
--prom-pgw http://localhost:9091 \
6667
--report-period 250 \
6768
--time ${{inputs.slo_workload_duration_seconds || 600 }} \

slo/src/AdoNet/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// See https://aka.ms/new-console-template for more information
22

3-
using AdoNet;
43
using Internal;
4+
using Ydb.Sdk.Ado;
55

6-
await Cli.Run(new SloTableContext(), args);
6+
await Cli.Run((_, config) => new AdoNet.SloTableContext(
7+
new YdbDataSource(new YdbConnectionStringBuilder(config.ConnectionString)
8+
{ LoggerFactory = ISloContext.Factory })), args);

slo/src/AdoNet/SloTableContext.cs

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace AdoNet;
1010

11-
public class SloTableContext : SloTableContext<YdbDataSource>
11+
public class SloTableContext(YdbDataSource client) : SloTableContextBase
1212
{
1313
private readonly AsyncPolicy _policy = Policy.Handle<YdbException>(exception => exception.IsTransient)
1414
.WaitAndRetryAsync(10, attempt => TimeSpan.FromMilliseconds(attempt * 10),
@@ -22,7 +22,7 @@ public class SloTableContext : SloTableContext<YdbDataSource>
2222

2323
protected override string Job => "AdoNet";
2424

25-
protected override async Task Create(YdbDataSource client, int operationTimeout)
25+
protected override async Task Create(int operationTimeout)
2626
{
2727
await using var ydbConnection = await client.OpenConnectionAsync();
2828
await new YdbCommand(ydbConnection)
@@ -34,15 +34,15 @@ protected override async Task Create(YdbDataSource client, int operationTimeout)
3434
PayloadStr Text,
3535
PayloadDouble Double,
3636
PayloadTimestamp Timestamp,
37-
PRIMARY KEY (hash, id)
38-
)
37+
PRIMARY KEY (Guid, Id)
38+
);
39+
{SloTable.Options}
3940
""",
4041
CommandTimeout = operationTimeout
4142
}.ExecuteNonQueryAsync();
4243
}
4344

4445
protected override async Task<(int, StatusCode)> Save(
45-
YdbDataSource dataSource,
4646
SloTable sloTable,
4747
int writeTimeout,
4848
Counter? errorsTotal = null
@@ -56,7 +56,7 @@ PRIMARY KEY (hash, id)
5656

5757
var policyResult = await _policy.ExecuteAndCaptureAsync(async _ =>
5858
{
59-
await using var ydbConnection = await dataSource.OpenConnectionAsync();
59+
await using var ydbConnection = await client.OpenConnectionAsync();
6060

6161
var ydbCommand = new YdbCommand(ydbConnection)
6262
{
@@ -68,15 +68,35 @@ PRIMARY KEY (hash, id)
6868
Parameters =
6969
{
7070
new YdbParameter
71-
{ DbType = DbType.Guid, ParameterName = "Guid", Value = sloTable.Guid },
71+
{
72+
DbType = DbType.Guid,
73+
ParameterName = "Guid",
74+
Value = sloTable.Guid
75+
},
7276
new YdbParameter
73-
{ DbType = DbType.Int32, ParameterName = "Id", Value = sloTable.Id },
77+
{
78+
DbType = DbType.Int32,
79+
ParameterName = "Id",
80+
Value = sloTable.Id
81+
},
7482
new YdbParameter
75-
{ DbType = DbType.String, ParameterName = "PayloadStr", Value = sloTable.PayloadStr },
83+
{
84+
DbType = DbType.String,
85+
ParameterName = "PayloadStr",
86+
Value = sloTable.PayloadStr
87+
},
7688
new YdbParameter
77-
{ DbType = DbType.Double, ParameterName = "PayloadDouble", Value = sloTable.PayloadDouble },
89+
{
90+
DbType = DbType.Double,
91+
ParameterName = "PayloadDouble",
92+
Value = sloTable.PayloadDouble
93+
},
7894
new YdbParameter
79-
{ DbType = DbType.Guid, ParameterName = "PayloadTimestamp", Value = sloTable.PayloadTimestamp }
95+
{
96+
DbType = DbType.DateTime2,
97+
ParameterName = "PayloadTimestamp",
98+
Value = sloTable.PayloadTimestamp
99+
}
80100
}
81101
};
82102

@@ -89,7 +109,6 @@ PRIMARY KEY (hash, id)
89109
}
90110

91111
protected override async Task<(int, StatusCode, object?)> Select(
92-
YdbDataSource dataSource,
93112
dynamic select,
94113
int readTimeout,
95114
Counter? errorsTotal = null
@@ -105,7 +124,7 @@ PRIMARY KEY (hash, id)
105124
var policyResult = await _policy.ExecuteAndCaptureAsync(async _ =>
106125
{
107126
attempts++;
108-
await using var ydbConnection = await dataSource.OpenConnectionAsync();
127+
await using var ydbConnection = await client.OpenConnectionAsync();
109128

110129
var ydbCommand = new YdbCommand(ydbConnection)
111130
{
@@ -127,13 +146,10 @@ PRIMARY KEY (hash, id)
127146
return (attempts, ((YdbException)policyResult.FinalException)?.Code ?? StatusCode.Success, policyResult.Result);
128147
}
129148

130-
protected override async Task<int> SelectCount(YdbDataSource client, string sql)
149+
protected override async Task<int> SelectCount(string sql)
131150
{
132151
await using var ydbConnection = await client.OpenConnectionAsync();
133152

134153
return (int)(await new YdbCommand(ydbConnection) { CommandText = sql }.ExecuteScalarAsync())!;
135154
}
136-
137-
protected override YdbDataSource CreateClient(string connectionString) =>
138-
new(new YdbConnectionStringBuilder(connectionString) { LoggerFactory = ISloContext.Factory });
139155
}

slo/src/EF/Program.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
// See https://aka.ms/new-console-template for more information
22

33
using EF;
4+
using EntityFrameworkCore.Ydb.Extensions;
45
using Internal;
6+
using Microsoft.EntityFrameworkCore;
7+
using Microsoft.EntityFrameworkCore.Infrastructure;
58

6-
await Cli.Run(new SloTableContext(), args);
9+
await Cli.Run((mode, config) =>
10+
{
11+
return mode switch
12+
{
13+
CliMode.Create => new SloTableContext(new PooledDbContextFactory<TableDbContext>(
14+
new DbContextOptionsBuilder<TableDbContext>()
15+
.UseYdb(config.ConnectionString, builder => builder.DisableRetryOnFailure())
16+
.UseLoggerFactory(ISloContext.Factory)
17+
.Options)),
18+
CliMode.Run => new SloTableContext(new PooledDbContextFactory<TableDbContext>(
19+
new DbContextOptionsBuilder<TableDbContext>()
20+
.UseYdb(config.ConnectionString)
21+
.UseLoggerFactory(ISloContext.Factory)
22+
.Options)),
23+
_ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null)
24+
};
25+
}, args);

slo/src/EF/SloTableContext.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using EntityFrameworkCore.Ydb.Extensions;
21
using Internal;
32
using Microsoft.EntityFrameworkCore;
43
using Microsoft.EntityFrameworkCore.Infrastructure;
@@ -7,12 +6,11 @@
76

87
namespace EF;
98

10-
public class SloTableContext : SloTableContext<PooledDbContextFactory<TableDbContext>>
9+
public class SloTableContext(PooledDbContextFactory<TableDbContext> client) : SloTableContextBase
1110
{
1211
protected override string Job => "EF";
1312

1413
protected override async Task Create(
15-
PooledDbContextFactory<TableDbContext> client,
1614
int operationTimeout
1715
)
1816
{
@@ -22,7 +20,6 @@ int operationTimeout
2220
}
2321

2422
protected override async Task<(int, StatusCode)> Save(
25-
PooledDbContextFactory<TableDbContext> client,
2623
SloTable sloTable,
2724
int writeTimeout,
2825
Counter? errorsTotal = null)
@@ -35,7 +32,6 @@ int operationTimeout
3532
}
3633

3734
protected override async Task<(int, StatusCode, object?)> Select(
38-
PooledDbContextFactory<TableDbContext> client,
3935
dynamic select,
4036
int readTimeout,
4137
Counter? errorsTotal = null
@@ -47,17 +43,10 @@ int operationTimeout
4743
return (0, StatusCode.Success, null);
4844
}
4945

50-
protected override async Task<int> SelectCount(PooledDbContextFactory<TableDbContext> client, string sql)
46+
protected override async Task<int> SelectCount(string sql)
5147
{
5248
await using var dbContext = await client.CreateDbContextAsync();
5349

5450
return await dbContext.Database.SqlQuery<int>($"SELECT COUNT(*) FROM {SloTable.Name}").SingleAsync();
5551
}
56-
57-
protected override PooledDbContextFactory<TableDbContext> CreateClient(string connectionString) => new(
58-
new DbContextOptionsBuilder<TableDbContext>()
59-
.UseYdb(connectionString)
60-
.UseLoggerFactory(ISloContext.Factory)
61-
.Options
62-
);
6352
}

slo/src/Internal/Cli.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ public static class Cli
7676
CreateCommand, RunCommand
7777
};
7878

79-
public static async Task<int> Run(ISloContext sloContext, string[] args)
79+
public static async Task<int> Run(Func<CliMode, Config, ISloContext> sloContext, string[] args)
8080
{
8181
CreateCommand.SetHandler(
82-
async createConfig => { await sloContext.Create(createConfig); },
82+
async createConfig => { await sloContext.Invoke(CliMode.Create, createConfig).Create(createConfig); },
8383
new CreateConfigBinder(
8484
ConnectionStringArgument,
8585
InitialDataCountOption,
@@ -88,7 +88,7 @@ public static async Task<int> Run(ISloContext sloContext, string[] args)
8888
);
8989

9090
RunCommand.SetHandler(
91-
async runConfig => { await sloContext.Run(runConfig); },
91+
async runConfig => { await sloContext.Invoke(CliMode.Run, runConfig).Run(runConfig); },
9292
new RunConfigBinder(
9393
ConnectionStringArgument,
9494
PromPgwOption,
@@ -103,4 +103,10 @@ public static async Task<int> Run(ISloContext sloContext, string[] args)
103103

104104
return await RootCommand.InvokeAsync(args);
105105
}
106+
}
107+
108+
public enum CliMode
109+
{
110+
Create,
111+
Run
106112
}

slo/src/Internal/SloTable.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ public class SloTable
88
public const string Name = "slo_test_table";
99

1010
public const string Options = $"""
11-
ALTER TABLE ${Name} SET (AUTO_PARTITIONING_BY_SIZE = ENABLED);
12-
ALTER TABLE ${Name} SET (AUTO_PARTITIONING_BY_LOAD = ENABLED);
13-
ALTER TABLE ${Name} SET (AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 5);
14-
ALTER TABLE ${Name} SET (AUTO_PARTITIONING_MAX_PARTITIONS_COUNT = 10);
15-
""";
16-
11+
ALTER TABLE {Name} SET (AUTO_PARTITIONING_BY_SIZE = ENABLED);
12+
ALTER TABLE {Name} SET (AUTO_PARTITIONING_BY_LOAD = ENABLED);
13+
ALTER TABLE {Name} SET (AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 5);
14+
ALTER TABLE {Name} SET (AUTO_PARTITIONING_MAX_PARTITIONS_COUNT = 10);
15+
""";
16+
1717
public Guid Guid { get; set; }
1818
public int Id { get; set; }
19-
19+
2020
public string PayloadStr { get; set; }
2121
public double PayloadDouble { get; set; }
2222
public DateTime PayloadTimestamp { get; set; }

0 commit comments

Comments
 (0)