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
31 changes: 14 additions & 17 deletions .github/workflows/slo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@ on:
pull_request:
branches:
- main
workflow_dispatch:
inputs:
github_pull_request_number:
required: true
slo_workload_duration_seconds:
default: '600'
required: false
slo_workload_read_max_rps:
default: '1000'
required: false
slo_workload_write_max_rps:
default: '1000'
required: false

jobs:
ydb-slo-action:
Expand All @@ -32,7 +19,17 @@ jobs:
workload:
- AdoNet
- Dapper
# - EF
- EF
include:
- workload: AdoNet
read_rps: 1000
write_rps: 1000
- workload: Dapper
read_rps: 1000
write_rps: 1000
- workload: EF
read_rps: 400
write_rps: 400

concurrency:
group: slo-${{ github.ref }}-${{ matrix.workload }}
Expand Down Expand Up @@ -66,9 +63,9 @@ jobs:
dotnet run run "Host=localhost;Port=2135;Database=/Root/testdb" \
--prom-pgw http://localhost:9091 \
--report-period 250 \
--time ${{inputs.slo_workload_duration_seconds || 600 }} \
--read-rps ${{inputs.slo_workload_read_max_rps || 1000 }} \
--write-rps ${{inputs.slo_workload_write_max_rps || 1000 }} \
--time 600 \
--read-rps ${{matrix.read_rps || 1000 }} \
--write-rps ${{matrix.write_rps || 1000 }} \
--read-timeout 1000 \
--write-timeout 1000

Expand Down
52 changes: 45 additions & 7 deletions slo/src/EF/SloTableContext.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Data;
using EntityFrameworkCore.Ydb.Extensions;
using Internal;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Ydb.Sdk;
using Ydb.Sdk.Ado;

namespace EF;

Expand All @@ -29,9 +31,46 @@ int operationTimeout
int writeTimeout
)
{
await using var dbContext = await client.CreateDbContextAsync();
dbContext.SloEntities.Add(sloTable);
await dbContext.SaveChangesAsync();
await using var context = await client.CreateDbContextAsync();
var executeStrategy = context.Database.CreateExecutionStrategy();
await executeStrategy.ExecuteAsync(async () =>
{
var dbContext = await client.CreateDbContextAsync();

return await dbContext.Database.ExecuteSqlRawAsync(
$"UPSERT INTO `{SloTable.Name}` (Guid, Id, PayloadStr, PayloadDouble, PayloadTimestamp) " +
"VALUES (@Guid, @Id, @PayloadStr, @PayloadDouble, @PayloadTimestamp)",
new YdbParameter
{
DbType = DbType.Guid,
ParameterName = "Guid",
Value = sloTable.Guid
},
new YdbParameter
{
DbType = DbType.Int32,
ParameterName = "Id",
Value = sloTable.Id
},
new YdbParameter
{
DbType = DbType.String,
ParameterName = "PayloadStr",
Value = sloTable.PayloadStr
},
new YdbParameter
{
DbType = DbType.Double,
ParameterName = "PayloadDouble",
Value = sloTable.PayloadDouble
},
new YdbParameter
{
DbType = DbType.DateTime2,
ParameterName = "PayloadTimestamp",
Value = sloTable.PayloadTimestamp
});
});

return (1, StatusCode.Success);
}
Expand All @@ -43,15 +82,14 @@ int readTimeout
)
{
await using var dbContext = await client.CreateDbContextAsync();
await dbContext.SloEntities.FindAsync(select.Guid, select.Id);

return (0, StatusCode.Success, null);
return (0, StatusCode.Success,
await dbContext.SloEntities.FirstOrDefaultAsync(table =>
table.Guid == select.Guid && table.Id == select.Id));
}

