Skip to content

Commit

Permalink
Reproducing YDB SDK bug
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalyisaev2 committed Oct 14, 2024
1 parent 4c48944 commit 3210559
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
File renamed without changes.
15 changes: 15 additions & 0 deletions tools/ydb/query_service_negative/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
ydb:
image: ghcr.io/ydb-platform/local-ydb:24.2.8
container_name: ${USER}-fq-connector-go-tests-ydb
hostname: localhost
ports:
- '2136:2136'
- '8765:8765'
environment:
YDB_DEFAULT_LOG_LEVEL: ERROR
POSTGRES_USER: admin
POSTGRES_PASSWORD: password
volumes:
- ./init/init_ydb:/init_ydb
- ./init/01_basic.sh:/01_basic.sh
15 changes: 15 additions & 0 deletions tools/ydb/query_service_negative/init/01_basic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

/ydb -p tests-ydb-client yql -s '
CREATE TABLE simple (id Int32 NOT NULL, col1 String NOT NULL, col2 Int32 NOT NULL, PRIMARY KEY (id));
COMMIT;
INSERT INTO simple (id, col1, col2) VALUES
(1, "ydb_a", 10),
(2, "ydb_b", 20),
(3, "ydb_c", 30),
(4, "ydb_d", 40),
(5, "ydb_e", 50);
COMMIT;
'

7 changes: 7 additions & 0 deletions tools/ydb/query_service_negative/init/init_ydb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -ex

/ydb config profile create tests-ydb-client --endpoint grpc://localhost:2136 --database /local

/bin/bash ./01_basic.sh
87 changes: 87 additions & 0 deletions tools/ydb/query_service_negative/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package main

import (
"context"
"fmt"
"log"
"path"
"time"

"github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3/balancers"
"github.com/ydb-platform/ydb-go-sdk/v3/config"
"github.com/ydb-platform/ydb-go-sdk/v3/sugar"
"github.com/ydb-platform/ydb-go-sdk/v3/table"
"github.com/ydb-platform/ydb-go-sdk/v3/table/options"
"google.golang.org/grpc"
)

const (
dbName = "/local"
tableName = "simple"
endpoint = "grpc://localhost:2136"
)

func main() {
log.Println("Correct credentials")
obtainTableDesciption("admin", "password")
}

func obtainTableDesciption(login, password string) {
ydbDriver, err := makeDriver(login, password)
if err != nil {
log.Fatal(err)
}

desc, err := getTableDescription(ydbDriver)
if err != nil {
log.Fatal(err)
}

log.Printf("Table description: %+v", desc)
}

func makeDriver(login, password string) (*ydb.Driver, error) {
ydbOptions := []ydb.Option{
ydb.WithStaticCredentials(login, password),
ydb.WithDialTimeout(5 * time.Second),
ydb.WithBalancer(balancers.SingleConn()), // see YQ-3089
ydb.With(config.WithGrpcOptions(grpc.WithDisableServiceConfig())),
}

dsn := sugar.DSN("localhost:2136", dbName, false)

ydbDriver, err := ydb.Open(context.Background(), dsn, ydbOptions...)
if err != nil {
return nil, fmt.Errorf("open driver error: %w", err)
}

return ydbDriver, nil
}

func getTableDescription(ydbDriver *ydb.Driver) (*options.Description, error) {
desc := options.Description{}
path := path.Join(dbName, tableName)

Check warning on line 64 in tools/ydb/query_service_negative/main.go

View workflow job for this annotation

GitHub Actions / lint

import-shadowing: The name 'path' shadows an import name (revive)

log.Println("Getting table description for table", path)

err := ydbDriver.Table().Do(
context.Background(),
func(ctx context.Context, s table.Session) error {
var errInner error
desc, errInner = s.DescribeTable(ctx, path)
if errInner != nil {
return fmt.Errorf("describe table: %w", errInner)
}

return nil
},
table.WithIdempotent(),
)

if err != nil {
return nil, fmt.Errorf("get table description: %w", err)
}

return &desc, nil
}

0 comments on commit 3210559

Please sign in to comment.