-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Reproducing YDB SDK bug * Reproducing YDB SDK bug - no success * Linter complaining
- Loading branch information
1 parent
4c48944
commit ec3f6b7
Showing
5 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
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 ( | ||
dbEndpoint = "localhost:2136" | ||
dbName = "/local" | ||
tableName = "simple" | ||
) | ||
|
||
func main() { | ||
log.Println("Correct credentials") | ||
obtainTableDesciption(dbEndpoint, "admin", "password") | ||
|
||
log.Println("Invalid credentials") | ||
obtainTableDesciption(dbEndpoint, "admin2", "password") | ||
} | ||
|
||
func obtainTableDesciption(endpoint, login, password string) { | ||
ydbDriver, err := makeDriver(endpoint, login, password) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
defer func() { | ||
if closeErr := ydbDriver.Close(context.Background()); closeErr != nil { | ||
log.Fatal(closeErr) | ||
} | ||
}() | ||
|
||
desc, err := getTableDescription(ydbDriver) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Printf("Table description: %+v", desc) | ||
} | ||
|
||
func makeDriver(endpoint, 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(endpoint, 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{} | ||
filePath := path.Join(dbName, tableName) | ||
|
||
log.Println("Getting table description for table", filePath) | ||
|
||
err := ydbDriver.Table().Do( | ||
context.Background(), | ||
func(ctx context.Context, s table.Session) error { | ||
var errInner error | ||
desc, errInner = s.DescribeTable(ctx, filePath) | ||
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 | ||
} |