Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into txLogs
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
rekby committed Dec 14, 2023
2 parents 5c69889 + 5ccb9cd commit a331d34
Show file tree
Hide file tree
Showing 93 changed files with 3,349 additions and 82 deletions.
26 changes: 18 additions & 8 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ on:

jobs:
autoformatter:
strategy:
matrix:
source-dir: ["./src/", "./examples/src/", "./slo/src/"]
include:
- source-dir: "./src/"
solutionFile: "YdbSdk.sln"
- source-dir: "./examples/src/"
solutionFile: "YdbExamples.sln"
- source-dir: "./slo/src/"
solutionFile: "src.sln"
name: autoformat check
concurrency:
group: lint-autoformat-${{ github.ref }}
cancel-in-progress: true
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -21,15 +28,18 @@ jobs:
with:
dotnet-version: '6.0.x'
- name: Restore
run: dotnet restore ./src/YdbSdk.sln
run: dotnet restore ${{ matrix.source-dir }}${{ matrix.solutionFile }}
- name: Install ReSharper
run: dotnet tool install -g JetBrains.ReSharper.GlobalTools
run: dotnet tool install -g JetBrains.ReSharper.GlobalTools --version 2023.2.1
- name: format all files with auto-formatter
run: bash ./.github/scripts/format-all-dotnet-code.sh ./src/ YdbSdk.sln "Custom Cleanup"
run: bash ./.github/scripts/format-all-dotnet-code.sh ${{ matrix.source-dir }} ${{ matrix.solutionFile }} "Custom Cleanup"
- name: Check repository diff
run: bash ./.github/scripts/check-work-copy-equals-to-committed.sh "auto-format broken"

inspection:
strategy:
matrix:
solutionPath: ["./src/YdbSdk.sln", "./examples/src/YdbExamples.sln", "./slo/src/src.sln"]
runs-on: ubuntu-latest
name: Inspection
steps:
Expand All @@ -40,11 +50,11 @@ jobs:
with:
dotnet-version: '6.0.x'
- name: Restore
run: dotnet restore ./src/YdbSdk.sln
run: dotnet restore ${{ matrix.solutionPath }}
- name: Inspect code
uses: muno92/resharper_inspectcode@v1
with:
solutionPath: ./src/YdbSdk.sln
solutionPath: ${{ matrix.solutionPath }}
version: 2023.2.1
include: |
**.cs
Expand Down
68 changes: 68 additions & 0 deletions .github/workflows/slo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

name: SLO

jobs:
test-slo:
concurrency:
group: slo-${{ github.ref }}
if: (!contains(github.event.pull_request.labels.*.name, 'no slo'))

runs-on: ubuntu-latest
name: SLO test
permissions:
checks: write
pull-requests: write
contents: read
issues: write

steps:
- name: Checkout repository
uses: actions/checkout@v3
if: env.DOCKER_REPO != null
env:
DOCKER_REPO: ${{ secrets.SLO_DOCKER_REPO }}

- name: Run SLO
uses: ydb-platform/slo-tests@php-version
if: env.DOCKER_REPO != null
env:
DOCKER_REPO: ${{ secrets.SLO_DOCKER_REPO }}
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
KUBECONFIG_B64: ${{ secrets.SLO_KUBE_CONFIG }}
AWS_CREDENTIALS_B64: ${{ secrets.SLO_AWS_CREDENTIALS }}
AWS_CONFIG_B64: ${{ secrets.SLO_AWS_CONFIG }}
DOCKER_USERNAME: ${{ secrets.SLO_DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.SLO_DOCKER_PASSWORD }}
DOCKER_REPO: ${{ secrets.SLO_DOCKER_REPO }}
DOCKER_FOLDER: ${{ secrets.SLO_DOCKER_FOLDER }}
s3_endpoint: ${{ secrets.SLO_S3_ENDPOINT }}
s3_images_folder: ${{ vars.SLO_S3_IMAGES_FOLDER }}
grafana_domain: ${{ vars.SLO_GRAFANA_DOMAIN }}
# grafana_dashboard: ${{ vars.SLO_GRAFANA_DASHBOARD }}
grafana_dashboard: dca60386-0d3d-43f5-a2af-5f3fd3e3b295
grafana_dashboard_width: 2000
grafana_dashboard_height: 2300
ydb_version: 'newest'
timeBetweenPhases: 30
shutdownTime: 30

language_id0: 'dotnet'
workload_path0: 'slo/src'
language0: '.NET SDK'
workload_build_context0: ../..
workload_build_options0: -f Dockerfile

- uses: actions/upload-artifact@v3
if: always() && env.DOCKER_REPO != null
env:
DOCKER_REPO: ${{ secrets.SLO_DOCKER_REPO }}
with:
name: slo-logs
path: logs/
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
- Add logging for transactions
- Add static auth

## v0.1.5
- Fix timeout error on create session
- Fix transport error on delete session

## v0.1.4
- Add exception throwing when results truncated
- lint: add line feed at file end

## v0.1.3
- Add static auth
## v0.1.1
- Add static code analysis
- Add CodeQL analysis
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ foreach (var row in resultSet.Rows)

## Examples