protected override async Task<int> SelectCount(PooledDbContextFactory<TableDbContext> client)
{
await using var dbContext = await client.CreateDbContextAsync();

return await dbContext.SloEntities.CountAsync();
}
}
1 change: 1 addition & 0 deletions src/EFCore.Ydb/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Supported Guid (Uuid YDB type).
- PrivateAssets="none" is set to flow the EF Core analyzer to users referencing this package [issue](https://github.com/aspnet/EntityFrameworkCore/pull/11350).

## v0.0.2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using Microsoft.EntityFrameworkCore.Storage;

namespace EntityFrameworkCore.Ydb.Storage.Internal.Mapping;
Expand All @@ -8,9 +7,11 @@ public class YdbDecimalTypeMapping : DecimalTypeMapping
private const byte DefaultPrecision = 22;
private const byte DefaultScale = 9;

public YdbDecimalTypeMapping(Type? type) : this(
public new static YdbDecimalTypeMapping Default => new();

public YdbDecimalTypeMapping() : this(
new RelationalTypeMappingParameters(
new CoreTypeMappingParameters(type ?? typeof(decimal)),
new CoreTypeMappingParameters(typeof(decimal)),
storeType: "Decimal",
dbType: System.Data.DbType.Decimal
)
Expand Down
21 changes: 21 additions & 0 deletions src/EFCore.Ydb/src/Storage/Internal/Mapping/YdbGuidTypeMapping.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.EntityFrameworkCore.Storage;

namespace EntityFrameworkCore.Ydb.Storage.Internal.Mapping;

public class YdbGuidTypeMapping : GuidTypeMapping
{
public new static YdbGuidTypeMapping Default => new();

private YdbGuidTypeMapping() : base("Uuid", System.Data.DbType.Guid)
{
}

protected YdbGuidTypeMapping(RelationalTypeMappingParameters parameters) : base(parameters)
{
}

protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) =>
new YdbGuidTypeMapping(parameters);

protected override string SqlLiteralFormatString => "Uuid('{0}')";
}
12 changes: 9 additions & 3 deletions src/EFCore.Ydb/src/Storage/Internal/YdbTypeMappingSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ RelationalTypeMappingSourceDependencies relationalDependencies
private static readonly FloatTypeMapping Float = new("Float", DbType.Single);
private static readonly DoubleTypeMapping Double = new("Double", DbType.Double);

private static readonly YdbDecimalTypeMapping Decimal = new(typeof(decimal));
private static readonly YdbDecimalTypeMapping Decimal = YdbDecimalTypeMapping.Default;

private static readonly GuidTypeMapping Guid = YdbGuidTypeMapping.Default;

private static readonly YdbTextTypeMapping Text = YdbTextTypeMapping.Default;
private static readonly YdbBytesTypeMapping Bytes = YdbBytesTypeMapping.Default;
Expand Down Expand Up @@ -64,6 +66,10 @@ RelationalTypeMappingSourceDependencies relationalDependencies
{ "Float", [Float] },
{ "Double", [Double] },

{ "Decimal", [Decimal] },

{ "Guid", [Guid] },

{ "Date", [Date] },
{ "DateTime", [DateTime] },
{ "Timestamp", [Timestamp] },
Expand All @@ -72,8 +78,6 @@ RelationalTypeMappingSourceDependencies relationalDependencies
{ "Text", [Text] },
{ "Bytes", [Bytes] },

{ "Decimal", [Decimal] },

{ "Json", [Json] }
};

Expand All @@ -95,6 +99,8 @@ RelationalTypeMappingSourceDependencies relationalDependencies
{ typeof(double), Double },
{ typeof(decimal), Decimal },

{ typeof(Guid), Guid },

{ typeof(string), Text },
{ typeof(byte[]), Bytes },
{ typeof(JsonElement), Json },
Expand Down
7 changes: 3 additions & 4 deletions src/Ydb.Sdk/tests/Topic/ReaderUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,14 +1086,13 @@ public async Task
Assert.Equal("Hello", batch.Batch[0].Data);
Assert.Equal("World!", batch.Batch[1].Data);

_mockStream.Verify(stream => stream.Write(It.IsAny<FromClient>()), Times.Between(11, 12, Range.Inclusive));
_mockStream.Verify(stream => stream.Write(It.IsAny<FromClient>()), Times.AtLeast(11));
_mockStream.Verify(stream => stream.MoveNextAsync(), Times.Between(8, 9, Range.Inclusive));
_mockStream.Verify(stream => stream.Current, Times.Exactly(7));

_mockStream.Verify(stream => stream.Write(It.Is<FromClient>(msg =>
msg.InitRequest != null &&
msg.InitRequest.Consumer == "Consumer" &&
msg.InitRequest.TopicsReadSettings[0].Path == "/topic")), Times.Exactly(2));
msg.InitRequest != null && msg.InitRequest.Consumer == "Consumer" &&
msg.InitRequest.TopicsReadSettings[0].Path == "/topic")), Times.Between(2, 3, Range.Inclusive));
_mockStream.Verify(stream => stream.Write(It.Is<FromClient>(msg =>
msg.ReadRequest != null && msg.ReadRequest.BytesSize == 100)), Times.Exactly(2));
_mockStream.Verify(stream => stream.Write(It.Is<FromClient>(msg =>
Expand Down
Loading