diff --git a/.github/workflows/breaking.yml b/.github/workflows/breaking.yml index 17eeb19c3..7594b1f82 100644 --- a/.github/workflows/breaking.yml +++ b/.github/workflows/breaking.yml @@ -16,11 +16,11 @@ jobs: contents: read steps: - name: Install Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: go-version: "1.21" - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install gorelease run: test -e ~/go/bin/gorelease || go install golang.org/x/exp/cmd/gorelease@latest - name: Check broken API changes diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 5c3508bd1..65f19da5b 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout sources - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Changelog updated uses: Zomzog/changelog-checker@v1.3.0 diff --git a/.github/workflows/check-codegen.yml b/.github/workflows/check-codegen.yml index 0ee6bd406..8d9f701e3 100644 --- a/.github/workflows/check-codegen.yml +++ b/.github/workflows/check-codegen.yml @@ -18,10 +18,10 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: go-version: ${{ matrix.go-version }} diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 678e69070..f37a6b49c 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -45,11 +45,11 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -63,7 +63,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@v3 # ℹī¸ Command-line programs to run using the OS shell. # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun @@ -76,4 +76,4 @@ jobs: # ./location_of_script_within_repo/buildscript.sh - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 745864a37..4eca7b4b2 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -38,9 +38,9 @@ jobs: YDB_VERSION: ${{ matrix.ydb-version }} steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: cache: true - name: Run basic example ${{ matrix.application }} @@ -74,9 +74,9 @@ jobs: POSTGRES_CONNECTION_STRING: postgres://postgres:postgres@localhost:5432/basic?sslmode=disable steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: cache: true - name: Run basic example ${{ matrix.application }} with postgres @@ -97,9 +97,9 @@ jobs: SQLITE_CONNECTION_STRING: ${{ matrix.application }}.db steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: cache: true - name: Run basic example ${{ matrix.application }} with sqlite diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c4b89aa7a..e922c39e2 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -16,9 +16,9 @@ jobs: cancel-in-progress: true runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v4 with: version: ${{ env.GOLANGCI_LINT_VERSION }} args: --timeout=5m @@ -29,11 +29,11 @@ jobs: cancel-in-progress: true runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: generate examples golangci-lint config run: sed 's/github.com\/ydb-platform\/ydb-go-sdk\/v3/examples/g' .golangci.yml > examples/.golangci.yml - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v4 with: version: ${{ env.GOLANGCI_LINT_VERSION }} args: --timeout=5m @@ -45,11 +45,11 @@ jobs: cancel-in-progress: true runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: generate slo golangci-lint config run: sed 's/github.com\/ydb-platform\/ydb-go-sdk\/v3/slo/g' .golangci.yml > tests/slo/.golangci.yml - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v4 with: version: ${{ env.GOLANGCI_LINT_VERSION }} args: --timeout=5m @@ -61,9 +61,9 @@ jobs: cancel-in-progress: true runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: go-version: "1.21" - name: Install utilities diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 61361f822..64f30b640 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -28,7 +28,7 @@ jobs: CHANGELOG_FILE: CHANGELOG.md GITHUB_TOKEN: ${{ secrets.YDB_PLATFORM_BOT_TOKEN_REPO }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: token: ${{ secrets.YDB_PLATFORM_BOT_TOKEN_REPO }} fetch-depth: 0 diff --git a/.github/workflows/slo.yml b/.github/workflows/slo.yml index d1922303e..bc63cacbe 100644 --- a/.github/workflows/slo.yml +++ b/.github/workflows/slo.yml @@ -21,7 +21,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Run SLO uses: ydb-platform/slo-tests@js-version @@ -73,7 +73,7 @@ jobs: workload_build_context4: ../.. workload_build_options4: -f Dockerfile --build-arg SRC_PATH=xorm --build-arg JOB_NAME=workload-xorm - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 if: always() with: name: slo-logs diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 756b2fd38..55e6629fe 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,16 +22,16 @@ jobs: runs-on: ${{ matrix.os }}-latest steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: go-version: ${{ matrix.go-version }} cache: true - name: Test run: go test -race -coverprofile unit.txt -covermode atomic ./... - name: Upload coverage report to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: file: ./unit.txt flags: unit,${{ matrix.os }},go-${{ matrix.go-version }} @@ -71,16 +71,16 @@ jobs: HIDE_APPLICATION_OUTPUT: 1 steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: go-version: ${{ matrix.go-version }} cache: true - name: Integration test run: go test -race -tags integration -coverpkg=./... -coverprofile integration-secure.txt -covermode atomic ./tests/integration - name: Upload Test secure connection coverage report to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: file: ./integration-secure.txt flags: integration,${{ matrix.os }},go-${{ matrix.go-version }},ydb-${{ matrix.ydb-version }} diff --git a/.golangci.yml b/.golangci.yml index a4f93bda2..e2100ce23 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -234,14 +234,12 @@ linters: - godot - goerr113 - golint - - gomnd - ifshort - interfacebloat - ireturn - maintidx - nonamedreturns - paralleltest - - scopelint - structcheck - testableexamples - testpackage @@ -295,6 +293,7 @@ issues: - predeclared - path: _test\.go linters: + - scopelint - funlen - unused - unparam @@ -304,6 +303,9 @@ issues: - staticcheck - path: _test\.go text: "ydb.Connection is deprecated" + - path: examples + linters: + - gomnd # Allow underscore and capital camel case for readability # Examples: Type_PRIMITIVE_TYPE_ID_UNSPECIFIED, Ydb_Discovery_V1, _voidValue diff --git a/CHANGELOG.md b/CHANGELOG.md index 423d46527..03957b2fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,27 @@ +## v3.65.1 +* Updated dependency `ydb-go-genproto` +* Added processing of `Ydb.StatusIds_EXTERNAL_ERROR` in `retry.Retry` + +## v3.65.0 +* Supported OAuth 2.0 Token Exchange credentials provider + +## v3.64.0 +* Supported `table.Session.RenameTables` method +* Fixed out of range panic if next query result set part is empty +* Updated the indirect dependencies `golang.org/x/net` to `v0.17.0` and `golang.org/x/sys` to `v0.13.0` due to vulnerability issue + +## v3.63.0 +* Added versioning policy + +## v3.62.0 +* Restored `WithSessionPoolKeepAliveMinSize` and `WithSessionPoolKeepAliveTimeout` for backward compatibility. +* Fixed leak timers +* Changed default StartTime (time of retries for connect to server) for topic writer from 1 minute to infinite (can be overrided by WithWriterStartTimeout topic option) +* Added `Struct` support for `Variant` in `ydb.ParamsBuilder()` +* Added `go` with anonymous function case in `gstack` + ## v3.61.2 -* Changed default transaction control to `NoTx` for execute query through query service client +* Changed default transaction control to `NoTx` for execute query through query service client ## v3.61.1 * Renamed `db.Coordination().CreateSession()` to `db.Coordination().Session()` for compatibility with protos @@ -82,7 +104,7 @@ * Fixed sometime panic on topic writer closing * Added experimental query parameters builder `ydb.ParamsBuilder()` * Changed types of `table/table.{QueryParameters,ParameterOption}` to aliases on `internal/params.{Parameters,NamedValue}` -* Fixed bug with optional decimal serialization +* Fixed bug with optional decimal serialization ## v3.56.2 * Fixed return private error for commit to stopped partition in topic reader. diff --git a/README.md b/README.md index 66967a039..ef0c47e06 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,10 @@ Supports `table`, `query`, `discovery`, `coordination`, `ratelimiter`, `scheme`, `ydb-go-sdk` supports all Go versions supported by the official [Go Release Policy](https://go.dev/doc/devel/release#policy). That is, the two most recent releases of Go. +## Versioning Policy + +`ydb-go-sdk` comply to guidelines from [SemVer2.0.0](https://semver.org/) with an several [exceptions](VERSIONING.md). + ## Installation ```sh diff --git a/VERSIONING.md b/VERSIONING.md new file mode 100644 index 000000000..40cb9171c --- /dev/null +++ b/VERSIONING.md @@ -0,0 +1,24 @@ +# YDB-Go-SDK Versioning Policy + +By adhering to these guidelines and exceptions, we aim to provide a stable and reliable development experience for our users (aka [LTS](https://en.wikipedia.org/wiki/Long-term_support)) while still allowing for innovation and improvement. + +We endeavor to adhere to versioning guidelines as defined by [SemVer2.0.0](https://semver.org/). + +We making the following exceptions to those guidelines: +## Experimental + - We use the `// Experimental` comment for new features in the `ydb-go-sdk`. + - Early adopters of newest feature can report bugs and imperfections in functionality. + - For fix this issues we can make broken changes in experimental API. + - We reserve the right to remove or modify these experimental features at any time without increase of major part of version. + - We want to make experimental API as stable in the future +## Deprecated + - We use the `// Deprecated` comment for deprecated features in the `ydb-go-sdk`. + - Usage of some entity marked with `// Deprecated` can be detected with linters such as [check-deprecated](https://github.com/black-06/check-deprecated), [staticcheck](https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck) or [go-critic](https://github.com/go-critic/go-critic). + - This helps to our users to soft decline to use the deprecated feature without any impact on their code. + - Deprecated features will not be removed or changed for a minimum period of **six months** since the mark added. + - We reserve the right to remove or modify these deprecated features without increase of major part of version. +## Internals + - Some public API of `ydb-go-sdk` relate to the internals. + - We use the `// Internals` comment for public internals in the `ydb-go-sdk`. + - `ydb-go-sdk` internals can be changed at any time without increase of major part of version. + - Internals will never marked as stable diff --git a/balancers/balancers.go b/balancers/balancers.go index c73c8f503..2fe525a53 100644 --- a/balancers/balancers.go +++ b/balancers/balancers.go @@ -9,7 +9,9 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/internal/xstring" ) -// Deprecated: RoundRobin is RandomChoice now +// Deprecated: RoundRobin is an alias to RandomChoice now +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func RoundRobin() *balancerConfig.Config { return &balancerConfig.Config{} } @@ -115,6 +117,8 @@ type Endpoint interface { // Deprecated: LocalDC check "local" by compare endpoint location with discovery "selflocation" field. // It work good only if connection url always point to local dc. + // Will be removed after Oct 2024. + // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated LocalDC() bool } diff --git a/config/config.go b/config/config.go index 96756e9ec..28ffd0f90 100644 --- a/config/config.go +++ b/config/config.go @@ -107,7 +107,9 @@ type Option func(c *Config) // WithInternalDNSResolver // -// Deprecated: always used internal dns-resolver +// Deprecated: always used internal dns-resolver. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithInternalDNSResolver() Option { return func(c *Config) {} } @@ -170,7 +172,9 @@ func WithApplicationName(applicationName string) Option { // WithUserAgent add provided user agent to all api requests // -// Deprecated: use WithApplicationName instead +// Deprecated: use WithApplicationName instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithUserAgent(userAgent string) Option { return func(c *Config) { c.metaOptions = append(c.metaOptions, meta.WithApplicationNameOption(userAgent)) diff --git a/connection.go b/connection.go index 9bff94e31..14adc7470 100644 --- a/connection.go +++ b/connection.go @@ -16,10 +16,10 @@ import ( // Connection interface provide access to YDB service clients // Interface and list of clients may be changed in the future // -// Deprecated: use directly *Driver type from ydb.Open instead -// -//nolint:interfacebloat -type Connection interface { +// Deprecated: use Driver instance instead. +// Will be removed at next major release. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated +type Connection interface { //nolint:interfacebloat // Endpoint returns initial endpoint Endpoint() string @@ -37,9 +37,7 @@ type Connection interface { // Query returns query client // - // # Experimental - // - // Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. + // Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental Query() query.Client // Scheme returns scheme client diff --git a/coordination/coordination.go b/coordination/coordination.go index bfe6e9870..b0ff0c011 100644 --- a/coordination/coordination.go +++ b/coordination/coordination.go @@ -26,9 +26,7 @@ type Client interface { // - close the Client which the session was created with, // - call any method of the Session until the ErrSessionClosed is returned. // - // # Experimental - // - // Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. + // Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental Session(ctx context.Context, path string, opts ...options.SessionOption) (Session, error) } diff --git a/credentials/credentials.go b/credentials/credentials.go index 8829eb973..b11106414 100644 --- a/credentials/credentials.go +++ b/credentials/credentials.go @@ -34,3 +34,21 @@ func NewStaticCredentials( ) *credentials.Static { return credentials.NewStaticCredentials(user, password, authEndpoint, opts...) } + +// NewOauth2TokenExchangeCredentials makes OAuth 2.0 token exchange protocol credentials object +// https://www.rfc-editor.org/rfc/rfc8693 +func NewOauth2TokenExchangeCredentials( + opts ...credentials.Oauth2TokenExchangeCredentialsOption, +) (Credentials, error) { + return credentials.NewOauth2TokenExchangeCredentials(opts...) +} + +// NewJWTTokenSource makes JWT token source for OAuth 2.0 token exchange credentials +func NewJWTTokenSource(opts ...credentials.JWTTokenSourceOption) (credentials.TokenSource, error) { + return credentials.NewJWTTokenSource(opts...) +} + +// NewFixedTokenSource makes fixed token source for OAuth 2.0 token exchange credentials +func NewFixedTokenSource(token, tokenType string) credentials.TokenSource { + return credentials.NewFixedTokenSource(token, tokenType) +} diff --git a/credentials/options.go b/credentials/options.go index 9da142092..5d944dae6 100644 --- a/credentials/options.go +++ b/credentials/options.go @@ -1,11 +1,20 @@ package credentials import ( + "time" + + "github.com/golang-jwt/jwt/v4" "google.golang.org/grpc" "github.com/ydb-platform/ydb-go-sdk/v3/internal/credentials" ) +type Oauth2TokenExchangeCredentialsOption = credentials.Oauth2TokenExchangeCredentialsOption + +type TokenSource = credentials.TokenSource + +type Token = credentials.Token + // WithSourceInfo option append to credentials object the source info for reporting source info details on error case func WithSourceInfo(sourceInfo string) credentials.SourceInfoOption { return credentials.WithSourceInfo(sourceInfo) @@ -15,3 +24,118 @@ func WithSourceInfo(sourceInfo string) credentials.SourceInfoOption { func WithGrpcDialOptions(opts ...grpc.DialOption) credentials.StaticCredentialsOption { return credentials.WithGrpcDialOptions(opts...) } + +// TokenEndpoint +func WithTokenEndpoint(endpoint string) Oauth2TokenExchangeCredentialsOption { + return credentials.WithTokenEndpoint(endpoint) +} + +// GrantType +func WithGrantType(grantType string) Oauth2TokenExchangeCredentialsOption { + return credentials.WithGrantType(grantType) +} + +// Resource +func WithResource(resource string) Oauth2TokenExchangeCredentialsOption { + return credentials.WithResource(resource) +} + +// RequestedTokenType +func WithRequestedTokenType(requestedTokenType string) Oauth2TokenExchangeCredentialsOption { + return credentials.WithRequestedTokenType(requestedTokenType) +} + +// Scope +func WithScope(scope ...string) Oauth2TokenExchangeCredentialsOption { + return credentials.WithScope(scope...) +} + +// RequestTimeout +func WithRequestTimeout(timeout time.Duration) Oauth2TokenExchangeCredentialsOption { + return credentials.WithRequestTimeout(timeout) +} + +// SubjectTokenSource +func WithSubjectToken(subjectToken credentials.TokenSource) Oauth2TokenExchangeCredentialsOption { + return credentials.WithSubjectToken(subjectToken) +} + +// SubjectTokenSource +func WithFixedSubjectToken(token, tokenType string) Oauth2TokenExchangeCredentialsOption { + return credentials.WithFixedSubjectToken(token, tokenType) +} + +// SubjectTokenSource +func WithJWTSubjectToken(opts ...credentials.JWTTokenSourceOption) Oauth2TokenExchangeCredentialsOption { + return credentials.WithJWTSubjectToken(opts...) +} + +// ActorTokenSource +func WithActorToken(actorToken credentials.TokenSource) Oauth2TokenExchangeCredentialsOption { + return credentials.WithActorToken(actorToken) +} + +// ActorTokenSource +func WithFixedActorToken(token, tokenType string) Oauth2TokenExchangeCredentialsOption { + return credentials.WithFixedActorToken(token, tokenType) +} + +// ActorTokenSource +func WithJWTActorToken(opts ...credentials.JWTTokenSourceOption) Oauth2TokenExchangeCredentialsOption { + return credentials.WithJWTActorToken(opts...) +} + +// Audience +type oauthCredentialsAndJWTCredentialsOption interface { + credentials.Oauth2TokenExchangeCredentialsOption + credentials.JWTTokenSourceOption +} + +func WithAudience(audience ...string) oauthCredentialsAndJWTCredentialsOption { + return credentials.WithAudience(audience...) +} + +// Issuer +func WithIssuer(issuer string) credentials.JWTTokenSourceOption { + return credentials.WithIssuer(issuer) +} + +// Subject +func WithSubject(subject string) credentials.JWTTokenSourceOption { + return credentials.WithSubject(subject) +} + +// ID +func WithID(id string) credentials.JWTTokenSourceOption { + return credentials.WithID(id) +} + +// TokenTTL +func WithTokenTTL(ttl time.Duration) credentials.JWTTokenSourceOption { + return credentials.WithTokenTTL(ttl) +} + +// SigningMethod +func WithSigningMethod(method jwt.SigningMethod) credentials.JWTTokenSourceOption { + return credentials.WithSigningMethod(method) +} + +// KeyID +func WithKeyID(id string) credentials.JWTTokenSourceOption { + return credentials.WithKeyID(id) +} + +// PrivateKey +func WithPrivateKey(key interface{}) credentials.JWTTokenSourceOption { + return credentials.WithPrivateKey(key) +} + +// PrivateKey +func WithRSAPrivateKeyPEMContent(key []byte) credentials.JWTTokenSourceOption { + return credentials.WithRSAPrivateKeyPEMContent(key) +} + +// PrivateKey +func WithRSAPrivateKeyPEMFile(path string) credentials.JWTTokenSourceOption { + return credentials.WithRSAPrivateKeyPEMFile(path) +} diff --git a/driver.go b/driver.go index 7adfab361..592466443 100644 --- a/driver.go +++ b/driver.go @@ -191,9 +191,7 @@ func (d *Driver) Table() table.Client { // Query returns query client // -// # Experimental -// -// Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. +// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental func (d *Driver) Query() query.Client { return d.query.Get() } @@ -275,10 +273,12 @@ func MustOpen(ctx context.Context, dsn string, opts ...Option) *Driver { // New connects to database and return driver runtime holder // -// Deprecated: use Open with required param connectionString instead -// -//nolint:nonamedreturns -func New(ctx context.Context, opts ...Option) (_ *Driver, err error) { +// Deprecated: use ydb.Open instead. +// New func have no required arguments, such as connection string. +// Thats why we recognize that New have wrong signature. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated +func New(ctx context.Context, opts ...Option) (_ *Driver, err error) { //nolint:nonamedreturns d, err := newConnectionFromOptions(ctx, opts...) if err != nil { return nil, xerrors.WithStackTrace(err) diff --git a/examples/auth/README.md b/examples/auth/README.md index 273113372..e2b384488 100644 --- a/examples/auth/README.md +++ b/examples/auth/README.md @@ -4,6 +4,7 @@ Auth examples helps to understand YDB authentication: * `access_token_credentials` - example of use access token credentials * `anonymous_credentials` - example of use anonymous credentials * `metadata_credentials` - example of use metadata credentials +* `oauth2_token_exchange_credentials` - example of use oauth 2.0 token exchange credentials * `service_account_credentials` - example of use service account key file credentials * `static_credentials` - example of use static credentials * `environ` - example of use environment variables to configure YDB authenticate diff --git a/examples/auth/oauth2_token_exchange_credentials/README.md b/examples/auth/oauth2_token_exchange_credentials/README.md new file mode 100644 index 000000000..a13adf8d8 --- /dev/null +++ b/examples/auth/oauth2_token_exchange_credentials/README.md @@ -0,0 +1,8 @@ +# Authenticate with oauth 2.0 token exchange credentials + +`oauth2_token_exchange_credentials` example provides code snippet for authentication to YDB with oauth 2.0 token exchange credentials + +## Runing code snippet +```bash +oauth2_token_exchange_credentials -ydb="grpcs://endpoint/?database=database" -token-endpoint="https://exchange.token.endpoint/oauth2/token/exchange" -key-id="123" -private-key-file="path/to/key/file" -audience="test-aud" -issuer="test-issuer" -subject="test-subject" +``` diff --git a/examples/auth/oauth2_token_exchange_credentials/main.go b/examples/auth/oauth2_token_exchange_credentials/main.go new file mode 100644 index 000000000..e20e8a882 --- /dev/null +++ b/examples/auth/oauth2_token_exchange_credentials/main.go @@ -0,0 +1,107 @@ +package main + +import ( + "context" + "flag" + "fmt" + "os" + + "github.com/golang-jwt/jwt/v4" + ydb "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/credentials" +) + +var ( + dsn string + tokenEndpoint string + keyID string + privateKeyFile string + audience string + issuer string + subject string +) + +func init() { //nolint:gochecknoinits + required := []string{"ydb", "private-key-file", "key-id", "token-endpoint"} + flagSet := flag.NewFlagSet(os.Args[0], flag.ExitOnError) + flagSet.Usage = func() { + out := flagSet.Output() + _, _ = fmt.Fprintf(out, "Usage:\n%s [options]\n", os.Args[0]) + _, _ = fmt.Fprintf(out, "\nOptions:\n") + flagSet.PrintDefaults() + } + flagSet.StringVar(&dsn, + "ydb", "", + "YDB connection string", + ) + flagSet.StringVar(&tokenEndpoint, + "token-endpoint", "", + "oauth 2.0 token exchange endpoint", + ) + flagSet.StringVar(&keyID, + "key-id", "", + "key id for jwt token", + ) + flagSet.StringVar(&privateKeyFile, + "private-key-file", "", + "RSA private key file for jwt token in pem format", + ) + flagSet.StringVar(&audience, + "audience", "", + "audience", + ) + flagSet.StringVar(&issuer, + "issuer", "", + "jwt token issuer", + ) + flagSet.StringVar(&subject, + "subject", "", + "jwt token subject", + ) + if err := flagSet.Parse(os.Args[1:]); err != nil { + flagSet.Usage() + os.Exit(1) + } + flagSet.Visit(func(f *flag.Flag) { + for i, arg := range required { + if arg == f.Name { + required = append(required[:i], required[i+1:]...) + } + } + }) + if len(required) > 0 { + fmt.Printf("\nSome required options not defined: %v\n\n", required) + flagSet.Usage() + os.Exit(1) + } +} + +func main() { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + db, err := ydb.Open(ctx, dsn, + ydb.WithOauth2TokenExchangeCredentials( + credentials.WithTokenEndpoint(tokenEndpoint), + credentials.WithAudience(audience), + credentials.WithJWTSubjectToken( + credentials.WithSigningMethod(jwt.SigningMethodRS256), + credentials.WithKeyID(keyID), + credentials.WithRSAPrivateKeyPEMFile(privateKeyFile), + credentials.WithIssuer(issuer), + credentials.WithSubject(subject), + credentials.WithAudience(audience), + ), + ), + ) + if err != nil { + panic(err) + } + defer func() { _ = db.Close(ctx) }() + + whoAmI, err := db.Discovery().WhoAmI(ctx) + if err != nil { + panic(err) + } + + fmt.Println(whoAmI.String()) +} diff --git a/examples/go.mod b/examples/go.mod index 4e15e2a0b..0e3ecce2c 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -3,6 +3,7 @@ module examples go 1.21 require ( + github.com/golang-jwt/jwt/v4 v4.4.3 github.com/google/uuid v1.3.0 github.com/gorilla/mux v1.8.0 github.com/lib/pq v1.10.2 @@ -28,7 +29,6 @@ require ( github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/goccy/go-json v0.9.11 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect - github.com/golang-jwt/jwt/v4 v4.4.3 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect @@ -51,11 +51,11 @@ require ( github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect github.com/syndtr/goleveldb v1.0.0 // indirect github.com/yandex-cloud/go-genproto v0.0.0-20220815090733-4c139c0154e2 // indirect - github.com/ydb-platform/ydb-go-genproto v0.0.0-20240126124512-dbb0e1720dbf // indirect + github.com/ydb-platform/ydb-go-genproto v0.0.0-20240316140903-4a47abca1cca // indirect github.com/ydb-platform/ydb-go-yc-metadata v0.5.4 // indirect golang.org/x/crypto v0.17.0 // indirect golang.org/x/mod v0.11.0 // indirect - golang.org/x/net v0.15.0 // indirect + golang.org/x/net v0.17.0 // indirect golang.org/x/sys v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/tools v0.7.0 // indirect diff --git a/examples/go.sum b/examples/go.sum index 79278f3b3..f3fbe27f4 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -1197,8 +1197,8 @@ github.com/ydb-platform/gorm-driver v0.0.5 h1:q6Cg/iSFw4TAmSyMh25YM0GRmr6LVM2gnF github.com/ydb-platform/gorm-driver v0.0.5/go.mod h1:fkCvWZlA3PzL5MiMc7yFOzxUOzLpY1uT8yZo+e4SV4Y= github.com/ydb-platform/xorm v0.0.3 h1:MXk42lANB6r/MMLg/XdJfyXJycGUDlCeLiMlLGDKVPw= github.com/ydb-platform/xorm v0.0.3/go.mod h1:hFsU7EUF0o3S+l5c0eyP2yPVjJ0d4gsFdqCsyazzwBc= -github.com/ydb-platform/ydb-go-genproto v0.0.0-20240126124512-dbb0e1720dbf h1:ckwNHVo4bv2tqNkgx3W3HANh3ta1j6TR5qw08J1A7Tw= -github.com/ydb-platform/ydb-go-genproto v0.0.0-20240126124512-dbb0e1720dbf/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I= +github.com/ydb-platform/ydb-go-genproto v0.0.0-20240316140903-4a47abca1cca h1:PliQWLwi2gTSOk7QyYQ9GfjvvikmibLWmaplKHy+kfo= +github.com/ydb-platform/ydb-go-genproto v0.0.0-20240316140903-4a47abca1cca/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I= github.com/ydb-platform/ydb-go-sdk-auth-environ v0.1.2 h1:EYSI1kulnHb0H0zt3yOw4cRj4ABMSMGwNe43D+fX7e4= github.com/ydb-platform/ydb-go-sdk-auth-environ v0.1.2/go.mod h1:Xfjce+VMU9yJVr1lj60yK2fFPWjB4jr/4cp3K7cjzi4= github.com/ydb-platform/ydb-go-sdk-prometheus/v2 v2.0.1 h1:Lsir3AC2VQOTlp8UjZY9zQdCVfWvBNHT3hZn+jSGoo0= @@ -1269,7 +1269,7 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= -golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -1401,8 +1401,8 @@ golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1551,7 +1551,7 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= @@ -1565,7 +1565,7 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= -golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/examples/topic/topicreader/topicreader_advanced.go b/examples/topic/topicreader/topicreader_advanced.go index 962f4700b..256d38494 100644 --- a/examples/topic/topicreader/topicreader_advanced.go +++ b/examples/topic/topicreader/topicreader_advanced.go @@ -50,14 +50,14 @@ func UnmarshalMessageContentToOwnType(ctx context.Context, reader *topicreader.R // ProcessMessagesWithSyncCommit example about guarantee wait for commit accepted by server func ProcessMessagesWithSyncCommit(ctx context.Context, db *ydb.Driver) { reader, _ := db.Topic().StartReader("consumer", nil, - topicoptions.WithCommitMode(topicoptions.CommitModeSync), + topicoptions.WithReaderCommitMode(topicoptions.CommitModeSync), ) defer func() { _ = reader.Close(ctx) }() for { - batch, _ := reader.ReadMessageBatch(ctx) + batch, _ := reader.ReadMessagesBatch(ctx) processBatch(batch.Context(), batch) _ = reader.Commit(ctx, batch) // will wait response about commit from server } @@ -67,7 +67,7 @@ func ProcessMessagesWithSyncCommit(ctx context.Context, db *ydb.Driver) { // commit messages to YDB func OwnReadProgressStorage(ctx context.Context, db *ydb.Driver) { reader, _ := db.Topic().StartReader("consumer", topicoptions.ReadTopic("asd"), - topicoptions.WithGetPartitionStartOffset( + topicoptions.WithReaderGetPartitionStartOffset( func( ctx context.Context, req topicoptions.GetPartitionStartOffsetRequest, @@ -84,7 +84,7 @@ func OwnReadProgressStorage(ctx context.Context, db *ydb.Driver) { ) for { - batch, _ := reader.ReadMessageBatch(ctx) + batch, _ := reader.ReadMessagesBatch(ctx) processBatch(batch.Context(), batch) _ = externalSystemCommit( diff --git a/examples/topic/topicreader/topicreader_simple.go b/examples/topic/topicreader/topicreader_simple.go index 6fb568037..793485fbb 100644 --- a/examples/topic/topicreader/topicreader_simple.go +++ b/examples/topic/topicreader/topicreader_simple.go @@ -24,7 +24,7 @@ func PrintMessageContent(ctx context.Context, reader *topicreader.Reader) { // ReadMessagesByBatch it is recommended way for process messages func ReadMessagesByBatch(ctx context.Context, reader *topicreader.Reader) { for { - batch, _ := reader.ReadMessageBatch(ctx) + batch, _ := reader.ReadMessagesBatch(ctx) processBatch(batch.Context(), batch) _ = reader.Commit(batch.Context(), batch) } diff --git a/examples/topic/topicreader/topicreader_trace.go b/examples/topic/topicreader/topicreader_trace.go index 28ab11427..b31390fb2 100644 --- a/examples/topic/topicreader/topicreader_trace.go +++ b/examples/topic/topicreader/topicreader_trace.go @@ -71,7 +71,7 @@ func ExplicitPartitionStartStopHandler(ctx context.Context, db *ydb.Driver) { }() for { - batch, _ := reader.ReadMessageBatch(readContext) + batch, _ := reader.ReadMessagesBatch(readContext) processBatch(batch.Context(), batch) _ = externalSystemCommit( @@ -129,8 +129,7 @@ func PartitionStartStopHandlerAndOwnReadProgressStorage(ctx context.Context, db } r, _ := db.Topic().StartReader("consumer", topicoptions.ReadTopic("asd"), - - topicoptions.WithGetPartitionStartOffset(readStartPosition), + topicoptions.WithReaderGetPartitionStartOffset(readStartPosition), topicoptions.WithReaderTrace( trace.Topic{ OnReaderPartitionReadStartResponse: onPartitionStart, @@ -144,7 +143,7 @@ func PartitionStartStopHandlerAndOwnReadProgressStorage(ctx context.Context, db }() for { - batch, _ := r.ReadMessageBatch(readContext) + batch, _ := r.ReadMessagesBatch(readContext) processBatch(batch.Context(), batch) _ = externalSystemCommit(batch.Context(), batch.Topic(), batch.PartitionID(), getEndOffset(batch)) diff --git a/examples/topic/topicwriter/topicwriter.go b/examples/topic/topicwriter/topicwriter.go index a378f8a90..354d3f454 100644 --- a/examples/topic/topicwriter/topicwriter.go +++ b/examples/topic/topicwriter/topicwriter.go @@ -17,13 +17,13 @@ func ConnectSimple(ctx context.Context, db *ydb.Driver) *topicwriter.Writer { } func ConnectWithSyncWrite(ctx context.Context, db *ydb.Driver) *topicwriter.Writer { - writer, _ := db.Topic().StartWriter("topicName", topicoptions.WithSyncWrite(true)) + writer, _ := db.Topic().StartWriter("topicName", topicoptions.WithWriterWaitServerAck(true)) return writer } func ConnectSelectCodec(ctx context.Context, db *ydb.Driver) *topicwriter.Writer { - writer, _ := db.Topic().StartWriter("topicName", topicoptions.WithCodec(topictypes.CodecGzip)) + writer, _ := db.Topic().StartWriter("topicName", topicoptions.WithWriterCodec(topictypes.CodecGzip)) return writer } diff --git a/examples/ttl/series.go b/examples/ttl/series.go index a6e4753c3..67f7759dc 100644 --- a/examples/ttl/series.go +++ b/examples/ttl/series.go @@ -268,9 +268,10 @@ func createTables(ctx context.Context, c table.Client, prefix string) (err error } for i := 0; i < expirationQueueCount; i++ { + tableName := path.Join(prefix, fmt.Sprintf("expiration_queue_%v", i)) err = c.Do(ctx, func(ctx context.Context, s table.Session) error { - return s.CreateTable(ctx, path.Join(prefix, fmt.Sprintf("expiration_queue_%v", i)), + return s.CreateTable(ctx, tableName, options.WithColumn("doc_id", types.Optional(types.TypeUint64)), options.WithColumn("ts", types.Optional(types.TypeUint64)), options.WithPrimaryKeyColumn("ts", "doc_id"), diff --git a/go.mod b/go.mod index 339491ffc..6f67d5b64 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,8 @@ require ( github.com/golang-jwt/jwt/v4 v4.4.1 github.com/google/uuid v1.3.0 github.com/jonboulle/clockwork v0.3.0 - github.com/ydb-platform/ydb-go-genproto v0.0.0-20240126124512-dbb0e1720dbf + github.com/ydb-platform/ydb-go-genproto v0.0.0-20240316140903-4a47abca1cca + golang.org/x/net v0.17.0 golang.org/x/sync v0.3.0 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 google.golang.org/grpc v1.57.1 @@ -24,8 +25,7 @@ require ( github.com/davecgh/go-spew v1.1.0 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/net v0.15.0 // indirect - golang.org/x/sys v0.12.0 // indirect + golang.org/x/sys v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect gopkg.in/yaml.v3 v3.0.0 // indirect diff --git a/go.sum b/go.sum index 4cfd88ee1..8d8988e36 100644 --- a/go.sum +++ b/go.sum @@ -65,8 +65,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/ydb-platform/ydb-go-genproto v0.0.0-20240126124512-dbb0e1720dbf h1:ckwNHVo4bv2tqNkgx3W3HANh3ta1j6TR5qw08J1A7Tw= -github.com/ydb-platform/ydb-go-genproto v0.0.0-20240126124512-dbb0e1720dbf/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I= +github.com/ydb-platform/ydb-go-genproto v0.0.0-20240316140903-4a47abca1cca h1:PliQWLwi2gTSOk7QyYQ9GfjvvikmibLWmaplKHy+kfo= +github.com/ydb-platform/ydb-go-genproto v0.0.0-20240316140903-4a47abca1cca/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= @@ -84,8 +84,8 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -100,8 +100,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= diff --git a/internal/allocator/allocator.go b/internal/allocator/allocator.go index ee44ca7d3..9b0219916 100644 --- a/internal/allocator/allocator.go +++ b/internal/allocator/allocator.go @@ -396,7 +396,7 @@ type structAllocator struct { func (a *structAllocator) Struct() (v *Ydb.StructType) { v = structPool.Get() if cap(v.GetMembers()) <= 0 { - v.Members = make([]*Ydb.StructMember, 0, 10) + v.Members = make([]*Ydb.StructMember, 0, 10) //nolint:gomnd } a.allocations = append(a.allocations, v) diff --git a/internal/backoff/backoff.go b/internal/backoff/backoff.go index c3a6902fe..d4b9cceeb 100644 --- a/internal/backoff/backoff.go +++ b/internal/backoff/backoff.go @@ -22,11 +22,11 @@ const ( var ( Fast = New( WithSlotDuration(fastSlot), - WithCeiling(6), + WithCeiling(6), //nolint:gomnd ) Slow = New( WithSlotDuration(slowSlot), - WithCeiling(6), + WithCeiling(6), //nolint:gomnd ) ) diff --git a/internal/balancer/local_dc.go b/internal/balancer/local_dc.go index e764af7d8..b1ee2e086 100644 --- a/internal/balancer/local_dc.go +++ b/internal/balancer/local_dc.go @@ -69,7 +69,7 @@ func detectFastestEndpoint(ctx context.Context, endpoints []endpoint.Endpoint) ( var lastErr error // common is 2 ip address for every fqdn: ipv4 + ipv6 - initialAddressToEndpointCapacity := len(endpoints) * 2 + initialAddressToEndpointCapacity := len(endpoints) * 2 //nolint:gomnd addressToEndpoint := make(map[string]endpoint.Endpoint, initialAddressToEndpointCapacity) for _, ep := range endpoints { host, port, err := extractHostPort(ep.Address()) diff --git a/internal/cmd/gstack/main.go b/internal/cmd/gstack/main.go index 12f427668..10f3ed061 100644 --- a/internal/cmd/gstack/main.go +++ b/internal/cmd/gstack/main.go @@ -79,6 +79,12 @@ func getCallExpressionsFromStmt(statement ast.Stmt) (listOfCallExpressions []*as body = stmt.Body case *ast.ForStmt: body = stmt.Body + case *ast.GoStmt: + if fun, ok := stmt.Call.Fun.(*ast.FuncLit); ok { + listOfCallExpressions = append(listOfCallExpressions, getListOfCallExpressionsFromBlockStmt(fun.Body)...) + } else { + listOfCallExpressions = append(listOfCallExpressions, stmt.Call) + } case *ast.RangeStmt: body = stmt.Body case *ast.DeclStmt: diff --git a/internal/cmd/gtrace/main.go b/internal/cmd/gtrace/main.go index 99f2bf98a..84a16add4 100644 --- a/internal/cmd/gtrace/main.go +++ b/internal/cmd/gtrace/main.go @@ -67,7 +67,7 @@ func main() { f, err = os.OpenFile( filepath.Join(workDir, filepath.Clean(name)), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, - 0o600, + 0o600, //nolint:gomnd ) if err != nil { log.Fatal(err) diff --git a/internal/cmd/gtrace/writer.go b/internal/cmd/gtrace/writer.go index fcc87a43e..8b0b30552 100644 --- a/internal/cmd/gtrace/writer.go +++ b/internal/cmd/gtrace/writer.go @@ -324,6 +324,7 @@ func (w *Writer) compose(trace *Trace) { w.line(`// Compose returns a new `, trace.Name, ` which has functional fields composed both from `, t, ` and `, x, `.`, ) + w.line(`// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals`) w.code(`func (`, t, ` *`, trace.Name, `) Compose(`, x, ` *`, trace.Name, `, opts ...`+trace.Name+`ComposeOption) `) w.line(`*`, trace.Name, ` {`) w.block(func() { @@ -405,9 +406,9 @@ func (w *Writer) composeHookCall(fn *Func, h1, h2 string) { w.line("if " + h + " != nil {") w.block(func() { if fn.HasResult() { - w.code(rs[i], ` = `) + w.code(rs[i], ` = `) //nolint:scopelint } - w.code(h) + w.code(h) //nolint:scopelint w.call(args) }) w.line("}") @@ -440,11 +441,13 @@ func (w *Writer) options(trace *Trace) { }) w.newScope(func() { w.line(fmt.Sprintf(`// %sOption specified %s compose option`, trace.Name, trace.Name)) + w.line(`// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals`) w.line(fmt.Sprintf(`type %sComposeOption func(o *%sComposeOptions)`, trace.Name, unexported(trace.Name))) _ = w.bw.WriteByte('\n') }) w.newScope(func() { w.line(fmt.Sprintf(`// With%sPanicCallback specified behavior on panic`, trace.Name)) + w.line(`// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals`) w.line(fmt.Sprintf(`func With%sPanicCallback(cb func(e interface{})) %sComposeOption {`, trace.Name, trace.Name)) w.block(func() { w.line(fmt.Sprintf(`return func(o *%sComposeOptions) {`, unexported(trace.Name))) @@ -641,6 +644,7 @@ func (w *Writer) hookShortcut(trace *Trace, hook Hook) { w.newScope(func() { t := w.declare("t") + w.line(`// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals`) w.code(`func `, name) w.code(`(`) var ctx string @@ -1028,7 +1032,7 @@ func (s *scope) set(v string) bool { if _, has := s.vars[v]; has { return false } - _, file, line, _ := runtime.Caller(2) + _, file, line, _ := runtime.Caller(2) //nolint:gomnd s.vars[v] = decl{ where: fmt.Sprintf("%s:%d", file, line), } diff --git a/internal/conn/conn.go b/internal/conn/conn.go index 66278bb94..8192e38e7 100644 --- a/internal/conn/conn.go +++ b/internal/conn/conn.go @@ -19,6 +19,7 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/xsync" "github.com/ydb-platform/ydb-go-sdk/v3/trace" ) @@ -55,7 +56,8 @@ type conn struct { endpoint endpoint.Endpoint // ro access closed bool state atomic.Uint32 - lastUsage *lastUsage + childStreams *xcontext.CancelsGuard + lastUsage xsync.LastUsage onClose []func(*conn) onTransportErrors []func(ctx context.Context, cc Conn, cause error) } @@ -392,7 +394,7 @@ func (c *conn) NewStream( desc *grpc.StreamDesc, method string, opts ...grpc.CallOption, -) (_ grpc.ClientStream, err error) { +) (_ grpc.ClientStream, finalErr error) { var ( onDone = trace.DriverOnConnNewStream( c.config.Trace(), &ctx, @@ -400,15 +402,13 @@ func (c *conn) NewStream( c.endpoint.Copy(), trace.Method(method), ) useWrapping = UseWrapping(ctx) - cc *grpc.ClientConn - s grpc.ClientStream ) defer func() { - onDone(err, c.GetState()) + onDone(finalErr, c.GetState()) }() - cc, err = c.realConn(ctx) + cc, err := c.realConn(ctx) if err != nil { return nil, c.wrapError(err) } @@ -423,7 +423,19 @@ func (c *conn) NewStream( ctx, sentMark := markContext(meta.WithTraceID(ctx, traceID)) - s, err = cc.NewStream(ctx, desc, method, opts...) + ctx, cancel := xcontext.WithCancel(ctx) + defer func() { + if finalErr != nil { + cancel() + } else { + c.childStreams.Remember(&cancel) + } + }() + + s, err := cc.NewStream(ctx, desc, method, append(opts, grpc.OnFinish(func(err error) { + cancel() + c.childStreams.Forget(&cancel) + }))...) if err != nil { if xerrors.IsContextError(err) { return nil, xerrors.WithStackTrace(err) @@ -490,10 +502,16 @@ func withOnTransportError(onTransportError func(ctx context.Context, cc Conn, ca func newConn(e endpoint.Endpoint, config Config, opts ...option) *conn { c := &conn{ - endpoint: e, - config: config, - done: make(chan struct{}), - lastUsage: newLastUsage(nil), + endpoint: e, + config: config, + done: make(chan struct{}), + lastUsage: xsync.NewLastUsage(), + childStreams: xcontext.NewCancelsGuard(), + onClose: []func(*conn){ + func(c *conn) { + c.childStreams.Cancel() + }, + }, } c.state.Store(uint32(Created)) for _, opt := range opts { diff --git a/internal/conn/last_usage.go b/internal/conn/last_usage.go deleted file mode 100644 index b0ca293a9..000000000 --- a/internal/conn/last_usage.go +++ /dev/null @@ -1,47 +0,0 @@ -package conn - -import ( - "sync" - "sync/atomic" - "time" - - "github.com/jonboulle/clockwork" -) - -type lastUsage struct { - locks atomic.Int64 - t atomic.Pointer[time.Time] - clock clockwork.Clock -} - -func newLastUsage(clock clockwork.Clock) *lastUsage { - if clock == nil { - clock = clockwork.NewRealClock() - } - now := clock.Now() - usage := &lastUsage{ - clock: clock, - } - usage.t.Store(&now) - - return usage -} - -func (l *lastUsage) Get() time.Time { - if l.locks.Load() == 0 { - return *l.t.Load() - } - - return l.clock.Now() -} - -func (l *lastUsage) Start() (stop func()) { - l.locks.Add(1) - - return sync.OnceFunc(func() { - if l.locks.Add(-1) == 0 { - now := l.clock.Now() - l.t.Store(&now) - } - }) -} diff --git a/internal/conn/pool.go b/internal/conn/pool.go index 6115c612f..783b7a880 100644 --- a/internal/conn/pool.go +++ b/internal/conn/pool.go @@ -246,7 +246,7 @@ func NewPool(ctx context.Context, config Config) *Pool { } if ttl := config.ConnectionTTL(); ttl > 0 { - go p.connParker(xcontext.ValueOnly(ctx), ttl, ttl/2) + go p.connParker(xcontext.ValueOnly(ctx), ttl, ttl/2) //nolint:gomnd } return p diff --git a/internal/coordination/client.go b/internal/coordination/client.go index 70322f702..e7c194049 100644 --- a/internal/coordination/client.go +++ b/internal/coordination/client.go @@ -336,11 +336,11 @@ func (c *Client) closeSessions(ctx context.Context) { func defaultCreateSessionConfig() *options.CreateSessionOptions { return &options.CreateSessionOptions{ Description: "YDB Go SDK", - SessionTimeout: time.Second * 5, + SessionTimeout: time.Second * 5, //nolint:gomnd SessionStartTimeout: time.Second * 1, SessionStopTimeout: time.Second * 1, - SessionKeepAliveTimeout: time.Second * 10, - SessionReconnectDelay: time.Millisecond * 500, + SessionKeepAliveTimeout: time.Second * 10, //nolint:gomnd + SessionReconnectDelay: time.Millisecond * 500, //nolint:gomnd } } diff --git a/internal/coordination/session.go b/internal/coordination/session.go index 4d7ec4649..9e7e2bb23 100644 --- a/internal/coordination/session.go +++ b/internal/coordination/session.go @@ -73,7 +73,7 @@ func createSession( } func newProtectionKey() []byte { - key := make([]byte, 8) + key := make([]byte, 8) //nolint:gomnd binary.LittleEndian.PutUint64(key, rand.Uint64()) //nolint:gosec return key @@ -120,7 +120,7 @@ func (s *session) newStream( deadline = s.getLastGoodResponseTime().Add(s.options.SessionTimeout) } else { // Large enough to make the loop infinite, small enough to allow the maximum duration value (~290 years). - deadline = time.Now().Add(time.Hour * 24 * 365 * 100) + deadline = time.Now().Add(time.Hour * 24 * 365 * 100) //nolint:gomnd } lastChance := false @@ -139,10 +139,12 @@ func (s *session) newStream( var client Ydb_Coordination_V1.CoordinationService_SessionClient if lastChance { + timer := time.NewTimer(s.options.SessionKeepAliveTimeout) select { - case <-time.After(s.options.SessionKeepAliveTimeout): + case <-timer.C: case client = <-result: } + timer.Stop() if client != nil { return client, nil @@ -175,10 +177,12 @@ func (s *session) newStream( } // Waiting for some time before trying to reconnect. + sessionReconnectDelay := time.NewTimer(s.options.SessionReconnectDelay) select { - case <-time.After(s.options.SessionReconnectDelay): + case <-sessionReconnectDelay.C: case <-s.ctx.Done(): } + sessionReconnectDelay.Stop() if s.ctx.Err() != nil { // Give this session the last chance to stop gracefully if the session is canceled in the reconnect cycle. @@ -226,7 +230,7 @@ func (s *session) mainLoop(path string, sessionStartedChan chan struct{}) { // Start the loops. wg := sync.WaitGroup{} - wg.Add(2) + wg.Add(2) //nolint:gomnd sessionStarted := make(chan *Ydb_Coordination.SessionResponse_SessionStarted, 1) sessionStopped := make(chan *Ydb_Coordination.SessionResponse_SessionStopped, 1) startSending := make(chan struct{}) @@ -247,6 +251,7 @@ func (s *session) mainLoop(path string, sessionStartedChan chan struct{}) { // Wait for the session started response unless the stream context is done. We intentionally do not take into // account stream context cancellation in order to proceed with the graceful shutdown if it requires reconnect. + sessionStartTimer := time.NewTimer(s.options.SessionStartTimeout) select { case start := <-sessionStarted: trace.CoordinationOnSessionStarted(s.client.config.Trace(), start.GetSessionId(), s.sessionID) @@ -258,13 +263,14 @@ func (s *session) mainLoop(path string, sessionStartedChan chan struct{}) { cancelStream() } close(startSending) - case <-time.After(s.options.SessionStartTimeout): + case <-sessionStartTimer.C: // Reconnect if no response was received before the timeout occurred. trace.CoordinationOnSessionStartTimeout(s.client.config.Trace(), s.options.SessionStartTimeout) cancelStream() case <-streamCtx.Done(): case <-s.ctx.Done(): } + sessionStartTimer.Stop() for { // Respect the failure reason priority: if the session context is done, we must stop the session, even @@ -280,8 +286,9 @@ func (s *session) mainLoop(path string, sessionStartedChan chan struct{}) { } keepAliveTime := time.Until(s.getLastGoodResponseTime().Add(s.options.SessionKeepAliveTimeout)) + keepAliveTimeTimer := time.NewTimer(keepAliveTime) select { - case <-time.After(keepAliveTime): + case <-keepAliveTimeTimer.C: last := s.getLastGoodResponseTime() if time.Since(last) > s.options.SessionKeepAliveTimeout { // Reconnect if the underlying stream is likely to be dead. @@ -295,6 +302,7 @@ func (s *session) mainLoop(path string, sessionStartedChan chan struct{}) { case <-streamCtx.Done(): case <-s.ctx.Done(): } + keepAliveTimeTimer.Stop() } if closing { @@ -318,8 +326,10 @@ func (s *session) mainLoop(path string, sessionStartedChan chan struct{}) { ) // Wait for the session stopped response unless the stream context is done. + sessionStopTimeout := time.NewTimer(s.options.SessionStopTimeout) select { case stop := <-sessionStopped: + sessionStopTimeout.Stop() trace.CoordinationOnSessionStopped(s.client.config.Trace(), stop.GetSessionId(), s.sessionID) if stop.GetSessionId() == s.sessionID { cancelStream() @@ -329,15 +339,19 @@ func (s *session) mainLoop(path string, sessionStartedChan chan struct{}) { // Reconnect if the server response is invalid. cancelStream() - case <-time.After(s.options.SessionStopTimeout): + case <-sessionStopTimeout.C: + sessionStopTimeout.Stop() // no really need, call stop for common style only + // Reconnect if no response was received before the timeout occurred. trace.CoordinationOnSessionStopTimeout(s.client.config.Trace(), s.options.SessionStopTimeout) cancelStream() case <-s.ctx.Done(): + sessionStopTimeout.Stop() cancelStream() return case <-streamCtx.Done(): + sessionStopTimeout.Stop() } } diff --git a/internal/credentials/oauth2.go b/internal/credentials/oauth2.go new file mode 100644 index 000000000..f49826127 --- /dev/null +++ b/internal/credentials/oauth2.go @@ -0,0 +1,846 @@ +package credentials + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "io" + "net/http" + "net/url" + "os" + "os/user" + "path/filepath" + "strconv" + "strings" + "sync" + "sync/atomic" + "time" + + "github.com/golang-jwt/jwt/v4" + + "github.com/ydb-platform/ydb-go-sdk/v3/internal/secret" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/xstring" +) + +const ( + defaultRequestTimeout = time.Second * 10 + defaultJWTTokenTTL = 3600 * time.Second + updateTimeDivider = 2 +) + +var ( + errEmptyTokenEndpointError = errors.New("OAuth2 token exchange: empty token endpoint") + errCouldNotParseResponse = errors.New("OAuth2 token exchange: could not parse response") + errCouldNotExchangeToken = errors.New("OAuth2 token exchange: could not exchange token") + errUnsupportedTokenType = errors.New("OAuth2 token exchange: unsupported token type") + errIncorrectExpirationTime = errors.New("OAuth2 token exchange: incorrect expiration time") + errDifferentScope = errors.New("OAuth2 token exchange: got different scope") + errCouldNotMakeHTTPRequest = errors.New("OAuth2 token exchange: could not make http request") + errCouldNotApplyOption = errors.New("OAuth2 token exchange: could not apply option") + errCouldNotCreateTokenSource = errors.New("OAuth2 token exchange: could not createTokenSource") + errNoSigningMethodError = errors.New("JWT token source: no signing method") + errNoPrivateKeyError = errors.New("JWT token source: no private key") + errCouldNotSignJWTToken = errors.New("JWT token source: could not sign jwt token") + errCouldNotApplyJWTOption = errors.New("JWT token source: could not apply option") + errCouldNotparseRSAPrivateKey = errors.New("JWT token source: could not parse RSA private key from PEM") + errCouldNotParseHomeDir = errors.New("JWT token source: could not parse home dir for private key") + errCouldNotReadPrivateKeyFile = errors.New("JWT token source: could not read from private key file") +) + +type Oauth2TokenExchangeCredentialsOption interface { + ApplyOauth2CredentialsOption(c *oauth2TokenExchange) error +} + +// TokenEndpoint +type tokenEndpointOption string + +func (endpoint tokenEndpointOption) ApplyOauth2CredentialsOption(c *oauth2TokenExchange) error { + c.tokenEndpoint = string(endpoint) + + return nil +} + +func WithTokenEndpoint(endpoint string) tokenEndpointOption { + return tokenEndpointOption(endpoint) +} + +// GrantType +type grantTypeOption string + +func (grantType grantTypeOption) ApplyOauth2CredentialsOption(c *oauth2TokenExchange) error { + c.grantType = string(grantType) + + return nil +} + +func WithGrantType(grantType string) grantTypeOption { + return grantTypeOption(grantType) +} + +// Resource +type resourceOption string + +func (resource resourceOption) ApplyOauth2CredentialsOption(c *oauth2TokenExchange) error { + c.resource = string(resource) + + return nil +} + +func WithResource(resource string) resourceOption { + return resourceOption(resource) +} + +// RequestedTokenType +type requestedTokenTypeOption string + +func (requestedTokenType requestedTokenTypeOption) ApplyOauth2CredentialsOption(c *oauth2TokenExchange) error { + c.requestedTokenType = string(requestedTokenType) + + return nil +} + +func WithRequestedTokenType(requestedTokenType string) requestedTokenTypeOption { + return requestedTokenTypeOption(requestedTokenType) +} + +// Audience +type audienceOption []string + +func (audience audienceOption) ApplyOauth2CredentialsOption(c *oauth2TokenExchange) error { + c.audience = audience + + return nil +} + +func WithAudience(audience ...string) audienceOption { + return audience +} + +// Scope +type scopeOption []string + +func (scope scopeOption) ApplyOauth2CredentialsOption(c *oauth2TokenExchange) error { + c.scope = scope + + return nil +} + +func WithScope(scope ...string) scopeOption { + return scope +} + +// RequestTimeout +type requestTimeoutOption time.Duration + +func (timeout requestTimeoutOption) ApplyOauth2CredentialsOption(c *oauth2TokenExchange) error { + c.requestTimeout = time.Duration(timeout) + + return nil +} + +func WithRequestTimeout(timeout time.Duration) requestTimeoutOption { + return requestTimeoutOption(timeout) +} + +const ( + SubjectTokenSourceType = 1 + ActorTokenSourceType = 2 +) + +// SubjectTokenSource/ActorTokenSource +type tokenSourceOption struct { + source TokenSource + createFunc func() (TokenSource, error) + tokenSourceType int +} + +func (tokenSource *tokenSourceOption) ApplyOauth2CredentialsOption(c *oauth2TokenExchange) error { + src := tokenSource.source + var err error + if src == nil { + src, err = tokenSource.createFunc() + if err != nil { + return xerrors.WithStackTrace(fmt.Errorf("%w: %w", errCouldNotCreateTokenSource, err)) + } + } + switch tokenSource.tokenSourceType { + case SubjectTokenSourceType: + c.subjectTokenSource = src + case ActorTokenSourceType: + c.actorTokenSource = src + } + + return nil +} + +func WithSubjectToken(subjectToken TokenSource) *tokenSourceOption { + return &tokenSourceOption{ + source: subjectToken, + tokenSourceType: SubjectTokenSourceType, + } +} + +func WithFixedSubjectToken(token, tokenType string) *tokenSourceOption { + return &tokenSourceOption{ + createFunc: func() (TokenSource, error) { + return NewFixedTokenSource(token, tokenType), nil + }, + tokenSourceType: SubjectTokenSourceType, + } +} + +func WithJWTSubjectToken(opts ...JWTTokenSourceOption) *tokenSourceOption { + return &tokenSourceOption{ + createFunc: func() (TokenSource, error) { + return NewJWTTokenSource(opts...) + }, + tokenSourceType: SubjectTokenSourceType, + } +} + +// ActorTokenSource +func WithActorToken(actorToken TokenSource) *tokenSourceOption { + return &tokenSourceOption{ + source: actorToken, + tokenSourceType: ActorTokenSourceType, + } +} + +func WithFixedActorToken(token, tokenType string) *tokenSourceOption { + return &tokenSourceOption{ + createFunc: func() (TokenSource, error) { + return NewFixedTokenSource(token, tokenType), nil + }, + tokenSourceType: ActorTokenSourceType, + } +} + +func WithJWTActorToken(opts ...JWTTokenSourceOption) *tokenSourceOption { + return &tokenSourceOption{ + createFunc: func() (TokenSource, error) { + return NewJWTTokenSource(opts...) + }, + tokenSourceType: ActorTokenSourceType, + } +} + +type oauth2TokenExchange struct { + tokenEndpoint string + + // grant_type parameter + // urn:ietf:params:oauth:grant-type:token-exchange by default + grantType string + + resource string + audience []string + scope []string + + // requested_token_type parameter + // urn:ietf:params:oauth:token-type:access_token by default + requestedTokenType string + + subjectTokenSource TokenSource + + actorTokenSource TokenSource + + // Http request timeout + // 10 by default + requestTimeout time.Duration + + // Received data + receivedToken string + updateTokenTime time.Time + receivedTokenExpireTime time.Time + + mutex sync.RWMutex + updating atomic.Bool // true if separate goroutine is run and updates token in background + + sourceInfo string +} + +func NewOauth2TokenExchangeCredentials( + opts ...Oauth2TokenExchangeCredentialsOption, +) (*oauth2TokenExchange, error) { + c := &oauth2TokenExchange{ + grantType: "urn:ietf:params:oauth:grant-type:token-exchange", + requestedTokenType: "urn:ietf:params:oauth:token-type:access_token", + requestTimeout: defaultRequestTimeout, + sourceInfo: stack.Record(1), + } + + var err error + for _, opt := range opts { + if opt != nil { + err = opt.ApplyOauth2CredentialsOption(c) + if err != nil { + return nil, xerrors.WithStackTrace(fmt.Errorf("%w: %w", errCouldNotApplyOption, err)) + } + } + } + + if c.tokenEndpoint == "" { + return nil, xerrors.WithStackTrace(errEmptyTokenEndpointError) + } + + return c, nil +} + +func (provider *oauth2TokenExchange) getScopeParam() string { + var scope string + if len(provider.scope) != 0 { + for _, s := range provider.scope { + if s != "" { + if scope != "" { + scope += " " + } + scope += s + } + } + } + + return scope +} + +func (provider *oauth2TokenExchange) addTokenSrc(params *url.Values, src TokenSource, tName, tTypeName string) error { + if src != nil { + token, err := src.Token() + if err != nil { + return xerrors.WithStackTrace(err) + } + params.Set(tName, token.Token) + params.Set(tTypeName, token.TokenType) + } + + return nil +} + +func (provider *oauth2TokenExchange) getRequestParams() (string, error) { + params := url.Values{} + params.Set("grant_type", provider.grantType) + if provider.resource != "" { + params.Set("resource", provider.resource) + } + for _, aud := range provider.audience { + if aud != "" { + params.Add("audience", aud) + } + } + scope := provider.getScopeParam() + if scope != "" { + params.Set("scope", scope) + } + + params.Set("requested_token_type", provider.requestedTokenType) + + err := provider.addTokenSrc(¶ms, provider.subjectTokenSource, "subject_token", "subject_token_type") + if err != nil { + return "", xerrors.WithStackTrace(err) + } + + err = provider.addTokenSrc(¶ms, provider.actorTokenSource, "actor_token", "actor_token_type") + if err != nil { + return "", xerrors.WithStackTrace(err) + } + + return params.Encode(), nil +} + +func (provider *oauth2TokenExchange) processTokenExchangeResponse(result *http.Response, now time.Time) error { + var ( + data []byte + err error + ) + if result.Body != nil { + data, err = io.ReadAll(result.Body) + if err != nil { + return xerrors.WithStackTrace(err) + } + } else { + data = make([]byte, 0) + } + + if result.StatusCode != http.StatusOK { + description := result.Status + + //nolint:tagliatelle + type errorResponse struct { + ErrorName string `json:"error"` + ErrorDescription string `json:"error_description"` + ErrorURI string `json:"error_uri"` + } + var parsedErrorResponse errorResponse + if err := json.Unmarshal(data, &parsedErrorResponse); err != nil { + description += ", could not parse response: " + err.Error() + + return xerrors.WithStackTrace(fmt.Errorf("%w: %s", errCouldNotExchangeToken, description)) + } + + if parsedErrorResponse.ErrorName != "" { + description += ", error: " + parsedErrorResponse.ErrorName + } + + if parsedErrorResponse.ErrorDescription != "" { + description += fmt.Sprintf(", description: %q", parsedErrorResponse.ErrorDescription) + } + + if parsedErrorResponse.ErrorURI != "" { + description += ", error_uri: " + parsedErrorResponse.ErrorURI + } + + return xerrors.WithStackTrace(fmt.Errorf("%w: %s", errCouldNotExchangeToken, description)) + } + + //nolint:tagliatelle + type response struct { + AccessToken string `json:"access_token"` + TokenType string `json:"token_type"` + ExpiresIn int64 `json:"expires_in"` + Scope string `json:"scope"` + } + var parsedResponse response + if err := json.Unmarshal(data, &parsedResponse); err != nil { + return xerrors.WithStackTrace(fmt.Errorf("%w: %w", errCouldNotParseResponse, err)) + } + + if !strings.EqualFold(parsedResponse.TokenType, "bearer") { + return xerrors.WithStackTrace( + fmt.Errorf("%w: %q", errUnsupportedTokenType, parsedResponse.TokenType)) + } + + if parsedResponse.ExpiresIn <= 0 { + return xerrors.WithStackTrace( + fmt.Errorf("%w: %d", errIncorrectExpirationTime, parsedResponse.ExpiresIn)) + } + + if parsedResponse.Scope != "" { + scope := provider.getScopeParam() + if parsedResponse.Scope != scope { + return xerrors.WithStackTrace( + fmt.Errorf("%w. Expected %q, but got %q", errDifferentScope, scope, parsedResponse.Scope)) + } + } + + provider.receivedToken = "Bearer " + parsedResponse.AccessToken + + // Expire time + expireDelta := time.Duration(parsedResponse.ExpiresIn) + expireDelta *= time.Second + provider.receivedTokenExpireTime = now.Add(expireDelta) + + updateDelta := time.Duration(parsedResponse.ExpiresIn / updateTimeDivider) + updateDelta *= time.Second + provider.updateTokenTime = now.Add(updateDelta) + + return nil +} + +func (provider *oauth2TokenExchange) exchangeToken(ctx context.Context, now time.Time) error { + body, err := provider.getRequestParams() + if err != nil { + return xerrors.WithStackTrace(fmt.Errorf("%w: %w", errCouldNotMakeHTTPRequest, err)) + } + + req, err := http.NewRequestWithContext(ctx, http.MethodPost, provider.tokenEndpoint, strings.NewReader(body)) + if err != nil { + return xerrors.WithStackTrace(fmt.Errorf("%w: %w", errCouldNotMakeHTTPRequest, err)) + } + req.Header.Add("Content-Type", "application/x-www-form-urlencoded") + req.Header.Add("Content-Length", strconv.Itoa(len(body))) + req.Close = true + + client := http.Client{ + Transport: http.DefaultTransport, + Timeout: provider.requestTimeout, + } + + result, err := client.Do(req) + if err != nil { + return xerrors.WithStackTrace(fmt.Errorf("%w: %w", errCouldNotExchangeToken, err)) + } + + defer result.Body.Close() + + return provider.processTokenExchangeResponse(result, now) +} + +func (provider *oauth2TokenExchange) exchangeTokenInBackground() { + provider.mutex.Lock() + defer provider.mutex.Unlock() + + now := time.Now() + if !provider.needUpdate(now) { + return + } + + ctx := context.Background() + _ = provider.exchangeToken(ctx, now) + + provider.updating.Store(false) +} + +func (provider *oauth2TokenExchange) checkBackgroundUpdate(now time.Time) { + if provider.needUpdate(now) && !provider.updating.Load() { + if provider.updating.CompareAndSwap(false, true) { + go provider.exchangeTokenInBackground() + } + } +} + +func (provider *oauth2TokenExchange) expired(now time.Time) bool { + return now.Compare(provider.receivedTokenExpireTime) > 0 +} + +func (provider *oauth2TokenExchange) needUpdate(now time.Time) bool { + return now.Compare(provider.updateTokenTime) > 0 +} + +func (provider *oauth2TokenExchange) fastCheck(now time.Time) string { + provider.mutex.RLock() + defer provider.mutex.RUnlock() + + if !provider.expired(now) { + provider.checkBackgroundUpdate(now) + + return provider.receivedToken + } + + return "" +} + +func (provider *oauth2TokenExchange) Token(ctx context.Context) (string, error) { + now := time.Now() + + token := provider.fastCheck(now) + if token != "" { + return token, nil + } + + provider.mutex.Lock() + defer provider.mutex.Unlock() + + if !provider.expired(now) { + return provider.receivedToken, nil + } + + if err := provider.exchangeToken(ctx, now); err != nil { + return "", err + } + + return provider.receivedToken, nil +} + +func (provider *oauth2TokenExchange) String() string { + buffer := xstring.Buffer() + defer buffer.Free() + fmt.Fprintf( + buffer, + "OAuth2TokenExchange{Endpoint:%q,GrantType:%s,Resource:%s,Audience:%v,Scope:%v,RequestedTokenType:%s", + provider.tokenEndpoint, + provider.grantType, + provider.resource, + provider.audience, + provider.scope, + provider.requestedTokenType, + ) + if provider.subjectTokenSource != nil { + fmt.Fprintf(buffer, ",SubjectToken:%s", provider.subjectTokenSource) + } + if provider.actorTokenSource != nil { + fmt.Fprintf(buffer, ",ActorToken:%s", provider.actorTokenSource) + } + if provider.sourceInfo != "" { + fmt.Fprintf(buffer, ",From:%q", provider.sourceInfo) + } + buffer.WriteByte('}') + + return buffer.String() +} + +type Token struct { + Token string + + // token type according to OAuth 2.0 token exchange protocol + // https://www.rfc-editor.org/rfc/rfc8693#TokenTypeIdentifiers + // for example urn:ietf:params:oauth:token-type:jwt + TokenType string +} + +type TokenSource interface { + Token() (Token, error) +} + +type fixedTokenSource struct { + fixedToken Token +} + +func (s *fixedTokenSource) Token() (Token, error) { + return s.fixedToken, nil +} + +func (s *fixedTokenSource) String() string { + buffer := xstring.Buffer() + defer buffer.Free() + fmt.Fprintf( + buffer, + "FixedTokenSource{Token:%q,Type:%s}", + secret.Token(s.fixedToken.Token), + s.fixedToken.TokenType, + ) + + return buffer.String() +} + +func NewFixedTokenSource(token, tokenType string) *fixedTokenSource { + return &fixedTokenSource{ + fixedToken: Token{ + Token: token, + TokenType: tokenType, + }, + } +} + +type JWTTokenSourceOption interface { + ApplyJWTTokenSourceOption(s *jwtTokenSource) error +} + +// Issuer +type issuerOption string + +func (issuer issuerOption) ApplyJWTTokenSourceOption(s *jwtTokenSource) error { + s.issuer = string(issuer) + + return nil +} + +func WithIssuer(issuer string) issuerOption { + return issuerOption(issuer) +} + +// Subject +type subjectOption string + +func (subject subjectOption) ApplyJWTTokenSourceOption(s *jwtTokenSource) error { + s.subject = string(subject) + + return nil +} + +func WithSubject(subject string) subjectOption { + return subjectOption(subject) +} + +// Audience +func (audience audienceOption) ApplyJWTTokenSourceOption(s *jwtTokenSource) error { + s.audience = audience + + return nil +} + +// ID +type idOption string + +func (id idOption) ApplyJWTTokenSourceOption(s *jwtTokenSource) error { + s.id = string(id) + + return nil +} + +func WithID(id string) idOption { + return idOption(id) +} + +// TokenTTL +type tokenTTLOption time.Duration + +func (ttl tokenTTLOption) ApplyJWTTokenSourceOption(s *jwtTokenSource) error { + s.tokenTTL = time.Duration(ttl) + + return nil +} + +func WithTokenTTL(ttl time.Duration) tokenTTLOption { + return tokenTTLOption(ttl) +} + +// SigningMethod +type signingMethodOption struct { + method jwt.SigningMethod +} + +func (method *signingMethodOption) ApplyJWTTokenSourceOption(s *jwtTokenSource) error { + s.signingMethod = method.method + + return nil +} + +func WithSigningMethod(method jwt.SigningMethod) *signingMethodOption { + return &signingMethodOption{method} +} + +// KeyID +type keyIDOption string + +func (id keyIDOption) ApplyJWTTokenSourceOption(s *jwtTokenSource) error { + s.keyID = string(id) + + return nil +} + +func WithKeyID(id string) keyIDOption { + return keyIDOption(id) +} + +// PrivateKey +type privateKeyOption struct { + key interface{} +} + +func (key *privateKeyOption) ApplyJWTTokenSourceOption(s *jwtTokenSource) error { + s.privateKey = key.key + + return nil +} + +func WithPrivateKey(key interface{}) *privateKeyOption { + return &privateKeyOption{key} +} + +// PrivateKey +type rsaPrivateKeyPemContentOption struct { + keyContent []byte +} + +func (key *rsaPrivateKeyPemContentOption) ApplyJWTTokenSourceOption(s *jwtTokenSource) error { + privateKey, err := jwt.ParseRSAPrivateKeyFromPEM(key.keyContent) + if err != nil { + return xerrors.WithStackTrace(fmt.Errorf("%w: %w", errCouldNotparseRSAPrivateKey, err)) + } + s.privateKey = privateKey + + return nil +} + +func WithRSAPrivateKeyPEMContent(key []byte) *rsaPrivateKeyPemContentOption { + return &rsaPrivateKeyPemContentOption{key} +} + +// PrivateKey +type rsaPrivateKeyPemFileOption struct { + path string +} + +func (key *rsaPrivateKeyPemFileOption) ApplyJWTTokenSourceOption(s *jwtTokenSource) error { + if len(key.path) > 0 && key.path[0] == '~' { + usr, err := user.Current() + if err != nil { + return xerrors.WithStackTrace(fmt.Errorf("%w: %w", errCouldNotParseHomeDir, err)) + } + key.path = filepath.Join(usr.HomeDir, key.path[1:]) + } + bytes, err := os.ReadFile(key.path) + if err != nil { + return xerrors.WithStackTrace(fmt.Errorf("%w: %w", errCouldNotReadPrivateKeyFile, err)) + } + + o := rsaPrivateKeyPemContentOption{bytes} + + return o.ApplyJWTTokenSourceOption(s) +} + +func WithRSAPrivateKeyPEMFile(path string) *rsaPrivateKeyPemFileOption { + return &rsaPrivateKeyPemFileOption{path} +} + +func NewJWTTokenSource(opts ...JWTTokenSourceOption) (*jwtTokenSource, error) { + s := &jwtTokenSource{ + tokenTTL: defaultJWTTokenTTL, + } + + var err error + for _, opt := range opts { + if opt != nil { + err = opt.ApplyJWTTokenSourceOption(s) + if err != nil { + return nil, xerrors.WithStackTrace(fmt.Errorf("%w: %w", errCouldNotApplyJWTOption, err)) + } + } + } + + if s.signingMethod == nil { + return nil, xerrors.WithStackTrace(errNoSigningMethodError) + } + + if s.privateKey == nil { + return nil, xerrors.WithStackTrace(errNoPrivateKeyError) + } + + return s, nil +} + +type jwtTokenSource struct { + signingMethod jwt.SigningMethod + keyID string + privateKey interface{} // symmetric key in case of symmetric algorithm + + // JWT claims + issuer string + subject string + audience []string + id string + tokenTTL time.Duration +} + +func (s *jwtTokenSource) Token() (Token, error) { + var ( + now = time.Now() + issued = jwt.NewNumericDate(now.UTC()) + expire = jwt.NewNumericDate(now.Add(s.tokenTTL).UTC()) + err error + ) + t := jwt.Token{ + Header: map[string]interface{}{ + "typ": "JWT", + "alg": s.signingMethod.Alg(), + "kid": s.keyID, + }, + Claims: jwt.RegisteredClaims{ + Issuer: s.issuer, + Subject: s.subject, + IssuedAt: issued, + Audience: s.audience, + ExpiresAt: expire, + ID: s.id, + }, + Method: s.signingMethod, + } + + var token Token + token.Token, err = t.SignedString(s.privateKey) + if err != nil { + return token, xerrors.WithStackTrace(fmt.Errorf("%w: %w", errCouldNotSignJWTToken, err)) + } + token.TokenType = "urn:ietf:params:oauth:token-type:jwt" + + return token, nil +} + +func (s *jwtTokenSource) String() string { + buffer := xstring.Buffer() + defer buffer.Free() + fmt.Fprintf( + buffer, + "JWTTokenSource{Method:%s,KeyID:%s,Issuer:%q,Subject:%q,Audience:%v,ID:%s,TokenTTL:%s}", + s.signingMethod.Alg(), + s.keyID, + s.issuer, + s.subject, + s.audience, + s.id, + s.tokenTTL, + ) + + return buffer.String() +} diff --git a/internal/credentials/oauth2_test.go b/internal/credentials/oauth2_test.go new file mode 100644 index 000000000..3ce391961 --- /dev/null +++ b/internal/credentials/oauth2_test.go @@ -0,0 +1,470 @@ +package credentials + +import ( + "context" + "errors" + "fmt" + "io" + "net" + "net/http" + "net/url" + "os" + "os/user" + "path/filepath" + "reflect" + "strconv" + "testing" + "time" + + "github.com/golang-jwt/jwt/v4" + "github.com/stretchr/testify/require" +) + +var ( + testPrivateKeyContent = "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC75/JS3rMcLJxv\nFgpOzF5+2gH+Yig3RE2MTl9uwC0BZKAv6foYr7xywQyWIK+W1cBhz8R4LfFmZo2j\nM0aCvdRmNBdW0EDSTnHLxCsFhoQWLVq+bI5f5jzkcoiioUtaEpADPqwgVULVtN/n\nnPJiZ6/dU30C3jmR6+LUgEntUtWt3eq3xQIn5lG3zC1klBY/HxtfH5Hu8xBvwRQT\nJnh3UpPLj8XwSmriDgdrhR7o6umWyVuGrMKlLHmeivlfzjYtfzO1MOIMG8t2/zxG\nR+xb4Vwks73sH1KruH/0/JMXU97npwpe+Um+uXhpldPygGErEia7abyZB2gMpXqr\nWYKMo02NAgMBAAECggEAO0BpC5OYw/4XN/optu4/r91bupTGHKNHlsIR2rDzoBhU\nYLd1evpTQJY6O07EP5pYZx9mUwUdtU4KRJeDGO/1/WJYp7HUdtxwirHpZP0lQn77\nuccuX/QQaHLrPekBgz4ONk+5ZBqukAfQgM7fKYOLk41jgpeDbM2Ggb6QUSsJISEp\nzrwpI/nNT/wn+Hvx4DxrzWU6wF+P8kl77UwPYlTA7GsT+T7eKGVH8xsxmK8pt6lg\nsvlBA5XosWBWUCGLgcBkAY5e4ZWbkdd183o+oMo78id6C+PQPE66PLDtHWfpRRmN\nm6XC03x6NVhnfvfozoWnmS4+e4qj4F/emCHvn0GMywKBgQDLXlj7YPFVXxZpUvg/\nrheVcCTGbNmQJ+4cZXx87huqwqKgkmtOyeWsRc7zYInYgraDrtCuDBCfP//ZzOh0\nLxepYLTPk5eNn/GT+VVrqsy35Ccr60g7Lp/bzb1WxyhcLbo0KX7/6jl0lP+VKtdv\nmto+4mbSBXSM1Y5BVVoVgJ3T/wKBgQDsiSvPRzVi5TTj13x67PFymTMx3HCe2WzH\nJUyepCmVhTm482zW95pv6raDr5CTO6OYpHtc5sTTRhVYEZoEYFTM9Vw8faBtluWG\nBjkRh4cIpoIARMn74YZKj0C/0vdX7SHdyBOU3bgRPHg08Hwu3xReqT1kEPSI/B2V\n4pe5fVrucwKBgQCNFgUxUA3dJjyMES18MDDYUZaRug4tfiYouRdmLGIxUxozv6CG\nZnbZzwxFt+GpvPUV4f+P33rgoCvFU+yoPctyjE6j+0aW0DFucPmb2kBwCu5J/856\nkFwCx3blbwFHAco+SdN7g2kcwgmV2MTg/lMOcU7XwUUcN0Obe7UlWbckzQKBgQDQ\nnXaXHL24GGFaZe4y2JFmujmNy1dEsoye44W9ERpf9h1fwsoGmmCKPp90az5+rIXw\nFXl8CUgk8lXW08db/r4r+ma8Lyx0GzcZyplAnaB5/6j+pazjSxfO4KOBy4Y89Tb+\nTP0AOcCi6ws13bgY+sUTa/5qKA4UVw+c5zlb7nRpgwKBgGXAXhenFw1666482iiN\ncHSgwc4ZHa1oL6aNJR1XWH+aboBSwR+feKHUPeT4jHgzRGo/aCNHD2FE5I8eBv33\nof1kWYjAO0YdzeKrW0rTwfvt9gGg+CS397aWu4cy+mTI+MNfBgeDAIVBeJOJXLlX\nhL8bFAuNNVrCOp79TNnNIsh7\n-----END PRIVATE KEY-----\n" //nolint:lll + testPublicKeyContent = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu+fyUt6zHCycbxYKTsxe\nftoB/mIoN0RNjE5fbsAtAWSgL+n6GK+8csEMliCvltXAYc/EeC3xZmaNozNGgr3U\nZjQXVtBA0k5xy8QrBYaEFi1avmyOX+Y85HKIoqFLWhKQAz6sIFVC1bTf55zyYmev\n3VN9At45kevi1IBJ7VLVrd3qt8UCJ+ZRt8wtZJQWPx8bXx+R7vMQb8EUEyZ4d1KT\ny4/F8Epq4g4Ha4Ue6OrplslbhqzCpSx5nor5X842LX8ztTDiDBvLdv88RkfsW+Fc\nJLO97B9Sq7h/9PyTF1Pe56cKXvlJvrl4aZXT8oBhKxImu2m8mQdoDKV6q1mCjKNN\njQIDAQAB\n-----END PUBLIC KEY-----\n" //nolint:lll +) + +type httpServerKey int + +const ( + keyServerAddr httpServerKey = 42 +) + +func WriteErr(w http.ResponseWriter, err error) { + WriteResponse(w, http.StatusInternalServerError, err.Error(), "text/html") +} + +func WriteResponse(w http.ResponseWriter, code int, body string, bodyType string) { + w.Header().Add("Content-Type", bodyType) + w.Header().Add("Content-Length", strconv.Itoa(len(body))) + w.WriteHeader(code) + _, _ = w.Write([]byte(body)) +} + +func runTokenExchangeServer( + ctx context.Context, + cancel context.CancelFunc, + port int, + currentTestParams *Oauth2TokenExchangeTestParams, +) { + defer cancel() + mux := http.NewServeMux() + mux.HandleFunc("/exchange", func(w http.ResponseWriter, r *http.Request) { + body, err := io.ReadAll(r.Body) + if err != nil { + WriteErr(w, err) + } + + fmt.Printf("got token exchange request: %s\n", body) + + params, err := url.ParseQuery(string(body)) + if err != nil { + WriteErr(w, err) + } + expectedParams := url.Values{} + expectedParams.Set("scope", "test_scope1 test_scope2") + expectedParams.Set("audience", "test_audience") + expectedParams.Set("grant_type", "urn:ietf:params:oauth:grant-type:token-exchange") + expectedParams.Set("requested_token_type", "urn:ietf:params:oauth:token-type:access_token") + expectedParams.Set("subject_token", "test_source_token") + expectedParams.Set("subject_token_type", "urn:ietf:params:oauth:token-type:test_jwt") + + if !reflect.DeepEqual(expectedParams, params) { + WriteResponse(w, 555, fmt.Sprintf("Params are not as expected: \"%s\" != \"%s\"", + expectedParams.Encode(), body), "text/html") // error will be checked in test thread + } else { + WriteResponse(w, currentTestParams.Status, currentTestParams.Response, "application/json") + } + }) + server := http.Server{ + Addr: fmt.Sprintf(":%d", port), + Handler: mux, + BaseContext: func(l net.Listener) context.Context { + ctx = context.WithValue(ctx, keyServerAddr, l.Addr().String()) + + return ctx + }, + ReadHeaderTimeout: 10 * time.Second, + } + err := server.ListenAndServe() + if err != nil { + fmt.Printf("Failed to run http server: %s", err.Error()) + } +} + +type Oauth2TokenExchangeTestParams struct { + Response string + Status int + ExpectedToken string + ExpectedError error + ExpectedErrorPart string +} + +func TestOauth2TokenExchange(t *testing.T) { + var currentTestParams Oauth2TokenExchangeTestParams + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + runCtx, runCancel := context.WithCancel(ctx) + go runTokenExchangeServer(runCtx, runCancel, 14321, ¤tTestParams) + + testsParams := []Oauth2TokenExchangeTestParams{ + { + Response: `{"access_token":"test_token","token_type":"BEARER","expires_in":42,"some_other_field":"x"}`, + Status: http.StatusOK, + ExpectedToken: "Bearer test_token", + }, + { + Response: `aaa`, + Status: http.StatusOK, + ExpectedToken: "", + ExpectedError: errCouldNotParseResponse, + }, + { + Response: `{}`, + Status: http.StatusBadRequest, + ExpectedToken: "", + ExpectedError: errCouldNotExchangeToken, + }, + { + Response: `not json`, + Status: http.StatusNotFound, + ExpectedToken: "", + ExpectedError: errCouldNotExchangeToken, + }, + { + Response: `{"error": "invalid_request"}`, + Status: http.StatusBadRequest, + ExpectedToken: "", + ExpectedError: errCouldNotExchangeToken, + ExpectedErrorPart: "400 Bad Request, error: invalid_request", + }, + { + Response: `{"error":"unauthorized_client","error_description":"something went bad"}`, + Status: http.StatusInternalServerError, + ExpectedToken: "", + ExpectedError: errCouldNotExchangeToken, + ExpectedErrorPart: "500 Internal Server Error, error: unauthorized_client, description: \"something went bad\"", //nolint:lll + }, + { + Response: `{"error_description":"something went bad","error_uri":"my_error_uri"}`, + Status: http.StatusForbidden, + ExpectedToken: "", + ExpectedError: errCouldNotExchangeToken, + ExpectedErrorPart: "403 Forbidden, description: \"something went bad\", error_uri: my_error_uri", + }, + { + Response: `{"access_token":"test_token","token_type":"","expires_in":42,"some_other_field":"x"}`, + Status: http.StatusOK, + ExpectedToken: "", + ExpectedError: errUnsupportedTokenType, + }, + { + Response: `{"access_token":"test_token","token_type":"basic","expires_in":42,"some_other_field":"x"}`, + Status: http.StatusOK, + ExpectedToken: "", + ExpectedError: errUnsupportedTokenType, + }, + { + Response: `{"access_token":"test_token","token_type":"Bearer","expires_in":-42,"some_other_field":"x"}`, + Status: http.StatusOK, + ExpectedToken: "", + ExpectedError: errIncorrectExpirationTime, + }, + { + Response: `{"access_token":"test_token","token_type":"Bearer","expires_in":42,"scope":"s"}`, + Status: http.StatusOK, + ExpectedToken: "", + ExpectedError: errDifferentScope, + ExpectedErrorPart: "Expected \"test_scope1 test_scope2\", but got \"s\"", + }, + } + + for _, params := range testsParams { + currentTestParams = params + + client, err := NewOauth2TokenExchangeCredentials( + WithTokenEndpoint("http://localhost:14321/exchange"), + WithAudience("test_audience"), + WithScope("test_scope1", "test_scope2"), + WithSubjectToken(NewFixedTokenSource("test_source_token", "urn:ietf:params:oauth:token-type:test_jwt")), + ) + require.NoError(t, err) + + token, err := client.Token(ctx) + if params.ExpectedErrorPart == "" && params.ExpectedError == nil { + require.NoError(t, err) + } else { + if params.ExpectedErrorPart != "" { + require.ErrorContains(t, err, params.ExpectedErrorPart) + } + if params.ExpectedError != nil { + require.ErrorIs(t, err, params.ExpectedError) + } + } + require.Equal(t, params.ExpectedToken, token) + } +} + +func TestOauth2TokenUpdate(t *testing.T) { + var currentTestParams Oauth2TokenExchangeTestParams + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + runCtx, runCancel := context.WithCancel(ctx) + go runTokenExchangeServer(runCtx, runCancel, 14322, ¤tTestParams) + + // First exchange + currentTestParams = Oauth2TokenExchangeTestParams{ + Response: `{"access_token":"test_token_1", "token_type":"Bearer","expires_in":2}`, + Status: http.StatusOK, + } + + client, err := NewOauth2TokenExchangeCredentials( + WithTokenEndpoint("http://localhost:14322/exchange"), + WithAudience("test_audience"), + WithScope("test_scope1", "test_scope2"), + WithFixedSubjectToken("test_source_token", "urn:ietf:params:oauth:token-type:test_jwt"), + ) + require.NoError(t, err) + + token, err := client.Token(ctx) + t1 := time.Now() + require.NoError(t, err) + require.Equal(t, "Bearer test_token_1", token) + + // Second exchange + currentTestParams = Oauth2TokenExchangeTestParams{ + Response: `{"access_token":"test_token_2", "token_type":"Bearer","expires_in":10000}`, + Status: http.StatusOK, + } + + token, err = client.Token(ctx) + t2 := time.Now() + require.NoError(t, err) + if t2.Sub(t1) <= time.Second { // half expire period => no attempts to update + require.Equal(t, "Bearer test_token_1", token) + } + + time.Sleep(time.Second) // wait half expire period + for i := 1; i <= 100; i++ { + t3 := time.Now() + token, err = client.Token(ctx) + require.NoError(t, err) + if t3.Sub(t1) >= 2*time.Second { + require.Equal(t, "Bearer test_token_2", token) // Must update at least sync + } + if token == "Bearer test_token_2" { // already updated + break + } + require.Equal(t, "Bearer test_token_1", token) + + time.Sleep(10 * time.Millisecond) + } + + // Third exchange (never got, because token will be expired later) + currentTestParams = Oauth2TokenExchangeTestParams{ + Response: `{}`, + Status: http.StatusInternalServerError, + } + + for i := 1; i <= 5; i++ { + token, err = client.Token(ctx) + require.NoError(t, err) + require.Equal(t, "Bearer test_token_2", token) + } +} + +func TestWrongParameters(t *testing.T) { + _, err := NewOauth2TokenExchangeCredentials( + // No endpoint + WithFixedActorToken("test_source_token", "urn:ietf:params:oauth:token-type:test_jwt"), + WithRequestedTokenType("access_token"), + ) + require.ErrorIs(t, err, errEmptyTokenEndpointError) +} + +type errorTokenSource struct{} + +var errTokenSource = errors.New("test error") + +func (s *errorTokenSource) Token() (Token, error) { + return Token{"", ""}, errTokenSource +} + +func TestErrorInSourceToken(t *testing.T) { + // Create + _, err := NewOauth2TokenExchangeCredentials( + WithTokenEndpoint("http:trololo"), + WithJWTSubjectToken( + WithRSAPrivateKeyPEMContent([]byte("invalid")), + WithKeyID("key_id"), + WithSigningMethod(jwt.SigningMethodRS256), + WithIssuer("test_issuer"), + WithAudience("test_audience"), + ), + ) + require.ErrorIs(t, err, errCouldNotCreateTokenSource) + + // Use + client, err := NewOauth2TokenExchangeCredentials( + WithTokenEndpoint("http:trololo"), + WithGrantType("grant_type"), + WithRequestTimeout(time.Second), + WithResource("res"), + WithFixedSubjectToken("t", "tt"), + WithActorToken(&errorTokenSource{}), + WithSourceInfo("TestErrorInSourceToken"), + ) + require.NoError(t, err) + + // Check that token prints well + formatted := fmt.Sprint(client) + require.Equal(t, `OAuth2TokenExchange{Endpoint:"http:trololo",GrantType:grant_type,Resource:res,Audience:[],Scope:[],RequestedTokenType:urn:ietf:params:oauth:token-type:access_token,SubjectToken:FixedTokenSource{Token:"****(CRC-32c: 856A5AA8)",Type:tt},ActorToken:&{},From:"TestErrorInSourceToken"}`, formatted) //nolint:lll + + token, err := client.Token(context.Background()) + require.ErrorIs(t, err, errTokenSource) + require.Equal(t, "", token) + + client, err = NewOauth2TokenExchangeCredentials( + WithTokenEndpoint("http:trololo"), + WithGrantType("grant_type"), + WithRequestTimeout(time.Second), + WithResource("res"), + WithSubjectToken(&errorTokenSource{}), + ) + require.NoError(t, err) + + token, err = client.Token(context.Background()) + require.ErrorIs(t, err, errTokenSource) + require.Equal(t, "", token) +} + +func TestErrorInHTTPRequest(t *testing.T) { + client, err := NewOauth2TokenExchangeCredentials( + WithTokenEndpoint("http://invalid_host:42/exchange"), + WithJWTSubjectToken( + WithRSAPrivateKeyPEMContent([]byte(testPrivateKeyContent)), + WithKeyID("key_id"), + WithSigningMethod(jwt.SigningMethodRS256), + WithIssuer("test_issuer"), + WithAudience("test_audience"), + ), + WithJWTActorToken( + WithRSAPrivateKeyPEMContent([]byte(testPrivateKeyContent)), + WithKeyID("key_id"), + WithSigningMethod(jwt.SigningMethodRS256), + WithIssuer("test_issuer"), + ), + WithScope("1", "2", "3"), + WithSourceInfo("TestErrorInHTTPRequest"), + ) + require.NoError(t, err) + + token, err := client.Token(context.Background()) + require.ErrorIs(t, err, errCouldNotExchangeToken) + require.Equal(t, "", token) + + // check format: + formatted := fmt.Sprint(client) + require.Equal(t, `OAuth2TokenExchange{Endpoint:"http://invalid_host:42/exchange",GrantType:urn:ietf:params:oauth:grant-type:token-exchange,Resource:,Audience:[],Scope:[1 2 3],RequestedTokenType:urn:ietf:params:oauth:token-type:access_token,SubjectToken:JWTTokenSource{Method:RS256,KeyID:key_id,Issuer:"test_issuer",Subject:"",Audience:[test_audience],ID:,TokenTTL:1h0m0s},ActorToken:JWTTokenSource{Method:RS256,KeyID:key_id,Issuer:"test_issuer",Subject:"",Audience:[],ID:,TokenTTL:1h0m0s},From:"TestErrorInHTTPRequest"}`, formatted) //nolint:lll +} + +func TestJWTTokenSource(t *testing.T) { + publicKey, err := jwt.ParseRSAPublicKeyFromPEM([]byte(testPublicKeyContent)) + require.NoError(t, err) + getPublicKey := func(*jwt.Token) (interface{}, error) { + return publicKey, nil + } + + var src TokenSource + src, err = NewJWTTokenSource( + WithRSAPrivateKeyPEMContent([]byte(testPrivateKeyContent)), + WithKeyID("key_id"), + WithSigningMethod(jwt.SigningMethodRS256), + WithIssuer("test_issuer"), + WithAudience("test_audience"), + ) + require.NoError(t, err) + + token, err := src.Token() + require.NoError(t, err) + require.Equal(t, "urn:ietf:params:oauth:token-type:jwt", token.TokenType) + + claims := jwt.RegisteredClaims{} + parsedToken, err := jwt.ParseWithClaims(token.Token, &claims, getPublicKey) + require.NoError(t, err) + + require.True(t, parsedToken.Valid) + require.NoError(t, parsedToken.Claims.Valid()) + require.Equal(t, "test_issuer", claims.Issuer) + require.Equal(t, "test_audience", claims.Audience[0]) + require.Equal(t, "key_id", parsedToken.Header["kid"].(string)) + require.Equal(t, "RS256", parsedToken.Header["alg"].(string)) +} + +func TestJWTTokenBadParams(t *testing.T) { + privateKey, err := jwt.ParseRSAPrivateKeyFromPEM([]byte(testPrivateKeyContent)) + require.NoError(t, err) + + _, err = NewJWTTokenSource( + // no private key + WithKeyID("key_id"), + WithSigningMethod(jwt.SigningMethodRS256), + WithIssuer("test_issuer"), + WithAudience("test_audience"), + WithID("id"), + ) + require.ErrorIs(t, err, errNoPrivateKeyError) + + _, err = NewJWTTokenSource( + WithPrivateKey(privateKey), + WithKeyID("key_id"), + // no signing method + WithSubject("s"), + WithTokenTTL(time.Minute), + WithAudience("test_audience"), + ) + require.ErrorIs(t, err, errNoSigningMethodError) +} + +func TestJWTTokenSourceReadPrivateKeyFromFile(t *testing.T) { + const perm = 0o600 + usr, err := user.Current() + require.NoError(t, err) + fileName := strconv.Itoa(time.Now().Second()) + filePath := filepath.Join(usr.HomeDir, fileName) + beautifulFilePath := filepath.Join("~", fileName) + err = os.WriteFile( + filePath, + []byte(testPrivateKeyContent), + perm, + ) + require.NoError(t, err) + defer os.Remove(filePath) + + var src TokenSource + src, err = NewJWTTokenSource( + WithRSAPrivateKeyPEMFile(beautifulFilePath), + WithKeyID("key_id"), + WithSigningMethod(jwt.SigningMethodRS256), + WithIssuer("test_issuer"), + WithAudience("test_audience"), + ) + require.NoError(t, err) + + token, err := src.Token() + require.NoError(t, err) + + // parse token + publicKey, err := jwt.ParseRSAPublicKeyFromPEM([]byte(testPublicKeyContent)) + require.NoError(t, err) + getPublicKey := func(*jwt.Token) (interface{}, error) { + return publicKey, nil + } + + claims := jwt.RegisteredClaims{} + _, err = jwt.ParseWithClaims(token.Token, &claims, getPublicKey) + require.NoError(t, err) +} diff --git a/internal/credentials/source_info.go b/internal/credentials/source_info.go index 017a49a2e..53f7c5065 100644 --- a/internal/credentials/source_info.go +++ b/internal/credentials/source_info.go @@ -14,6 +14,12 @@ func (sourceInfo SourceInfoOption) ApplyAccessTokenCredentialsOption(h *AccessTo h.sourceInfo = string(sourceInfo) } +func (sourceInfo SourceInfoOption) ApplyOauth2CredentialsOption(h *oauth2TokenExchange) error { + h.sourceInfo = string(sourceInfo) + + return nil +} + // WithSourceInfo option append to credentials object the source info for reporting source info details on error case func WithSourceInfo(sourceInfo string) SourceInfoOption { return SourceInfoOption(sourceInfo) diff --git a/internal/credentials/static.go b/internal/credentials/static.go index 298785bf1..7d9437dfb 100644 --- a/internal/credentials/static.go +++ b/internal/credentials/static.go @@ -19,6 +19,8 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/internal/xstring" ) +const TokenRefreshDivisor = 10 + var ( _ Credentials = (*Static)(nil) _ fmt.Stringer = (*Static)(nil) @@ -133,7 +135,7 @@ func (c *Static) Token(ctx context.Context) (token string, err error) { return "", xerrors.WithStackTrace(err) } - c.requestAt = time.Now().Add(time.Until(expiresAt) / 10) + c.requestAt = time.Now().Add(time.Until(expiresAt) / TokenRefreshDivisor) c.token = result.GetToken() return c.token, nil diff --git a/internal/decimal/decimal.go b/internal/decimal/decimal.go index 4b7f4330d..2795592e8 100644 --- a/internal/decimal/decimal.go +++ b/internal/decimal/decimal.go @@ -12,12 +12,12 @@ const ( ) var ( - ten = big.NewInt(10) + ten = big.NewInt(10) //nolint:gomnd zero = big.NewInt(0) one = big.NewInt(1) inf = big.NewInt(0).Mul( - big.NewInt(100000000000000000), - big.NewInt(1000000000000000000), + big.NewInt(100000000000000000), //nolint:gomnd + big.NewInt(1000000000000000000), //nolint:gomnd ) nan = big.NewInt(0).Add(inf, one) err = big.NewInt(0).Add(nan, one) diff --git a/internal/endpoint/endpoint.go b/internal/endpoint/endpoint.go index 823d721d0..37a889b81 100644 --- a/internal/endpoint/endpoint.go +++ b/internal/endpoint/endpoint.go @@ -9,10 +9,15 @@ import ( type Info interface { NodeID() uint32 Address() string - LocalDC() bool Location() string LastUpdated() time.Time LoadFactor() float32 + + // Deprecated: LocalDC check "local" by compare endpoint location with discovery "selflocation" field. + // It work good only if connection url always point to local dc. + // Will be removed after Oct 2024. + // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated + LocalDC() bool } type Endpoint interface { @@ -23,17 +28,17 @@ type Endpoint interface { Touch(opts ...Option) } -type endpoint struct { +type endpoint struct { //nolint:maligned mu sync.RWMutex id uint32 address string location string services []string - loadFactor float32 - local bool - + loadFactor float32 lastUpdated time.Time + + local bool } func (e *endpoint) Copy() Endpoint { @@ -86,6 +91,10 @@ func (e *endpoint) Location() string { return e.location } +// Deprecated: LocalDC check "local" by compare endpoint location with discovery "selflocation" field. +// It work good only if connection url always point to local dc. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func (e *endpoint) LocalDC() bool { e.mu.RLock() defer e.mu.RUnlock() diff --git a/internal/grpcwrapper/rawtopic/rawtopicwriter/streamwriter.go b/internal/grpcwrapper/rawtopic/rawtopicwriter/streamwriter.go index e2689df5a..8ff0b9727 100644 --- a/internal/grpcwrapper/rawtopic/rawtopicwriter/streamwriter.go +++ b/internal/grpcwrapper/rawtopic/rawtopicwriter/streamwriter.go @@ -177,6 +177,7 @@ func sendWriteRequest(send sendFunc, req *Ydb_Topic.StreamWriteMessage_FromClien return sendErr } + //nolint:gomnd splitIndex := len(grpcMessages) / 2 firstMessages, lastMessages := grpcMessages[:splitIndex], grpcMessages[splitIndex:] defer func() { diff --git a/internal/meta/context.go b/internal/meta/context.go index b3a410dcc..049d0a6da 100644 --- a/internal/meta/context.go +++ b/internal/meta/context.go @@ -41,7 +41,7 @@ func WithRequestType(ctx context.Context, requestType string) context.Context { // WithAllowFeatures returns a copy of parent context with allowed client feature func WithAllowFeatures(ctx context.Context, features ...string) context.Context { - kv := make([]string, 0, len(features)*2) + kv := make([]string, 0, len(features)*2) //nolint:gomnd for _, feature := range features { kv = append(kv, HeaderClientCapabilities, feature) } diff --git a/internal/mock/conn.go b/internal/mock/conn.go index ac57f6c41..b4ceb9f69 100644 --- a/internal/mock/conn.go +++ b/internal/mock/conn.go @@ -95,6 +95,10 @@ func (e *Endpoint) Address() string { return e.AddrField } +// Deprecated: LocalDC check "local" by compare endpoint location with discovery "selflocation" field. +// It work good only if connection url always point to local dc. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func (e *Endpoint) LocalDC() bool { return e.LocalDCField } diff --git a/internal/params/variant.go b/internal/params/variant.go index 8a5f1b444..16815e38e 100644 --- a/internal/params/variant.go +++ b/internal/params/variant.go @@ -24,8 +24,14 @@ func (vb *variantBuilder) EndVariant() Builder { return vb.variant.parent } -func (v *variant) Tuple() *variantTuple { +func (v *variant) BeginTuple() *variantTuple { return &variantTuple{ parent: v, } } + +func (v *variant) BeginStruct() *variantStruct { + return &variantStruct{ + parent: v, + } +} diff --git a/internal/params/variant_struct.go b/internal/params/variant_struct.go new file mode 100644 index 000000000..190e7d85f --- /dev/null +++ b/internal/params/variant_struct.go @@ -0,0 +1,489 @@ +package params + +import ( + "time" + + "github.com/ydb-platform/ydb-go-sdk/v3/internal/types" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/value" +) + +type ( + variantStruct struct { + parent *variant + + fields []types.StructField + name string + value value.Value + } + + variantStructField struct { + name string + parent *variantStruct + } + + variantStructItem struct { + parent *variantStruct + } + + variantStructBuilder struct { + parent *variantStruct + } +) + +func (vs *variantStruct) Field(name string) *variantStructField { + return &variantStructField{ + name: name, + parent: vs, + } +} + +func (vs *variantStruct) AddFields(args ...types.StructField) *variantStruct { + vs.fields = append(vs.fields, args...) + + return vs +} + +func (vsf *variantStructField) Text() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.Text, + }) + + return vsf.parent +} + +func (vsf *variantStructField) Bytes() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.Bytes, + }) + + return vsf.parent +} + +func (vsf *variantStructField) Bool() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.Bool, + }) + + return vsf.parent +} + +func (vsf *variantStructField) Uint64() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.Uint64, + }) + + return vsf.parent +} + +func (vsf *variantStructField) Int64() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.Int64, + }) + + return vsf.parent +} + +func (vsf *variantStructField) Uint32() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.Uint32, + }) + + return vsf.parent +} + +func (vsf *variantStructField) Int32() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.Int32, + }) + + return vsf.parent +} + +func (vsf *variantStructField) Uint16() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.Uint16, + }) + + return vsf.parent +} + +func (vsf *variantStructField) Int16() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.Int16, + }) + + return vsf.parent +} + +func (vsf *variantStructField) Uint8() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.Uint8, + }) + + return vsf.parent +} + +func (vsf *variantStructField) Int8() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.Int8, + }) + + return vsf.parent +} + +func (vsf *variantStructField) Float() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.Float, + }) + + return vsf.parent +} + +func (vsf *variantStructField) Double() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.Double, + }) + + return vsf.parent +} + +func (vsf *variantStructField) Decimal(precision, scale uint32) *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.NewDecimal(precision, scale), + }) + + return vsf.parent +} + +func (vsf *variantStructField) Timestamp() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.Timestamp, + }) + + return vsf.parent +} + +func (vsf *variantStructField) Date() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.Date, + }) + + return vsf.parent +} + +func (vsf *variantStructField) Datetime() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.Datetime, + }) + + return vsf.parent +} + +func (vsf *variantStructField) Interval() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.Interval, + }) + + return vsf.parent +} + +func (vsf *variantStructField) JSON() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.JSON, + }) + + return vsf.parent +} + +func (vsf *variantStructField) JSONDocument() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.JSONDocument, + }) + + return vsf.parent +} + +func (vsf *variantStructField) YSON() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.YSON, + }) + + return vsf.parent +} + +func (vsf *variantStructField) UUID() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.UUID, + }) + + return vsf.parent +} + +func (vsf *variantStructField) TzDate() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.TzDate, + }) + + return vsf.parent +} + +func (vsf *variantStructField) TzTimestamp() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.TzTimestamp, + }) + + return vsf.parent +} + +func (vsf *variantStructField) TzDatetime() *variantStruct { + vsf.parent.fields = append(vsf.parent.fields, types.StructField{ + Name: vsf.name, + T: types.TzDatetime, + }) + + return vsf.parent +} + +func (vs *variantStruct) Name(name string) *variantStructItem { + vs.name = name + + return &variantStructItem{ + parent: vs, + } +} + +func (vsi *variantStructItem) Text(v string) *variantStructBuilder { + vsi.parent.value = value.TextValue(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) Bytes(v []byte) *variantStructBuilder { + vsi.parent.value = value.BytesValue(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) Bool(v bool) *variantStructBuilder { + vsi.parent.value = value.BoolValue(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) Uint64(v uint64) *variantStructBuilder { + vsi.parent.value = value.Uint64Value(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) Int64(v int64) *variantStructBuilder { + vsi.parent.value = value.Int64Value(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) Uint32(v uint32) *variantStructBuilder { + vsi.parent.value = value.Uint32Value(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) Int32(v int32) *variantStructBuilder { + vsi.parent.value = value.Int32Value(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) Uint16(v uint16) *variantStructBuilder { + vsi.parent.value = value.Uint16Value(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) Int16(v int16) *variantStructBuilder { + vsi.parent.value = value.Int16Value(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) Uint8(v uint8) *variantStructBuilder { + vsi.parent.value = value.Uint8Value(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) Int8(v int8) *variantStructBuilder { + vsi.parent.value = value.Int8Value(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) Float(v float32) *variantStructBuilder { + vsi.parent.value = value.FloatValue(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) Double(v float64) *variantStructBuilder { + vsi.parent.value = value.DoubleValue(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) Decimal(v [16]byte, precision, scale uint32) *variantStructBuilder { + vsi.parent.value = value.DecimalValue(v, precision, scale) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) Timestamp(v time.Time) *variantStructBuilder { + vsi.parent.value = value.TimestampValueFromTime(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) Date(v time.Time) *variantStructBuilder { + vsi.parent.value = value.DateValueFromTime(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) Datetime(v time.Time) *variantStructBuilder { + vsi.parent.value = value.DatetimeValueFromTime(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) Interval(v time.Duration) *variantStructBuilder { + vsi.parent.value = value.IntervalValueFromDuration(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) JSON(v string) *variantStructBuilder { + vsi.parent.value = value.JSONValue(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) JSONDocument(v string) *variantStructBuilder { + vsi.parent.value = value.JSONDocumentValue(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) YSON(v []byte) *variantStructBuilder { + vsi.parent.value = value.YSONValue(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) UUID(v [16]byte) *variantStructBuilder { + vsi.parent.value = value.UUIDValue(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) TzDate(v time.Time) *variantStructBuilder { + vsi.parent.value = value.TzDateValueFromTime(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) TzTimestamp(v time.Time) *variantStructBuilder { + vsi.parent.value = value.TzTimestampValueFromTime(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsi *variantStructItem) TzDatetime(v time.Time) *variantStructBuilder { + vsi.parent.value = value.TzDatetimeValueFromTime(v) + + return &variantStructBuilder{ + parent: vsi.parent, + } +} + +func (vsb *variantStructBuilder) EndStruct() *variantBuilder { + vsb.parent.parent.value = value.VariantValueStruct( + vsb.parent.value, + vsb.parent.name, + types.NewVariantStruct(vsb.parent.fields...), + ) + + return &variantBuilder{ + variant: vsb.parent.parent, + } +} diff --git a/internal/params/variant_struct_test.go b/internal/params/variant_struct_test.go new file mode 100644 index 000000000..cf8330da0 --- /dev/null +++ b/internal/params/variant_struct_test.go @@ -0,0 +1,557 @@ +package params + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + "github.com/ydb-platform/ydb-go-genproto/protos/Ydb" + + "github.com/ydb-platform/ydb-go-sdk/v3/internal/allocator" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/types" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest" +) + +func TestVariantStruct(t *testing.T) { + type expected struct { + Type *Ydb.Type + Value *Ydb.Value + } + + tests := []struct { + method string + + typeArgs []any + itemArgs []any + + expected expected + }{ + { + method: "Uint64", + itemArgs: []any{uint64(123)}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT64}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_Uint64Value{ + Uint64Value: 123, + }, + VariantIndex: 0, + }, + }, + }, + { + method: "Int64", + itemArgs: []any{int64(123)}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT64}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_Int64Value{ + Int64Value: 123, + }, + VariantIndex: 0, + }, + }, + }, + { + method: "Uint32", + itemArgs: []any{uint32(123)}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT32}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_Uint32Value{ + Uint32Value: 123, + }, + VariantIndex: 0, + }, + }, + }, + { + method: "Int32", + itemArgs: []any{int32(123)}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT32}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_Int32Value{ + Int32Value: 123, + }, + VariantIndex: 0, + }, + }, + }, + { + method: "Uint16", + itemArgs: []any{uint16(123)}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT16}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_Uint32Value{ + Uint32Value: 123, + }, + VariantIndex: 0, + }, + }, + }, + { + method: "Int16", + itemArgs: []any{int16(123)}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT16}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_Int32Value{ + Int32Value: 123, + }, + VariantIndex: 0, + }, + }, + }, + { + method: "Uint8", + itemArgs: []any{uint8(123)}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UINT8}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_Uint32Value{ + Uint32Value: 123, + }, + VariantIndex: 0, + }, + }, + }, + { + method: "Int8", + itemArgs: []any{int8(123)}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INT8}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_Int32Value{ + Int32Value: 123, + }, + VariantIndex: 0, + }, + }, + }, + { + method: "Bool", + itemArgs: []any{true}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_BOOL}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_BoolValue{ + BoolValue: true, + }, + VariantIndex: 0, + }, + }, + }, + { + method: "Text", + itemArgs: []any{"test"}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UTF8}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_TextValue{ + TextValue: "test", + }, + VariantIndex: 0, + }, + }, + }, + { + method: "Bytes", + itemArgs: []any{[]byte("test")}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_STRING}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_BytesValue{ + BytesValue: []byte("test"), + }, + VariantIndex: 0, + }, + }, + }, + { + method: "Float", + itemArgs: []any{float32(123)}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_FLOAT}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_FloatValue{ + FloatValue: float32(123), + }, + VariantIndex: 0, + }, + }, + }, + { + method: "Double", + itemArgs: []any{float64(123)}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DOUBLE}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_DoubleValue{ + DoubleValue: float64(123), + }, + VariantIndex: 0, + }, + }, + }, + { + method: "Interval", + itemArgs: []any{time.Second}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_INTERVAL}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_Int64Value{ + Int64Value: 1000000, + }, + VariantIndex: 0, + }, + }, + }, + { + method: "Datetime", + itemArgs: []any{time.Unix(123456789, 456)}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DATETIME}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_Uint32Value{ + Uint32Value: 123456789, + }, + VariantIndex: 0, + }, + }, + }, + { + method: "Date", + itemArgs: []any{time.Unix(123456789, 456)}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_DATE}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_Uint32Value{ + Uint32Value: 1428, + }, + VariantIndex: 0, + }, + }, + }, + { + method: "Timestamp", + itemArgs: []any{time.Unix(123456789, 456)}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TIMESTAMP}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_Uint64Value{ + Uint64Value: 123456789000000, + }, + VariantIndex: 0, + }, + }, + }, + { + method: "Decimal", + typeArgs: []any{uint32(22), uint32(9)}, + itemArgs: []any{[...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6}, uint32(22), uint32(9)}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_DecimalType{ + DecimalType: &Ydb.DecimalType{ + Precision: 22, + Scale: 9, + }, + }, + }, + Value: &Ydb.Value{ + High_128: 72623859790382856, + Value: &Ydb.Value_Low_128{ + Low_128: 648519454493508870, + }, + VariantIndex: 0, + }, + }, + }, + { + method: "JSON", + itemArgs: []any{`{"a": 1,"b": "B"}`}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_JSON}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_TextValue{ + TextValue: `{"a": 1,"b": "B"}`, + }, + VariantIndex: 0, + }, + }, + }, + { + method: "JSONDocument", + itemArgs: []any{`{"a": 1,"b": "B"}`}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_JSON_DOCUMENT}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_TextValue{ + TextValue: `{"a": 1,"b": "B"}`, + }, + VariantIndex: 0, + }, + }, + }, + { + method: "YSON", + itemArgs: []any{[]byte(`{"a": 1,"b": "B"}`)}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_YSON}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_BytesValue{ + BytesValue: []byte(`{"a": 1,"b": "B"}`), + }, + VariantIndex: 0, + }, + }, + }, + { + method: "UUID", + itemArgs: []any{[...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_Low_128{ + Low_128: 651345242494996240, + }, + High_128: 72623859790382856, + VariantIndex: 0, + }, + }, + }, + { + method: "TzDatetime", + itemArgs: []any{time.Unix(123456789, 456).UTC()}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_DATETIME}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_TextValue{ + TextValue: "1973-11-29T21:33:09Z", + }, + VariantIndex: 0, + }, + }, + }, + { + method: "TzDate", + itemArgs: []any{time.Unix(123456789, 456).UTC()}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_DATE}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_TextValue{ + TextValue: "1973-11-29", + }, + VariantIndex: 0, + }, + }, + }, + { + method: "TzTimestamp", + itemArgs: []any{time.Unix(123456789, 456).UTC()}, + + expected: expected{ + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_TZ_TIMESTAMP}, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_TextValue{ + TextValue: "1973-11-29T21:33:09.000000Z", + }, + VariantIndex: 0, + }, + }, + }, + } + + for _, tc := range tests { + t.Run(tc.method, func(t *testing.T) { + a := allocator.New() + defer a.Free() + + item := Builder{}.Param("$x").BeginVariant().BeginStruct().Field("key") + + vs, ok := xtest.CallMethod(item, tc.method, tc.typeArgs...)[0].(*variantStruct) + require.True(t, ok) + + builder, ok := xtest.CallMethod(vs.Name("key"), tc.method, tc.itemArgs...)[0].(*variantStructBuilder) + require.True(t, ok) + + params := builder.EndStruct().EndVariant().Build().ToYDB(a) + + require.Equal(t, xtest.ToJSON( + map[string]*Ydb.TypedValue{ + "$x": { + Type: &Ydb.Type{ + Type: &Ydb.Type_VariantType{ + VariantType: &Ydb.VariantType{ + Type: &Ydb.VariantType_StructItems{ + StructItems: &Ydb.StructType{ + Members: []*Ydb.StructMember{ + { + Name: "key", + Type: tc.expected.Type, + }, + }, + }, + }, + }, + }, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_NestedValue{ + NestedValue: tc.expected.Value, + }, + VariantIndex: 0, + }, + }, + }), xtest.ToJSON(params)) + }) + } +} + +func TestVariantStruct_AddFields(t *testing.T) { + a := allocator.New() + defer a.Free() + + params := Builder{}.Param("$x").BeginVariant().BeginStruct(). + AddFields([]types.StructField{ + { + Name: "key1", + T: types.Bool, + }, + { + Name: "key2", + T: types.Uint64, + }, + { + Name: "key3", + T: types.Text, + }, + }...).Name("key3").Text("Hello, World!").EndStruct(). + EndVariant().Build().ToYDB(a) + + require.Equal(t, xtest.ToJSON( + map[string]*Ydb.TypedValue{ + "$x": { + Type: &Ydb.Type{ + Type: &Ydb.Type_VariantType{ + VariantType: &Ydb.VariantType{ + Type: &Ydb.VariantType_StructItems{ + StructItems: &Ydb.StructType{ + Members: []*Ydb.StructMember{ + { + Name: "key1", + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{ + TypeId: Ydb.Type_BOOL, + }, + }, + }, + { + Name: "key2", + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{ + TypeId: Ydb.Type_UINT64, + }, + }, + }, + { + Name: "key3", + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{ + TypeId: Ydb.Type_UTF8, + }, + }, + }, + }, + }, + }, + }, + }, + }, + Value: &Ydb.Value{ + Value: &Ydb.Value_NestedValue{ + NestedValue: &Ydb.Value{ + Value: &Ydb.Value_TextValue{ + TextValue: "Hello, World!", + }, + }, + }, + VariantIndex: 2, + }, + }, + }), xtest.ToJSON(params)) +} diff --git a/internal/params/variant_tuple_test.go b/internal/params/variant_tuple_test.go index 1ae4356d1..b24480d38 100644 --- a/internal/params/variant_tuple_test.go +++ b/internal/params/variant_tuple_test.go @@ -441,7 +441,7 @@ func TestVariantTuple(t *testing.T) { a := allocator.New() defer a.Free() - item := Builder{}.Param("$x").BeginVariant().Tuple().Types() + item := Builder{}.Param("$x").BeginVariant().BeginTuple().Types() types, ok := xtest.CallMethod(item, tc.method, tc.typeArgs...)[0].(*variantTupleTypes) require.True(t, ok) @@ -482,7 +482,7 @@ func TestVariantTuple_AddTypes(t *testing.T) { a := allocator.New() defer a.Free() - params := Builder{}.Param("$x").BeginVariant().Tuple(). + params := Builder{}.Param("$x").BeginVariant().BeginTuple(). Types().AddTypes(types.Int64, types.Bool). Index(1). Bool(true). diff --git a/internal/pool/pool.go b/internal/pool/pool.go index b7a5e8a3f..3368aadc8 100644 --- a/internal/pool/pool.go +++ b/internal/pool/pool.go @@ -4,6 +4,8 @@ import ( "context" "time" + "golang.org/x/sync/errgroup" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/pool/stats" "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext" @@ -465,20 +467,16 @@ func (p *Pool[PT, T]) Close(ctx context.Context) (finalErr error) { p.mu.Lock() defer p.mu.Unlock() - errs := make([]error, 0, len(p.index)) - + var g errgroup.Group for item := range p.index { - if err := item.Close(ctx); err != nil { - errs = append(errs, err) - } + item := item + g.Go(func() error { + return item.Close(ctx) + }) } - - switch len(errs) { - case 0: - return nil - case 1: - return errs[0] - default: - return xerrors.Join(errs...) + if err := g.Wait(); err != nil { + return xerrors.WithStackTrace(err) } + + return nil } diff --git a/internal/query/result_set.go b/internal/query/result_set.go index 47d90301f..8d2ae8b71 100644 --- a/internal/query/result_set.go +++ b/internal/query/result_set.go @@ -48,39 +48,43 @@ func newResultSet( func (rs *resultSet) nextRow(ctx context.Context) (*row, error) { rs.rowIndex++ - select { - case <-rs.done: - return nil, io.EOF - case <-ctx.Done(): - return nil, xerrors.WithStackTrace(ctx.Err()) - default: - if rs.rowIndex == len(rs.currentPart.GetResultSet().GetRows()) { - part, err := rs.recv() - if err != nil { - if xerrors.Is(err, io.EOF) { - close(rs.done) + for { + select { + case <-rs.done: + return nil, io.EOF + case <-ctx.Done(): + return nil, xerrors.WithStackTrace(ctx.Err()) + default: + if rs.rowIndex == len(rs.currentPart.GetResultSet().GetRows()) { + part, err := rs.recv() + if err != nil { + if xerrors.Is(err, io.EOF) { + close(rs.done) + } + + return nil, xerrors.WithStackTrace(err) } + rs.rowIndex = 0 + rs.currentPart = part + if part == nil { + close(rs.done) - return nil, xerrors.WithStackTrace(err) + return nil, xerrors.WithStackTrace(io.EOF) + } } - rs.rowIndex = 0 - rs.currentPart = part - if part == nil { + if rs.index != rs.currentPart.GetResultSetIndex() { close(rs.done) - return nil, xerrors.WithStackTrace(io.EOF) + return nil, xerrors.WithStackTrace(fmt.Errorf( + "received part with result set index = %d, current result set index = %d: %w", + rs.index, rs.currentPart.GetResultSetIndex(), errWrongResultSetIndex, + )) } - } - if rs.index != rs.currentPart.GetResultSetIndex() { - close(rs.done) - return nil, xerrors.WithStackTrace(fmt.Errorf( - "received part with result set index = %d, current result set index = %d: %w", - rs.index, rs.currentPart.GetResultSetIndex(), errWrongResultSetIndex, - )) + if rs.rowIndex < len(rs.currentPart.GetResultSet().GetRows()) { + return newRow(ctx, rs.columns, rs.currentPart.GetResultSet().GetRows()[rs.rowIndex], rs.trace) + } } - - return newRow(ctx, rs.columns, rs.currentPart.GetResultSet().GetRows()[rs.rowIndex], rs.trace) } } diff --git a/internal/query/result_set_test.go b/internal/query/result_set_test.go index a011d2781..93f0491bf 100644 --- a/internal/query/result_set_test.go +++ b/internal/query/result_set_test.go @@ -20,6 +20,324 @@ import ( func TestResultSetNext(t *testing.T) { ctx := xtest.Context(t) ctrl := gomock.NewController(t) + t.Run("EmptyResultSet", func(t *testing.T) { + stream := NewMockQueryService_ExecuteQueryClient(ctrl) + stream.EXPECT().Recv().Return(&Ydb_Query.ExecuteQueryResponsePart{ + Status: Ydb.StatusIds_SUCCESS, + ResultSetIndex: 0, + ResultSet: &Ydb.ResultSet{ + Columns: []*Ydb.Column{ + { + Name: "a", + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{ + TypeId: Ydb.Type_UINT64, + }, + }, + }, + { + Name: "b", + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{ + TypeId: Ydb.Type_UTF8, + }, + }, + }, + }, + Rows: []*Ydb.Value{}, + }, + }, nil) + stream.EXPECT().Recv().Return(nil, io.EOF) + recv, err := stream.Recv() + require.NoError(t, err) + rs := newResultSet(func() (*Ydb_Query.ExecuteQueryResponsePart, error) { + part, err := stream.Recv() + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + + return part, nil + }, recv, nil) + require.EqualValues(t, 0, rs.index) + { + _, err := rs.nextRow(ctx) + require.ErrorIs(t, err, io.EOF) + } + }) + t.Run("SecondResultSetEmpty", func(t *testing.T) { + stream := NewMockQueryService_ExecuteQueryClient(ctrl) + stream.EXPECT().Recv().Return(&Ydb_Query.ExecuteQueryResponsePart{ + Status: Ydb.StatusIds_SUCCESS, + ResultSetIndex: 0, + ResultSet: &Ydb.ResultSet{ + Columns: []*Ydb.Column{ + { + Name: "a", + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{ + TypeId: Ydb.Type_UINT64, + }, + }, + }, + { + Name: "b", + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{ + TypeId: Ydb.Type_UTF8, + }, + }, + }, + }, + Rows: []*Ydb.Value{ + { + Items: []*Ydb.Value{{ + Value: &Ydb.Value_Uint64Value{ + Uint64Value: 1, + }, + }, { + Value: &Ydb.Value_TextValue{ + TextValue: "1", + }, + }}, + }, + { + Items: []*Ydb.Value{{ + Value: &Ydb.Value_Uint64Value{ + Uint64Value: 2, + }, + }, { + Value: &Ydb.Value_TextValue{ + TextValue: "2", + }, + }}, + }, + { + Items: []*Ydb.Value{{ + Value: &Ydb.Value_Uint64Value{ + Uint64Value: 3, + }, + }, { + Value: &Ydb.Value_TextValue{ + TextValue: "3", + }, + }}, + }, + }, + }, + }, nil) + stream.EXPECT().Recv().Return(&Ydb_Query.ExecuteQueryResponsePart{ + Status: Ydb.StatusIds_SUCCESS, + ResultSetIndex: 0, + ResultSet: &Ydb.ResultSet{ + Rows: []*Ydb.Value{}, + }, + }, nil) + stream.EXPECT().Recv().Return(nil, io.EOF) + recv, err := stream.Recv() + require.NoError(t, err) + rs := newResultSet(func() (*Ydb_Query.ExecuteQueryResponsePart, error) { + part, err := stream.Recv() + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + + return part, nil + }, recv, nil) + require.EqualValues(t, 0, rs.index) + { + _, err := rs.nextRow(ctx) + require.NoError(t, err) + require.EqualValues(t, 0, rs.rowIndex) + } + { + _, err := rs.nextRow(ctx) + require.NoError(t, err) + require.EqualValues(t, 1, rs.rowIndex) + } + { + _, err := rs.nextRow(ctx) + require.NoError(t, err) + require.EqualValues(t, 2, rs.rowIndex) + } + { + _, err := rs.nextRow(ctx) + require.ErrorIs(t, err, io.EOF) + } + }) + t.Run("IntermediateResultSetEmpty", func(t *testing.T) { + stream := NewMockQueryService_ExecuteQueryClient(ctrl) + stream.EXPECT().Recv().Return(&Ydb_Query.ExecuteQueryResponsePart{ + Status: Ydb.StatusIds_SUCCESS, + ResultSetIndex: 0, + ResultSet: &Ydb.ResultSet{ + Columns: []*Ydb.Column{ + { + Name: "a", + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{ + TypeId: Ydb.Type_UINT64, + }, + }, + }, + { + Name: "b", + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{ + TypeId: Ydb.Type_UTF8, + }, + }, + }, + }, + Rows: []*Ydb.Value{ + { + Items: []*Ydb.Value{{ + Value: &Ydb.Value_Uint64Value{ + Uint64Value: 1, + }, + }, { + Value: &Ydb.Value_TextValue{ + TextValue: "1", + }, + }}, + }, + { + Items: []*Ydb.Value{{ + Value: &Ydb.Value_Uint64Value{ + Uint64Value: 2, + }, + }, { + Value: &Ydb.Value_TextValue{ + TextValue: "2", + }, + }}, + }, + { + Items: []*Ydb.Value{{ + Value: &Ydb.Value_Uint64Value{ + Uint64Value: 3, + }, + }, { + Value: &Ydb.Value_TextValue{ + TextValue: "3", + }, + }}, + }, + }, + }, + }, nil) + stream.EXPECT().Recv().Return(&Ydb_Query.ExecuteQueryResponsePart{ + Status: Ydb.StatusIds_SUCCESS, + ResultSetIndex: 0, + ResultSet: &Ydb.ResultSet{ + Rows: []*Ydb.Value{}, + }, + }, nil) + stream.EXPECT().Recv().Return(&Ydb_Query.ExecuteQueryResponsePart{ + Status: Ydb.StatusIds_SUCCESS, + ResultSetIndex: 0, + ResultSet: &Ydb.ResultSet{ + Columns: []*Ydb.Column{ + { + Name: "a", + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{ + TypeId: Ydb.Type_UINT64, + }, + }, + }, + { + Name: "b", + Type: &Ydb.Type{ + Type: &Ydb.Type_TypeId{ + TypeId: Ydb.Type_UTF8, + }, + }, + }, + }, + Rows: []*Ydb.Value{ + { + Items: []*Ydb.Value{{ + Value: &Ydb.Value_Uint64Value{ + Uint64Value: 1, + }, + }, { + Value: &Ydb.Value_TextValue{ + TextValue: "1", + }, + }}, + }, + { + Items: []*Ydb.Value{{ + Value: &Ydb.Value_Uint64Value{ + Uint64Value: 2, + }, + }, { + Value: &Ydb.Value_TextValue{ + TextValue: "2", + }, + }}, + }, + { + Items: []*Ydb.Value{{ + Value: &Ydb.Value_Uint64Value{ + Uint64Value: 3, + }, + }, { + Value: &Ydb.Value_TextValue{ + TextValue: "3", + }, + }}, + }, + }, + }, + }, nil) + stream.EXPECT().Recv().Return(nil, io.EOF) + recv, err := stream.Recv() + require.NoError(t, err) + rs := newResultSet(func() (*Ydb_Query.ExecuteQueryResponsePart, error) { + part, err := stream.Recv() + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + + return part, nil + }, recv, nil) + require.EqualValues(t, 0, rs.index) + { + _, err := rs.nextRow(ctx) + require.NoError(t, err) + require.EqualValues(t, 0, rs.rowIndex) + } + { + _, err := rs.nextRow(ctx) + require.NoError(t, err) + require.EqualValues(t, 1, rs.rowIndex) + } + { + _, err := rs.nextRow(ctx) + require.NoError(t, err) + require.EqualValues(t, 2, rs.rowIndex) + } + { + _, err := rs.nextRow(ctx) + require.NoError(t, err) + require.EqualValues(t, 0, rs.rowIndex) + } + { + _, err := rs.nextRow(ctx) + require.NoError(t, err) + require.EqualValues(t, 1, rs.rowIndex) + } + { + _, err := rs.nextRow(ctx) + require.NoError(t, err) + require.EqualValues(t, 2, rs.rowIndex) + } + { + _, err := rs.nextRow(ctx) + require.ErrorIs(t, err, io.EOF) + } + }) t.Run("OverTwoParts", func(t *testing.T) { stream := NewMockQueryService_ExecuteQueryClient(ctrl) stream.EXPECT().Recv().Return(&Ydb_Query.ExecuteQueryResponsePart{ diff --git a/internal/repeater/repeater.go b/internal/repeater/repeater.go index 8cb2fb0c0..ec75be3c1 100644 --- a/internal/repeater/repeater.go +++ b/internal/repeater/repeater.go @@ -172,8 +172,8 @@ func (r *repeater) worker(ctx context.Context, tick clockwork.Ticker) { // force returns backoff with delays [500ms...32s] force := backoff.New( - backoff.WithSlotDuration(500*time.Millisecond), - backoff.WithCeiling(6), + backoff.WithSlotDuration(500*time.Millisecond), //nolint:gomnd + backoff.WithCeiling(6), //nolint:gomnd backoff.WithJitterLimit(1), ) diff --git a/internal/secret/token.go b/internal/secret/token.go index dc90e0c59..5383a8e0f 100644 --- a/internal/secret/token.go +++ b/internal/secret/token.go @@ -6,9 +6,11 @@ import ( "hash/crc32" ) +const minTokenLength = 16 + func Token(token string) string { var mask bytes.Buffer - if len(token) > 16 { + if len(token) > minTokenLength { mask.WriteString(token[:4]) mask.WriteString("****") mask.WriteString(token[len(token)-4:]) diff --git a/internal/stack/function_id_test.go b/internal/stack/function_id_test.go index f1161fe3d..b7adabee5 100644 --- a/internal/stack/function_id_test.go +++ b/internal/stack/function_id_test.go @@ -1,7 +1,9 @@ package stack import ( + "sync" "testing" + "time" "github.com/stretchr/testify/require" ) @@ -22,6 +24,22 @@ func (e *starType) starredCall() string { return FunctionID("").FunctionID() } +func anonymousFunctionCall() string { + var result string + var mu sync.Mutex + go func() { + mu.Lock() + defer mu.Unlock() + result = FunctionID("").FunctionID() + }() + time.Sleep(time.Second) + + mu.Lock() + defer mu.Unlock() + + return result +} + func TestFunctionIDForGenericType(t *testing.T) { t.Run("StaticFunc", func(t *testing.T) { require.Equal(t, @@ -42,4 +60,10 @@ func TestFunctionIDForGenericType(t *testing.T) { x.starredCall(), ) }) + t.Run("AnonymousFunctionCall", func(t *testing.T) { + require.Equal(t, + "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack.anonymousFunctionCall", + anonymousFunctionCall(), + ) + }) } diff --git a/internal/table/client.go b/internal/table/client.go index 20dd9cb6e..7d063346b 100644 --- a/internal/table/client.go +++ b/internal/table/client.go @@ -489,7 +489,10 @@ func (c *Client) internalPoolWaitFromCh(ctx context.Context, t *trace.Table) (s var createSessionTimeoutCh <-chan time.Time if timeout := c.config.CreateSessionTimeout(); timeout > 0 { - createSessionTimeoutCh = c.clock.After(timeout) + createSessionTimeoutChTimer := c.clock.NewTimer(timeout) + defer createSessionTimeoutChTimer.Stop() + + createSessionTimeoutCh = createSessionTimeoutChTimer.Chan() } select { @@ -778,7 +781,7 @@ func (c *Client) internalPoolGC(ctx context.Context, idleThreshold time.Duration case <-timer.Chan(): c.internalPoolGCTick(ctx, idleThreshold) - timer.Reset(idleThreshold / 2) + timer.Reset(idleThreshold / 2) //nolint:gomnd } } } diff --git a/internal/table/config/config.go b/internal/table/config/config.go index de94fb3e6..7c03b33e8 100644 --- a/internal/table/config/config.go +++ b/internal/table/config/config.go @@ -15,13 +15,19 @@ const ( DefaultSessionPoolSizeLimit = 50 DefaultSessionPoolIdleThreshold = 5 * time.Minute - // Deprecated: table client do not supports background session keep-aliving now + // Deprecated: table client do not supports background session keep-aliving now. + // Will be removed after Oct 2024. + // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated DefaultKeepAliveMinSize = 10 - // Deprecated: table client do not supports background session keep-aliving now + // Deprecated: table client do not supports background session keep-aliving now. + // Will be removed after Oct 2024. + // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated DefaultIdleKeepAliveThreshold = 2 - // Deprecated: table client do not supports background session keep-aliving now + // Deprecated: table client do not supports background session keep-aliving now. + // Will be removed after Oct 2024. + // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated DefaultSessionPoolKeepAliveTimeout = 500 * time.Millisecond ) @@ -61,7 +67,9 @@ func WithSizeLimit(sizeLimit int) Option { // If keepAliveMinSize is less than zero, then no sessions will be preserved // If keepAliveMinSize is zero, the DefaultKeepAliveMinSize is used // -// Deprecated: table client do not supports background session keep-aliving now +// Deprecated: table client do not supports background session keep-aliving now. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithKeepAliveMinSize(keepAliveMinSize int) Option { return func(c *Config) {} } @@ -73,7 +81,9 @@ func WithKeepAliveMinSize(keepAliveMinSize int) Option { // be removed ever. // If IdleKeepAliveThreshold is equal to zero, it will be set to DefaultIdleKeepAliveThreshold // -// Deprecated: table client do not support background session keep-aliving now +// Deprecated: table client do not supports background session keep-aliving now. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithIdleKeepAliveThreshold(idleKeepAliveThreshold int) Option { return func(c *Config) {} } @@ -95,7 +105,9 @@ func WithIdleThreshold(idleThreshold time.Duration) Option { // WithKeepAliveTimeout limits maximum time spent on KeepAlive request // If keepAliveTimeout is less than or equal to zero then the DefaultSessionPoolKeepAliveTimeout is used. // -// Deprecated: table client do not support background session keep-aliving now +// Deprecated: table client do not supports background session keep-aliving now. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithKeepAliveTimeout(keepAliveTimeout time.Duration) Option { return func(c *Config) {} } @@ -182,7 +194,9 @@ func (c *Config) SizeLimit() int { // If KeepAliveMinSize is less than zero, then no sessions will be preserved // If KeepAliveMinSize is zero, the DefaultKeepAliveMinSize is used // -// Deprecated: table client do not support background session keep-aliving now +// Deprecated: table client do not supports background session keep-aliving now. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func (c *Config) KeepAliveMinSize() int { return DefaultKeepAliveMinSize } @@ -199,7 +213,9 @@ func (c *Config) IgnoreTruncated() bool { // be removed ever. // If IdleKeepAliveThreshold is equal to zero, it will be set to DefaultIdleKeepAliveThreshold // -// Deprecated: table client do not support background session keep-aliving now +// Deprecated: table client do not supports background session keep-aliving now. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func (c *Config) IdleKeepAliveThreshold() int { return DefaultIdleKeepAliveThreshold } @@ -216,7 +232,9 @@ func (c *Config) IdleThreshold() time.Duration { // KeepAliveTimeout limits maximum time spent on KeepAlive request // If KeepAliveTimeout is less than or equal to zero then the DefaultSessionPoolKeepAliveTimeout is used. // -// Deprecated: table client do not support background session keep-aliving now +// Deprecated: table client do not supports background session keep-aliving now. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func (c *Config) KeepAliveTimeout() time.Duration { return DefaultSessionPoolKeepAliveTimeout } diff --git a/internal/table/scanner/result.go b/internal/table/scanner/result.go index 1cbc88eb6..fdebc2859 100644 --- a/internal/table/scanner/result.go +++ b/internal/table/scanner/result.go @@ -170,7 +170,7 @@ func (r *unaryResult) NextResultSet(ctx context.Context, columns ...string) bool func (r *streamResult) nextResultSetErr(ctx context.Context, columns ...string) (err error) { // skipping second recv because first call of recv is from New Stream(), second call is from user - if r.nextResultSetCounter.Add(1) == 2 { + if r.nextResultSetCounter.Add(1) == 2 { //nolint:gomnd r.setColumnIndexes(columns) return ctx.Err() diff --git a/internal/table/scanner/scanner.go b/internal/table/scanner/scanner.go index f541a1235..8a3effb2b 100644 --- a/internal/table/scanner/scanner.go +++ b/internal/table/scanner/scanner.go @@ -1174,7 +1174,7 @@ func (s *valueScanner) errorf(depth int, f string, args ...interface{}) error { func (s *valueScanner) typeError(act, exp interface{}) { _ = s.errorf( - 2, + 2, //nolint:gomnd "unexpected types during scan at %q %s: %s; want %s", s.path(), s.getType(), @@ -1186,7 +1186,7 @@ func (s *valueScanner) typeError(act, exp interface{}) { func (s *valueScanner) valueTypeError(act, exp interface{}) { // unexpected value during scan at \"migration_status\" Int64: NullFlag; want Int64 _ = s.errorf( - 2, + 2, //nolint:gomnd "unexpected value during scan at %q %s: %s; want %s", s.path(), s.getType(), @@ -1197,7 +1197,7 @@ func (s *valueScanner) valueTypeError(act, exp interface{}) { func (s *valueScanner) notFoundColumnByIndex(idx int) error { return s.errorf( - 2, + 2, //nolint:gomnd "not found %d column", idx, ) @@ -1205,7 +1205,7 @@ func (s *valueScanner) notFoundColumnByIndex(idx int) error { func (s *valueScanner) notFoundColumnName(name string) error { return s.errorf( - 2, + 2, //nolint:gomnd "not found column '%s'", name, ) @@ -1213,7 +1213,7 @@ func (s *valueScanner) notFoundColumnName(name string) error { func (s *valueScanner) noColumnError(name string) error { return s.errorf( - 2, + 2, //nolint:gomnd "no column %q", name, ) @@ -1221,7 +1221,7 @@ func (s *valueScanner) noColumnError(name string) error { func (s *valueScanner) overflowError(i, n interface{}) error { return s.errorf( - 2, + 2, //nolint:gomnd "overflow error: %d overflows capacity of %t", i, n, diff --git a/internal/table/session.go b/internal/table/session.go index 3c9fe585c..98e8ce4db 100644 --- a/internal/table/session.go +++ b/internal/table/session.go @@ -602,6 +602,56 @@ func (s *session) CopyTables( return nil } +func renameTables( + ctx context.Context, + sessionID string, + operationTimeout time.Duration, + operationCancelAfter time.Duration, + service interface { + RenameTables( + ctx context.Context, in *Ydb_Table.RenameTablesRequest, opts ...grpc.CallOption, + ) (*Ydb_Table.RenameTablesResponse, error) + }, + opts ...options.RenameTablesOption, +) (err error) { + request := Ydb_Table.RenameTablesRequest{ + SessionId: sessionID, + OperationParams: operation.Params( + ctx, + operationTimeout, + operationCancelAfter, + operation.ModeSync, + ), + } + for _, opt := range opts { + if opt != nil { + opt((*options.RenameTablesDesc)(&request)) + } + } + if len(request.GetTables()) == 0 { + return xerrors.WithStackTrace(fmt.Errorf("no RenameTablesItem: %w", errParamsRequired)) + } + _, err = service.RenameTables(ctx, &request) + if err != nil { + return xerrors.WithStackTrace(err) + } + + return nil +} + +// RenameTables renames tables. +func (s *session) RenameTables( + ctx context.Context, + opts ...options.RenameTablesOption, +) (err error) { + err = renameTables(ctx, s.id, s.config.OperationTimeout(), s.config.OperationCancelAfter(), s.tableService, opts...) + if err != nil { + return xerrors.WithStackTrace(err) + } + + return nil +} + // Explain explains data query represented by text. func (s *session) Explain( ctx context.Context, diff --git a/internal/table/session_test.go b/internal/table/session_test.go index 006086369..710bd57b6 100644 --- a/internal/table/session_test.go +++ b/internal/table/session_test.go @@ -639,7 +639,7 @@ func (mock *copyTablesMock) CopyTables( return nil, fmt.Errorf("%w: %s, exp: %s", errUnexpectedRequest, in, mock.String()) } -func Test_copyTables(t *testing.T) { +func TestCopyTables(t *testing.T) { ctx := xtest.Context(t) for _, tt := range []struct { sessionID string @@ -758,3 +758,137 @@ func Test_copyTables(t *testing.T) { }) } } + +type renameTablesMock struct { + *Ydb_Table.RenameTablesRequest +} + +func (mock *renameTablesMock) RenameTables( + _ context.Context, in *Ydb_Table.RenameTablesRequest, opts ...grpc.CallOption, +) (*Ydb_Table.RenameTablesResponse, error) { + if in.String() == mock.String() { + return &Ydb_Table.RenameTablesResponse{}, nil + } + + return nil, fmt.Errorf("%w: %s, exp: %s", errUnexpectedRequest, in, mock.String()) +} + +func TestRenameTables(t *testing.T) { + ctx := xtest.Context(t) + for _, tt := range []struct { + sessionID string + operationTimeout time.Duration + operationCancelAfter time.Duration + service *renameTablesMock + opts []options.RenameTablesOption + err error + }{ + { + sessionID: "1", + operationTimeout: time.Second, + operationCancelAfter: time.Second, + service: &renameTablesMock{ + RenameTablesRequest: &Ydb_Table.RenameTablesRequest{ + SessionId: "1", + Tables: []*Ydb_Table.RenameTableItem{ + { + SourcePath: "from", + DestinationPath: "to", + ReplaceDestination: true, + }, + }, + OperationParams: &Ydb_Operations.OperationParams{ + OperationMode: Ydb_Operations.OperationParams_SYNC, + OperationTimeout: durationpb.New(time.Second), + CancelAfter: durationpb.New(time.Second), + }, + }, + }, + opts: []options.RenameTablesOption{ + options.RenameTablesItem("from", "to", true), + }, + err: nil, + }, + { + sessionID: "2", + operationTimeout: 2 * time.Second, + operationCancelAfter: 2 * time.Second, + service: &renameTablesMock{ + RenameTablesRequest: &Ydb_Table.RenameTablesRequest{ + SessionId: "2", + Tables: []*Ydb_Table.RenameTableItem{ + { + SourcePath: "from1", + DestinationPath: "to1", + ReplaceDestination: true, + }, + { + SourcePath: "from2", + DestinationPath: "to2", + ReplaceDestination: false, + }, + { + SourcePath: "from3", + DestinationPath: "to3", + ReplaceDestination: true, + }, + }, + OperationParams: &Ydb_Operations.OperationParams{ + OperationMode: Ydb_Operations.OperationParams_SYNC, + OperationTimeout: durationpb.New(2 * time.Second), + CancelAfter: durationpb.New(2 * time.Second), + }, + }, + }, + opts: []options.RenameTablesOption{ + options.RenameTablesItem("from1", "to1", true), + options.RenameTablesItem("from2", "to2", false), + options.RenameTablesItem("from3", "to3", true), + }, + err: nil, + }, + { + sessionID: "3", + operationTimeout: time.Second, + operationCancelAfter: time.Second, + service: &renameTablesMock{ + RenameTablesRequest: &Ydb_Table.RenameTablesRequest{ + SessionId: "1", + Tables: []*Ydb_Table.RenameTableItem{ + { + SourcePath: "from", + DestinationPath: "to", + ReplaceDestination: true, + }, + }, + OperationParams: &Ydb_Operations.OperationParams{ + OperationMode: Ydb_Operations.OperationParams_SYNC, + OperationTimeout: durationpb.New(time.Second), + CancelAfter: durationpb.New(time.Second), + }, + }, + }, + opts: []options.RenameTablesOption{ + options.RenameTablesItem("from1", "to1", true), + }, + err: errUnexpectedRequest, + }, + { + sessionID: "4", + operationTimeout: time.Second, + operationCancelAfter: time.Second, + service: &renameTablesMock{}, + opts: nil, + err: errParamsRequired, + }, + } { + t.Run("", func(t *testing.T) { + err := renameTables(ctx, tt.sessionID, tt.operationTimeout, tt.operationCancelAfter, tt.service, tt.opts...) + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + } else { + require.NoError(t, err) + } + }) + } +} diff --git a/internal/topic/retriable_error.go b/internal/topic/retriable_error.go index 23ef3c49c..744aca97a 100644 --- a/internal/topic/retriable_error.go +++ b/internal/topic/retriable_error.go @@ -13,7 +13,7 @@ import ( ) const ( - DefaultStartTimeout = time.Minute + DefaultStartTimeout = value.InfiniteDuration connectionEstablishedTimeout = time.Minute ) @@ -41,7 +41,7 @@ type PublicCheckRetryResult struct { var ( PublicRetryDecisionDefault = PublicCheckRetryResult{val: 0} PublicRetryDecisionRetry = PublicCheckRetryResult{val: 1} - PublicRetryDecisionStop = PublicCheckRetryResult{val: 2} + PublicRetryDecisionStop = PublicCheckRetryResult{val: 2} //nolint:gomnd ) func CheckResetReconnectionCounters(lastTry, now time.Time, connectionTimeout time.Duration) bool { diff --git a/internal/topic/topicreaderinternal/commit_range.go b/internal/topic/topicreaderinternal/commit_range.go index c744cd49b..18d00b0d8 100644 --- a/internal/topic/topicreaderinternal/commit_range.go +++ b/internal/topic/topicreaderinternal/commit_range.go @@ -158,9 +158,7 @@ func (r *CommitRanges) toRawPartitionCommitOffset() []rawtopicreader.PartitionCo // PublicCommitRange contains data for commit messages range // -// # Experimental -// -// Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. +// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental type PublicCommitRange struct { priv commitRange } diff --git a/internal/topic/topicreaderinternal/committer.go b/internal/topic/topicreaderinternal/committer.go index c3f22849f..f0fa1c425 100644 --- a/internal/topic/topicreaderinternal/committer.go +++ b/internal/topic/topicreaderinternal/committer.go @@ -126,7 +126,7 @@ func (c *committer) pushCommitsLoop(ctx context.Context) { var commits CommitRanges c.m.WithLock(func() { commits = c.commits - c.commits = NewCommitRangesWithCapacity(commits.len() * 2) + c.commits = NewCommitRangesWithCapacity(commits.len() * 2) //nolint:gomnd }) if commits.len() == 0 && c.backgroundWorker.Context().Err() != nil { @@ -166,7 +166,10 @@ func (c *committer) waitSendTrigger(ctx context.Context) { return } - finish := c.clock.After(c.BufferTimeLagTrigger) + bufferTimeLagTriggerTimer := c.clock.NewTimer(c.BufferTimeLagTrigger) + defer bufferTimeLagTriggerTimer.Stop() + + finish := bufferTimeLagTriggerTimer.Chan() if c.BufferCountTrigger == 0 { select { case <-ctxDone: diff --git a/internal/topic/topicreaderinternal/stream_reader_impl.go b/internal/topic/topicreaderinternal/stream_reader_impl.go index 381ccd690..fec186ffc 100644 --- a/internal/topic/topicreaderinternal/stream_reader_impl.go +++ b/internal/topic/topicreaderinternal/stream_reader_impl.go @@ -22,6 +22,8 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/trace" ) +const defaultBufferSize = 1024 * 1024 + var ( PublicErrCommitSessionToExpiredSession = xerrors.Wrap(errors.New("ydb: commit to expired session")) @@ -73,7 +75,7 @@ type topicStreamReaderConfig struct { func newTopicStreamReaderConfig() topicStreamReaderConfig { return topicStreamReaderConfig{ BaseContext: context.Background(), - BufferSizeProtoBytes: 1024 * 1024, + BufferSizeProtoBytes: defaultBufferSize, Cred: credentials.NewAnonymousCredentials(), CredUpdateInterval: time.Hour, CommitMode: CommitModeAsync, diff --git a/internal/topic/topicreaderinternal/stream_reconnector.go b/internal/topic/topicreaderinternal/stream_reconnector.go index 393b0ecea..ec601ba67 100644 --- a/internal/topic/topicreaderinternal/stream_reconnector.go +++ b/internal/topic/topicreaderinternal/stream_reconnector.go @@ -328,9 +328,12 @@ func (r *readerReconnector) connectWithTimeout() (_ batchedStreamReader, err err result <- connectResult{stream: stream, err: err} }() + connectionTimoutTimer := r.clock.NewTimer(r.connectTimeout) + defer connectionTimoutTimer.Stop() + var res connectResult select { - case <-r.clock.After(r.connectTimeout): + case <-connectionTimoutTimer.Chan(): // cancel connection context only if timeout exceed while connection // because if cancel context after connect - it will break cancel() diff --git a/internal/topic/topicwriterinternal/encoders.go b/internal/topic/topicwriterinternal/encoders.go index 7ae89d534..a1ca73ad9 100644 --- a/internal/topic/topicwriterinternal/encoders.go +++ b/internal/topic/topicwriterinternal/encoders.go @@ -225,7 +225,7 @@ func cacheMessages(messages []messageWithDataContent, codec rawtopiccommon.Codec } // no need goroutines and synchronization for zero or one worker - if workerCount < 2 { + if workerCount < 2 { //nolint:gomnd for i := range messages { if _, err := messages[i].GetEncodedBytes(codec); err != nil { return err diff --git a/internal/topic/topicwriterinternal/queue.go b/internal/topic/topicwriterinternal/queue.go index 25ff072d3..799b02d16 100644 --- a/internal/topic/topicwriterinternal/queue.go +++ b/internal/topic/topicwriterinternal/queue.go @@ -21,6 +21,7 @@ var ( ) const ( + //nolint:gomnd intSize = 32 << (^uint(0) >> 63) // copy from math package for use in go <= 1.16 maxInt = 1<<(intSize-1) - 1 // copy from math package for use in go <= 1.16 minInt = -1 << (intSize - 1) // copy from math package for use in go <= 1.16 diff --git a/internal/topic/topicwriterinternal/writer_options.go b/internal/topic/topicwriterinternal/writer_options.go index 51b21b93d..5c88bdbb3 100644 --- a/internal/topic/topicwriterinternal/writer_options.go +++ b/internal/topic/topicwriterinternal/writer_options.go @@ -51,9 +51,7 @@ func WithTokenUpdateInterval(interval time.Duration) PublicWriterOption { // WithCommonConfig // -// # Experimental -// -// Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. +// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental func WithCommonConfig(common config.Common) PublicWriterOption { return func(cfg *WriterReconnectorConfig) { cfg.Common = common diff --git a/internal/topic/topicwriterinternal/writer_reconnector.go b/internal/topic/topicwriterinternal/writer_reconnector.go index dd7c1b72d..dd119e1c3 100644 --- a/internal/topic/topicwriterinternal/writer_reconnector.go +++ b/internal/topic/topicwriterinternal/writer_reconnector.go @@ -84,8 +84,8 @@ func newWriterReconnectorConfig(options ...PublicWriterOption) WriterReconnector }, AutoSetSeqNo: true, AutoSetCreatedTime: true, - MaxMessageSize: 50 * 1024 * 1024, - MaxQueueLen: 1000, + MaxMessageSize: 50 * 1024 * 1024, //nolint:gomnd + MaxQueueLen: 1000, //nolint:gomnd RetrySettings: topic.RetrySettings{ StartTimeout: topic.DefaultStartTimeout, }, @@ -380,16 +380,21 @@ func (w *WriterReconnector) connectionLoop(ctx context.Context) { prevAttemptTime = now if reconnectReason != nil { - if backoff, retry := topic.CheckRetryMode(reconnectReason, w.retrySettings, w.clock.Since(startOfRetries)); retry { + retryDuration := w.clock.Since(startOfRetries) + if backoff, retry := topic.CheckRetryMode(reconnectReason, w.retrySettings, retryDuration); retry { delay := backoff.Delay(attempt) + delayTimer := w.clock.NewTimer(delay) select { case <-doneCtx: + delayTimer.Stop() + return - case <-w.clock.After(delay): + case <-delayTimer.Chan(): + delayTimer.Stop() // no really need, stop for common style only // pass } } else { - _ = w.close(ctx, reconnectReason) + _ = w.close(ctx, fmt.Errorf("%w, was retried (%v)", reconnectReason, retryDuration)) return } diff --git a/internal/value/time.go b/internal/value/time.go index 37f7aa374..f8d836098 100644 --- a/internal/value/time.go +++ b/internal/value/time.go @@ -12,9 +12,11 @@ import ( const InfiniteDuration = time.Duration(math.MaxInt64) const ( - secondsPerMinute uint64 = 60 - secondsPerHour = 60 * secondsPerMinute - secondsPerDay = 24 * secondsPerHour + secondsPerMinute uint64 = 60 + secondsPerHour = 60 * secondsPerMinute + secondsPerDay = 24 * secondsPerHour + microsecondsPerSecond = 1e6 + nanosecondsPerMicrosecond = 1000 ) // Date format layouts described in time.Format and time.ANSIC docs. @@ -52,15 +54,15 @@ func DatetimeToTime(n uint32) time.Time { // TimestampToTime converts given microseconds to time.Time // Up to 586524-01-19 08:01:49.000551615 +0000 UTC. func TimestampToTime(n uint64) time.Time { - sec := n / 1e6 - nsec := (n - (sec * 1e6)) * 1000 + sec := n / microsecondsPerSecond + nsec := (n - (sec * microsecondsPerSecond)) * nanosecondsPerMicrosecond return time.Unix(int64(sec), int64(nsec)) } func TzDateToTime(s string) (t time.Time, err error) { ss := strings.Split(s, ",") - if len(ss) != 2 { + if len(ss) != 2 { //nolint:gomnd return t, xerrors.WithStackTrace(fmt.Errorf("not found timezone location in '%s'", s)) } location, err := time.LoadLocation(ss[1]) @@ -77,7 +79,7 @@ func TzDateToTime(s string) (t time.Time, err error) { func TzDatetimeToTime(s string) (t time.Time, err error) { ss := strings.Split(s, ",") - if len(ss) != 2 { + if len(ss) != 2 { //nolint:gomnd return t, xerrors.WithStackTrace(fmt.Errorf("not found timezone location in '%s'", s)) } location, err := time.LoadLocation(ss[1]) @@ -94,7 +96,7 @@ func TzDatetimeToTime(s string) (t time.Time, err error) { func TzTimestampToTime(s string) (t time.Time, err error) { ss := strings.Split(s, ",") - if len(ss) != 2 { + if len(ss) != 2 { //nolint:gomnd return t, xerrors.WithStackTrace(fmt.Errorf("not found timezone location in '%s'", s)) } location, err := time.LoadLocation(ss[1]) diff --git a/internal/value/value.go b/internal/value/value.go index 14a8b43f7..8052667cf 100644 --- a/internal/value/value.go +++ b/internal/value/value.go @@ -19,6 +19,11 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/internal/xstring" ) +const ( + decimalPrecision uint32 = 22 + decimalScale uint32 = 9 +) + type Value interface { Type() types.Type Yql() string @@ -1037,6 +1042,7 @@ func (v intervalValue) Yql() string { d = -d } buffer.WriteByte('P') + //nolint:gomnd if days := d / time.Hour / 24; days > 0 { d -= days * time.Hour * 24 //nolint:durationcheck buffer.WriteString(strconv.FormatInt(int64(days), 10)) @@ -2420,7 +2426,7 @@ func ZeroValue(t types.Type) Value { return values }()...) case *types.Decimal: - return DecimalValue([16]byte{}, 22, 9) + return DecimalValue([16]byte{}, decimalPrecision, decimalScale) default: panic(fmt.Sprintf("type '%T' have not a zero value", t)) diff --git a/internal/version/parse.go b/internal/version/parse.go index e901ed031..a57a14718 100644 --- a/internal/version/parse.go +++ b/internal/version/parse.go @@ -68,6 +68,7 @@ func Gte(lhs, rhs string) bool { return true } +//nolint:gomnd func parse(s string) (v version, err error) { ss := strings.SplitN(s, "-", 2) if len(ss) == 2 { diff --git a/internal/version/version.go b/internal/version/version.go index a20971e2f..0238c9656 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -2,8 +2,8 @@ package version const ( Major = "3" - Minor = "61" - Patch = "2" + Minor = "65" + Patch = "1" Prefix = "ydb-go-sdk" ) diff --git a/internal/xcontext/cancels_quard.go b/internal/xcontext/cancels_quard.go new file mode 100644 index 000000000..7fd344696 --- /dev/null +++ b/internal/xcontext/cancels_quard.go @@ -0,0 +1,38 @@ +package xcontext + +import ( + "context" + "sync" +) + +type CancelsGuard struct { + mu sync.Mutex + cancels map[*context.CancelFunc]struct{} +} + +func NewCancelsGuard() *CancelsGuard { + return &CancelsGuard{ + cancels: make(map[*context.CancelFunc]struct{}), + } +} + +func (g *CancelsGuard) Remember(cancel *context.CancelFunc) { + g.mu.Lock() + defer g.mu.Unlock() + g.cancels[cancel] = struct{}{} +} + +func (g *CancelsGuard) Forget(cancel *context.CancelFunc) { + g.mu.Lock() + defer g.mu.Unlock() + delete(g.cancels, cancel) +} + +func (g *CancelsGuard) Cancel() { + g.mu.Lock() + defer g.mu.Unlock() + for cancel := range g.cancels { + (*cancel)() + } + g.cancels = make(map[*context.CancelFunc]struct{}) +} diff --git a/internal/xcontext/cancels_quard_test.go b/internal/xcontext/cancels_quard_test.go new file mode 100644 index 000000000..98c2faf2c --- /dev/null +++ b/internal/xcontext/cancels_quard_test.go @@ -0,0 +1,24 @@ +package xcontext + +import ( + "testing" + + "github.com/stretchr/testify/require" + "golang.org/x/net/context" +) + +func TestCancelsGuard(t *testing.T) { + g := NewCancelsGuard() + ctx, cancel1 := context.WithCancel(context.Background()) + g.Remember(&cancel1) + require.Len(t, g.cancels, 1) + g.Forget(&cancel1) + require.Empty(t, g.cancels, 0) + cancel2 := context.CancelFunc(func() { + cancel1() + }) + g.Remember(&cancel2) + require.Len(t, g.cancels, 1) + g.Cancel() + require.Error(t, ctx.Err()) +} diff --git a/internal/xsql/connector.go b/internal/xsql/connector.go index da43852e9..8009f66d1 100644 --- a/internal/xsql/connector.go +++ b/internal/xsql/connector.go @@ -262,10 +262,14 @@ func (c *Connector) idleCloser() (idleStopper func()) { ctx, idleStopper = xcontext.WithCancel(context.Background()) go func() { for { + idleThresholdTimer := c.clock.NewTimer(c.idleThreshold) select { case <-ctx.Done(): + idleThresholdTimer.Stop() + return - case <-c.clock.After(c.idleThreshold): + case <-idleThresholdTimer.Chan(): + idleThresholdTimer.Stop() // no really need, stop for common style only c.connsMtx.RLock() conns := make([]*conn, 0, len(c.conns)) for cc := range c.conns { diff --git a/internal/xsync/last_usage_guard.go b/internal/xsync/last_usage_guard.go new file mode 100644 index 000000000..f11d5ba49 --- /dev/null +++ b/internal/xsync/last_usage_guard.go @@ -0,0 +1,62 @@ +package xsync + +import ( + "sync" + "sync/atomic" + "time" + + "github.com/jonboulle/clockwork" +) + +type ( + LastUsage interface { + Get() time.Time + Start() (stop func()) + } + lastUsage struct { + locks atomic.Int64 + t atomic.Pointer[time.Time] + clock clockwork.Clock + } + lastUsageOption func(g *lastUsage) +) + +func WithClock(clock clockwork.Clock) lastUsageOption { + return func(g *lastUsage) { + g.clock = clock + } +} + +func NewLastUsage(opts ...lastUsageOption) *lastUsage { + lastUsage := &lastUsage{ + clock: clockwork.NewRealClock(), + } + for _, opt := range opts { + opt(lastUsage) + } + + now := lastUsage.clock.Now() + + lastUsage.t.Store(&now) + + return lastUsage +} + +func (g *lastUsage) Get() time.Time { + if g.locks.Load() == 0 { + return *g.t.Load() + } + + return g.clock.Now() +} + +func (g *lastUsage) Start() (stop func()) { + g.locks.Add(1) + + return sync.OnceFunc(func() { + if g.locks.Add(-1) == 0 { + now := g.clock.Now() + g.t.Store(&now) + } + }) +} diff --git a/internal/conn/last_usage_test.go b/internal/xsync/last_usage_guard_test.go similarity index 97% rename from internal/conn/last_usage_test.go rename to internal/xsync/last_usage_guard_test.go index b7c79695e..52b390a8d 100644 --- a/internal/conn/last_usage_test.go +++ b/internal/xsync/last_usage_guard_test.go @@ -1,4 +1,4 @@ -package conn +package xsync import ( "testing" @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" ) -func Test_lastUsage_Lock(t *testing.T) { +func TestLastUsageGuardLock(t *testing.T) { t.Run("NowFromLocked", func(t *testing.T) { start := time.Unix(0, 0) clock := clockwork.NewFakeClockAt(start) diff --git a/meta.go b/meta.go index f039f40fe..34f192053 100644 --- a/meta.go +++ b/meta.go @@ -8,14 +8,18 @@ import ( // WithTraceID returns a copy of parent context with traceID // -// Deprecated: use meta.WithTraceID instead +// Deprecated: use meta.WithTraceID instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithTraceID(ctx context.Context, traceID string) context.Context { return meta.WithTraceID(ctx, traceID) } // WithRequestType returns a copy of parent context with custom request type // -// Deprecated: use meta.WithRequestType instead +// Deprecated: use meta.WithRequestType instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithRequestType(ctx context.Context, requestType string) context.Context { return meta.WithRequestType(ctx, requestType) } diff --git a/meta/context.go b/meta/context.go index 5ea200db6..3f8673003 100644 --- a/meta/context.go +++ b/meta/context.go @@ -15,7 +15,9 @@ func WithTraceID(ctx context.Context, traceID string) context.Context { // WithUserAgent returns a copy of parent context with custom user-agent info // -// Deprecated: use WithApplicationName instead +// Deprecated: use WithApplicationName instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithUserAgent(ctx context.Context, _ string) context.Context { return ctx } diff --git a/metrics/config.go b/metrics/config.go index 85902821f..e87f190c7 100644 --- a/metrics/config.go +++ b/metrics/config.go @@ -2,7 +2,9 @@ package metrics import "github.com/ydb-platform/ydb-go-sdk/v3/trace" -// Config is experimental interface for metrics registry config +// Config is interface for metrics registry config +// +// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental type Config interface { Registry diff --git a/metrics/driver.go b/metrics/driver.go index 5b2f12fbc..b477f8f3d 100644 --- a/metrics/driver.go +++ b/metrics/driver.go @@ -11,7 +11,7 @@ import ( // driver makes driver with New publishing func driver(config Config) (t trace.Driver) { config = config.WithSystem("driver") - endpoints := config.WithSystem("balancer").GaugeVec("endpoints", "local_dc", "az") + endpoints := config.WithSystem("balancer").GaugeVec("endpoints", "az") balancersDiscoveries := config.WithSystem("balancer").CounterVec("discoveries", "status", "cause") balancerUpdates := config.WithSystem("balancer").CounterVec("updates", "cause") conns := config.GaugeVec("conns", "endpoint", "node_id") @@ -20,8 +20,7 @@ func driver(config Config) (t trace.Driver) { tli := config.CounterVec("transaction_locks_invalidated") type endpointKey struct { - localDC bool - az string + az string } knownEndpoints := make(map[endpointKey]struct{}) @@ -100,8 +99,7 @@ func driver(config Config) (t trace.Driver) { newEndpoints := make(map[endpointKey]int, len(info.Endpoints)) for _, e := range info.Endpoints { e := endpointKey{ - localDC: e.LocalDC(), - az: e.Location(), + az: e.Location(), } newEndpoints[e]++ } @@ -109,16 +107,14 @@ func driver(config Config) (t trace.Driver) { if _, has := newEndpoints[e]; !has { delete(knownEndpoints, e) endpoints.With(map[string]string{ - "local_dc": strconv.FormatBool(e.localDC), - "az": e.az, + "az": e.az, }).Set(0) } } for e, count := range newEndpoints { knownEndpoints[e] = struct{}{} endpoints.With(map[string]string{ - "local_dc": strconv.FormatBool(e.localDC), - "az": e.az, + "az": e.az, }).Set(float64(count)) } } diff --git a/metrics/registry.go b/metrics/registry.go index 738afd886..efadda86f 100644 --- a/metrics/registry.go +++ b/metrics/registry.go @@ -1,6 +1,8 @@ package metrics -// Registry is experimental interface for metrics registry +// Registry is interface for metrics registry +// +// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental type Registry interface { // CounterVec returns CounterVec by name, subsystem and labels // If counter by args already created - return counter from cache diff --git a/options.go b/options.go index 9734b9b75..305f700fc 100644 --- a/options.go +++ b/options.go @@ -54,6 +54,19 @@ func WithAccessTokenCredentials(accessToken string) Option { ) } +// WithOauth2TokenExchangeCredentials adds credentials that exchange token using +// OAuth 2.0 token exchange protocol: +// https://www.rfc-editor.org/rfc/rfc8693 +func WithOauth2TokenExchangeCredentials( + opts ...credentials.Oauth2TokenExchangeCredentialsOption, +) Option { + opts = append(opts, credentials.WithSourceInfo("ydb.WithOauth2TokenExchangeCredentials(opts)")) + + return WithCreateCredentialsFunc(func(context.Context) (credentials.Credentials, error) { + return credentials.NewOauth2TokenExchangeCredentials(opts...) + }) +} + // WithApplicationName add provided application name to all api requests func WithApplicationName(applicationName string) Option { return func(ctx context.Context, c *Driver) error { @@ -65,7 +78,9 @@ func WithApplicationName(applicationName string) Option { // WithUserAgent add provided user agent value to all api requests // -// Deprecated: use WithApplicationName instead +// Deprecated: use WithApplicationName instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithUserAgent(userAgent string) Option { return func(ctx context.Context, c *Driver) error { c.options = append(c.options, config.WithApplicationName(userAgent)) @@ -432,6 +447,24 @@ func WithSessionPoolDeleteTimeout(deleteTimeout time.Duration) Option { } } +// WithSessionPoolKeepAliveMinSize set minimum sessions should be keeped alive in table.Client +// +// Deprecated: use WithApplicationName instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated +func WithSessionPoolKeepAliveMinSize(keepAliveMinSize int) Option { + return func(ctx context.Context, c *Driver) error { return nil } +} + +// WithSessionPoolKeepAliveTimeout set timeout of keep alive requests for session in table.Client +// +// Deprecated: use WithApplicationName instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated +func WithSessionPoolKeepAliveTimeout(keepAliveTimeout time.Duration) Option { + return func(ctx context.Context, c *Driver) error { return nil } +} + // WithIgnoreTruncated disables errors on truncated flag func WithIgnoreTruncated() Option { return func(ctx context.Context, c *Driver) error { diff --git a/params_builder.go b/params_builder.go index e9e3f5dfb..64768b55c 100644 --- a/params_builder.go +++ b/params_builder.go @@ -4,9 +4,7 @@ import "github.com/ydb-platform/ydb-go-sdk/v3/internal/params" // ParamsBuilder used for create query arguments instead of tons options. // -// # Experimental -// -// Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. +// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental func ParamsBuilder() params.Builder { return params.Builder{} } diff --git a/retry/context.go b/retry/context.go index a3898fc0b..282d9543e 100644 --- a/retry/context.go +++ b/retry/context.go @@ -7,19 +7,28 @@ type ( ) // WithIdempotentOperation returns a copy of parent context with idempotent operation feature -// Deprecated: use retry.WithIdempotent option instead +// +// Deprecated: use retry.WithIdempotent option instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithIdempotentOperation(ctx context.Context) context.Context { return context.WithValue(ctx, ctxIsOperationIdempotentKey{}, true) } // WithNonIdempotentOperation returns a copy of parent context with non-idempotent operation feature -// Deprecated: idempotent flag is false by default +// +// Deprecated: idempotent flag is false by default. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithNonIdempotentOperation(ctx context.Context) context.Context { return context.WithValue(ctx, ctxIsOperationIdempotentKey{}, false) } // IsOperationIdempotent returns the flag for retry with no idempotent errors -// Deprecated: context cannot store idempotent value now +// +// Deprecated: context cannot store idempotent value now. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func IsOperationIdempotent(ctx context.Context) bool { v, ok := ctx.Value(ctxIsOperationIdempotentKey{}).(bool) diff --git a/retry/errors_data_test.go b/retry/errors_data_test.go index 5253b505f..b2d5b2819 100644 --- a/retry/errors_data_test.go +++ b/retry/errors_data_test.go @@ -292,6 +292,17 @@ var errsToCheck = []struct { nonIdempotent: false, }, }, + { + err: xerrors.Operation( + xerrors.WithStatusCode(Ydb.StatusIds_EXTERNAL_ERROR), + ), + backoff: backoff.TypeNoBackoff, + deleteSession: false, + canRetry: map[idempotency]bool{ + idempotent: false, + nonIdempotent: false, + }, + }, { err: xerrors.Operation( xerrors.WithStatusCode(Ydb.StatusIds_ABORTED), diff --git a/retry/retry.go b/retry/retry.go index 1b847f3dc..43a112692 100644 --- a/retry/retry.go +++ b/retry/retry.go @@ -227,7 +227,7 @@ func WithPanicCallback(panicCallback func(e interface{})) panicCallbackOption { // // - retry operation returned nil as error // -// Warning: if deadline without deadline or cancellation func Retry will be worked infinite +// Warning: if context without deadline or cancellation func was passed, Retry will work infinitely. // // If you need to retry your op func on some logic errors - you must return RetryableError() from retryOperation // @@ -247,8 +247,10 @@ func Retry(ctx context.Context, op retryOperation, opts ...Option) (finalErr err if options.idempotent { ctx = xcontext.WithIdempotent(ctx, options.idempotent) } + defer func() { if finalErr != nil && options.stackTrace { + //nolint:gomnd finalErr = xerrors.WithStackTrace(finalErr, xerrors.WithSkipDepth(2), // 1 - exit from defer, 1 - exit from Retry call ) diff --git a/retry/sql.go b/retry/sql.go index affde98e2..9b826a1ca 100644 --- a/retry/sql.go +++ b/retry/sql.go @@ -32,7 +32,9 @@ func (retryOptions doRetryOptionsOption) ApplyDoOption(opts *doOptions) { } // WithDoRetryOptions specified retry options -// Deprecated: use implicit options instead +// Deprecated: use explicit options instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithDoRetryOptions(opts ...Option) doRetryOptionsOption { return opts } @@ -102,7 +104,9 @@ func (doTxRetryOptions doTxRetryOptionsOption) ApplyDoTxOption(o *doTxOptions) { } // WithDoTxRetryOptions specified retry options -// Deprecated: use implicit options instead +// Deprecated: use explicit options instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithDoTxRetryOptions(opts ...Option) doTxRetryOptionsOption { return opts } diff --git a/sugar/params.go b/sugar/params.go index 612268260..4285969a5 100644 --- a/sugar/params.go +++ b/sugar/params.go @@ -18,7 +18,10 @@ type constraint interface { // GenerateDeclareSection generates DECLARE section text in YQL query by params // -// Deprecated: use testutil.QueryBind(ydb.WithAutoDeclare()) helper +// Deprecated: use testutil.QueryBind(ydb.WithAutoDeclare()) helper. +// In YDB since version 24.1 declare sections not requires. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func GenerateDeclareSection[T constraint](parameters T) (string, error) { switch v := any(parameters).(type) { case *params.Parameters: @@ -36,7 +39,7 @@ func GenerateDeclareSection[T constraint](parameters T) (string, error) { // ToYdbParam converts // -// Deprecated: use testutil/QueryBind helper +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func ToYdbParam(param sql.NamedArg) (*params.Parameter, error) { params, err := bind.Params(param) if err != nil { diff --git a/sugar/result.go b/sugar/result.go index 33c2339d9..4a2275dcf 100644 --- a/sugar/result.go +++ b/sugar/result.go @@ -73,9 +73,7 @@ func (r *result) Close() error { // Result converts query.Result to iterable result for compatibility with table/result.Result usage // -// # Experimental -// -// Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. +// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental func Result(r query.Result) *result { return &result{ r: r, diff --git a/table/options/models.go b/table/options/models.go index 4692d9d4a..eb875e63d 100644 --- a/table/options/models.go +++ b/table/options/models.go @@ -421,7 +421,8 @@ func (kr KeyRange) String() string { } // Deprecated: use TimeToLiveSettings instead. -// Will be removed after Jan 2022. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated type TTLSettings struct { DateTimeColumn string TTLSeconds uint32 diff --git a/table/options/options.go b/table/options/options.go index db85556a7..922333a17 100644 --- a/table/options/options.go +++ b/table/options/options.go @@ -518,7 +518,9 @@ func WithPartitioningPolicyMode(mode PartitioningMode) PartitioningPolicyOption } } -// Deprecated: use WithUniformPartitions instead +// Deprecated: use WithUniformPartitions instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithPartitioningPolicyUniformPartitions(n uint64) PartitioningPolicyOption { return func(p *partitioningPolicy, a *allocator.Allocator) { p.Partitions = &Ydb_Table.PartitioningPolicy_UniformPartitions{ @@ -527,7 +529,9 @@ func WithPartitioningPolicyUniformPartitions(n uint64) PartitioningPolicyOption } } -// Deprecated: use WithExplicitPartitions instead +// Deprecated: use WithExplicitPartitions instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithPartitioningPolicyExplicitPartitions(splitPoints ...value.Value) PartitioningPolicyOption { return func(p *partitioningPolicy, a *allocator.Allocator) { values := make([]*Ydb.TypedValue, len(splitPoints)) @@ -806,6 +810,21 @@ func CopyTablesItem(src, dst string, omitIndexes bool) CopyTablesOption { } } +type ( + RenameTablesDesc Ydb_Table.RenameTablesRequest + RenameTablesOption func(desc *RenameTablesDesc) +) + +func RenameTablesItem(src, dst string, replaceDestination bool) RenameTablesOption { + return func(desc *RenameTablesDesc) { + desc.Tables = append(desc.Tables, &Ydb_Table.RenameTableItem{ + SourcePath: src, + DestinationPath: dst, + ReplaceDestination: replaceDestination, + }) + } +} + type ( ExecuteSchemeQueryDesc Ydb_Table.ExecuteSchemeQueryRequest ExecuteSchemeQueryOption func(*ExecuteSchemeQueryDesc) @@ -892,7 +911,8 @@ func WithIgnoreTruncated() ExecuteDataQueryOption { // WithQueryCachePolicyKeepInCache manages keep-in-cache policy // // Deprecated: data queries always executes with enabled keep-in-cache policy. -// Use WithKeepInCache for disabling keep-in-cache policy +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithQueryCachePolicyKeepInCache() QueryCachePolicyOption { return withQueryCachePolicyKeepInCache(true) } @@ -905,7 +925,9 @@ func withQueryCachePolicyKeepInCache(keepInCache bool) QueryCachePolicyOption { // WithQueryCachePolicy manages query cache policy // -// Deprecated: use WithKeepInCache for disabling keep-in-cache policy +// Deprecated: use WithKeepInCache for disabling keep-in-cache policy. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithQueryCachePolicy(opts ...QueryCachePolicyOption) ExecuteDataQueryOption { return withQueryCachePolicy(opts...) } diff --git a/table/table.go b/table/table.go index 6d2305a1e..1cb1ed8e0 100644 --- a/table/table.go +++ b/table/table.go @@ -39,8 +39,9 @@ type Client interface { // - context was canceled or deadlined // - session was created // - // Deprecated: don't use CreateSession explicitly. This method only for ORM's compatibility. - // Use Do for queries with session + // Deprecated: not for public usage. Because explicit session often leaked on server-side due to bad client-side usage. + // Will be removed after Oct 2024. + // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated CreateSession(ctx context.Context, opts ...Option) (s ClosableSession, err error) // Do provide the best effort for execute operation. @@ -111,6 +112,9 @@ type Session interface { opts ...options.AlterTableOption, ) (err error) + // Deprecated: use CopyTables method instead + // Will be removed after Oct 2024. + // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated CopyTable( ctx context.Context, dst, src string, @@ -122,6 +126,11 @@ type Session interface { opts ...options.CopyTablesOption, ) (err error) + RenameTables( + ctx context.Context, + opts ...options.RenameTablesOption, + ) (err error) + Explain( ctx context.Context, query string, diff --git a/table/types/cast.go b/table/types/cast.go index 71d8476ea..064967678 100644 --- a/table/types/cast.go +++ b/table/types/cast.go @@ -93,7 +93,9 @@ func VariantValue(v Value) (name string, idx uint32, _ Value, _ error) { // DictFields returns dict values from abstract Value // -// Deprecated: use DictValues instead +// Deprecated: use DictValues instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func DictFields(v Value) (map[Value]Value, error) { return DictValues(v) } diff --git a/table/types/types.go b/table/types/types.go index cca6b5c09..530ed77b0 100644 --- a/table/types/types.go +++ b/table/types/types.go @@ -7,6 +7,11 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/internal/types" ) +const ( + decimalPrecision uint32 = 22 + decimalScale uint32 = 9 +) + // Type describes YDB data types. type Type = types.Type @@ -76,7 +81,7 @@ func Optional(t Type) Type { return types.NewOptional(t) } -var DefaultDecimal = DecimalType(22, 9) +var DefaultDecimal = DecimalType(decimalPrecision, decimalScale) func DecimalType(precision, scale uint32) Type { return types.NewDecimal(precision, scale) @@ -120,7 +125,9 @@ const ( // WriteTypeStringTo writes ydb type string representation into buffer // -// Deprecated: use types.Type.Yql() instead +// Deprecated: use types.Type.Yql() instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WriteTypeStringTo(buf *bytes.Buffer, t Type) { //nolint: interfacer buf.WriteString(t.Yql()) } diff --git a/table/types/value.go b/table/types/value.go index 9249c4e3c..8f1ed8cb4 100644 --- a/table/types/value.go +++ b/table/types/value.go @@ -47,7 +47,9 @@ func IntervalValueFromMicroseconds(v int64) Value { return value.IntervalValue(v // IntervalValue makes Value from given microseconds value // -// Deprecated: use IntervalValueFromMicroseconds instead +// Deprecated: use IntervalValueFromMicroseconds instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func IntervalValue(v int64) Value { return value.IntervalValue(v) } // TzDateValue makes TzDate value from string @@ -117,7 +119,9 @@ func TzTimestampValueFromTime(t time.Time) Value { // StringValue returns bytes value // -// Deprecated: use BytesValue instead +// Deprecated: use BytesValue instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func StringValue(v []byte) Value { return value.BytesValue(v) } func BytesValue(v []byte) Value { return value.BytesValue(v) } @@ -345,7 +349,9 @@ func NullableTzTimestampValueFromTime(v *time.Time) Value { // NullableIntervalValue makes Value which maybe nil or valued // -// Deprecated: use NullableIntervalValueFromMicroseconds instead +// Deprecated: use NullableIntervalValueFromMicroseconds instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func NullableIntervalValue(v *int64) Value { return value.NullableIntervalValueFromMicroseconds(v) } @@ -360,7 +366,9 @@ func NullableIntervalValueFromDuration(v *time.Duration) Value { // NullableStringValue // -// Deprecated: use NullableBytesValue instead +// Deprecated: use NullableBytesValue instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func NullableStringValue(v *[]byte) Value { return value.NullableBytesValue(v) } diff --git a/tests/slo/database/sql/storage.go b/tests/slo/database/sql/storage.go index 6468764f0..8c740803c 100755 --- a/tests/slo/database/sql/storage.go +++ b/tests/slo/database/sql/storage.go @@ -77,7 +77,7 @@ type Storage struct { } func NewStorage(ctx context.Context, cfg *config.Config, poolSize int) (s *Storage, err error) { - ctx, cancel := context.WithTimeout(ctx, time.Minute*5) + ctx, cancel := context.WithTimeout(ctx, time.Minute*5) //nolint:gomnd defer cancel() s = &Storage{ diff --git a/tests/slo/go.mod b/tests/slo/go.mod index e8f010142..f0f99850d 100644 --- a/tests/slo/go.mod +++ b/tests/slo/go.mod @@ -6,7 +6,6 @@ require ( github.com/prometheus/client_golang v1.14.0 github.com/ydb-platform/gorm-driver v0.1.1 github.com/ydb-platform/ydb-go-sdk/v3 v3.58.0 - go.opentelemetry.io/otel v1.21.0 golang.org/x/sync v0.6.0 golang.org/x/time v0.3.0 gorm.io/gorm v1.25.1 @@ -16,13 +15,12 @@ require ( require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/go-logr/logr v1.4.1 // indirect - github.com/go-logr/stdr v1.2.2 // indirect github.com/goccy/go-json v0.9.11 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/golang/snappy v0.0.4 // indirect + github.com/google/go-cmp v0.6.0 // indirect github.com/google/uuid v1.5.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect @@ -37,13 +35,11 @@ require ( github.com/prometheus/procfs v0.8.0 // indirect github.com/syndtr/goleveldb v1.0.0 // indirect github.com/yandex-cloud/go-genproto v0.0.0-20230403093326-123923969dc6 // indirect - github.com/ydb-platform/ydb-go-genproto v0.0.0-20240126124512-dbb0e1720dbf // indirect + github.com/ydb-platform/ydb-go-genproto v0.0.0-20240316140903-4a47abca1cca // indirect github.com/ydb-platform/ydb-go-sdk-auth-environ v0.2.0 // indirect github.com/ydb-platform/ydb-go-yc v0.10.2 // indirect github.com/ydb-platform/ydb-go-yc-metadata v0.5.3 // indirect - go.opentelemetry.io/otel/metric v1.21.0 // indirect - go.opentelemetry.io/otel/trace v1.21.0 // indirect - golang.org/x/net v0.20.0 // indirect + golang.org/x/net v0.17.0 // indirect golang.org/x/sys v0.16.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917 // indirect diff --git a/tests/slo/go.sum b/tests/slo/go.sum index 78bb98723..59f24a544 100644 --- a/tests/slo/go.sum +++ b/tests/slo/go.sum @@ -733,11 +733,6 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9 github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= -github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= -github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= -github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= -github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-pdf/fpdf v0.5.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M= github.com/go-pdf/fpdf v0.6.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= @@ -1195,8 +1190,8 @@ github.com/ydb-platform/gorm-driver v0.1.1 h1:PkN+sGSJehOZn9jQIFEmAOfhE73FNDMq+u github.com/ydb-platform/gorm-driver v0.1.1/go.mod h1:Zv368SD5tHqkblmaOG6r2KTvtSIzPuB5p8rBaE6wVmw= github.com/ydb-platform/xorm v0.0.3 h1:MXk42lANB6r/MMLg/XdJfyXJycGUDlCeLiMlLGDKVPw= github.com/ydb-platform/xorm v0.0.3/go.mod h1:hFsU7EUF0o3S+l5c0eyP2yPVjJ0d4gsFdqCsyazzwBc= -github.com/ydb-platform/ydb-go-genproto v0.0.0-20240126124512-dbb0e1720dbf h1:ckwNHVo4bv2tqNkgx3W3HANh3ta1j6TR5qw08J1A7Tw= -github.com/ydb-platform/ydb-go-genproto v0.0.0-20240126124512-dbb0e1720dbf/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I= +github.com/ydb-platform/ydb-go-genproto v0.0.0-20240316140903-4a47abca1cca h1:PliQWLwi2gTSOk7QyYQ9GfjvvikmibLWmaplKHy+kfo= +github.com/ydb-platform/ydb-go-genproto v0.0.0-20240316140903-4a47abca1cca/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I= github.com/ydb-platform/ydb-go-sdk-auth-environ v0.2.0 h1:IG5bPd+Lqyc+zsw2kmxqfGLkaDHuAEnWX63/8RBBiA4= github.com/ydb-platform/ydb-go-sdk-auth-environ v0.2.0/go.mod h1:l6lZ+osdQOjDRBgRA4PQ06BuvmXN2neYjnRw8rCfd7s= github.com/ydb-platform/ydb-go-yc v0.10.2 h1:RAHy6g7ncxk1y0N4oS2MwYXLATqRqKBI6DYXuxpV2wo= @@ -1227,12 +1222,6 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= -go.opentelemetry.io/otel v1.21.0 h1:hzLeKBZEL7Okw2mGzZ0cc4k/A7Fta0uoPgaJCr8fsFc= -go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znnUvNNEo= -go.opentelemetry.io/otel/metric v1.21.0 h1:tlYWfeo+Bocx5kLEloTjbcDwBuELRrIFxwdQ36PlJu4= -go.opentelemetry.io/otel/metric v1.21.0/go.mod h1:o1p3CA8nNHW8j5yuQLdc1eeqEaPfzug24uvsyIEJRWM= -go.opentelemetry.io/otel/trace v1.21.0 h1:WD9i5gzvoUPuXIXH24ZNBudiarZDKuekPqi/E8fpfLc= -go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.opentelemetry.io/proto/otlp v0.15.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U= go.opentelemetry.io/proto/otlp v0.19.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U= @@ -1269,7 +1258,7 @@ golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= -golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -1398,9 +1387,8 @@ golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= -golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= -golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1550,7 +1538,7 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= @@ -1564,7 +1552,7 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= -golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/tests/slo/internal/config/config.go b/tests/slo/internal/config/config.go index b858d27b8..612bc0ae3 100644 --- a/tests/slo/internal/config/config.go +++ b/tests/slo/internal/config/config.go @@ -35,6 +35,7 @@ type Config struct { ShutdownTime int } +//nolint:gomnd func New() (*Config, error) { cfg := &Config{} diff --git a/tests/slo/internal/metrics/metrics.go b/tests/slo/internal/metrics/metrics.go index ee7778152..67b4af470 100644 --- a/tests/slo/internal/metrics/metrics.go +++ b/tests/slo/internal/metrics/metrics.go @@ -63,7 +63,7 @@ func New(url, label, jobName string) (*Metrics, error) { 0.99: 0, 1.0: 0, }, - MaxAge: 15 * time.Second, + MaxAge: 15 * time.Second, //nolint:gomnd }, []string{"status", "jobName"}, ) @@ -71,7 +71,7 @@ func New(url, label, jobName string) (*Metrics, error) { prometheus.HistogramOpts{ Name: "attempts", Help: "summary of amount for request", - Buckets: prometheus.LinearBuckets(1, 1, 10), + Buckets: prometheus.LinearBuckets(1, 1, 10), //nolint:gomnd }, []string{"status", "jobName"}, ) diff --git a/tests/slo/native/query/storage.go b/tests/slo/native/query/storage.go index 89377d012..4c0132adc 100755 --- a/tests/slo/native/query/storage.go +++ b/tests/slo/native/query/storage.go @@ -66,7 +66,7 @@ DROP TABLE %s ` func NewStorage(ctx context.Context, cfg *config.Config, poolSize int) (*Storage, error) { - ctx, cancel := context.WithTimeout(ctx, time.Minute*5) + ctx, cancel := context.WithTimeout(ctx, time.Minute*5) //nolint:gomnd defer cancel() db, err := ydb.Open(ctx, diff --git a/tests/slo/native/table/storage.go b/tests/slo/native/table/storage.go index b31f72a0e..220054aa0 100755 --- a/tests/slo/native/table/storage.go +++ b/tests/slo/native/table/storage.go @@ -65,7 +65,7 @@ type Storage struct { } func NewStorage(ctx context.Context, cfg *config.Config, poolSize int) (*Storage, error) { - ctx, cancel := context.WithTimeout(ctx, time.Minute*5) + ctx, cancel := context.WithTimeout(ctx, time.Minute*5) //nolint:gomnd defer cancel() db, err := ydb.Open( diff --git a/testutil/compare.go b/testutil/compare.go index a021ff909..8caf4b9bf 100644 --- a/testutil/compare.go +++ b/testutil/compare.go @@ -309,11 +309,11 @@ func compareBool(l, r *Ydb.Value) int { func compareDyNumber(l, r *Ydb.Value) (int, error) { ll := l.GetTextValue() rr := r.GetTextValue() - lf, _, err := big.ParseFloat(ll, 10, 127, big.ToNearestEven) + lf, _, err := big.ParseFloat(ll, 10, 127, big.ToNearestEven) //nolint:gomnd if err != nil { return 0, xerrors.WithStackTrace(err) } - rf, _, err := big.ParseFloat(rr, 10, 127, big.ToNearestEven) + rf, _, err := big.ParseFloat(rr, 10, 127, big.ToNearestEven) //nolint:gomnd if err != nil { return 0, err } diff --git a/topic/topicoptions/topicoptions_reader.go b/topic/topicoptions/topicoptions_reader.go index 549211688..862f4e7de 100644 --- a/topic/topicoptions/topicoptions_reader.go +++ b/topic/topicoptions/topicoptions_reader.go @@ -26,9 +26,7 @@ type ReaderOption = topicreaderinternal.PublicReaderOption // WithReaderOperationTimeout // -// # Experimental -// -// Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. +// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental func WithReaderOperationTimeout(timeout time.Duration) ReaderOption { return func(cfg *topicreaderinternal.ReaderConfig) { config.SetOperationTimeout(&cfg.Common, timeout) @@ -37,9 +35,7 @@ func WithReaderOperationTimeout(timeout time.Duration) ReaderOption { // WithReaderStartTimeout mean timeout for connect to reader stream and work some time without errors // -// # Experimental -// -// Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. +// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental func WithReaderStartTimeout(timeout time.Duration) ReaderOption { return func(cfg *topicreaderinternal.ReaderConfig) { cfg.RetrySettings.StartTimeout = timeout @@ -58,9 +54,7 @@ func WithReaderCheckRetryErrorFunction(callback CheckErrorRetryFunction) ReaderO // WithReaderOperationCancelAfter // -// # Experimental -// -// Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. +// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental func WithReaderOperationCancelAfter(cancelAfter time.Duration) ReaderOption { return func(cfg *topicreaderinternal.ReaderConfig) { config.SetOperationCancelAfter(&cfg.Common, cancelAfter) @@ -69,9 +63,7 @@ func WithReaderOperationCancelAfter(cancelAfter time.Duration) ReaderOption { // WithCommonConfig // -// # Experimental -// -// Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. +// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental func WithCommonConfig(common config.Common) ReaderOption { return func(cfg *topicreaderinternal.ReaderConfig) { cfg.Common = common @@ -79,8 +71,11 @@ func WithCommonConfig(common config.Common) ReaderOption { } // WithCommitTimeLagTrigger -// Deprecated: (was experimental) will be removed soon. -// Use WithReaderCommitTimeLagTrigger instead +// +// Deprecated: was experimental and not actual now. +// Use WithReaderCommitTimeLagTrigger instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithCommitTimeLagTrigger(lag time.Duration) ReaderOption { return WithReaderCommitTimeLagTrigger(lag) } @@ -96,8 +91,11 @@ func WithReaderCommitTimeLagTrigger(lag time.Duration) ReaderOption { } // WithCommitCountTrigger -// Deprecated: (was experimental) will be removed soon. -// Use WithReaderCommitCountTrigger instead +// +// Deprecated: was experimental and not actual now. +// Use WithReaderCommitCountTrigger instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithCommitCountTrigger(count int) ReaderOption { return WithReaderCommitCountTrigger(count) } @@ -115,9 +113,10 @@ func WithReaderCommitCountTrigger(count int) ReaderOption { // prefer min count messages in batch // sometimes batch can contain fewer messages, for example if local buffer is full and SDK can't receive more messages // -// Deprecated: (was experimental) the method will be removed soon. -// -// The option will be removed for simplify code internals +// Deprecated: was experimental and not actual now. +// The option will be removed for simplify code internals. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithBatchReadMinCount(count int) ReaderOption { return func(cfg *topicreaderinternal.ReaderConfig) { cfg.DefaultBatchConfig.MinCount = count @@ -125,8 +124,11 @@ func WithBatchReadMinCount(count int) ReaderOption { } // WithBatchReadMaxCount -// Deprecated: (was experimental) will be removed soon. +// +// Deprecated: was experimental and not actual now. // Use WithReaderBatchMaxCount instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithBatchReadMaxCount(count int) ReaderOption { return func(cfg *topicreaderinternal.ReaderConfig) { cfg.DefaultBatchConfig.MaxCount = count @@ -141,8 +143,11 @@ func WithReaderBatchMaxCount(count int) ReaderOption { } // WithMessagesBufferSize -// Deprecated: (was experimental) will be removed soon +// +// Deprecated: was experimental and not actual now. // Use WithReaderBufferSizeBytes instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithMessagesBufferSize(size int) ReaderOption { return WithReaderBufferSizeBytes(size) } @@ -191,8 +196,11 @@ const ( ) // WithCommitMode -// Deprecated: (was experimental) will be removed soon. +// +// Deprecated: was experimental and not actual now. // Use WithReaderCommitMode instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithCommitMode(mode CommitMode) ReaderOption { return WithReaderCommitMode(mode) } @@ -217,8 +225,11 @@ type ( ) // WithGetPartitionStartOffset -// Deprecated: (was experimental) will be removed soon. -// Use WithReaderGetPartitionStartOffset instead +// +// Deprecated: was experimental and not actual now. +// Use WithReaderGetPartitionStartOffset instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithGetPartitionStartOffset(f GetPartitionStartOffsetFunc) ReaderOption { return WithReaderGetPartitionStartOffset(f) } @@ -233,9 +244,7 @@ func WithReaderGetPartitionStartOffset(f GetPartitionStartOffsetFunc) ReaderOpti // WithReaderTrace set tracer for the topic reader // -// # Experimental -// -// Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. +// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental func WithReaderTrace(t trace.Topic) ReaderOption { //nolint:gocritic return func(cfg *topicreaderinternal.ReaderConfig) { cfg.Trace = cfg.Trace.Compose(&t) diff --git a/topic/topicoptions/topicoptions_topic.go b/topic/topicoptions/topicoptions_topic.go index f79b710e2..f14522866 100644 --- a/topic/topicoptions/topicoptions_topic.go +++ b/topic/topicoptions/topicoptions_topic.go @@ -10,16 +10,12 @@ import ( // TopicOption // -// # Experimental -// -// Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. +// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental type TopicOption func(c *topic.Config) // WithTrace defines trace over persqueue client calls // -// # Experimental -// -// Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. +// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental func WithTrace(trace trace.Topic, opts ...trace.TopicComposeOption) TopicOption { //nolint:gocritic return func(c *topic.Config) { c.Trace = c.Trace.Compose(&trace, opts...) @@ -32,9 +28,7 @@ func WithTrace(trace trace.Topic, opts ...trace.TopicComposeOption) TopicOption // the client. // If OperationTimeout is zero then no timeout is used. // -// # Experimental -// -// Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. +// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental func WithOperationTimeout(operationTimeout time.Duration) TopicOption { return func(c *topic.Config) { config.SetOperationTimeout(&c.Common, operationTimeout) @@ -47,9 +41,7 @@ func WithOperationTimeout(operationTimeout time.Duration) TopicOption { // processing will be continued. // If OperationCancelAfter is zero then no timeout is used. // -// # Experimental -// -// Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. +// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental func WithOperationCancelAfter(operationCancelAfter time.Duration) TopicOption { return func(c *topic.Config) { config.SetOperationCancelAfter(&c.Common, operationCancelAfter) diff --git a/topic/topicoptions/topicoptions_writer.go b/topic/topicoptions/topicoptions_writer.go index a29c501cb..86d4b9c57 100644 --- a/topic/topicoptions/topicoptions_writer.go +++ b/topic/topicoptions/topicoptions_writer.go @@ -45,9 +45,7 @@ func WithWriterCompressorCount(num int) WriterOption { // WithWriterMaxQueueLen set max len of queue for wait ack // -// # Experimental -// -// Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. +// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental func WithWriterMaxQueueLen(num int) WriterOption { return topicwriterinternal.WithMaxQueueLen(num) } @@ -61,8 +59,11 @@ func WithWriterMessageMaxBytesSize(size int) WriterOption { } // WithWriteSessionMeta -// Deprecated: (was experimental) will be removed soon. -// Use WithWriterSessionMeta instead +// +// Deprecated: was experimental and not actual now. +// Use WithWriterSessionMeta instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithWriteSessionMeta(meta map[string]string) WriterOption { return WithWriterSessionMeta(meta) } @@ -73,8 +74,11 @@ func WithWriterSessionMeta(meta map[string]string) WriterOption { } // WithProducerID -// Deprecated: (was experimental) will be removed soon. -// Use WithWriterProducerID instead +// +// Deprecated: was experimental and not actual now. +// Use WithWriterProducerID instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithProducerID(producerID string) WriterOption { return WithWriterProducerID(producerID) } @@ -85,8 +89,11 @@ func WithWriterProducerID(producerID string) WriterOption { } // WithPartitionID -// Deprecated: (was experimental) will be removed soon -// Use WithWriterPartitionID instead +// +// Deprecated: was experimental and not actual now. +// Use WithWriterPartitionID instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithPartitionID(partitionID int64) WriterOption { return WithWriterPartitionID(partitionID) } @@ -97,7 +104,11 @@ func WithWriterPartitionID(partitionID int64) WriterOption { } // WithSyncWrite -// Deprecated: (was experimental) use WithWriterWaitServerAck instead +// +// Deprecated: was experimental and not actual now. +// Use WithWriterWaitServerAck instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithSyncWrite(sync bool) WriterOption { return WithWriterWaitServerAck(sync) } @@ -110,17 +121,26 @@ func WithWriterWaitServerAck(wait bool) WriterOption { type ( // WithOnWriterConnectedInfo present information, received from server - // Deprecated: (was experimental) will be removed soon + // + // Deprecated: was experimental and not actual now. + // Will be removed after Oct 2024. + // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated WithOnWriterConnectedInfo = topicwriterinternal.PublicWithOnWriterConnectedInfo // OnWriterInitResponseCallback - // Deprecated: (was experimental) will be removed soon. + // + // Deprecated: was experimental and not actual now. + // Will be removed after Oct 2024. + // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated OnWriterInitResponseCallback = topicwriterinternal.PublicOnWriterInitResponseCallback ) // WithOnWriterFirstConnected set callback f, which will called once - after first successfully init topic writer stream -// Deprecated: (was experimental) will be removed soon. -// Use Writer.WaitInit function instead +// +// Deprecated: was experimental and not actual now. +// Use Writer.WaitInit function instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithOnWriterFirstConnected(f OnWriterInitResponseCallback) WriterOption { return func(cfg *topicwriterinternal.WriterReconnectorConfig) { cfg.OnWriterInitResponseCallback = f @@ -128,8 +148,11 @@ func WithOnWriterFirstConnected(f OnWriterInitResponseCallback) WriterOption { } // WithCodec -// Deprecated: (was experimental) will be removed soon. -// Use WithWriterCodec instead +// +// Deprecated: was experimental and not actual now. +// Use WithWriterCodec instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithCodec(codec topictypes.Codec) WriterOption { return WithWriterCodec(codec) } @@ -140,8 +163,11 @@ func WithWriterCodec(codec topictypes.Codec) WriterOption { } // WithCodecAutoSelect -// Deprecated: (was experimental) will be removed soon. +// +// Deprecated: was experimental and not actual now. // Use WithWriterCodecAutoSelect instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func WithCodecAutoSelect() WriterOption { return topicwriterinternal.WithAutoCodec() } diff --git a/topic/topicreader/batch_options.go b/topic/topicreader/batch_options.go index 166432535..2566f161c 100644 --- a/topic/topicreader/batch_options.go +++ b/topic/topicreader/batch_options.go @@ -22,8 +22,10 @@ func (count WithBatchMaxCount) Apply( // count must be 1 or greater // it will panic if count < 1 // -// Deprecated: (was experimental) will be removed soon. -// The option will be removed for simplify code internals +// Deprecated: was experimental and not actual now. +// The option will be removed for simplify code internals. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated type WithBatchPreferMinCount int // Apply implements ReadBatchOption interface diff --git a/topic/topicreader/reader.go b/topic/topicreader/reader.go index 9c50d4a51..ec8f43b5e 100644 --- a/topic/topicreader/reader.go +++ b/topic/topicreader/reader.go @@ -75,8 +75,11 @@ func (r *Reader) Commit(ctx context.Context, obj CommitRangeGetter) error { type CommitRangeGetter = topicreaderinternal.PublicCommitRangeGetter // ReadMessageBatch -// Deprecated: (was experimental) will be removed soon. +// +// Deprecated: was experimental and not actual now. // Use ReadMessagesBatch instead. +// Will be removed after Oct 2024. +// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated func (r *Reader) ReadMessageBatch(ctx context.Context, opts ...ReadBatchOption) (*Batch, error) { if err := r.inCall(&r.readInFlyght); err != nil { return nil, err diff --git a/trace/coordination.go b/trace/coordination.go index 8c9ac18a0..41ca39d2c 100644 --- a/trace/coordination.go +++ b/trace/coordination.go @@ -15,31 +15,53 @@ type ( // Coordination specified trace of coordination client activity. // gtrace:gen Coordination struct { - OnNew func(CoordinationNewStartInfo) func(CoordinationNewDoneInfo) - OnCreateNode func(CoordinationCreateNodeStartInfo) func(CoordinationCreateNodeDoneInfo) - OnAlterNode func(CoordinationAlterNodeStartInfo) func(CoordinationAlterNodeDoneInfo) - OnDropNode func(CoordinationDropNodeStartInfo) func(CoordinationDropNodeDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnNew func(CoordinationNewStartInfo) func(CoordinationNewDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnCreateNode func(CoordinationCreateNodeStartInfo) func(CoordinationCreateNodeDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnAlterNode func(CoordinationAlterNodeStartInfo) func(CoordinationAlterNodeDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnDropNode func(CoordinationDropNodeStartInfo) func(CoordinationDropNodeDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnDescribeNode func(CoordinationDescribeNodeStartInfo) func(CoordinationDescribeNodeDoneInfo) - OnSession func(CoordinationSessionStartInfo) func(CoordinationSessionDoneInfo) - OnClose func(CoordinationCloseStartInfo) func(CoordinationCloseDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnSession func(CoordinationSessionStartInfo) func(CoordinationSessionDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnClose func(CoordinationCloseStartInfo) func(CoordinationCloseDoneInfo) - OnStreamNew func(CoordinationStreamNewStartInfo) func(CoordinationStreamNewDoneInfo) - OnSessionStarted func(CoordinationSessionStartedInfo) - OnSessionStartTimeout func(CoordinationSessionStartTimeoutInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnStreamNew func(CoordinationStreamNewStartInfo) func(CoordinationStreamNewDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnSessionStarted func(CoordinationSessionStartedInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnSessionStartTimeout func(CoordinationSessionStartTimeoutInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnSessionKeepAliveTimeout func(CoordinationSessionKeepAliveTimeoutInfo) - OnSessionStopped func(CoordinationSessionStoppedInfo) - OnSessionStopTimeout func(CoordinationSessionStopTimeoutInfo) - OnSessionClientTimeout func(CoordinationSessionClientTimeoutInfo) - OnSessionServerExpire func(CoordinationSessionServerExpireInfo) - OnSessionServerError func(CoordinationSessionServerErrorInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnSessionStopped func(CoordinationSessionStoppedInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnSessionStopTimeout func(CoordinationSessionStopTimeoutInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnSessionClientTimeout func(CoordinationSessionClientTimeoutInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnSessionServerExpire func(CoordinationSessionServerExpireInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnSessionServerError func(CoordinationSessionServerErrorInfo) - OnSessionReceive func(CoordinationSessionReceiveStartInfo) func(CoordinationSessionReceiveDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnSessionReceive func(CoordinationSessionReceiveStartInfo) func(CoordinationSessionReceiveDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnSessionReceiveUnexpected func(CoordinationSessionReceiveUnexpectedInfo) - OnSessionStop func(CoordinationSessionStopInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnSessionStop func(CoordinationSessionStopInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnSessionStart func(CoordinationSessionStartStartInfo) func(CoordinationSessionStartDoneInfo) - OnSessionSend func(CoordinationSessionSendStartInfo) func(CoordinationSessionSendDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnSessionSend func(CoordinationSessionSendStartInfo) func(CoordinationSessionSendDoneInfo) } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationNewStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -48,7 +70,9 @@ type ( Context *context.Context Call call } - CoordinationNewDoneInfo struct{} + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + CoordinationNewDoneInfo struct{} + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationCloseStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -57,9 +81,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationCloseDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationCreateNodeStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -70,9 +96,11 @@ type ( Path string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationCreateNodeDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationAlterNodeStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -83,9 +111,11 @@ type ( Path string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationAlterNodeDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationDropNodeStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -96,9 +126,11 @@ type ( Path string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationDropNodeDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationDescribeNodeStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -109,9 +141,11 @@ type ( Path string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationDescribeNodeDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationSessionStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -122,59 +156,78 @@ type ( Path string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationSessionDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationStreamNewStartInfo struct{} - CoordinationStreamNewDoneInfo struct { + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + CoordinationStreamNewDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationSessionStartedInfo struct { SessionID uint64 ExpectedSessionID uint64 } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationSessionStartTimeoutInfo struct { Timeout time.Duration } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationSessionKeepAliveTimeoutInfo struct { LastGoodResponseTime time.Time Timeout time.Duration } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationSessionStoppedInfo struct { SessionID uint64 ExpectedSessionID uint64 } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationSessionStopTimeoutInfo struct { Timeout time.Duration } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationSessionClientTimeoutInfo struct { LastGoodResponseTime time.Time Timeout time.Duration } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationSessionServerExpireInfo struct { Failure *Ydb_Coordination.SessionResponse_Failure } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationSessionServerErrorInfo struct { Failure *Ydb_Coordination.SessionResponse_Failure } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationSessionReceiveStartInfo struct{} - CoordinationSessionReceiveDoneInfo struct { + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + CoordinationSessionReceiveDoneInfo struct { Response *Ydb_Coordination.SessionResponse Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationSessionReceiveUnexpectedInfo struct { Response *Ydb_Coordination.SessionResponse } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationSessionStartStartInfo struct{} - CoordinationSessionStartDoneInfo struct { + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + CoordinationSessionStartDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationSessionStopInfo struct { SessionID uint64 } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationSessionSendStartInfo struct { Request *Ydb_Coordination.SessionRequest } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals CoordinationSessionSendDoneInfo struct { Error error } diff --git a/trace/coordination_gtrace.go b/trace/coordination_gtrace.go index 91ccf3747..422f61153 100644 --- a/trace/coordination_gtrace.go +++ b/trace/coordination_gtrace.go @@ -15,9 +15,11 @@ type coordinationComposeOptions struct { } // CoordinationOption specified Coordination compose option +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals type CoordinationComposeOption func(o *coordinationComposeOptions) // WithCoordinationPanicCallback specified behavior on panic +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func WithCoordinationPanicCallback(cb func(e interface{})) CoordinationComposeOption { return func(o *coordinationComposeOptions) { o.panicCallback = cb @@ -25,6 +27,7 @@ func WithCoordinationPanicCallback(cb func(e interface{})) CoordinationComposeOp } // Compose returns a new Coordination which has functional fields composed both from t and x. +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func (t *Coordination) Compose(x *Coordination, opts ...CoordinationComposeOption) *Coordination { var ret Coordination options := coordinationComposeOptions{} @@ -845,6 +848,7 @@ func (t *Coordination) onSessionSend(c CoordinationSessionSendStartInfo) func(Co } return res } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnNew(t *Coordination, c *context.Context, call call) func() { var p CoordinationNewStartInfo p.Context = c @@ -855,6 +859,7 @@ func CoordinationOnNew(t *Coordination, c *context.Context, call call) func() { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnCreateNode(t *Coordination, c *context.Context, call call, path string) func(error) { var p CoordinationCreateNodeStartInfo p.Context = c @@ -867,6 +872,7 @@ func CoordinationOnCreateNode(t *Coordination, c *context.Context, call call, pa res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnAlterNode(t *Coordination, c *context.Context, call call, path string) func(error) { var p CoordinationAlterNodeStartInfo p.Context = c @@ -879,6 +885,7 @@ func CoordinationOnAlterNode(t *Coordination, c *context.Context, call call, pat res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnDropNode(t *Coordination, c *context.Context, call call, path string) func(error) { var p CoordinationDropNodeStartInfo p.Context = c @@ -891,6 +898,7 @@ func CoordinationOnDropNode(t *Coordination, c *context.Context, call call, path res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnDescribeNode(t *Coordination, c *context.Context, call call, path string) func(error) { var p CoordinationDescribeNodeStartInfo p.Context = c @@ -903,6 +911,7 @@ func CoordinationOnDescribeNode(t *Coordination, c *context.Context, call call, res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnSession(t *Coordination, c *context.Context, call call, path string) func(error) { var p CoordinationSessionStartInfo p.Context = c @@ -915,6 +924,7 @@ func CoordinationOnSession(t *Coordination, c *context.Context, call call, path res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnClose(t *Coordination, c *context.Context, call call) func(error) { var p CoordinationCloseStartInfo p.Context = c @@ -926,6 +936,7 @@ func CoordinationOnClose(t *Coordination, c *context.Context, call call) func(er res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnStreamNew(t *Coordination) func(error) { var p CoordinationStreamNewStartInfo res := t.onStreamNew(p) @@ -935,50 +946,59 @@ func CoordinationOnStreamNew(t *Coordination) func(error) { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnSessionStarted(t *Coordination, sessionID uint64, expectedSessionID uint64) { var p CoordinationSessionStartedInfo p.SessionID = sessionID p.ExpectedSessionID = expectedSessionID t.onSessionStarted(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnSessionStartTimeout(t *Coordination, timeout time.Duration) { var p CoordinationSessionStartTimeoutInfo p.Timeout = timeout t.onSessionStartTimeout(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnSessionKeepAliveTimeout(t *Coordination, lastGoodResponseTime time.Time, timeout time.Duration) { var p CoordinationSessionKeepAliveTimeoutInfo p.LastGoodResponseTime = lastGoodResponseTime p.Timeout = timeout t.onSessionKeepAliveTimeout(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnSessionStopped(t *Coordination, sessionID uint64, expectedSessionID uint64) { var p CoordinationSessionStoppedInfo p.SessionID = sessionID p.ExpectedSessionID = expectedSessionID t.onSessionStopped(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnSessionStopTimeout(t *Coordination, timeout time.Duration) { var p CoordinationSessionStopTimeoutInfo p.Timeout = timeout t.onSessionStopTimeout(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnSessionClientTimeout(t *Coordination, lastGoodResponseTime time.Time, timeout time.Duration) { var p CoordinationSessionClientTimeoutInfo p.LastGoodResponseTime = lastGoodResponseTime p.Timeout = timeout t.onSessionClientTimeout(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnSessionServerExpire(t *Coordination, failure *Ydb_Coordination.SessionResponse_Failure) { var p CoordinationSessionServerExpireInfo p.Failure = failure t.onSessionServerExpire(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnSessionServerError(t *Coordination, failure *Ydb_Coordination.SessionResponse_Failure) { var p CoordinationSessionServerErrorInfo p.Failure = failure t.onSessionServerError(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnSessionReceive(t *Coordination) func(response *Ydb_Coordination.SessionResponse, _ error) { var p CoordinationSessionReceiveStartInfo res := t.onSessionReceive(p) @@ -989,16 +1009,19 @@ func CoordinationOnSessionReceive(t *Coordination) func(response *Ydb_Coordinati res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnSessionReceiveUnexpected(t *Coordination, response *Ydb_Coordination.SessionResponse) { var p CoordinationSessionReceiveUnexpectedInfo p.Response = response t.onSessionReceiveUnexpected(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnSessionStop(t *Coordination, sessionID uint64) { var p CoordinationSessionStopInfo p.SessionID = sessionID t.onSessionStop(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnSessionStart(t *Coordination) func(error) { var p CoordinationSessionStartStartInfo res := t.onSessionStart(p) @@ -1008,6 +1031,7 @@ func CoordinationOnSessionStart(t *Coordination) func(error) { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func CoordinationOnSessionSend(t *Coordination, request *Ydb_Coordination.SessionRequest) func(error) { var p CoordinationSessionSendStartInfo p.Request = request diff --git a/trace/discovery.go b/trace/discovery.go index 5b0496eef..e2888cb46 100644 --- a/trace/discovery.go +++ b/trace/discovery.go @@ -9,10 +9,14 @@ import "context" type ( // Discovery specified trace of discovery client activity. // gtrace:gen + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals Discovery struct { + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnDiscover func(DiscoveryDiscoverStartInfo) func(DiscoveryDiscoverDoneInfo) - OnWhoAmI func(DiscoveryWhoAmIStartInfo) func(DiscoveryWhoAmIDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnWhoAmI func(DiscoveryWhoAmIStartInfo) func(DiscoveryWhoAmIDoneInfo) } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DiscoveryDiscoverStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -23,11 +27,13 @@ type ( Address string Database string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DiscoveryDiscoverDoneInfo struct { Location string Endpoints []EndpointInfo Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DiscoveryWhoAmIStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -36,6 +42,7 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DiscoveryWhoAmIDoneInfo struct { User string Groups []string diff --git a/trace/discovery_gtrace.go b/trace/discovery_gtrace.go index 362d5c0e5..20d40ebda 100644 --- a/trace/discovery_gtrace.go +++ b/trace/discovery_gtrace.go @@ -12,9 +12,11 @@ type discoveryComposeOptions struct { } // DiscoveryOption specified Discovery compose option +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals type DiscoveryComposeOption func(o *discoveryComposeOptions) // WithDiscoveryPanicCallback specified behavior on panic +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func WithDiscoveryPanicCallback(cb func(e interface{})) DiscoveryComposeOption { return func(o *discoveryComposeOptions) { o.panicCallback = cb @@ -22,6 +24,7 @@ func WithDiscoveryPanicCallback(cb func(e interface{})) DiscoveryComposeOption { } // Compose returns a new Discovery which has functional fields composed both from t and x. +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func (t *Discovery) Compose(x *Discovery, opts ...DiscoveryComposeOption) *Discovery { var ret Discovery options := discoveryComposeOptions{} @@ -132,6 +135,7 @@ func (t *Discovery) onWhoAmI(d DiscoveryWhoAmIStartInfo) func(DiscoveryWhoAmIDon } return res } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DiscoveryOnDiscover(t *Discovery, c *context.Context, call call, address string, database string) func(location string, endpoints []EndpointInfo, _ error) { var p DiscoveryDiscoverStartInfo p.Context = c @@ -147,6 +151,7 @@ func DiscoveryOnDiscover(t *Discovery, c *context.Context, call call, address st res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DiscoveryOnWhoAmI(t *Discovery, c *context.Context, call call) func(user string, groups []string, _ error) { var p DiscoveryWhoAmIStartInfo p.Context = c diff --git a/trace/driver.go b/trace/driver.go index e33dac555..8cf5dedc3 100644 --- a/trace/driver.go +++ b/trace/driver.go @@ -14,49 +14,73 @@ import ( type ( // Driver specified trace of common driver activity. // gtrace:gen + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals Driver struct { // Driver runtime events - OnInit func(DriverInitStartInfo) func(DriverInitDoneInfo) - OnWith func(DriverWithStartInfo) func(DriverWithDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnInit func(DriverInitStartInfo) func(DriverInitDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnWith func(DriverWithStartInfo) func(DriverWithDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnClose func(DriverCloseStartInfo) func(DriverCloseDoneInfo) // Pool of connections - OnPoolNew func(DriverConnPoolNewStartInfo) func(DriverConnPoolNewDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnPoolNew func(DriverConnPoolNewStartInfo) func(DriverConnPoolNewDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnPoolRelease func(DriverConnPoolReleaseStartInfo) func(DriverConnPoolReleaseDoneInfo) // Resolver events + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnResolve func(DriverResolveStartInfo) func(DriverResolveDoneInfo) // Conn events - OnConnStateChange func(DriverConnStateChangeStartInfo) func(DriverConnStateChangeDoneInfo) - OnConnInvoke func(DriverConnInvokeStartInfo) func(DriverConnInvokeDoneInfo) - OnConnNewStream func(DriverConnNewStreamStartInfo) func(DriverConnNewStreamDoneInfo) - OnConnStreamRecvMsg func(DriverConnStreamRecvMsgStartInfo) func(DriverConnStreamRecvMsgDoneInfo) - OnConnStreamSendMsg func(DriverConnStreamSendMsgStartInfo) func(DriverConnStreamSendMsgDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnConnStateChange func(DriverConnStateChangeStartInfo) func(DriverConnStateChangeDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnConnInvoke func(DriverConnInvokeStartInfo) func(DriverConnInvokeDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnConnNewStream func(DriverConnNewStreamStartInfo) func(DriverConnNewStreamDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnConnStreamRecvMsg func(DriverConnStreamRecvMsgStartInfo) func(DriverConnStreamRecvMsgDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnConnStreamSendMsg func(DriverConnStreamSendMsgStartInfo) func(DriverConnStreamSendMsgDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnConnStreamCloseSend func(DriverConnStreamCloseSendStartInfo) func(DriverConnStreamCloseSendDoneInfo) - OnConnDial func(DriverConnDialStartInfo) func(DriverConnDialDoneInfo) - OnConnBan func(DriverConnBanStartInfo) func(DriverConnBanDoneInfo) - OnConnAllow func(DriverConnAllowStartInfo) func(DriverConnAllowDoneInfo) - OnConnPark func(DriverConnParkStartInfo) func(DriverConnParkDoneInfo) - OnConnClose func(DriverConnCloseStartInfo) func(DriverConnCloseDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnConnDial func(DriverConnDialStartInfo) func(DriverConnDialDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnConnBan func(DriverConnBanStartInfo) func(DriverConnBanDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnConnAllow func(DriverConnAllowStartInfo) func(DriverConnAllowDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnConnPark func(DriverConnParkStartInfo) func(DriverConnParkDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnConnClose func(DriverConnCloseStartInfo) func(DriverConnCloseDoneInfo) // Repeater events + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnRepeaterWakeUp func(DriverRepeaterWakeUpStartInfo) func(DriverRepeaterWakeUpDoneInfo) // Balancer events + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnBalancerInit func(DriverBalancerInitStartInfo) func(DriverBalancerInitDoneInfo) - OnBalancerClose func(DriverBalancerCloseStartInfo) func(DriverBalancerCloseDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnBalancerClose func(DriverBalancerCloseStartInfo) func(DriverBalancerCloseDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnBalancerChooseEndpoint func( DriverBalancerChooseEndpointStartInfo, ) func( DriverBalancerChooseEndpointDoneInfo, ) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnBalancerClusterDiscoveryAttempt func( DriverBalancerClusterDiscoveryAttemptStartInfo, ) func( DriverBalancerClusterDiscoveryAttemptDoneInfo, ) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnBalancerUpdate func(DriverBalancerUpdateStartInfo) func(DriverBalancerUpdateDoneInfo) // Credentials events @@ -65,9 +89,11 @@ type ( ) // Method represents rpc method. +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals type Method string // Name returns the rpc method name. +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func (m Method) Name() (s string) { _, s = m.Split() @@ -75,6 +101,7 @@ func (m Method) Name() (s string) { } // Service returns the rpc service name. +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func (m Method) Service() (s string) { s, _ = m.Split() @@ -82,6 +109,7 @@ func (m Method) Service() (s string) { } // Issue declare interface of operation error issues +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals type Issue interface { GetMessage() string GetIssueCode() uint32 @@ -89,6 +117,7 @@ type Issue interface { } // Split returns service name and method. +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func (m Method) Split() (service, method string) { i := strings.LastIndex(string(m), "/") if i == -1 { @@ -98,6 +127,7 @@ func (m Method) Split() (service, method string) { return strings.TrimPrefix(string(m[:i]), "/"), string(m[i+1:]) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals type ConnState interface { fmt.Stringer @@ -105,18 +135,25 @@ type ConnState interface { Code() int } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals type EndpointInfo interface { fmt.Stringer NodeID() uint32 Address() string - LocalDC() bool Location() string LoadFactor() float32 LastUpdated() time.Time + + // Deprecated: LocalDC check "local" by compare endpoint location with discovery "selflocation" field. + // It work good only if connection url always point to local dc. + // Will be removed after Oct 2024. + // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated + LocalDC() bool } type ( + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnStateChangeStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -127,17 +164,21 @@ type ( Endpoint EndpointInfo State ConnState } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnStateChangeDoneInfo struct { State ConnState } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverResolveStartInfo struct { Call call Target string Resolved []string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverResolveDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverBalancerUpdateStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -147,12 +188,14 @@ type ( Call call NeedLocalDC bool } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverBalancerUpdateDoneInfo struct { Endpoints []EndpointInfo Added []EndpointInfo Dropped []EndpointInfo LocalDC string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverBalancerClusterDiscoveryAttemptStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -162,27 +205,33 @@ type ( Call call Address string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverBalancerClusterDiscoveryAttemptDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverNetReadStartInfo struct { Call call Address string Buffer int } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverNetReadDoneInfo struct { Received int Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverNetWriteStartInfo struct { Call call Address string Bytes int } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverNetWriteDoneInfo struct { Sent int Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverNetDialStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -192,16 +241,20 @@ type ( Call call Address string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverNetDialDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverNetCloseStartInfo struct { Call call Address string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverNetCloseDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnTakeStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -211,9 +264,11 @@ type ( Call call Endpoint EndpointInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnTakeDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnDialStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -223,9 +278,11 @@ type ( Call call Endpoint EndpointInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnDialDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnParkStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -235,9 +292,11 @@ type ( Call call Endpoint EndpointInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnParkDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnCloseStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -247,9 +306,11 @@ type ( Call call Endpoint EndpointInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnCloseDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnBanStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -261,9 +322,11 @@ type ( State ConnState Cause error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnBanDoneInfo struct { State ConnState } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnAllowStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -274,9 +337,11 @@ type ( Endpoint EndpointInfo State ConnState } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnAllowDoneInfo struct { State ConnState } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnInvokeStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -287,6 +352,7 @@ type ( Endpoint EndpointInfo Method Method } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnInvokeDoneInfo struct { Error error Issues []Issue @@ -294,6 +360,7 @@ type ( State ConnState Metadata map[string][]string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnNewStreamStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -304,10 +371,12 @@ type ( Endpoint EndpointInfo Method Method } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnNewStreamDoneInfo struct { Error error State ConnState } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnStreamRecvMsgStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -316,9 +385,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnStreamRecvMsgDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnStreamSendMsgStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -327,9 +398,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnStreamSendMsgDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnStreamCloseSendStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -338,9 +411,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnStreamCloseSendDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverBalancerInitStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -350,9 +425,11 @@ type ( Call call Name string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverBalancerInitDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverBalancerDialEntrypointStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -362,9 +439,11 @@ type ( Call call Address string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverBalancerDialEntrypointDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverBalancerCloseStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -373,9 +452,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverBalancerCloseDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverBalancerChooseEndpointStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -384,10 +465,12 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverBalancerChooseEndpointDoneInfo struct { Endpoint EndpointInfo Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverRepeaterWakeUpStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -398,9 +481,11 @@ type ( Name string Event string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverRepeaterWakeUpDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverGetCredentialsStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -409,10 +494,12 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverGetCredentialsDoneInfo struct { Token string Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverInitStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -424,9 +511,11 @@ type ( Database string Secure bool } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverInitDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverWithStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -438,9 +527,11 @@ type ( Database string Secure bool } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverWithDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnPoolNewStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -449,7 +540,9 @@ type ( Context *context.Context Call call } - DriverConnPoolNewDoneInfo struct{} + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + DriverConnPoolNewDoneInfo struct{} + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnPoolReleaseStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -458,9 +551,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverConnPoolReleaseDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverCloseStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -469,6 +564,7 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DriverCloseDoneInfo struct { Error error } diff --git a/trace/driver_gtrace.go b/trace/driver_gtrace.go index 4e737f5db..50491225a 100644 --- a/trace/driver_gtrace.go +++ b/trace/driver_gtrace.go @@ -12,9 +12,11 @@ type driverComposeOptions struct { } // DriverOption specified Driver compose option +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals type DriverComposeOption func(o *driverComposeOptions) // WithDriverPanicCallback specified behavior on panic +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func WithDriverPanicCallback(cb func(e interface{})) DriverComposeOption { return func(o *driverComposeOptions) { o.panicCallback = cb @@ -22,6 +24,7 @@ func WithDriverPanicCallback(cb func(e interface{})) DriverComposeOption { } // Compose returns a new Driver which has functional fields composed both from t and x. +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func (t *Driver) Compose(x *Driver, opts ...DriverComposeOption) *Driver { var ret Driver options := driverComposeOptions{} @@ -1232,6 +1235,7 @@ func (t *Driver) onGetCredentials(d DriverGetCredentialsStartInfo) func(DriverGe } return res } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnInit(t *Driver, c *context.Context, call call, endpoint string, database string, secure bool) func(error) { var p DriverInitStartInfo p.Context = c @@ -1246,6 +1250,7 @@ func DriverOnInit(t *Driver, c *context.Context, call call, endpoint string, dat res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnWith(t *Driver, c *context.Context, call call, endpoint string, database string, secure bool) func(error) { var p DriverWithStartInfo p.Context = c @@ -1260,6 +1265,7 @@ func DriverOnWith(t *Driver, c *context.Context, call call, endpoint string, dat res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnClose(t *Driver, c *context.Context, call call) func(error) { var p DriverCloseStartInfo p.Context = c @@ -1271,6 +1277,7 @@ func DriverOnClose(t *Driver, c *context.Context, call call) func(error) { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnPoolNew(t *Driver, c *context.Context, call call) func() { var p DriverConnPoolNewStartInfo p.Context = c @@ -1281,6 +1288,7 @@ func DriverOnPoolNew(t *Driver, c *context.Context, call call) func() { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnPoolRelease(t *Driver, c *context.Context, call call) func(error) { var p DriverConnPoolReleaseStartInfo p.Context = c @@ -1292,6 +1300,7 @@ func DriverOnPoolRelease(t *Driver, c *context.Context, call call) func(error) { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnResolve(t *Driver, call call, target string, resolved []string) func(error) { var p DriverResolveStartInfo p.Call = call @@ -1304,6 +1313,7 @@ func DriverOnResolve(t *Driver, call call, target string, resolved []string) fun res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnConnStateChange(t *Driver, c *context.Context, call call, endpoint EndpointInfo, state ConnState) func(state ConnState) { var p DriverConnStateChangeStartInfo p.Context = c @@ -1317,6 +1327,7 @@ func DriverOnConnStateChange(t *Driver, c *context.Context, call call, endpoint res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnConnInvoke(t *Driver, c *context.Context, call call, endpoint EndpointInfo, m Method) func(_ error, issues []Issue, opID string, state ConnState, metadata map[string][]string) { var p DriverConnInvokeStartInfo p.Context = c @@ -1334,6 +1345,7 @@ func DriverOnConnInvoke(t *Driver, c *context.Context, call call, endpoint Endpo res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnConnNewStream(t *Driver, c *context.Context, call call, endpoint EndpointInfo, m Method) func(_ error, state ConnState) { var p DriverConnNewStreamStartInfo p.Context = c @@ -1348,6 +1360,7 @@ func DriverOnConnNewStream(t *Driver, c *context.Context, call call, endpoint En res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnConnStreamRecvMsg(t *Driver, c *context.Context, call call) func(error) { var p DriverConnStreamRecvMsgStartInfo p.Context = c @@ -1359,6 +1372,7 @@ func DriverOnConnStreamRecvMsg(t *Driver, c *context.Context, call call) func(er res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnConnStreamSendMsg(t *Driver, c *context.Context, call call) func(error) { var p DriverConnStreamSendMsgStartInfo p.Context = c @@ -1370,6 +1384,7 @@ func DriverOnConnStreamSendMsg(t *Driver, c *context.Context, call call) func(er res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnConnStreamCloseSend(t *Driver, c *context.Context, call call) func(error) { var p DriverConnStreamCloseSendStartInfo p.Context = c @@ -1381,6 +1396,7 @@ func DriverOnConnStreamCloseSend(t *Driver, c *context.Context, call call) func( res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnConnDial(t *Driver, c *context.Context, call call, endpoint EndpointInfo) func(error) { var p DriverConnDialStartInfo p.Context = c @@ -1393,6 +1409,7 @@ func DriverOnConnDial(t *Driver, c *context.Context, call call, endpoint Endpoin res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnConnBan(t *Driver, c *context.Context, call call, endpoint EndpointInfo, state ConnState, cause error) func(state ConnState) { var p DriverConnBanStartInfo p.Context = c @@ -1407,6 +1424,7 @@ func DriverOnConnBan(t *Driver, c *context.Context, call call, endpoint Endpoint res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnConnAllow(t *Driver, c *context.Context, call call, endpoint EndpointInfo, state ConnState) func(state ConnState) { var p DriverConnAllowStartInfo p.Context = c @@ -1420,6 +1438,7 @@ func DriverOnConnAllow(t *Driver, c *context.Context, call call, endpoint Endpoi res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnConnPark(t *Driver, c *context.Context, call call, endpoint EndpointInfo) func(error) { var p DriverConnParkStartInfo p.Context = c @@ -1432,6 +1451,7 @@ func DriverOnConnPark(t *Driver, c *context.Context, call call, endpoint Endpoin res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnConnClose(t *Driver, c *context.Context, call call, endpoint EndpointInfo) func(error) { var p DriverConnCloseStartInfo p.Context = c @@ -1444,6 +1464,7 @@ func DriverOnConnClose(t *Driver, c *context.Context, call call, endpoint Endpoi res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnRepeaterWakeUp(t *Driver, c *context.Context, call call, name string, event string) func(error) { var p DriverRepeaterWakeUpStartInfo p.Context = c @@ -1457,6 +1478,7 @@ func DriverOnRepeaterWakeUp(t *Driver, c *context.Context, call call, name strin res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnBalancerInit(t *Driver, c *context.Context, call call, name string) func(error) { var p DriverBalancerInitStartInfo p.Context = c @@ -1469,6 +1491,7 @@ func DriverOnBalancerInit(t *Driver, c *context.Context, call call, name string) res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnBalancerClose(t *Driver, c *context.Context, call call) func(error) { var p DriverBalancerCloseStartInfo p.Context = c @@ -1480,6 +1503,7 @@ func DriverOnBalancerClose(t *Driver, c *context.Context, call call) func(error) res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnBalancerChooseEndpoint(t *Driver, c *context.Context, call call) func(endpoint EndpointInfo, _ error) { var p DriverBalancerChooseEndpointStartInfo p.Context = c @@ -1492,6 +1516,7 @@ func DriverOnBalancerChooseEndpoint(t *Driver, c *context.Context, call call) fu res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnBalancerClusterDiscoveryAttempt(t *Driver, c *context.Context, call call, address string) func(error) { var p DriverBalancerClusterDiscoveryAttemptStartInfo p.Context = c @@ -1504,6 +1529,7 @@ func DriverOnBalancerClusterDiscoveryAttempt(t *Driver, c *context.Context, call res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnBalancerUpdate(t *Driver, c *context.Context, call call, needLocalDC bool) func(endpoints []EndpointInfo, added []EndpointInfo, dropped []EndpointInfo, localDC string) { var p DriverBalancerUpdateStartInfo p.Context = c @@ -1519,6 +1545,7 @@ func DriverOnBalancerUpdate(t *Driver, c *context.Context, call call, needLocalD res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DriverOnGetCredentials(t *Driver, c *context.Context, call call) func(token string, _ error) { var p DriverGetCredentialsStartInfo p.Context = c diff --git a/trace/query.go b/trace/query.go index aefb54ddd..3fbaef522 100644 --- a/trace/query.go +++ b/trace/query.go @@ -20,25 +20,42 @@ type ( // Query specified trace of retry call activity. // gtrace:gen + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals Query struct { - OnNew func(QueryNewStartInfo) func(info QueryNewDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnNew func(QueryNewStartInfo) func(info QueryNewDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnClose func(QueryCloseStartInfo) func(info QueryCloseDoneInfo) - OnPoolNew func(QueryPoolNewStartInfo) func(QueryPoolNewDoneInfo) - OnPoolClose func(QueryPoolCloseStartInfo) func(QueryPoolCloseDoneInfo) - OnPoolTry func(QueryPoolTryStartInfo) func(QueryPoolTryDoneInfo) - OnPoolWith func(QueryPoolWithStartInfo) func(QueryPoolWithDoneInfo) - OnPoolPut func(QueryPoolPutStartInfo) func(QueryPoolPutDoneInfo) - OnPoolGet func(QueryPoolGetStartInfo) func(QueryPoolGetDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnPoolNew func(QueryPoolNewStartInfo) func(QueryPoolNewDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnPoolClose func(QueryPoolCloseStartInfo) func(QueryPoolCloseDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnPoolTry func(QueryPoolTryStartInfo) func(QueryPoolTryDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnPoolWith func(QueryPoolWithStartInfo) func(QueryPoolWithDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnPoolPut func(QueryPoolPutStartInfo) func(QueryPoolPutDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnPoolGet func(QueryPoolGetStartInfo) func(QueryPoolGetDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnPoolChange func(QueryPoolChange) - OnDo func(QueryDoStartInfo) func(QueryDoDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnDo func(QueryDoStartInfo) func(QueryDoDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnDoTx func(QueryDoTxStartInfo) func(QueryDoTxDoneInfo) - OnSessionCreate func(QuerySessionCreateStartInfo) func(info QuerySessionCreateDoneInfo) - OnSessionAttach func(QuerySessionAttachStartInfo) func(info QuerySessionAttachDoneInfo) - OnSessionDelete func(QuerySessionDeleteStartInfo) func(info QuerySessionDeleteDoneInfo) - OnSessionExecute func(QuerySessionExecuteStartInfo) func(info QuerySessionExecuteDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnSessionCreate func(QuerySessionCreateStartInfo) func(info QuerySessionCreateDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnSessionAttach func(QuerySessionAttachStartInfo) func(info QuerySessionAttachDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnSessionDelete func(QuerySessionDeleteStartInfo) func(info QuerySessionDeleteDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnSessionExecute func(QuerySessionExecuteStartInfo) func(info QuerySessionExecuteDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnSessionBegin func(QuerySessionBeginStartInfo) func(info QuerySessionBeginDoneInfo) OnTxExecute func(QueryTxExecuteStartInfo) func(info QueryTxExecuteDoneInfo) OnResultNew func(QueryResultNewStartInfo) func(info QueryResultNewDoneInfo) @@ -51,6 +68,7 @@ type ( OnRowScanStruct func(QueryRowScanStructStartInfo) func(info QueryRowScanStructDoneInfo) } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryDoStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -59,10 +77,12 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryDoDoneInfo struct { Attempts int Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryDoTxStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -71,10 +91,12 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryDoTxDoneInfo struct { Attempts int Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QuerySessionCreateStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -83,10 +105,12 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QuerySessionCreateDoneInfo struct { Session querySessionInfo Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QuerySessionExecuteStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -98,9 +122,11 @@ type ( Session querySessionInfo Query string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QuerySessionExecuteDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryTxExecuteStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -113,9 +139,11 @@ type ( Tx queryTransactionInfo Query string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryTxExecuteDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QuerySessionAttachStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -125,9 +153,11 @@ type ( Call call Session querySessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QuerySessionAttachDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QuerySessionBeginStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -137,10 +167,12 @@ type ( Call call Session querySessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QuerySessionBeginDoneInfo struct { Error error Tx queryTransactionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryResultNewStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -149,9 +181,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryResultNewDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryResultCloseStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -160,9 +194,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryResultCloseDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryResultNextPartStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -171,9 +207,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryResultNextPartDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryResultNextResultSetStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -182,9 +220,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryResultNextResultSetDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryResultSetNextRowStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -193,9 +233,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryResultSetNextRowDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryRowScanStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -204,9 +246,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryRowScanDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryRowScanNamedStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -215,9 +259,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryRowScanNamedDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryRowScanStructStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -226,9 +272,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryRowScanStructDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QuerySessionDeleteStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -238,9 +286,11 @@ type ( Call call Session querySessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QuerySessionDeleteDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryNewStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -249,7 +299,9 @@ type ( Context *context.Context Call call } - QueryNewDoneInfo struct{} + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + QueryNewDoneInfo struct{} + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryCloseStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -258,9 +310,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryCloseDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryPoolNewStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -269,9 +323,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryPoolNewDoneInfo struct { Limit int } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryPoolCloseStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -280,9 +336,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryPoolCloseDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryPoolTryStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -291,9 +349,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryPoolTryDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryPoolWithStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -302,11 +362,13 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryPoolWithDoneInfo struct { Error error Attempts int } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryPoolPutStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -315,9 +377,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryPoolPutDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryPoolGetStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -326,9 +390,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryPoolGetDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals QueryPoolChange struct { Limit int Index int diff --git a/trace/query_gtrace.go b/trace/query_gtrace.go index 2353b77b4..2bbc46f3c 100644 --- a/trace/query_gtrace.go +++ b/trace/query_gtrace.go @@ -12,9 +12,11 @@ type queryComposeOptions struct { } // QueryOption specified Query compose option +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals type QueryComposeOption func(o *queryComposeOptions) // WithQueryPanicCallback specified behavior on panic +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func WithQueryPanicCallback(cb func(e interface{})) QueryComposeOption { return func(o *queryComposeOptions) { o.panicCallback = cb @@ -22,6 +24,7 @@ func WithQueryPanicCallback(cb func(e interface{})) QueryComposeOption { } // Compose returns a new Query which has functional fields composed both from t and x. +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func (t *Query) Compose(x *Query, opts ...QueryComposeOption) *Query { var ret Query options := queryComposeOptions{} @@ -1258,6 +1261,7 @@ func (t *Query) onRowScanStruct(q QueryRowScanStructStartInfo) func(info QueryRo } return res } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnNew(t *Query, c *context.Context, call call) func() { var p QueryNewStartInfo p.Context = c @@ -1268,6 +1272,7 @@ func QueryOnNew(t *Query, c *context.Context, call call) func() { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnClose(t *Query, c *context.Context, call call) func(error) { var p QueryCloseStartInfo p.Context = c @@ -1279,6 +1284,7 @@ func QueryOnClose(t *Query, c *context.Context, call call) func(error) { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnPoolNew(t *Query, c *context.Context, call call) func(limit int) { var p QueryPoolNewStartInfo p.Context = c @@ -1290,6 +1296,7 @@ func QueryOnPoolNew(t *Query, c *context.Context, call call) func(limit int) { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnPoolClose(t *Query, c *context.Context, call call) func(error) { var p QueryPoolCloseStartInfo p.Context = c @@ -1301,6 +1308,7 @@ func QueryOnPoolClose(t *Query, c *context.Context, call call) func(error) { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnPoolTry(t *Query, c *context.Context, call call) func(error) { var p QueryPoolTryStartInfo p.Context = c @@ -1312,6 +1320,7 @@ func QueryOnPoolTry(t *Query, c *context.Context, call call) func(error) { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnPoolWith(t *Query, c *context.Context, call call) func(_ error, attempts int) { var p QueryPoolWithStartInfo p.Context = c @@ -1324,6 +1333,7 @@ func QueryOnPoolWith(t *Query, c *context.Context, call call) func(_ error, atte res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnPoolPut(t *Query, c *context.Context, call call) func(error) { var p QueryPoolPutStartInfo p.Context = c @@ -1335,6 +1345,7 @@ func QueryOnPoolPut(t *Query, c *context.Context, call call) func(error) { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnPoolGet(t *Query, c *context.Context, call call) func(error) { var p QueryPoolGetStartInfo p.Context = c @@ -1346,6 +1357,7 @@ func QueryOnPoolGet(t *Query, c *context.Context, call call) func(error) { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnPoolChange(t *Query, limit int, index int, idle int, inUse int) { var p QueryPoolChange p.Limit = limit @@ -1354,6 +1366,7 @@ func QueryOnPoolChange(t *Query, limit int, index int, idle int, inUse int) { p.InUse = inUse t.onPoolChange(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnDo(t *Query, c *context.Context, call call) func(attempts int, _ error) { var p QueryDoStartInfo p.Context = c @@ -1366,6 +1379,7 @@ func QueryOnDo(t *Query, c *context.Context, call call) func(attempts int, _ err res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnDoTx(t *Query, c *context.Context, call call) func(attempts int, _ error) { var p QueryDoTxStartInfo p.Context = c @@ -1378,6 +1392,7 @@ func QueryOnDoTx(t *Query, c *context.Context, call call) func(attempts int, _ e res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnSessionCreate(t *Query, c *context.Context, call call) func(session querySessionInfo, _ error) { var p QuerySessionCreateStartInfo p.Context = c @@ -1390,6 +1405,7 @@ func QueryOnSessionCreate(t *Query, c *context.Context, call call) func(session res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnSessionAttach(t *Query, c *context.Context, call call, session querySessionInfo) func(error) { var p QuerySessionAttachStartInfo p.Context = c @@ -1402,6 +1418,7 @@ func QueryOnSessionAttach(t *Query, c *context.Context, call call, session query res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnSessionDelete(t *Query, c *context.Context, call call, session querySessionInfo) func(error) { var p QuerySessionDeleteStartInfo p.Context = c @@ -1414,6 +1431,7 @@ func QueryOnSessionDelete(t *Query, c *context.Context, call call, session query res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnSessionExecute(t *Query, c *context.Context, call call, session querySessionInfo, query string) func(error) { var p QuerySessionExecuteStartInfo p.Context = c @@ -1427,6 +1445,7 @@ func QueryOnSessionExecute(t *Query, c *context.Context, call call, session quer res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnSessionBegin(t *Query, c *context.Context, call call, session querySessionInfo) func(_ error, tx queryTransactionInfo) { var p QuerySessionBeginStartInfo p.Context = c @@ -1440,6 +1459,7 @@ func QueryOnSessionBegin(t *Query, c *context.Context, call call, session queryS res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnTxExecute(t *Query, c *context.Context, call call, session querySessionInfo, tx queryTransactionInfo, query string) func(error) { var p QueryTxExecuteStartInfo p.Context = c @@ -1454,6 +1474,7 @@ func QueryOnTxExecute(t *Query, c *context.Context, call call, session querySess res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnResultNew(t *Query, c *context.Context, call call) func(error) { var p QueryResultNewStartInfo p.Context = c @@ -1465,6 +1486,7 @@ func QueryOnResultNew(t *Query, c *context.Context, call call) func(error) { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnResultNextPart(t *Query, c *context.Context, call call) func(error) { var p QueryResultNextPartStartInfo p.Context = c @@ -1476,6 +1498,7 @@ func QueryOnResultNextPart(t *Query, c *context.Context, call call) func(error) res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnResultNextResultSet(t *Query, c *context.Context, call call) func(error) { var p QueryResultNextResultSetStartInfo p.Context = c @@ -1487,6 +1510,7 @@ func QueryOnResultNextResultSet(t *Query, c *context.Context, call call) func(er res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnResultClose(t *Query, c *context.Context, call call) func(error) { var p QueryResultCloseStartInfo p.Context = c @@ -1498,6 +1522,7 @@ func QueryOnResultClose(t *Query, c *context.Context, call call) func(error) { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnResultSetNextRow(t *Query, c *context.Context, call call) func(error) { var p QueryResultSetNextRowStartInfo p.Context = c @@ -1509,6 +1534,7 @@ func QueryOnResultSetNextRow(t *Query, c *context.Context, call call) func(error res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnRowScan(t *Query, c *context.Context, call call) func(error) { var p QueryRowScanStartInfo p.Context = c @@ -1520,6 +1546,7 @@ func QueryOnRowScan(t *Query, c *context.Context, call call) func(error) { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnRowScanNamed(t *Query, c *context.Context, call call) func(error) { var p QueryRowScanNamedStartInfo p.Context = c @@ -1531,6 +1558,7 @@ func QueryOnRowScanNamed(t *Query, c *context.Context, call call) func(error) { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func QueryOnRowScanStruct(t *Query, c *context.Context, call call) func(error) { var p QueryRowScanStructStartInfo p.Context = c diff --git a/trace/ratelimiter.go b/trace/ratelimiter.go index 5aae16b93..6d411d13c 100644 --- a/trace/ratelimiter.go +++ b/trace/ratelimiter.go @@ -7,5 +7,6 @@ package trace type ( // Ratelimiter specified trace of ratelimiter client activity. // gtrace:gen + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals Ratelimiter struct{} ) diff --git a/trace/ratelimiter_gtrace.go b/trace/ratelimiter_gtrace.go index 015dba417..607e8a33d 100644 --- a/trace/ratelimiter_gtrace.go +++ b/trace/ratelimiter_gtrace.go @@ -8,9 +8,11 @@ type ratelimiterComposeOptions struct { } // RatelimiterOption specified Ratelimiter compose option +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals type RatelimiterComposeOption func(o *ratelimiterComposeOptions) // WithRatelimiterPanicCallback specified behavior on panic +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func WithRatelimiterPanicCallback(cb func(e interface{})) RatelimiterComposeOption { return func(o *ratelimiterComposeOptions) { o.panicCallback = cb @@ -18,6 +20,7 @@ func WithRatelimiterPanicCallback(cb func(e interface{})) RatelimiterComposeOpti } // Compose returns a new Ratelimiter which has functional fields composed both from t and x. +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func (t *Ratelimiter) Compose(x *Ratelimiter, opts ...RatelimiterComposeOption) *Ratelimiter { var ret Ratelimiter return &ret diff --git a/trace/retry.go b/trace/retry.go index c87a149d2..200ba783f 100644 --- a/trace/retry.go +++ b/trace/retry.go @@ -11,9 +11,12 @@ import ( type ( // Retry specified trace of retry call activity. // gtrace:gen + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals Retry struct { + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnRetry func(RetryLoopStartInfo) func(RetryLoopDoneInfo) } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals RetryLoopStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -27,6 +30,7 @@ type ( NestedCall bool // a sign for detect Retry calls inside head Retry } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals RetryLoopDoneInfo struct { Attempts int Error error diff --git a/trace/retry_gtrace.go b/trace/retry_gtrace.go index 14a35e413..a8a6ba50e 100644 --- a/trace/retry_gtrace.go +++ b/trace/retry_gtrace.go @@ -12,9 +12,11 @@ type retryComposeOptions struct { } // RetryOption specified Retry compose option +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals type RetryComposeOption func(o *retryComposeOptions) // WithRetryPanicCallback specified behavior on panic +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func WithRetryPanicCallback(cb func(e interface{})) RetryComposeOption { return func(o *retryComposeOptions) { o.panicCallback = cb @@ -22,6 +24,7 @@ func WithRetryPanicCallback(cb func(e interface{})) RetryComposeOption { } // Compose returns a new Retry which has functional fields composed both from t and x. +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func (t *Retry) Compose(x *Retry, opts ...RetryComposeOption) *Retry { var ret Retry options := retryComposeOptions{} @@ -82,6 +85,7 @@ func (t *Retry) onRetry(r RetryLoopStartInfo) func(RetryLoopDoneInfo) { } return res } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func RetryOnRetry(t *Retry, c *context.Context, call call, label string, idempotent bool, nestedCall bool) func(attempts int, _ error) { var p RetryLoopStartInfo p.Context = c diff --git a/trace/scheme.go b/trace/scheme.go index 2f4c6f48b..ed70a527e 100644 --- a/trace/scheme.go +++ b/trace/scheme.go @@ -11,14 +11,21 @@ import ( type ( // Scheme specified trace of scheme client activity. // gtrace:gen + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals Scheme struct { - OnListDirectory func(SchemeListDirectoryStartInfo) func(SchemeListDirectoryDoneInfo) - OnDescribePath func(SchemeDescribePathStartInfo) func(SchemeDescribePathDoneInfo) - OnMakeDirectory func(SchemeMakeDirectoryStartInfo) func(SchemeMakeDirectoryDoneInfo) - OnRemoveDirectory func(SchemeRemoveDirectoryStartInfo) func(SchemeRemoveDirectoryDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnListDirectory func(SchemeListDirectoryStartInfo) func(SchemeListDirectoryDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnDescribePath func(SchemeDescribePathStartInfo) func(SchemeDescribePathDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnMakeDirectory func(SchemeMakeDirectoryStartInfo) func(SchemeMakeDirectoryDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnRemoveDirectory func(SchemeRemoveDirectoryStartInfo) func(SchemeRemoveDirectoryDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnModifyPermissions func(SchemeModifyPermissionsStartInfo) func(SchemeModifyPermissionsDoneInfo) } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals SchemeListDirectoryStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -27,9 +34,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals SchemeListDirectoryDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals SchemeDescribePathStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -39,10 +48,12 @@ type ( Call call Path string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals SchemeDescribePathDoneInfo struct { EntryType string Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals SchemeMakeDirectoryStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -52,9 +63,11 @@ type ( Call call Path string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals SchemeMakeDirectoryDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals SchemeRemoveDirectoryStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -64,9 +77,11 @@ type ( Call call Path string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals SchemeRemoveDirectoryDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals SchemeModifyPermissionsStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -76,6 +91,7 @@ type ( Call call Path string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals SchemeModifyPermissionsDoneInfo struct { Error error } diff --git a/trace/scheme_gtrace.go b/trace/scheme_gtrace.go index 0001d9e17..e960696ca 100644 --- a/trace/scheme_gtrace.go +++ b/trace/scheme_gtrace.go @@ -12,9 +12,11 @@ type schemeComposeOptions struct { } // SchemeOption specified Scheme compose option +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals type SchemeComposeOption func(o *schemeComposeOptions) // WithSchemePanicCallback specified behavior on panic +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func WithSchemePanicCallback(cb func(e interface{})) SchemeComposeOption { return func(o *schemeComposeOptions) { o.panicCallback = cb @@ -22,6 +24,7 @@ func WithSchemePanicCallback(cb func(e interface{})) SchemeComposeOption { } // Compose returns a new Scheme which has functional fields composed both from t and x. +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func (t *Scheme) Compose(x *Scheme, opts ...SchemeComposeOption) *Scheme { var ret Scheme options := schemeComposeOptions{} @@ -282,6 +285,7 @@ func (t *Scheme) onModifyPermissions(s SchemeModifyPermissionsStartInfo) func(Sc } return res } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func SchemeOnListDirectory(t *Scheme, c *context.Context, call call) func(error) { var p SchemeListDirectoryStartInfo p.Context = c @@ -293,6 +297,7 @@ func SchemeOnListDirectory(t *Scheme, c *context.Context, call call) func(error) res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func SchemeOnDescribePath(t *Scheme, c *context.Context, call call, path string) func(entryType string, _ error) { var p SchemeDescribePathStartInfo p.Context = c @@ -306,6 +311,7 @@ func SchemeOnDescribePath(t *Scheme, c *context.Context, call call, path string) res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func SchemeOnMakeDirectory(t *Scheme, c *context.Context, call call, path string) func(error) { var p SchemeMakeDirectoryStartInfo p.Context = c @@ -318,6 +324,7 @@ func SchemeOnMakeDirectory(t *Scheme, c *context.Context, call call, path string res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func SchemeOnRemoveDirectory(t *Scheme, c *context.Context, call call, path string) func(error) { var p SchemeRemoveDirectoryStartInfo p.Context = c @@ -330,6 +337,7 @@ func SchemeOnRemoveDirectory(t *Scheme, c *context.Context, call call, path stri res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func SchemeOnModifyPermissions(t *Scheme, c *context.Context, call call, path string) func(error) { var p SchemeModifyPermissionsStartInfo p.Context = c diff --git a/trace/scripting.go b/trace/scripting.go index 4e018e07d..51f672d79 100644 --- a/trace/scripting.go +++ b/trace/scripting.go @@ -11,8 +11,11 @@ import ( type ( // Scripting specified trace of scripting client activity. // gtrace:gen + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals Scripting struct { - OnExecute func(ScriptingExecuteStartInfo) func(ScriptingExecuteDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnExecute func(ScriptingExecuteStartInfo) func(ScriptingExecuteDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnStreamExecute func( ScriptingStreamExecuteStartInfo, ) func( @@ -20,8 +23,10 @@ type ( ) func( ScriptingStreamExecuteDoneInfo, ) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnExplain func(ScriptingExplainStartInfo) func(ScriptingExplainDoneInfo) - OnClose func(ScriptingCloseStartInfo) func(ScriptingCloseDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnClose func(ScriptingCloseStartInfo) func(ScriptingCloseDoneInfo) } scriptingQueryParameters interface { String() string @@ -33,6 +38,7 @@ type ( scriptingResultErr ResultSetCount() int } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals ScriptingExecuteStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -43,10 +49,12 @@ type ( Query string Parameters scriptingQueryParameters } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals ScriptingExecuteDoneInfo struct { Result scriptingResult Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals ScriptingStreamExecuteStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -57,12 +65,15 @@ type ( Query string Parameters scriptingQueryParameters } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals ScriptingStreamExecuteIntermediateInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals ScriptingStreamExecuteDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals ScriptingExplainStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -72,10 +83,12 @@ type ( Call call Query string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals ScriptingExplainDoneInfo struct { Plan string Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals ScriptingCloseStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -84,6 +97,7 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals ScriptingCloseDoneInfo struct { Error error } diff --git a/trace/scripting_gtrace.go b/trace/scripting_gtrace.go index 8af5fd07e..c3de7b27f 100644 --- a/trace/scripting_gtrace.go +++ b/trace/scripting_gtrace.go @@ -12,9 +12,11 @@ type scriptingComposeOptions struct { } // ScriptingOption specified Scripting compose option +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals type ScriptingComposeOption func(o *scriptingComposeOptions) // WithScriptingPanicCallback specified behavior on panic +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func WithScriptingPanicCallback(cb func(e interface{})) ScriptingComposeOption { return func(o *scriptingComposeOptions) { o.panicCallback = cb @@ -22,6 +24,7 @@ func WithScriptingPanicCallback(cb func(e interface{})) ScriptingComposeOption { } // Compose returns a new Scripting which has functional fields composed both from t and x. +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func (t *Scripting) Compose(x *Scripting, opts ...ScriptingComposeOption) *Scripting { var ret Scripting options := scriptingComposeOptions{} @@ -260,6 +263,7 @@ func (t *Scripting) onClose(s ScriptingCloseStartInfo) func(ScriptingCloseDoneIn } return res } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func ScriptingOnExecute(t *Scripting, c *context.Context, call call, query string, parameters scriptingQueryParameters) func(result scriptingResult, _ error) { var p ScriptingExecuteStartInfo p.Context = c @@ -274,6 +278,7 @@ func ScriptingOnExecute(t *Scripting, c *context.Context, call call, query strin res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func ScriptingOnStreamExecute(t *Scripting, c *context.Context, call call, query string, parameters scriptingQueryParameters) func(error) func(error) { var p ScriptingStreamExecuteStartInfo p.Context = c @@ -292,6 +297,7 @@ func ScriptingOnStreamExecute(t *Scripting, c *context.Context, call call, query } } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func ScriptingOnExplain(t *Scripting, c *context.Context, call call, query string) func(plan string, _ error) { var p ScriptingExplainStartInfo p.Context = c @@ -305,6 +311,7 @@ func ScriptingOnExplain(t *Scripting, c *context.Context, call call, query strin res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func ScriptingOnClose(t *Scripting, c *context.Context, call call) func(error) { var p ScriptingCloseStartInfo p.Context = c diff --git a/trace/sql.go b/trace/sql.go index e6d5de6ec..9ee597a39 100644 --- a/trace/sql.go +++ b/trace/sql.go @@ -10,30 +10,49 @@ import ( type ( // DatabaseSQL specified trace of `database/sql` call activity. // gtrace:gen + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQL struct { + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnConnectorConnect func(DatabaseSQLConnectorConnectStartInfo) func(DatabaseSQLConnectorConnectDoneInfo) - OnConnPing func(DatabaseSQLConnPingStartInfo) func(DatabaseSQLConnPingDoneInfo) - OnConnPrepare func(DatabaseSQLConnPrepareStartInfo) func(DatabaseSQLConnPrepareDoneInfo) - OnConnClose func(DatabaseSQLConnCloseStartInfo) func(DatabaseSQLConnCloseDoneInfo) - OnConnBegin func(DatabaseSQLConnBeginStartInfo) func(DatabaseSQLConnBeginDoneInfo) - OnConnQuery func(DatabaseSQLConnQueryStartInfo) func(DatabaseSQLConnQueryDoneInfo) - OnConnExec func(DatabaseSQLConnExecStartInfo) func(DatabaseSQLConnExecDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnConnPing func(DatabaseSQLConnPingStartInfo) func(DatabaseSQLConnPingDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnConnPrepare func(DatabaseSQLConnPrepareStartInfo) func(DatabaseSQLConnPrepareDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnConnClose func(DatabaseSQLConnCloseStartInfo) func(DatabaseSQLConnCloseDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnConnBegin func(DatabaseSQLConnBeginStartInfo) func(DatabaseSQLConnBeginDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnConnQuery func(DatabaseSQLConnQueryStartInfo) func(DatabaseSQLConnQueryDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnConnExec func(DatabaseSQLConnExecStartInfo) func(DatabaseSQLConnExecDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnConnIsTableExists func(DatabaseSQLConnIsTableExistsStartInfo) func(DatabaseSQLConnIsTableExistsDoneInfo) - OnTxQuery func(DatabaseSQLTxQueryStartInfo) func(DatabaseSQLTxQueryDoneInfo) - OnTxExec func(DatabaseSQLTxExecStartInfo) func(DatabaseSQLTxExecDoneInfo) - OnTxPrepare func(DatabaseSQLTxPrepareStartInfo) func(DatabaseSQLTxPrepareDoneInfo) - OnTxCommit func(DatabaseSQLTxCommitStartInfo) func(DatabaseSQLTxCommitDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnTxQuery func(DatabaseSQLTxQueryStartInfo) func(DatabaseSQLTxQueryDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnTxExec func(DatabaseSQLTxExecStartInfo) func(DatabaseSQLTxExecDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnTxPrepare func(DatabaseSQLTxPrepareStartInfo) func(DatabaseSQLTxPrepareDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnTxCommit func(DatabaseSQLTxCommitStartInfo) func(DatabaseSQLTxCommitDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnTxRollback func(DatabaseSQLTxRollbackStartInfo) func(DatabaseSQLTxRollbackDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnStmtQuery func(DatabaseSQLStmtQueryStartInfo) func(DatabaseSQLStmtQueryDoneInfo) - OnStmtExec func(DatabaseSQLStmtExecStartInfo) func(DatabaseSQLStmtExecDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnStmtExec func(DatabaseSQLStmtExecStartInfo) func(DatabaseSQLStmtExecDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnStmtClose func(DatabaseSQLStmtCloseStartInfo) func(DatabaseSQLStmtCloseDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnDoTx func(DatabaseSQLDoTxStartInfo) func(DatabaseSQLDoTxIntermediateInfo) func(DatabaseSQLDoTxDoneInfo) } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnectorConnectStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -42,10 +61,12 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnectorConnectDoneInfo struct { Error error Session tableSessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnPingStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -54,9 +75,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnPingDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnPrepareStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -66,9 +89,11 @@ type ( Call call Query string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnPrepareDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLTxPrepareStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -80,9 +105,11 @@ type ( Tx tableTransactionInfo Query string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLTxPrepareDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnCloseStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -91,9 +118,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnCloseDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnBeginStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -102,10 +131,12 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnBeginDoneInfo struct { Tx tableTransactionInfo Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnQueryStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -118,9 +149,11 @@ type ( Idempotent bool IdleTime time.Duration } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnQueryDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnExecStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -133,9 +166,11 @@ type ( Idempotent bool IdleTime time.Duration } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnExecDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnIsTableExistsStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -145,10 +180,12 @@ type ( Call call TableName string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnIsTableExistsDoneInfo struct { Exists bool Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLTxQueryStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -160,9 +197,11 @@ type ( Tx tableTransactionInfo Query string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLTxQueryDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLTxExecStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -174,9 +213,11 @@ type ( Tx tableTransactionInfo Query string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLTxExecDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLTxCommitStartInfo struct { // TxContext make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -186,9 +227,11 @@ type ( Call call Tx tableTransactionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLTxCommitDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLTxRollbackStartInfo struct { // TxContext make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -198,16 +241,20 @@ type ( Call call Tx tableTransactionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLTxRollbackDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLStmtCloseStartInfo struct { StmtContext *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLStmtCloseDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLStmtQueryStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -218,9 +265,11 @@ type ( StmtContext context.Context Query string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLStmtQueryDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLStmtExecStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -231,9 +280,11 @@ type ( StmtContext context.Context Query string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLStmtExecDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLDoTxStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -244,9 +295,11 @@ type ( ID string Idempotent bool } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLDoTxIntermediateInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLDoTxDoneInfo struct { Attempts int Error error diff --git a/trace/sql_gtrace.go b/trace/sql_gtrace.go index e5d2a484f..c4a686e1d 100644 --- a/trace/sql_gtrace.go +++ b/trace/sql_gtrace.go @@ -13,9 +13,11 @@ type databaseSQLComposeOptions struct { } // DatabaseSQLOption specified DatabaseSQL compose option +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals type DatabaseSQLComposeOption func(o *databaseSQLComposeOptions) // WithDatabaseSQLPanicCallback specified behavior on panic +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func WithDatabaseSQLPanicCallback(cb func(e interface{})) DatabaseSQLComposeOption { return func(o *databaseSQLComposeOptions) { o.panicCallback = cb @@ -23,6 +25,7 @@ func WithDatabaseSQLPanicCallback(cb func(e interface{})) DatabaseSQLComposeOpti } // Compose returns a new DatabaseSQL which has functional fields composed both from t and x. +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func (t *DatabaseSQL) Compose(x *DatabaseSQL, opts ...DatabaseSQLComposeOption) *DatabaseSQL { var ret DatabaseSQL options := databaseSQLComposeOptions{} @@ -911,6 +914,7 @@ func (t *DatabaseSQL) onDoTx(d DatabaseSQLDoTxStartInfo) func(DatabaseSQLDoTxInt return res } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DatabaseSQLOnConnectorConnect(t *DatabaseSQL, c *context.Context, call call) func(_ error, session tableSessionInfo) { var p DatabaseSQLConnectorConnectStartInfo p.Context = c @@ -923,6 +927,7 @@ func DatabaseSQLOnConnectorConnect(t *DatabaseSQL, c *context.Context, call call res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DatabaseSQLOnConnPing(t *DatabaseSQL, c *context.Context, call call) func(error) { var p DatabaseSQLConnPingStartInfo p.Context = c @@ -934,6 +939,7 @@ func DatabaseSQLOnConnPing(t *DatabaseSQL, c *context.Context, call call) func(e res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DatabaseSQLOnConnPrepare(t *DatabaseSQL, c *context.Context, call call, query string) func(error) { var p DatabaseSQLConnPrepareStartInfo p.Context = c @@ -946,6 +952,7 @@ func DatabaseSQLOnConnPrepare(t *DatabaseSQL, c *context.Context, call call, que res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DatabaseSQLOnConnClose(t *DatabaseSQL, c *context.Context, call call) func(error) { var p DatabaseSQLConnCloseStartInfo p.Context = c @@ -957,6 +964,7 @@ func DatabaseSQLOnConnClose(t *DatabaseSQL, c *context.Context, call call) func( res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DatabaseSQLOnConnBegin(t *DatabaseSQL, c *context.Context, call call) func(tx tableTransactionInfo, _ error) { var p DatabaseSQLConnBeginStartInfo p.Context = c @@ -969,6 +977,7 @@ func DatabaseSQLOnConnBegin(t *DatabaseSQL, c *context.Context, call call) func( res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DatabaseSQLOnConnQuery(t *DatabaseSQL, c *context.Context, call call, query string, mode string, idempotent bool, idleTime time.Duration) func(error) { var p DatabaseSQLConnQueryStartInfo p.Context = c @@ -984,6 +993,7 @@ func DatabaseSQLOnConnQuery(t *DatabaseSQL, c *context.Context, call call, query res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DatabaseSQLOnConnExec(t *DatabaseSQL, c *context.Context, call call, query string, mode string, idempotent bool, idleTime time.Duration) func(error) { var p DatabaseSQLConnExecStartInfo p.Context = c @@ -999,6 +1009,7 @@ func DatabaseSQLOnConnExec(t *DatabaseSQL, c *context.Context, call call, query res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DatabaseSQLOnConnIsTableExists(t *DatabaseSQL, c *context.Context, call call, tableName string) func(exists bool, _ error) { var p DatabaseSQLConnIsTableExistsStartInfo p.Context = c @@ -1012,6 +1023,7 @@ func DatabaseSQLOnConnIsTableExists(t *DatabaseSQL, c *context.Context, call cal res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DatabaseSQLOnTxQuery(t *DatabaseSQL, c *context.Context, call call, txContext context.Context, tx tableTransactionInfo, query string) func(error) { var p DatabaseSQLTxQueryStartInfo p.Context = c @@ -1026,6 +1038,7 @@ func DatabaseSQLOnTxQuery(t *DatabaseSQL, c *context.Context, call call, txConte res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DatabaseSQLOnTxExec(t *DatabaseSQL, c *context.Context, call call, txContext context.Context, tx tableTransactionInfo, query string) func(error) { var p DatabaseSQLTxExecStartInfo p.Context = c @@ -1040,6 +1053,7 @@ func DatabaseSQLOnTxExec(t *DatabaseSQL, c *context.Context, call call, txContex res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DatabaseSQLOnTxPrepare(t *DatabaseSQL, c *context.Context, call call, txContext *context.Context, tx tableTransactionInfo, query string) func(error) { var p DatabaseSQLTxPrepareStartInfo p.Context = c @@ -1054,6 +1068,7 @@ func DatabaseSQLOnTxPrepare(t *DatabaseSQL, c *context.Context, call call, txCon res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DatabaseSQLOnTxCommit(t *DatabaseSQL, c *context.Context, call call, tx tableTransactionInfo) func(error) { var p DatabaseSQLTxCommitStartInfo p.Context = c @@ -1066,6 +1081,7 @@ func DatabaseSQLOnTxCommit(t *DatabaseSQL, c *context.Context, call call, tx tab res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DatabaseSQLOnTxRollback(t *DatabaseSQL, c *context.Context, call call, tx tableTransactionInfo) func(error) { var p DatabaseSQLTxRollbackStartInfo p.Context = c @@ -1078,6 +1094,7 @@ func DatabaseSQLOnTxRollback(t *DatabaseSQL, c *context.Context, call call, tx t res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DatabaseSQLOnStmtQuery(t *DatabaseSQL, c *context.Context, call call, stmtContext context.Context, query string) func(error) { var p DatabaseSQLStmtQueryStartInfo p.Context = c @@ -1091,6 +1108,7 @@ func DatabaseSQLOnStmtQuery(t *DatabaseSQL, c *context.Context, call call, stmtC res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DatabaseSQLOnStmtExec(t *DatabaseSQL, c *context.Context, call call, stmtContext context.Context, query string) func(error) { var p DatabaseSQLStmtExecStartInfo p.Context = c @@ -1104,6 +1122,7 @@ func DatabaseSQLOnStmtExec(t *DatabaseSQL, c *context.Context, call call, stmtCo res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DatabaseSQLOnStmtClose(t *DatabaseSQL, stmtContext *context.Context, call call) func(error) { var p DatabaseSQLStmtCloseStartInfo p.StmtContext = stmtContext @@ -1115,6 +1134,7 @@ func DatabaseSQLOnStmtClose(t *DatabaseSQL, stmtContext *context.Context, call c res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func DatabaseSQLOnDoTx(t *DatabaseSQL, c *context.Context, call call, iD string, idempotent bool) func(error) func(attempts int, _ error) { var p DatabaseSQLDoTxStartInfo p.Context = c diff --git a/trace/table.go b/trace/table.go index 4e944435a..d8f0622e7 100644 --- a/trace/table.go +++ b/trace/table.go @@ -12,49 +12,75 @@ import ( type ( // Table specified trace of table client activity. // gtrace:gen + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals Table struct { // Client events - OnInit func(TableInitStartInfo) func(TableInitDoneInfo) - OnClose func(TableCloseStartInfo) func(TableCloseDoneInfo) - OnDo func(TableDoStartInfo) func(TableDoDoneInfo) - OnDoTx func(TableDoTxStartInfo) func(TableDoTxDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnInit func(TableInitStartInfo) func(TableInitDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnClose func(TableCloseStartInfo) func(TableCloseDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnDo func(TableDoStartInfo) func(TableDoDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnDoTx func(TableDoTxStartInfo) func(TableDoTxDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnCreateSession func(TableCreateSessionStartInfo) func(TableCreateSessionDoneInfo) // Session events - OnSessionNew func(TableSessionNewStartInfo) func(TableSessionNewDoneInfo) - OnSessionDelete func(TableSessionDeleteStartInfo) func(TableSessionDeleteDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnSessionNew func(TableSessionNewStartInfo) func(TableSessionNewDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnSessionDelete func(TableSessionDeleteStartInfo) func(TableSessionDeleteDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnSessionKeepAlive func(TableKeepAliveStartInfo) func(TableKeepAliveDoneInfo) // Query events - OnSessionBulkUpsert func(TableBulkUpsertStartInfo) func(TableBulkUpsertDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnSessionBulkUpsert func(TableBulkUpsertStartInfo) func(TableBulkUpsertDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnSessionQueryPrepare func(TablePrepareDataQueryStartInfo) func(TablePrepareDataQueryDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnSessionQueryExecute func(TableExecuteDataQueryStartInfo) func(TableExecuteDataQueryDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnSessionQueryExplain func(TableExplainQueryStartInfo) func(TableExplainQueryDoneInfo) // Stream events + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnSessionQueryStreamExecute func(TableSessionQueryStreamExecuteStartInfo) func(TableSessionQueryStreamExecuteDoneInfo) - OnSessionQueryStreamRead func(TableSessionQueryStreamReadStartInfo) func(TableSessionQueryStreamReadDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnSessionQueryStreamRead func(TableSessionQueryStreamReadStartInfo) func(TableSessionQueryStreamReadDoneInfo) // Transaction events + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnTxBegin func(TableTxBeginStartInfo) func( TableTxBeginDoneInfo, ) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnTxExecute func(TableTransactionExecuteStartInfo) func( TableTransactionExecuteDoneInfo, ) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnTxExecuteStatement func(TableTransactionExecuteStatementStartInfo) func( TableTransactionExecuteStatementDoneInfo, ) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnTxCommit func(TableTxCommitStartInfo) func( TableTxCommitDoneInfo, ) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnTxRollback func(TableTxRollbackStartInfo) func(TableTxRollbackDoneInfo) // Pool state event + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnPoolStateChange func(TablePoolStateChangeInfo) // Pool session lifecycle events - OnPoolSessionAdd func(info TablePoolSessionAddInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnPoolSessionAdd func(info TablePoolSessionAddInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnPoolSessionRemove func(info TablePoolSessionRemoveInfo) // Pool common API events - OnPoolPut func(TablePoolPutStartInfo) func(TablePoolPutDoneInfo) - OnPoolGet func(TablePoolGetStartInfo) func(TablePoolGetDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnPoolPut func(TablePoolPutStartInfo) func(TablePoolPutDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnPoolGet func(TablePoolGetStartInfo) func(TablePoolGetDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnPoolWait func(TablePoolWaitStartInfo) func(TablePoolWaitDoneInfo) } ) @@ -84,6 +110,7 @@ type ( tableResultErr ResultSetCount() int } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableSessionNewStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -92,10 +119,12 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableSessionNewDoneInfo struct { Session tableSessionInfo Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableKeepAliveStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -105,9 +134,11 @@ type ( Call call Session tableSessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableKeepAliveDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableBulkUpsertStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -117,9 +148,11 @@ type ( Call call Session tableSessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableBulkUpsertDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableSessionDeleteStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -129,9 +162,11 @@ type ( Call call Session tableSessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableSessionDeleteDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePrepareDataQueryStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -142,10 +177,12 @@ type ( Session tableSessionInfo Query string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePrepareDataQueryDoneInfo struct { Result tableDataQuery Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableExecuteDataQueryStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -158,6 +195,7 @@ type ( Parameters tableQueryParameters KeepInCache bool } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTransactionExecuteStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -170,6 +208,7 @@ type ( Query tableDataQuery Parameters tableQueryParameters } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTransactionExecuteStatementStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -182,6 +221,7 @@ type ( StatementQuery tableDataQuery Parameters tableQueryParameters } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableExplainQueryStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -192,25 +232,30 @@ type ( Session tableSessionInfo Query string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableExplainQueryDoneInfo struct { AST string Plan string Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableExecuteDataQueryDoneInfo struct { Tx tableTransactionInfo Prepared bool Result tableResult Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTransactionExecuteDoneInfo struct { Result tableResult Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTransactionExecuteStatementDoneInfo struct { Result tableResult Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableSessionQueryStreamReadStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -220,9 +265,11 @@ type ( Call call Session tableSessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableSessionQueryStreamReadDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableSessionQueryStreamExecuteStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -234,9 +281,11 @@ type ( Query tableDataQuery Parameters tableQueryParameters } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableSessionQueryStreamExecuteDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTxBeginStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -246,10 +295,12 @@ type ( Call call Session tableSessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTxBeginDoneInfo struct { Tx tableTransactionInfo Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTxCommitStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -260,9 +311,11 @@ type ( Session tableSessionInfo Tx tableTransactionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTxCommitDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTxRollbackStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -273,9 +326,11 @@ type ( Session tableSessionInfo Tx tableTransactionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTxRollbackDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableInitStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -284,13 +339,16 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableInitDoneInfo struct { Limit int } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolStateChangeInfo struct { Size int Event string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolSessionNewStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -299,10 +357,12 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolSessionNewDoneInfo struct { Session tableSessionInfo Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolGetStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -311,11 +371,13 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolGetDoneInfo struct { Session tableSessionInfo Attempts int Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolWaitStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -327,10 +389,12 @@ type ( // TablePoolWaitDoneInfo means a wait iteration inside Get call is done // Warning: Session and Error may be nil at the same time. This means // that a wait iteration donned without any significant tableResultErr + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolWaitDoneInfo struct { Session tableSessionInfo Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolPutStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -340,9 +404,11 @@ type ( Call call Session tableSessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolPutDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolSessionCloseStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -352,13 +418,17 @@ type ( Call call Session tableSessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolSessionCloseDoneInfo struct{} - TablePoolSessionAddInfo struct { + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + TablePoolSessionAddInfo struct { Session tableSessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolSessionRemoveInfo struct { Session tableSessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableCloseStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -367,9 +437,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableCloseDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableDoStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -382,10 +454,12 @@ type ( Idempotent bool NestedCall bool // flag when Retry called inside head Retry } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableDoDoneInfo struct { Attempts int Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableDoTxStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -398,10 +472,12 @@ type ( Idempotent bool NestedCall bool // flag when Retry called inside head Retry } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableDoTxDoneInfo struct { Attempts int Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableCreateSessionStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -410,6 +486,7 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableCreateSessionDoneInfo struct { Session tableSessionInfo Attempts int diff --git a/trace/table_gtrace.go b/trace/table_gtrace.go index 6834d38b9..e2cf30606 100644 --- a/trace/table_gtrace.go +++ b/trace/table_gtrace.go @@ -12,9 +12,11 @@ type tableComposeOptions struct { } // TableOption specified Table compose option +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals type TableComposeOption func(o *tableComposeOptions) // WithTablePanicCallback specified behavior on panic +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func WithTablePanicCallback(cb func(e interface{})) TableComposeOption { return func(o *tableComposeOptions) { o.panicCallback = cb @@ -22,6 +24,7 @@ func WithTablePanicCallback(cb func(e interface{})) TableComposeOption { } // Compose returns a new Table which has functional fields composed both from t and x. +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func (t *Table) Compose(x *Table, opts ...TableComposeOption) *Table { var ret Table options := tableComposeOptions{} @@ -1210,6 +1213,7 @@ func (t *Table) onPoolWait(t1 TablePoolWaitStartInfo) func(TablePoolWaitDoneInfo } return res } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnInit(t *Table, c *context.Context, call call) func(limit int) { var p TableInitStartInfo p.Context = c @@ -1221,6 +1225,7 @@ func TableOnInit(t *Table, c *context.Context, call call) func(limit int) { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnClose(t *Table, c *context.Context, call call) func(error) { var p TableCloseStartInfo p.Context = c @@ -1232,6 +1237,7 @@ func TableOnClose(t *Table, c *context.Context, call call) func(error) { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnDo(t *Table, c *context.Context, call call, label string, idempotent bool, nestedCall bool) func(attempts int, _ error) { var p TableDoStartInfo p.Context = c @@ -1247,6 +1253,7 @@ func TableOnDo(t *Table, c *context.Context, call call, label string, idempotent res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnDoTx(t *Table, c *context.Context, call call, label string, idempotent bool, nestedCall bool) func(attempts int, _ error) { var p TableDoTxStartInfo p.Context = c @@ -1262,6 +1269,7 @@ func TableOnDoTx(t *Table, c *context.Context, call call, label string, idempote res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnCreateSession(t *Table, c *context.Context, call call) func(session tableSessionInfo, attempts int, _ error) { var p TableCreateSessionStartInfo p.Context = c @@ -1275,6 +1283,7 @@ func TableOnCreateSession(t *Table, c *context.Context, call call) func(session res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnSessionNew(t *Table, c *context.Context, call call) func(session tableSessionInfo, _ error) { var p TableSessionNewStartInfo p.Context = c @@ -1287,6 +1296,7 @@ func TableOnSessionNew(t *Table, c *context.Context, call call) func(session tab res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnSessionDelete(t *Table, c *context.Context, call call, session tableSessionInfo) func(error) { var p TableSessionDeleteStartInfo p.Context = c @@ -1299,6 +1309,7 @@ func TableOnSessionDelete(t *Table, c *context.Context, call call, session table res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnSessionKeepAlive(t *Table, c *context.Context, call call, session tableSessionInfo) func(error) { var p TableKeepAliveStartInfo p.Context = c @@ -1311,6 +1322,7 @@ func TableOnSessionKeepAlive(t *Table, c *context.Context, call call, session ta res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnSessionBulkUpsert(t *Table, c *context.Context, call call, session tableSessionInfo) func(error) { var p TableBulkUpsertStartInfo p.Context = c @@ -1323,6 +1335,7 @@ func TableOnSessionBulkUpsert(t *Table, c *context.Context, call call, session t res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnSessionQueryPrepare(t *Table, c *context.Context, call call, session tableSessionInfo, query string) func(result tableDataQuery, _ error) { var p TablePrepareDataQueryStartInfo p.Context = c @@ -1337,6 +1350,7 @@ func TableOnSessionQueryPrepare(t *Table, c *context.Context, call call, session res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnSessionQueryExecute(t *Table, c *context.Context, call call, session tableSessionInfo, query tableDataQuery, parameters tableQueryParameters, keepInCache bool) func(tx tableTransactionInfo, prepared bool, result tableResult, _ error) { var p TableExecuteDataQueryStartInfo p.Context = c @@ -1355,6 +1369,7 @@ func TableOnSessionQueryExecute(t *Table, c *context.Context, call call, session res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnSessionQueryExplain(t *Table, c *context.Context, call call, session tableSessionInfo, query string) func(aST string, plan string, _ error) { var p TableExplainQueryStartInfo p.Context = c @@ -1370,6 +1385,7 @@ func TableOnSessionQueryExplain(t *Table, c *context.Context, call call, session res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnSessionQueryStreamExecute(t *Table, c *context.Context, call call, session tableSessionInfo, query tableDataQuery, parameters tableQueryParameters) func(error) { var p TableSessionQueryStreamExecuteStartInfo p.Context = c @@ -1384,6 +1400,7 @@ func TableOnSessionQueryStreamExecute(t *Table, c *context.Context, call call, s res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnSessionQueryStreamRead(t *Table, c *context.Context, call call, session tableSessionInfo) func(error) { var p TableSessionQueryStreamReadStartInfo p.Context = c @@ -1396,6 +1413,7 @@ func TableOnSessionQueryStreamRead(t *Table, c *context.Context, call call, sess res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnTxBegin(t *Table, c *context.Context, call call, session tableSessionInfo) func(tx tableTransactionInfo, _ error) { var p TableTxBeginStartInfo p.Context = c @@ -1409,6 +1427,7 @@ func TableOnTxBegin(t *Table, c *context.Context, call call, session tableSessio res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnTxExecute(t *Table, c *context.Context, call call, session tableSessionInfo, tx tableTransactionInfo, query tableDataQuery, parameters tableQueryParameters) func(result tableResult, _ error) { var p TableTransactionExecuteStartInfo p.Context = c @@ -1425,6 +1444,7 @@ func TableOnTxExecute(t *Table, c *context.Context, call call, session tableSess res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnTxExecuteStatement(t *Table, c *context.Context, call call, session tableSessionInfo, tx tableTransactionInfo, statementQuery tableDataQuery, parameters tableQueryParameters) func(result tableResult, _ error) { var p TableTransactionExecuteStatementStartInfo p.Context = c @@ -1441,6 +1461,7 @@ func TableOnTxExecuteStatement(t *Table, c *context.Context, call call, session res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnTxCommit(t *Table, c *context.Context, call call, session tableSessionInfo, tx tableTransactionInfo) func(error) { var p TableTxCommitStartInfo p.Context = c @@ -1454,6 +1475,7 @@ func TableOnTxCommit(t *Table, c *context.Context, call call, session tableSessi res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnTxRollback(t *Table, c *context.Context, call call, session tableSessionInfo, tx tableTransactionInfo) func(error) { var p TableTxRollbackStartInfo p.Context = c @@ -1467,22 +1489,26 @@ func TableOnTxRollback(t *Table, c *context.Context, call call, session tableSes res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnPoolStateChange(t *Table, size int, event string) { var p TablePoolStateChangeInfo p.Size = size p.Event = event t.onPoolStateChange(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnPoolSessionAdd(t *Table, session tableSessionInfo) { var p TablePoolSessionAddInfo p.Session = session t.onPoolSessionAdd(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnPoolSessionRemove(t *Table, session tableSessionInfo) { var p TablePoolSessionRemoveInfo p.Session = session t.onPoolSessionRemove(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnPoolPut(t *Table, c *context.Context, call call, session tableSessionInfo) func(error) { var p TablePoolPutStartInfo p.Context = c @@ -1495,6 +1521,7 @@ func TableOnPoolPut(t *Table, c *context.Context, call call, session tableSessio res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnPoolGet(t *Table, c *context.Context, call call) func(session tableSessionInfo, attempts int, _ error) { var p TablePoolGetStartInfo p.Context = c @@ -1508,6 +1535,7 @@ func TableOnPoolGet(t *Table, c *context.Context, call call) func(session tableS res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TableOnPoolWait(t *Table, c *context.Context, call call) func(session tableSessionInfo, _ error) { var p TablePoolWaitStartInfo p.Context = c diff --git a/trace/topic.go b/trace/topic.go index b6498b52e..53077a3b8 100644 --- a/trace/topic.go +++ b/trace/topic.go @@ -11,23 +11,29 @@ import ( type ( // Topic specified trace of topic reader client activity. // gtrace:gen + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals Topic struct { // TopicReaderCustomerEvents - upper level, on bridge with customer code + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnReaderStart func(info TopicReaderStartInfo) // TopicReaderStreamLifeCycleEvents - OnReaderReconnect func(TopicReaderReconnectStartInfo) func(TopicReaderReconnectDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnReaderReconnect func(TopicReaderReconnectStartInfo) func(TopicReaderReconnectDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnReaderReconnectRequest func(TopicReaderReconnectRequestInfo) // TopicReaderPartitionEvents + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnReaderPartitionReadStartResponse func( TopicReaderPartitionReadStartResponseStartInfo, ) func( TopicReaderPartitionReadStartResponseDoneInfo, ) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnReaderPartitionReadStopResponse func( TopicReaderPartitionReadStopResponseStartInfo, ) func( @@ -36,13 +42,20 @@ type ( // TopicReaderStreamEvents - OnReaderCommit func(TopicReaderCommitStartInfo) func(TopicReaderCommitDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnReaderCommit func(TopicReaderCommitStartInfo) func(TopicReaderCommitDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnReaderSendCommitMessage func(TopicReaderSendCommitMessageStartInfo) func(TopicReaderSendCommitMessageDoneInfo) - OnReaderCommittedNotify func(TopicReaderCommittedNotifyInfo) - OnReaderClose func(TopicReaderCloseStartInfo) func(TopicReaderCloseDoneInfo) - OnReaderInit func(TopicReaderInitStartInfo) func(TopicReaderInitDoneInfo) - OnReaderError func(TopicReaderErrorInfo) - OnReaderUpdateToken func( + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnReaderCommittedNotify func(TopicReaderCommittedNotifyInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnReaderClose func(TopicReaderCloseStartInfo) func(TopicReaderCloseDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnReaderInit func(TopicReaderInitStartInfo) func(TopicReaderInitDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnReaderError func(TopicReaderErrorInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnReaderUpdateToken func( OnReadUpdateTokenStartInfo, ) func( OnReadUpdateTokenMiddleTokenReceivedInfo, @@ -52,24 +65,35 @@ type ( // TopicReaderMessageEvents - OnReaderSentDataRequest func(TopicReaderSentDataRequestInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnReaderSentDataRequest func(TopicReaderSentDataRequestInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnReaderReceiveDataResponse func(TopicReaderReceiveDataResponseStartInfo) func(TopicReaderReceiveDataResponseDoneInfo) - OnReaderReadMessages func(TopicReaderReadMessagesStartInfo) func(TopicReaderReadMessagesDoneInfo) - OnReaderUnknownGrpcMessage func(OnReadUnknownGrpcMessageInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnReaderReadMessages func(TopicReaderReadMessagesStartInfo) func(TopicReaderReadMessagesDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnReaderUnknownGrpcMessage func(OnReadUnknownGrpcMessageInfo) // TopicWriterStreamLifeCycleEvents - OnWriterReconnect func(TopicWriterReconnectStartInfo) func(TopicWriterReconnectDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnWriterReconnect func(TopicWriterReconnectStartInfo) func(TopicWriterReconnectDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnWriterInitStream func(TopicWriterInitStreamStartInfo) func(TopicWriterInitStreamDoneInfo) - OnWriterClose func(TopicWriterCloseStartInfo) func(TopicWriterCloseDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnWriterClose func(TopicWriterCloseStartInfo) func(TopicWriterCloseDoneInfo) // TopicWriterStreamEvents - OnWriterCompressMessages func(TopicWriterCompressMessagesStartInfo) func(TopicWriterCompressMessagesDoneInfo) - OnWriterSendMessages func(TopicWriterSendMessagesStartInfo) func(TopicWriterSendMessagesDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnWriterCompressMessages func(TopicWriterCompressMessagesStartInfo) func(TopicWriterCompressMessagesDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnWriterSendMessages func(TopicWriterSendMessagesStartInfo) func(TopicWriterSendMessagesDoneInfo) + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnWriterReadUnknownGrpcMessage func(TopicOnWriterReadUnknownGrpcMessageInfo) } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderPartitionReadStartResponseStartInfo struct { ReaderConnectionID string PartitionContext context.Context @@ -78,17 +102,20 @@ type ( PartitionSessionID int64 } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderStartInfo struct { ReaderID int64 Consumer string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderPartitionReadStartResponseDoneInfo struct { ReadOffset *int64 CommitOffset *int64 Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderPartitionReadStopResponseStartInfo struct { ReaderConnectionID string PartitionContext context.Context @@ -99,14 +126,17 @@ type ( Graceful bool } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderPartitionReadStopResponseDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderSendCommitMessageStartInfo struct { CommitsInfo TopicReaderStreamSendCommitMessageStartMessageInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderStreamCommitInfo struct { Topic string PartitionID int64 @@ -115,14 +145,17 @@ type ( EndOffset int64 } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderStreamSendCommitMessageStartMessageInfo interface { GetCommitsInfo() []TopicReaderStreamCommitInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderSendCommitMessageDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderCommittedNotifyInfo struct { ReaderConnectionID string Topic string @@ -131,32 +164,38 @@ type ( CommittedOffset int64 } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderErrorInfo struct { ReaderConnectionID string Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderSentDataRequestInfo struct { ReaderConnectionID string RequestBytes int LocalBufferSizeAfterSent int } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderReceiveDataResponseStartInfo struct { ReaderConnectionID string LocalBufferSizeAfterReceive int DataResponse TopicReaderDataResponseInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderDataResponseInfo interface { GetBytesSize() int GetPartitionBatchMessagesCounts() (partitionCount, batchCount, messagesCount int) } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderReceiveDataResponseDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderReadMessagesStartInfo struct { RequestContext context.Context MinCount int @@ -164,6 +203,7 @@ type ( FreeBufferCapacity int } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderReadMessagesDoneInfo struct { MessagesCount int Topic string @@ -175,24 +215,29 @@ type ( Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnReadUnknownGrpcMessageInfo struct { ReaderConnectionID string Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderReconnectStartInfo struct { Reason error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderReconnectDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderReconnectRequestInfo struct { Reason error WasSent bool } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderCommitStartInfo struct { RequestContext context.Context Topic string @@ -202,43 +247,52 @@ type ( EndOffset int64 } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderCommitDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderCloseStartInfo struct { ReaderConnectionID string CloseReason error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderCloseDoneInfo struct { CloseError error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderInitStartInfo struct { PreInitReaderConnectionID string InitRequestInfo TopicReadStreamInitRequestInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReadStreamInitRequestInfo interface { GetConsumer() string GetTopics() []string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicReaderInitDoneInfo struct { ReaderConnectionID string Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnReadUpdateTokenStartInfo struct { ReaderConnectionID string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnReadUpdateTokenMiddleTokenReceivedInfo struct { TokenLen int Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals OnReadStreamUpdateTokenDoneInfo struct { Error error } @@ -247,6 +301,7 @@ type ( //////////// TopicWriter //////////// + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicWriterReconnectStartInfo struct { WriterInstanceID string Topic string @@ -254,30 +309,36 @@ type ( Attempt int } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicWriterReconnectDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicWriterInitStreamStartInfo struct { WriterInstanceID string Topic string ProducerID string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicWriterInitStreamDoneInfo struct { SessionID string Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicWriterCloseStartInfo struct { WriterInstanceID string Reason error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicWriterCloseDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicWriterCompressMessagesStartInfo struct { WriterInstanceID string SessionID string @@ -287,10 +348,12 @@ type ( Reason TopicWriterCompressMessagesReason } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicWriterCompressMessagesDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicWriterSendMessagesStartInfo struct { WriterInstanceID string SessionID string @@ -299,10 +362,12 @@ type ( MessagesCount int } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicWriterSendMessagesDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TopicOnWriterReadUnknownGrpcMessageInfo struct { WriterInstanceID string SessionID string @@ -310,14 +375,19 @@ type ( } ) +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals type TopicWriterCompressMessagesReason string const ( - TopicWriterCompressMessagesReasonCompressData = TopicWriterCompressMessagesReason("compress-on-send") //nolint:lll - TopicWriterCompressMessagesReasonCompressDataOnWriteReadData = TopicWriterCompressMessagesReason("compress-on-call-write") //nolint:lll - TopicWriterCompressMessagesReasonCodecsMeasure = TopicWriterCompressMessagesReason("compress-on-codecs-measure") //nolint:lll + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + TopicWriterCompressMessagesReasonCompressData = TopicWriterCompressMessagesReason("compress-on-send") + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + TopicWriterCompressMessagesReasonCompressDataOnWriteReadData = TopicWriterCompressMessagesReason("compress-on-call-write") //nolint:lll + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + TopicWriterCompressMessagesReasonCodecsMeasure = TopicWriterCompressMessagesReason("compress-on-codecs-measure") //nolint:lll ) +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func (r TopicWriterCompressMessagesReason) String() string { return string(r) } diff --git a/trace/topic_gtrace.go b/trace/topic_gtrace.go index 8fa1c6b45..5f9dcde80 100644 --- a/trace/topic_gtrace.go +++ b/trace/topic_gtrace.go @@ -12,9 +12,11 @@ type topicComposeOptions struct { } // TopicOption specified Topic compose option +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals type TopicComposeOption func(o *topicComposeOptions) // WithTopicPanicCallback specified behavior on panic +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func WithTopicPanicCallback(cb func(e interface{})) TopicComposeOption { return func(o *topicComposeOptions) { o.panicCallback = cb @@ -22,6 +24,7 @@ func WithTopicPanicCallback(cb func(e interface{})) TopicComposeOption { } // Compose returns a new Topic which has functional fields composed both from t and x. +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func (t *Topic) Compose(x *Topic, opts ...TopicComposeOption) *Topic { var ret Topic options := topicComposeOptions{} @@ -992,12 +995,14 @@ func (t *Topic) onWriterReadUnknownGrpcMessage(t1 TopicOnWriterReadUnknownGrpcMe } fn(t1) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnReaderStart(t *Topic, readerID int64, consumer string) { var p TopicReaderStartInfo p.ReaderID = readerID p.Consumer = consumer t.onReaderStart(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnReaderReconnect(t *Topic, reason error) func(error) { var p TopicReaderReconnectStartInfo p.Reason = reason @@ -1008,12 +1013,14 @@ func TopicOnReaderReconnect(t *Topic, reason error) func(error) { res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnReaderReconnectRequest(t *Topic, reason error, wasSent bool) { var p TopicReaderReconnectRequestInfo p.Reason = reason p.WasSent = wasSent t.onReaderReconnectRequest(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnReaderPartitionReadStartResponse(t *Topic, readerConnectionID string, partitionContext context.Context, topic string, partitionID int64, partitionSessionID int64) func(readOffset *int64, commitOffset *int64, _ error) { var p TopicReaderPartitionReadStartResponseStartInfo p.ReaderConnectionID = readerConnectionID @@ -1030,6 +1037,7 @@ func TopicOnReaderPartitionReadStartResponse(t *Topic, readerConnectionID string res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnReaderPartitionReadStopResponse(t *Topic, readerConnectionID string, partitionContext context.Context, topic string, partitionID int64, partitionSessionID int64, committedOffset int64, graceful bool) func(error) { var p TopicReaderPartitionReadStopResponseStartInfo p.ReaderConnectionID = readerConnectionID @@ -1046,6 +1054,7 @@ func TopicOnReaderPartitionReadStopResponse(t *Topic, readerConnectionID string, res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnReaderCommit(t *Topic, requestContext context.Context, topic string, partitionID int64, partitionSessionID int64, startOffset int64, endOffset int64) func(error) { var p TopicReaderCommitStartInfo p.RequestContext = requestContext @@ -1061,6 +1070,7 @@ func TopicOnReaderCommit(t *Topic, requestContext context.Context, topic string, res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnReaderSendCommitMessage(t *Topic, commitsInfo TopicReaderStreamSendCommitMessageStartMessageInfo) func(error) { var p TopicReaderSendCommitMessageStartInfo p.CommitsInfo = commitsInfo @@ -1071,6 +1081,7 @@ func TopicOnReaderSendCommitMessage(t *Topic, commitsInfo TopicReaderStreamSendC res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnReaderCommittedNotify(t *Topic, readerConnectionID string, topic string, partitionID int64, partitionSessionID int64, committedOffset int64) { var p TopicReaderCommittedNotifyInfo p.ReaderConnectionID = readerConnectionID @@ -1080,6 +1091,7 @@ func TopicOnReaderCommittedNotify(t *Topic, readerConnectionID string, topic str p.CommittedOffset = committedOffset t.onReaderCommittedNotify(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnReaderClose(t *Topic, readerConnectionID string, closeReason error) func(closeError error) { var p TopicReaderCloseStartInfo p.ReaderConnectionID = readerConnectionID @@ -1091,6 +1103,7 @@ func TopicOnReaderClose(t *Topic, readerConnectionID string, closeReason error) res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnReaderInit(t *Topic, preInitReaderConnectionID string, initRequestInfo TopicReadStreamInitRequestInfo) func(readerConnectionID string, _ error) { var p TopicReaderInitStartInfo p.PreInitReaderConnectionID = preInitReaderConnectionID @@ -1103,12 +1116,14 @@ func TopicOnReaderInit(t *Topic, preInitReaderConnectionID string, initRequestIn res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnReaderError(t *Topic, readerConnectionID string, e error) { var p TopicReaderErrorInfo p.ReaderConnectionID = readerConnectionID p.Error = e t.onReaderError(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnReaderUpdateToken(t *Topic, readerConnectionID string) func(tokenLen int, _ error) func(error) { var p OnReadUpdateTokenStartInfo p.ReaderConnectionID = readerConnectionID @@ -1125,6 +1140,7 @@ func TopicOnReaderUpdateToken(t *Topic, readerConnectionID string) func(tokenLen } } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnReaderSentDataRequest(t *Topic, readerConnectionID string, requestBytes int, localBufferSizeAfterSent int) { var p TopicReaderSentDataRequestInfo p.ReaderConnectionID = readerConnectionID @@ -1132,6 +1148,7 @@ func TopicOnReaderSentDataRequest(t *Topic, readerConnectionID string, requestBy p.LocalBufferSizeAfterSent = localBufferSizeAfterSent t.onReaderSentDataRequest(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnReaderReceiveDataResponse(t *Topic, readerConnectionID string, localBufferSizeAfterReceive int, dataResponse TopicReaderDataResponseInfo) func(error) { var p TopicReaderReceiveDataResponseStartInfo p.ReaderConnectionID = readerConnectionID @@ -1144,6 +1161,7 @@ func TopicOnReaderReceiveDataResponse(t *Topic, readerConnectionID string, local res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnReaderReadMessages(t *Topic, requestContext context.Context, minCount int, maxCount int, freeBufferCapacity int) func(messagesCount int, topic string, partitionID int64, partitionSessionID int64, offsetStart int64, offsetEnd int64, freeBufferCapacity int, _ error) { var p TopicReaderReadMessagesStartInfo p.RequestContext = requestContext @@ -1164,12 +1182,14 @@ func TopicOnReaderReadMessages(t *Topic, requestContext context.Context, minCoun res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnReaderUnknownGrpcMessage(t *Topic, readerConnectionID string, e error) { var p OnReadUnknownGrpcMessageInfo p.ReaderConnectionID = readerConnectionID p.Error = e t.onReaderUnknownGrpcMessage(p) } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnWriterReconnect(t *Topic, writerInstanceID string, topic string, producerID string, attempt int) func(error) { var p TopicWriterReconnectStartInfo p.WriterInstanceID = writerInstanceID @@ -1183,6 +1203,7 @@ func TopicOnWriterReconnect(t *Topic, writerInstanceID string, topic string, pro res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnWriterInitStream(t *Topic, writerInstanceID string, topic string, producerID string) func(sessionID string, _ error) { var p TopicWriterInitStreamStartInfo p.WriterInstanceID = writerInstanceID @@ -1196,6 +1217,7 @@ func TopicOnWriterInitStream(t *Topic, writerInstanceID string, topic string, pr res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnWriterClose(t *Topic, writerInstanceID string, reason error) func(error) { var p TopicWriterCloseStartInfo p.WriterInstanceID = writerInstanceID @@ -1207,6 +1229,7 @@ func TopicOnWriterClose(t *Topic, writerInstanceID string, reason error) func(er res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnWriterCompressMessages(t *Topic, writerInstanceID string, sessionID string, codec int32, firstSeqNo int64, messagesCount int, reason TopicWriterCompressMessagesReason) func(error) { var p TopicWriterCompressMessagesStartInfo p.WriterInstanceID = writerInstanceID @@ -1222,6 +1245,7 @@ func TopicOnWriterCompressMessages(t *Topic, writerInstanceID string, sessionID res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnWriterSendMessages(t *Topic, writerInstanceID string, sessionID string, codec int32, firstSeqNo int64, messagesCount int) func(error) { var p TopicWriterSendMessagesStartInfo p.WriterInstanceID = writerInstanceID @@ -1236,6 +1260,7 @@ func TopicOnWriterSendMessages(t *Topic, writerInstanceID string, sessionID stri res(p) } } +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals func TopicOnWriterReadUnknownGrpcMessage(t *Topic, writerInstanceID string, sessionID string, e error) { var p TopicOnWriterReadUnknownGrpcMessageInfo p.WriterInstanceID = writerInstanceID diff --git a/trace/trace_test.go b/trace/trace_test.go index fbdf19668..b10945067 100644 --- a/trace/trace_test.go +++ b/trace/trace_test.go @@ -6,6 +6,82 @@ import ( "testing" ) +// Stub is a helper function that stubs all functional fields of x with given f. +func Stub(x interface{}, f func(name string, args ...interface{})) { + (FieldStubber{ + OnCall: f, + }).Stub(reflect.ValueOf(x)) +} + +func ClearContext(x interface{}) interface{} { + p := reflect.ValueOf(x).Index(0) + t := p.Elem().Type() + f, has := t.FieldByName("Context") + if has && f.Type.Kind() == reflect.Interface { + x := reflect.New(t) + x.Elem().Set(p.Elem()) + c := x.Elem().FieldByName(f.Name) + c.Set(reflect.Zero(c.Type())) + p.Set(x) + } + + return p.Interface() +} + +// FieldStubber contains options of filling all struct functional fields. +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals +type FieldStubber struct { + // OnStub is an optional callback that is called when field getting + // stubbed. + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnStub func(name string) + + // OnCall is an optional callback that will be called for each stubbed + // field getting called. + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnCall func(name string, args ...interface{}) +} + +// Stub fills in given x struct. +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals +func (f FieldStubber) Stub(x reflect.Value) { + var ( + v = x.Elem() + t = v.Type() + ) + for i := 0; i < t.NumField(); i++ { + var ( + fx = v.Field(i) + ft = fx.Type() + ) + if ft.Kind() != reflect.Func { + continue + } + name := t.Field(i).Name + if f.OnStub != nil { + f.OnStub(name) + } + out := []reflect.Value{} + for i := 0; i < ft.NumOut(); i++ { + ti := reflect.New(ft.Out(i)).Elem() + out = append(out, ti) + } + fn := reflect.MakeFunc(ft, func(args []reflect.Value) []reflect.Value { + if f.OnCall == nil { + return out + } + params := make([]interface{}, len(args)) + for i, arg := range args { + params[i] = arg.Interface() + } + f.OnCall(name, params...) + + return out + }) + fx.Set(fn) + } +} + func TestTable(t *testing.T) { testSingleTrace(t, &Table{}, "Table") } diff --git a/trace/traceutil.go b/trace/traceutil.go deleted file mode 100644 index 8ad52bfb6..000000000 --- a/trace/traceutil.go +++ /dev/null @@ -1,78 +0,0 @@ -package trace - -import ( - "reflect" -) - -// Stub is a helper function that stubs all functional fields of x with given -// f. -func Stub(x interface{}, f func(name string, args ...interface{})) { - (FieldStubber{ - OnCall: f, - }).Stub(reflect.ValueOf(x)) -} - -func ClearContext(x interface{}) interface{} { - p := reflect.ValueOf(x).Index(0) - t := p.Elem().Type() - f, has := t.FieldByName("Context") - if has && f.Type.Kind() == reflect.Interface { - x := reflect.New(t) - x.Elem().Set(p.Elem()) - c := x.Elem().FieldByName(f.Name) - c.Set(reflect.Zero(c.Type())) - p.Set(x) - } - - return p.Interface() -} - -// FieldStubber contains options of filling all struct functional fields. -type FieldStubber struct { - // OnStub is an optional callback that is called when field getting - // stubbed. - OnStub func(name string) - - // OnCall is an optional callback that will be called for each stubbed - // field getting called. - OnCall func(name string, args ...interface{}) -} - -// Stub fills in given x struct. -func (f FieldStubber) Stub(x reflect.Value) { - var ( - v = x.Elem() - t = v.Type() - ) - for i := 0; i < t.NumField(); i++ { - var ( - fx = v.Field(i) - ft = fx.Type() - ) - if ft.Kind() != reflect.Func { - continue - } - name := t.Field(i).Name - if f.OnStub != nil { - f.OnStub(name) - } - out := []reflect.Value{} - for i := 0; i < ft.NumOut(); i++ { - ti := reflect.New(ft.Out(i)).Elem() - out = append(out, ti) - } - fn := reflect.MakeFunc(ft, func(args []reflect.Value) []reflect.Value { - if f.OnCall == nil { - return out - } - params := make([]interface{}, len(args)) - for i, arg := range args { - params[i] = arg.Interface() - } - f.OnCall(name, params...) - - return out - }) - fx.Set(fn) - } -}