See **[ydb-dotnet-examples](https://github.com/ydb-platform/ydb-dotnet-examples)**.
See **[examples folder](https://github.com/ydb-platform/ydb-dotnet-sdk/tree/main/examples)**
35 changes: 35 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# YDB .NET SDK Examples

## Prerequisites
.NET 6

## Running examples

1. Clone repository
```bash
git clone https://github.com/ydb-platform/ydb-dotnet-sdk.git
```

2. Build solution
```bash
cd ydb-dotnet-sdk/examples/src
dotnet build
```

3. Run example
```bash
cd <ExampleName>
dotnet run -e <Endpoint> -d <Database>
```

## Provided examples

### BasicExample
Demonstrates basic operations with YDB, including:
* Driver initialization
* Table client initialization
* Table creation via SchemeQuery (DDL)
* Data queries (OLTP) & transactions (read, modify)
* Interactive transactions
* ReadTable for streaming read of table contents
* ScanQuery for streaming wide queries (OLAP)
81 changes: 81 additions & 0 deletions examples/src/BasicExample/BasicExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Ydb.Sdk.Auth;
using Ydb.Sdk.Services.Table;

namespace Ydb.Sdk.Examples;

internal partial class BasicExample : TableExampleBase
{
private BasicExample(TableClient client, string database, string path)
: base(client, database, path)
{
}

public static async Task Run(
string endpoint,
string database,
ICredentialsProvider credentialsProvider,
X509Certificate? customServerCertificate,
string path,
ILoggerFactory loggerFactory)
{
var config = new DriverConfig(
endpoint: endpoint,
database: database,
credentials: credentialsProvider,
customServerCertificate: customServerCertificate
);

await using var driver = await Driver.CreateInitialized(
config: config,
loggerFactory: loggerFactory
);

using var tableClient = new TableClient(driver, new TableClientConfig());

var example = new BasicExample(tableClient, database, path);

await example.SchemeQuery();
await example.FillData();
await example.SimpleSelect(1);
await example.SimpleUpsert(10, "Coming soon", DateTime.UtcNow);
await example.SimpleSelect(10);
await example.InteractiveTx();
await example.ReadTable();
await example.ScanQuery(DateTime.Parse("2007-01-01"));
}

private static ExecuteDataQuerySettings DefaultDataQuerySettings =>
new()
{
// Indicates that client is no longer interested in the result of operation after the
// specified duration starting from the moment when operation arrives at the server.
// Status code TIMEOUT will be returned from server in case when operation result in
// not available in the specified time period. This status code doesn't indicate the result
// of operation, it might be completed or cancelled.
OperationTimeout = TimeSpan.FromSeconds(1),

// Transport timeout from the moment operation was sent to server. It is useful in case
// of possible network issues, to that query doesn't hang forever.
// It is recommended to set this value to a larger value than OperationTimeout to give
// server some time to issue a response.
TransportTimeout = TimeSpan.FromSeconds(5),

// Keep query compilation result in query cache or not. Should be false for ad-hoc queries,
// and true (default) for high-RPS queries.
KeepInQueryCache = false
};

private ExecuteDataQuerySettings DefaultCachedDataQuerySettings
{
get
{
var settings = DefaultDataQuerySettings;
settings.KeepInQueryCache = true;
return settings;
}
}
}
28 changes: 28 additions & 0 deletions examples/src/BasicExample/BasicExample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<AssemblyName>Ydb.Sdk.Examples.BasicExample</AssemblyName>
<RootNamespace>Ydb.Sdk.Examples</RootNamespace>
</PropertyGroup>

<PropertyGroup>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/ydb-platform/ydb-dotnet-examples</RepositoryUrl>
<PackageProjectUrl>https://github.com/ydb-platform/ydb-dotnet-examples</PackageProjectUrl>
<Company>YANDEX LLC</Company>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
</ItemGroup>

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

</Project>
88 changes: 88 additions & 0 deletions examples/src/BasicExample/DataQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Ydb.Sdk.Services.Table;
using Ydb.Sdk.Value;

namespace Ydb.Sdk.Examples;

internal partial class BasicExample
{
private async Task SimpleSelect(ulong id)
{
var response = await Client.SessionExec(async session =>
{
var query = @$"
PRAGMA TablePathPrefix('{BasePath}');
DECLARE $id AS Uint64;
SELECT
series_id,
title,
release_date
FROM series
WHERE series_id = $id;
";
return await session.ExecuteDataQuery(
query: query,
txControl: TxControl.BeginSerializableRW().Commit(),
parameters: new Dictionary<string, YdbValue>
{
{ "$id", YdbValue.MakeUint64(id) }
},
settings: DefaultCachedDataQuerySettings
);
});

response.Status.EnsureSuccess();

var queryResponse = (ExecuteDataQueryResponse)response;
var resultSet = queryResponse.Result.ResultSets[0];

Console.WriteLine($"> SimpleSelect, " +
$"columns: {resultSet.Columns.Count}, " +
$"rows: {resultSet.Rows.Count}, " +
$"truncated: {resultSet.Truncated}");

foreach (var row in resultSet.Rows)
{
Console.WriteLine($"> Series, " +
$"series_id: {(ulong?)row["series_id"]}, " +
$"title: {(string?)row["title"]}, " +
$"release_date: {(DateTime?)row["release_date"]}");
}
}

private async Task SimpleUpsert(ulong id, string title, DateTime date)
{
var response = await Client.SessionExec(async session =>
{
var query = @$"
PRAGMA TablePathPrefix('{BasePath}');
DECLARE $id AS Uint64;
DECLARE $title AS Utf8;
DECLARE $release_date AS Date;
UPSERT INTO series (series_id, title, release_date) VALUES
($id, $title, $release_date);
";
return await session.ExecuteDataQuery(
query: query,
txControl: TxControl.BeginSerializableRW().Commit(),
parameters: new Dictionary<string, YdbValue>
{
{ "$id", YdbValue.MakeUint64(id) },
{ "$title", YdbValue.MakeUtf8(title) },
{ "$release_date", YdbValue.MakeDate(date) }
},
settings: DefaultCachedDataQuerySettings
);
});

response.Status.EnsureSuccess();
}
}
Loading

0 comments on commit a331d34

Please sign in to comment.