From 63e141b5f4b95af36afc4e9cd16990625a2395d4 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Fri, 2 Feb 2024 21:17:31 +0500 Subject: [PATCH 01/57] enable exhaustruct --- .golangci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 40e5b3514..92d5cc9e1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -222,7 +222,6 @@ linters: - errname - exhaustive - exhaustivestruct - - exhaustruct - forbidigo - forcetypeassert - funlen From d4987d9a5ec80bcc5bfa6f7e7368f377413181d5 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Wed, 7 Feb 2024 19:09:39 +0500 Subject: [PATCH 02/57] refactor initialization of 'endpoint' structure --- CHANGELOG.md | 2 ++ internal/endpoint/endpoint.go | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86c81bc7f..a3735879c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Added explicit initialization of all fields of the `endpoint` structure in `internal/endpoint/endpoint.go`, when golangci-lint exhaustruct enabled + * Fixed topic writer infinite reconnections in some cases * Refactored nil on err `internal/grpcwrapper/rawydb/issues.go`, when golangci-lint nilerr enabled * Refactored nil on err `internal/grpcwrapper/rawtopic/describe_topic.go`, when golangci-lint nilerr enabled diff --git a/internal/endpoint/endpoint.go b/internal/endpoint/endpoint.go index cdaba3710..937fdc3ee 100644 --- a/internal/endpoint/endpoint.go +++ b/internal/endpoint/endpoint.go @@ -41,6 +41,7 @@ func (e *endpoint) Copy() Endpoint { defer e.mu.RUnlock() return &endpoint{ + mu: sync.RWMutex{}, id: e.id, address: e.address, location: e.location, @@ -160,7 +161,13 @@ func withLastUpdated(ts time.Time) Option { func New(address string, opts ...Option) *endpoint { e := &endpoint{ + mu: sync.RWMutex{}, + id: 0, address: address, + location: "", + services: []string{}, + loadFactor: 0, + local: false, lastUpdated: time.Now(), } for _, o := range opts { From 62a8dfc7e513130ab23aba5b18490ed302df82b5 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Fri, 9 Feb 2024 20:24:23 +0500 Subject: [PATCH 03/57] refactor initialization of structures in internal/allocator/allocator.go --- CHANGELOG.md | 1 + internal/allocator/allocator.go | 48 ++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3735879c..a37e8efb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +* Added explicit initialization of fields of structures in `internal/allocator/allocator.go`, when golangci-lint exhaustruct enabled * Added explicit initialization of all fields of the `endpoint` structure in `internal/endpoint/endpoint.go`, when golangci-lint exhaustruct enabled * Fixed topic writer infinite reconnections in some cases diff --git a/internal/allocator/allocator.go b/internal/allocator/allocator.go index 6c55c51b4..c2d54de7d 100644 --- a/internal/allocator/allocator.go +++ b/internal/allocator/allocator.go @@ -5,6 +5,7 @@ import ( "github.com/ydb-platform/ydb-go-genproto/protos/Ydb" "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Table" + "google.golang.org/protobuf/types/known/structpb" ) type ( @@ -116,7 +117,7 @@ func (a *boolAllocator) Bool() (v *Ydb.Value_BoolValue) { func (a *boolAllocator) free() { for _, v := range a.allocations { - *v = Ydb.Value_BoolValue{} + *v = Ydb.Value_BoolValue{BoolValue: false} boolPool.Put(v) } a.allocations = a.allocations[:0] @@ -135,7 +136,7 @@ func (a *bytesAllocator) Bytes() (v *Ydb.Value_BytesValue) { func (a *bytesAllocator) free() { for _, v := range a.allocations { - *v = Ydb.Value_BytesValue{} + *v = Ydb.Value_BytesValue{BytesValue: []byte{}} bytesPool.Put(v) } a.allocations = a.allocations[:0] @@ -192,7 +193,7 @@ func (a *doubleAllocator) Double() (v *Ydb.Value_DoubleValue) { func (a *doubleAllocator) free() { for _, v := range a.allocations { - *v = Ydb.Value_DoubleValue{} + *v = Ydb.Value_DoubleValue{DoubleValue: 0} doublePool.Put(v) } a.allocations = a.allocations[:0] @@ -211,7 +212,7 @@ func (a *floatAllocator) Float() (v *Ydb.Value_FloatValue) { func (a *floatAllocator) free() { for _, v := range a.allocations { - *v = Ydb.Value_FloatValue{} + *v = Ydb.Value_FloatValue{FloatValue: 0} floatPool.Put(v) } a.allocations = a.allocations[:0] @@ -230,7 +231,7 @@ func (a *int32Allocator) Int32() (v *Ydb.Value_Int32Value) { func (a *int32Allocator) free() { for _, v := range a.allocations { - *v = Ydb.Value_Int32Value{} + *v = Ydb.Value_Int32Value{Int32Value: 0} int32Pool.Put(v) } a.allocations = a.allocations[:0] @@ -249,7 +250,7 @@ func (a *int64Allocator) Int64() (v *Ydb.Value_Int64Value) { func (a *int64Allocator) free() { for _, v := range a.allocations { - *v = Ydb.Value_Int64Value{} + *v = Ydb.Value_Int64Value{Int64Value: 0} int64Pool.Put(v) } a.allocations = a.allocations[:0] @@ -287,7 +288,7 @@ func (a *low128Allocator) Low128() (v *Ydb.Value_Low_128) { func (a *low128Allocator) free() { for _, v := range a.allocations { - *v = Ydb.Value_Low_128{} + *v = Ydb.Value_Low_128{Low_128: 0} low128Pool.Put(v) } a.allocations = a.allocations[:0] @@ -306,7 +307,7 @@ func (a *nestedAllocator) Nested() (v *Ydb.Value_NestedValue) { func (a *nestedAllocator) free() { for _, v := range a.allocations { - *v = Ydb.Value_NestedValue{} + *v = Ydb.Value_NestedValue{NestedValue: new(Ydb.Value)} nestedPool.Put(v) } a.allocations = a.allocations[:0] @@ -325,7 +326,7 @@ func (a *nullFlagAllocator) NullFlag() (v *Ydb.Value_NullFlagValue) { func (a *nullFlagAllocator) free() { for _, v := range a.allocations { - *v = Ydb.Value_NullFlagValue{} + *v = Ydb.Value_NullFlagValue{NullFlagValue: structpb.NullValue_NULL_VALUE} nullFlagPool.Put(v) } a.allocations = a.allocations[:0] @@ -363,7 +364,10 @@ func (a *pairAllocator) Pair() (v *Ydb.ValuePair) { func (a *pairAllocator) free() { for _, v := range a.allocations { - *v = Ydb.ValuePair{} + *v = Ydb.ValuePair{ + Key: new(Ydb.Value), + Payload: new(Ydb.Value), + } pairPool.Put(v) } a.allocations = a.allocations[:0] @@ -428,7 +432,7 @@ func (a *textAllocator) Text() (v *Ydb.Value_TextValue) { func (a *textAllocator) free() { for _, v := range a.allocations { - *v = Ydb.Value_TextValue{} + *v = Ydb.Value_TextValue{TextValue: ""} textPool.Put(v) } a.allocations = a.allocations[:0] @@ -471,7 +475,7 @@ func (a *typeDecimalAllocator) TypeDecimal() (v *Ydb.Type_DecimalType) { func (a *typeDecimalAllocator) free() { for _, v := range a.allocations { - *v = Ydb.Type_DecimalType{} + *v = Ydb.Type_DecimalType{DecimalType: new(Ydb.DecimalType)} typeDecimalPool.Put(v) } a.allocations = a.allocations[:0] @@ -490,7 +494,7 @@ func (a *typeDictAllocator) TypeDict() (v *Ydb.Type_DictType) { func (a *typeDictAllocator) free() { for _, v := range a.allocations { - *v = Ydb.Type_DictType{} + *v = Ydb.Type_DictType{DictType: new(Ydb.DictType)} typeDictPool.Put(v) } a.allocations = a.allocations[:0] @@ -509,7 +513,7 @@ func (a *typeEmptyListAllocator) TypeEmptyList() (v *Ydb.Type_EmptyListType) { func (a *typeEmptyListAllocator) free() { for _, v := range a.allocations { - *v = Ydb.Type_EmptyListType{} + *v = Ydb.Type_EmptyListType{EmptyListType: structpb.NullValue_NULL_VALUE} typeEmptyListPool.Put(v) } a.allocations = a.allocations[:0] @@ -528,7 +532,7 @@ func (a *typeEmptyDictAllocator) TypeEmptyDict() (v *Ydb.Type_EmptyDictType) { func (a *typeEmptyDictAllocator) free() { for _, v := range a.allocations { - *v = Ydb.Type_EmptyDictType{} + *v = Ydb.Type_EmptyDictType{EmptyDictType: structpb.NullValue_NULL_VALUE} typeEmptyDictPool.Put(v) } a.allocations = a.allocations[:0] @@ -566,7 +570,7 @@ func (a *typeListAllocator) TypeList() (v *Ydb.Type_ListType) { func (a *typeListAllocator) free() { for _, v := range a.allocations { - *v = Ydb.Type_ListType{} + *v = Ydb.Type_ListType{ListType: new(Ydb.ListType)} typeListPool.Put(v) } a.allocations = a.allocations[:0] @@ -585,7 +589,7 @@ func (a *typeOptionalAllocator) TypeOptional() (v *Ydb.Type_OptionalType) { func (a *typeOptionalAllocator) free() { for _, v := range a.allocations { - *v = Ydb.Type_OptionalType{} + *v = Ydb.Type_OptionalType{OptionalType: new(Ydb.OptionalType)} typeOptionalPool.Put(v) } a.allocations = a.allocations[:0] @@ -604,7 +608,7 @@ func (a *typeStructAllocator) TypeStruct() (v *Ydb.Type_StructType) { func (a *typeStructAllocator) free() { for _, v := range a.allocations { - *v = Ydb.Type_StructType{} + *v = Ydb.Type_StructType{StructType: new(Ydb.StructType)} typeStructPool.Put(v) } a.allocations = a.allocations[:0] @@ -623,7 +627,7 @@ func (a *typeTupleAllocator) TypeTuple() (v *Ydb.Type_TupleType) { func (a *typeTupleAllocator) free() { for _, v := range a.allocations { - *v = Ydb.Type_TupleType{} + *v = Ydb.Type_TupleType{TupleType: new(Ydb.TupleType)} typeTuplePool.Put(v) } a.allocations = a.allocations[:0] @@ -642,7 +646,7 @@ func (a *typeVariantAllocator) TypeVariant() (v *Ydb.Type_VariantType) { func (a *typeVariantAllocator) free() { for _, v := range a.allocations { - *v = Ydb.Type_VariantType{} + *v = Ydb.Type_VariantType{VariantType: new(Ydb.VariantType)} typeVariantPool.Put(v) } a.allocations = a.allocations[:0] @@ -680,7 +684,7 @@ func (a *uint32Allocator) Uint32() (v *Ydb.Value_Uint32Value) { func (a *uint32Allocator) free() { for _, v := range a.allocations { - *v = Ydb.Value_Uint32Value{} + *v = Ydb.Value_Uint32Value{Uint32Value: 0} uint32Pool.Put(v) } a.allocations = a.allocations[:0] @@ -699,7 +703,7 @@ func (a *uint64Allocator) Uint64() (v *Ydb.Value_Uint64Value) { func (a *uint64Allocator) free() { for _, v := range a.allocations { - *v = Ydb.Value_Uint64Value{} + *v = Ydb.Value_Uint64Value{Uint64Value: 0} uint64Pool.Put(v) } a.allocations = a.allocations[:0] From 4581e513b6aa89583986e33e24e0459bd6565ba8 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Sat, 10 Feb 2024 22:25:22 +0500 Subject: [PATCH 04/57] refactor initialization of structures in internal/backoff --- CHANGELOG.md | 1 + internal/backoff/backoff.go | 5 ++- internal/backoff/backoff_test.go | 68 ++++++++++++++++---------------- 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a37e8efb5..f8e704e91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +* Added explicit initialization of all fields of the `logBackoff` structure in `internal/backoff/backoff.go`, when golangci-lint exhaustruct enabled * Added explicit initialization of fields of structures in `internal/allocator/allocator.go`, when golangci-lint exhaustruct enabled * Added explicit initialization of all fields of the `endpoint` structure in `internal/endpoint/endpoint.go`, when golangci-lint exhaustruct enabled diff --git a/internal/backoff/backoff.go b/internal/backoff/backoff.go index 97beef0d9..2c65a8d82 100644 --- a/internal/backoff/backoff.go +++ b/internal/backoff/backoff.go @@ -84,7 +84,10 @@ func WithSeed(seed int64) option { func New(opts ...option) logBackoff { b := logBackoff{ - r: xrand.New(xrand.WithLock()), + slotDuration: time.Duration(0), + ceiling: 0, + jitterLimit: 0, + r: xrand.New(xrand.WithLock()), } for _, o := range opts { if o != nil { diff --git a/internal/backoff/backoff_test.go b/internal/backoff/backoff_test.go index 45cd7fd1e..85af1a0a9 100644 --- a/internal/backoff/backoff_test.go +++ b/internal/backoff/backoff_test.go @@ -60,13 +60,13 @@ func TestLogBackoff(t *testing.T) { WithSeed(0), ), exp: []exp{ - {gte: 0, lte: time.Second}, - {gte: 0, lte: 2 * time.Second}, - {gte: 0, lte: 4 * time.Second}, - {gte: 0, lte: 8 * time.Second}, - {gte: 0, lte: 8 * time.Second}, - {gte: 0, lte: 8 * time.Second}, - {gte: 0, lte: 8 * time.Second}, + {eq: 0, gte: 0, lte: time.Second}, + {eq: 0, gte: 0, lte: 2 * time.Second}, + {eq: 0, gte: 0, lte: 4 * time.Second}, + {eq: 0, gte: 0, lte: 8 * time.Second}, + {eq: 0, gte: 0, lte: 8 * time.Second}, + {eq: 0, gte: 0, lte: 8 * time.Second}, + {eq: 0, gte: 0, lte: 8 * time.Second}, }, seeds: 1000, }, @@ -78,13 +78,13 @@ func TestLogBackoff(t *testing.T) { WithSeed(0), ), exp: []exp{ - {gte: 500 * time.Millisecond, lte: time.Second}, - {gte: 1 * time.Second, lte: 2 * time.Second}, - {gte: 2 * time.Second, lte: 4 * time.Second}, - {gte: 4 * time.Second, lte: 8 * time.Second}, - {gte: 4 * time.Second, lte: 8 * time.Second}, - {gte: 4 * time.Second, lte: 8 * time.Second}, - {gte: 4 * time.Second, lte: 8 * time.Second}, + {eq: 0, gte: 500 * time.Millisecond, lte: time.Second}, + {eq: 0, gte: 1 * time.Second, lte: 2 * time.Second}, + {eq: 0, gte: 2 * time.Second, lte: 4 * time.Second}, + {eq: 0, gte: 4 * time.Second, lte: 8 * time.Second}, + {eq: 0, gte: 4 * time.Second, lte: 8 * time.Second}, + {eq: 0, gte: 4 * time.Second, lte: 8 * time.Second}, + {eq: 0, gte: 4 * time.Second, lte: 8 * time.Second}, }, seeds: 1000, }, @@ -96,14 +96,15 @@ func TestLogBackoff(t *testing.T) { WithSeed(0), ), exp: []exp{ - {eq: time.Second}, - {eq: 2 * time.Second}, - {eq: 4 * time.Second}, - {eq: 8 * time.Second}, - {eq: 8 * time.Second}, - {eq: 8 * time.Second}, - {eq: 8 * time.Second}, + {eq: time.Second, gte: 0, lte: 0}, + {eq: 2 * time.Second, gte: 0, lte: 0}, + {eq: 4 * time.Second, gte: 0, lte: 0}, + {eq: 8 * time.Second, gte: 0, lte: 0}, + {eq: 8 * time.Second, gte: 0, lte: 0}, + {eq: 8 * time.Second, gte: 0, lte: 0}, + {eq: 8 * time.Second, gte: 0, lte: 0}, }, + seeds: 0, }, { backoff: New( @@ -113,19 +114,20 @@ func TestLogBackoff(t *testing.T) { WithSeed(0), ), exp: []exp{ - {eq: time.Second}, - {eq: 2 * time.Second}, - {eq: 4 * time.Second}, - {eq: 8 * time.Second}, - {eq: 16 * time.Second}, - {eq: 32 * time.Second}, - {eq: 64 * time.Second}, - {eq: 64 * time.Second}, - {eq: 64 * time.Second}, - {eq: 64 * time.Second}, - {eq: 64 * time.Second}, - {eq: 64 * time.Second}, + {eq: time.Second, gte: 0, lte: 0}, + {eq: 2 * time.Second, gte: 0, lte: 0}, + {eq: 4 * time.Second, gte: 0, lte: 0}, + {eq: 8 * time.Second, gte: 0, lte: 0}, + {eq: 16 * time.Second, gte: 0, lte: 0}, + {eq: 32 * time.Second, gte: 0, lte: 0}, + {eq: 64 * time.Second, gte: 0, lte: 0}, + {eq: 64 * time.Second, gte: 0, lte: 0}, + {eq: 64 * time.Second, gte: 0, lte: 0}, + {eq: 64 * time.Second, gte: 0, lte: 0}, + {eq: 64 * time.Second, gte: 0, lte: 0}, + {eq: 64 * time.Second, gte: 0, lte: 0}, }, + seeds: 0, }, } { t.Run("", func(t *testing.T) { From 328f5da9a2ba455ff585df93d5dceaa43bac7a2e Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Mon, 12 Feb 2024 00:49:04 +0500 Subject: [PATCH 05/57] refactor initialization of structures in internal/bind --- CHANGELOG.md | 2 + internal/bind/numeric_args.go | 4 ++ internal/bind/numeric_args_test.go | 58 +++++++++++++++++++++------ internal/bind/params_test.go | 39 +++++++++--------- internal/bind/positional_args.go | 4 ++ internal/bind/positional_args_test.go | 51 +++++++++++++++++------ 6 files changed, 116 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8e704e91..0d5ee6119 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Added explicit initialization of all fields of the `sqlLexer` structure in `internal/bind/numeric_args.go`, when golangci-lint exhaustruct enabled +* Added explicit initialization of all fields of the `sqlLexer` structure in `internal/bind/positional_args.go`, when golangci-lint exhaustruct enabled * Added explicit initialization of all fields of the `logBackoff` structure in `internal/backoff/backoff.go`, when golangci-lint exhaustruct enabled * Added explicit initialization of fields of structures in `internal/allocator/allocator.go`, when golangci-lint exhaustruct enabled * Added explicit initialization of all fields of the `endpoint` structure in `internal/endpoint/endpoint.go`, when golangci-lint exhaustruct enabled diff --git a/internal/bind/numeric_args.go b/internal/bind/numeric_args.go index 89c9c4ecc..32b97afe1 100644 --- a/internal/bind/numeric_args.go +++ b/internal/bind/numeric_args.go @@ -21,8 +21,12 @@ func (m NumericArgs) RewriteQuery(sql string, args ...interface{}) ( ) { l := &sqlLexer{ src: sql, + start: 0, + pos: 0, + nested: 0, stateFn: numericArgsStateFn, rawStateFn: numericArgsStateFn, + parts: []interface{}{}, } for l.stateFn != nil { diff --git a/internal/bind/numeric_args_test.go b/internal/bind/numeric_args_test.go index 4f40da6c0..f5ad8ac13 100644 --- a/internal/bind/numeric_args_test.go +++ b/internal/bind/numeric_args_test.go @@ -27,7 +27,9 @@ func TestNumericArgsBindRewriteQuery(t *testing.T) { args: []interface{}{ 100, }, - err: ErrInconsistentArgs, + yql: "", + params: []interface{}{}, + err: ErrInconsistentArgs, }, { sql: `SELECT $123abc, $1`, @@ -39,6 +41,7 @@ SELECT $123abc, $p0`, params: []interface{}{ table.ValueParam("$p0", types.Int32Value(200)), }, + err: nil, }, { sql: `SELECT $1, $2`, @@ -52,6 +55,7 @@ SELECT $name1, $name2`, table.ValueParam("$name1", types.Int32Value(100)), table.ValueParam("$name2", types.Int32Value(200)), }, + err: nil, }, { sql: `SELECT $1, $2`, @@ -65,6 +69,7 @@ SELECT $namedArg, $p1`, table.ValueParam("$namedArg", types.Int32Value(100)), table.ValueParam("$p1", types.Int32Value(200)), }, + err: nil, }, { sql: `SELECT $0, $1`, @@ -72,7 +77,9 @@ SELECT $namedArg, $p1`, 100, 200, }, - err: ErrUnexpectedNumericArgZero, + yql: "", + params: []interface{}{}, + err: ErrUnexpectedNumericArgZero, }, { sql: `SELECT $1, $2`, @@ -86,13 +93,16 @@ SELECT $p0, $p1`, table.ValueParam("$p0", types.Int32Value(100)), table.ValueParam("$p1", types.Int32Value(200)), }, + err: nil, }, { sql: `SELECT $1, $2`, args: []interface{}{ 100, }, - err: ErrInconsistentArgs, + yql: "", + params: []interface{}{}, + err: ErrInconsistentArgs, }, { sql: `SELECT $1, "$2"`, @@ -104,6 +114,7 @@ SELECT $p0, "$2"`, params: []interface{}{ table.ValueParam("$p0", types.Int32Value(100)), }, + err: nil, }, { sql: `SELECT $1, '$2'`, @@ -115,6 +126,7 @@ SELECT $p0, '$2'`, params: []interface{}{ table.ValueParam("$p0", types.Int32Value(100)), }, + err: nil, }, { sql: "SELECT $1, `$2`", @@ -125,9 +137,12 @@ SELECT $p0, '$2'`, params: []interface{}{ table.ValueParam("$p0", types.Int32Value(100)), }, + err: nil, }, { sql: "SELECT ?, $1, $p0", + args: []interface{}{}, + yql: "", params: []interface{}{}, err: ErrInconsistentArgs, }, @@ -153,6 +168,7 @@ SELECT $p0, $p1, $p2`, types.TextValue("test3"), )), }, + err: nil, }, { sql: "SELECT $1, $2, $3, $1, $2", @@ -176,6 +192,7 @@ SELECT $p0, $p1, $p2, $p0, $p1`, types.TextValue("test3"), )), }, + err: nil, }, { sql: "SELECT $1, $2, $3", @@ -199,6 +216,7 @@ SELECT $p0, $p1, $p2`, types.TextValue("test3"), )), }, + err: nil, }, { sql: "SELECT $1, a, b, c WHERE id = $1 AND date < $2 AND value IN ($3)", @@ -212,23 +230,30 @@ SELECT $p0, a, b, c WHERE id = $p0 AND date < $p1 AND value IN ($p2)`, table.ValueParam("$p1", types.TimestampValueFromTime(now)), table.ValueParam("$p2", types.ListValue(types.TextValue("3"))), }, + err: nil, }, { - sql: "SELECT 1", - yql: "SELECT 1", + sql: "SELECT 1", + args: []interface{}{}, + yql: "SELECT 1", + params: []interface{}{}, + err: nil, }, { - sql: ` -SELECT 1`, - yql: ` -SELECT 1`, + sql: `SELECT 1`, + args: []interface{}{}, + yql: `SELECT 1`, + params: []interface{}{}, + err: nil, }, { sql: "SELECT $1, $2", args: []interface{}{ 1, }, - err: ErrInconsistentArgs, + yql: "", + params: []interface{}{}, + err: ErrInconsistentArgs, }, { sql: "SELECT $1, $2 -- some comment with $3", @@ -242,6 +267,7 @@ SELECT $p0, $p1 -- some comment with $3`, table.ValueParam("$p0", types.Int32Value(100)), table.ValueParam("$p1", types.Int32Value(200)), }, + err: nil, }, { sql: "SELECT $1 /* some comment with $3 */, $2", @@ -255,13 +281,16 @@ SELECT $p0 /* some comment with $3 */, $p1`, table.ValueParam("$p0", types.Int32Value(100)), table.ValueParam("$p1", types.Int32Value(200)), }, + err: nil, }, { sql: "SELECT $1, $2 -- some comment with $3", args: []interface{}{ 100, }, - err: ErrInconsistentArgs, + yql: "", + params: []interface{}{}, + err: ErrInconsistentArgs, }, { sql: "SELECT $1, $2, $3", @@ -269,7 +298,9 @@ SELECT $p0 /* some comment with $3 */, $p1`, 100, 200, }, - err: ErrInconsistentArgs, + yql: "", + params: []interface{}{}, + err: ErrInconsistentArgs, }, { sql: ` @@ -285,6 +316,7 @@ SELECT $p0 /* some comment with $3 */, $p1`, table.ValueParam("$p0", types.Int32Value(100)), table.ValueParam("$p1", types.Int32Value(200)), }, + err: nil, }, { sql: "SELECT $1, $2", @@ -298,6 +330,7 @@ SELECT $p0, $p1`, table.ValueParam("$p0", types.Int32Value(100)), table.ValueParam("$p1", types.Int32Value(200)), }, + err: nil, }, { sql: "SELECT $1, $2", @@ -311,6 +344,7 @@ SELECT $p0, $p1`, table.ValueParam("$p0", types.Int32Value(100)), table.ValueParam("$p1", types.Int32Value(200)), }, + err: nil, }, } { t.Run("", func(t *testing.T) { diff --git a/internal/bind/params_test.go b/internal/bind/params_test.go index 80d47b4a3..3721d17cc 100644 --- a/internal/bind/params_test.go +++ b/internal/bind/params_test.go @@ -338,8 +338,9 @@ func TestToValue(t *testing.T) { func named(name string, value interface{}) driver.NamedValue { return driver.NamedValue{ - Name: name, - Value: value, + Name: name, + Ordinal: 0, + Value: value, } } @@ -370,7 +371,7 @@ func TestYdbParam(t *testing.T) { err: nil, }, { - src: driver.NamedValue{Value: uint(42)}, + src: driver.NamedValue{Name: "", Ordinal: 0, Value: uint(42)}, dst: nil, err: errUnnamedParam, }, @@ -421,7 +422,8 @@ func TestArgsToParams(t *testing.T) { table.ValueParam("$p2", types.TextValue("3")), ), }, - err: errMultipleQueryParameters, + params: []table.ParameterOption{}, + err: errMultipleQueryParameters, }, { args: []interface{}{ @@ -451,9 +453,9 @@ func TestArgsToParams(t *testing.T) { }, { args: []interface{}{ - driver.NamedValue{Name: "$p0", Value: types.Int32Value(1)}, - driver.NamedValue{Name: "$p1", Value: types.Uint64Value(2)}, - driver.NamedValue{Name: "$p2", Value: types.TextValue("3")}, + driver.NamedValue{Name: "$p0", Ordinal: 0, Value: types.Int32Value(1)}, + driver.NamedValue{Name: "$p1", Ordinal: 0, Value: types.Uint64Value(2)}, + driver.NamedValue{Name: "$p2", Ordinal: 0, Value: types.TextValue("3")}, }, params: []table.ParameterOption{ table.ValueParam("$p0", types.Int32Value(1)), @@ -464,9 +466,9 @@ func TestArgsToParams(t *testing.T) { }, { args: []interface{}{ - driver.NamedValue{Value: table.ValueParam("$p0", types.Int32Value(1))}, - driver.NamedValue{Value: table.ValueParam("$p1", types.Uint64Value(2))}, - driver.NamedValue{Value: table.ValueParam("$p2", types.TextValue("3"))}, + driver.NamedValue{Name: "$p0", Ordinal: 0, Value: table.ValueParam("$p0", types.Int32Value(1))}, + driver.NamedValue{Name: "$p1", Ordinal: 0, Value: table.ValueParam("$p1", types.Uint64Value(2))}, + driver.NamedValue{Name: "$p2", Ordinal: 0, Value: table.ValueParam("$p2", types.TextValue("3"))}, }, params: []table.ParameterOption{ table.ValueParam("$p0", types.Int32Value(1)), @@ -477,9 +479,9 @@ func TestArgsToParams(t *testing.T) { }, { args: []interface{}{ - driver.NamedValue{Value: 1}, - driver.NamedValue{Value: uint64(2)}, - driver.NamedValue{Value: "3"}, + driver.NamedValue{Name: "$p0", Ordinal: 0, Value: 1}, + driver.NamedValue{Name: "$p1", Ordinal: 0, Value: uint64(2)}, + driver.NamedValue{Name: "$p2", Ordinal: 0, Value: "3"}, }, params: []table.ParameterOption{ table.ValueParam("$p0", types.Int32Value(1)), @@ -490,7 +492,7 @@ func TestArgsToParams(t *testing.T) { }, { args: []interface{}{ - driver.NamedValue{Value: table.NewQueryParameters( + driver.NamedValue{Name: "$p0 $p1 $p2", Ordinal: 0, Value: table.NewQueryParameters( table.ValueParam("$p0", types.Int32Value(1)), table.ValueParam("$p1", types.Uint64Value(2)), table.ValueParam("$p2", types.TextValue("3")), @@ -505,15 +507,16 @@ func TestArgsToParams(t *testing.T) { }, { args: []interface{}{ - driver.NamedValue{Value: table.NewQueryParameters( + driver.NamedValue{Name: "$p0 $p1 $p2", Ordinal: 0, Value: table.NewQueryParameters( table.ValueParam("$p0", types.Int32Value(1)), table.ValueParam("$p1", types.Uint64Value(2)), table.ValueParam("$p2", types.TextValue("3")), )}, - driver.NamedValue{Value: table.ValueParam("$p1", types.Uint64Value(2))}, - driver.NamedValue{Value: table.ValueParam("$p2", types.TextValue("3"))}, + driver.NamedValue{Name: "$p1", Ordinal: 0, Value: table.ValueParam("$p1", types.Uint64Value(2))}, + driver.NamedValue{Name: "$p2", Ordinal: 0, Value: table.ValueParam("$p2", types.TextValue("3"))}, }, - err: errMultipleQueryParameters, + params: []table.ParameterOption{}, + err: errMultipleQueryParameters, }, } { t.Run("", func(t *testing.T) { diff --git a/internal/bind/positional_args.go b/internal/bind/positional_args.go index e3c0afa13..1df73d5f0 100644 --- a/internal/bind/positional_args.go +++ b/internal/bind/positional_args.go @@ -21,8 +21,12 @@ func (m PositionalArgs) RewriteQuery(sql string, args ...interface{}) ( ) { l := &sqlLexer{ src: sql, + start: 0, + pos: 0, + nested: 0, stateFn: positionalArgsStateFn, rawStateFn: positionalArgsStateFn, + parts: []interface{}{}, } for l.stateFn != nil { diff --git a/internal/bind/positional_args_test.go b/internal/bind/positional_args_test.go index f1224730e..dce0cff32 100644 --- a/internal/bind/positional_args_test.go +++ b/internal/bind/positional_args_test.go @@ -34,13 +34,16 @@ SELECT $p0, $p1`, table.ValueParam("$p0", types.Int32Value(100)), table.ValueParam("$p1", types.Int32Value(200)), }, + err: nil, }, { sql: `SELECT ?, ?`, args: []interface{}{ 100, }, - err: ErrInconsistentArgs, + yql: "", + params: []interface{}{}, + err: ErrInconsistentArgs, }, { sql: `SELECT ?, "?"`, @@ -52,6 +55,7 @@ SELECT $p0, "?"`, params: []interface{}{ table.ValueParam("$p0", types.Int32Value(100)), }, + err: nil, }, { sql: `SELECT ?, '?'`, @@ -63,6 +67,7 @@ SELECT $p0, '?'`, params: []interface{}{ table.ValueParam("$p0", types.Int32Value(100)), }, + err: nil, }, { sql: "SELECT ?, `?`", @@ -73,10 +78,14 @@ SELECT $p0, '?'`, params: []interface{}{ table.ValueParam("$p0", types.Int32Value(100)), }, + err: nil, }, { - sql: "SELECT ?, $1, $p0", - err: ErrInconsistentArgs, + sql: "SELECT ?, $1, $p0", + args: []interface{}{}, + yql: "", + params: []interface{}{}, + err: ErrInconsistentArgs, }, { sql: "SELECT ?, ?, ?", @@ -100,6 +109,7 @@ SELECT $p0, $p1, $p2`, types.TextValue("test3"), )), }, + err: nil, }, { sql: "SELECT ?, ?, ?", @@ -123,6 +133,7 @@ SELECT $p0, $p1, $p2`, types.TextValue("test3"), )), }, + err: nil, }, { sql: "SELECT a, b, c WHERE id = ? AND date < ? AND value IN (?)", @@ -136,23 +147,30 @@ SELECT a, b, c WHERE id = $p0 AND date < $p1 AND value IN ($p2)`, table.ValueParam("$p1", types.TimestampValueFromTime(now)), table.ValueParam("$p2", types.ListValue(types.TextValue("3"))), }, + err: nil, }, { - sql: "SELECT 1", - yql: "SELECT 1", + sql: "SELECT 1", + args: []interface{}{}, + yql: "SELECT 1", + params: []interface{}{}, + err: nil, }, { - sql: ` -SELECT 1`, - yql: ` -SELECT 1`, + sql: `SELECT 1`, + args: []interface{}{}, + yql: `SELECT 1`, + params: []interface{}{}, + err: nil, }, { sql: "SELECT ?, ?", args: []interface{}{ 1, }, - err: ErrInconsistentArgs, + yql: "", + params: []interface{}{}, + err: ErrInconsistentArgs, }, { sql: "SELECT ?, ? -- some comment with ?", @@ -166,6 +184,7 @@ SELECT $p0, $p1 -- some comment with ?`, table.ValueParam("$p0", types.Int32Value(100)), table.ValueParam("$p1", types.Int32Value(200)), }, + err: nil, }, { sql: "SELECT ? /* some comment with ? */, ?", @@ -179,13 +198,16 @@ SELECT $p0 /* some comment with ? */, $p1`, table.ValueParam("$p0", types.Int32Value(100)), table.ValueParam("$p1", types.Int32Value(200)), }, + err: nil, }, { sql: "SELECT ?, ? -- some comment with ?", args: []interface{}{ 100, }, - err: ErrInconsistentArgs, + yql: "", + params: []interface{}{}, + err: ErrInconsistentArgs, }, { sql: "SELECT ?, ?, ?", @@ -193,7 +215,9 @@ SELECT $p0 /* some comment with ? */, $p1`, 100, 200, }, - err: ErrInconsistentArgs, + yql: "", + params: []interface{}{}, + err: ErrInconsistentArgs, }, { sql: ` @@ -209,6 +233,7 @@ SELECT $p0 /* some comment with ? */, $p1`, table.ValueParam("$p0", types.Int32Value(100)), table.ValueParam("$p1", types.Int32Value(200)), }, + err: nil, }, { sql: "SELECT ?, ?", @@ -222,6 +247,7 @@ SELECT $p0, $p1`, table.ValueParam("$p0", types.Int32Value(100)), table.ValueParam("$p1", types.Int32Value(200)), }, + err: nil, }, { sql: "SELECT ?, ?", @@ -235,6 +261,7 @@ SELECT $p0, $p1`, table.ValueParam("$p0", types.Int32Value(100)), table.ValueParam("$p1", types.Int32Value(200)), }, + err: nil, }, } { t.Run("", func(t *testing.T) { From 46235d23771921eb44316d9389519d1a453e779b Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Tue, 13 Feb 2024 23:41:40 +0500 Subject: [PATCH 06/57] edit CHANGELOG.md --- CHANGELOG.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d5ee6119..86c81bc7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,3 @@ -* Added explicit initialization of all fields of the `sqlLexer` structure in `internal/bind/numeric_args.go`, when golangci-lint exhaustruct enabled -* Added explicit initialization of all fields of the `sqlLexer` structure in `internal/bind/positional_args.go`, when golangci-lint exhaustruct enabled -* Added explicit initialization of all fields of the `logBackoff` structure in `internal/backoff/backoff.go`, when golangci-lint exhaustruct enabled -* Added explicit initialization of fields of structures in `internal/allocator/allocator.go`, when golangci-lint exhaustruct enabled -* Added explicit initialization of all fields of the `endpoint` structure in `internal/endpoint/endpoint.go`, when golangci-lint exhaustruct enabled - * Fixed topic writer infinite reconnections in some cases * Refactored nil on err `internal/grpcwrapper/rawydb/issues.go`, when golangci-lint nilerr enabled * Refactored nil on err `internal/grpcwrapper/rawtopic/describe_topic.go`, when golangci-lint nilerr enabled From 4bec025db36f8f86fbe3647c4f54a87ba250cb41 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Tue, 13 Feb 2024 23:46:16 +0500 Subject: [PATCH 07/57] refactor initialization of structures in internal/certificates --- internal/certificates/certificates.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/certificates/certificates.go b/internal/certificates/certificates.go index 8282dce79..be18ebc63 100644 --- a/internal/certificates/certificates.go +++ b/internal/certificates/certificates.go @@ -53,7 +53,11 @@ func loadFromFileCache(key string) (_ []*x509.Certificate, exists bool) { // FromFile reads and parses pem-encoded certificate(s) from file. func FromFile(file string, opts ...FromFileOption) ([]*x509.Certificate, error) { - options := fromFileOptions{} + options := fromFileOptions{ + onHit: nil, + onMiss: nil, + noCache: false, + } for _, opt := range opts { if opt != nil { opt(&options) @@ -108,7 +112,11 @@ func loadFromPemCache(key string) (_ *x509.Certificate, exists bool) { // parseCertificate is a cached version of x509.ParseCertificate. Cache key is string(der) func parseCertificate(der []byte, opts ...FromPemOption) (*x509.Certificate, error) { - options := fromPemOptions{} + options := fromPemOptions{ + onHit: nil, + onMiss: nil, + noCache: false, + } for _, opt := range opts { if opt != nil { opt(&options) From 5f972576b1ba47f1ff55ed2dd32169c51241c290 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Wed, 14 Feb 2024 00:17:15 +0500 Subject: [PATCH 08/57] add explicit initialization of fileds of structures in internal/credentials --- internal/credentials/access_error_test.go | 2 +- internal/credentials/static.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/credentials/access_error_test.go b/internal/credentials/access_error_test.go index 565ad8975..468c777eb 100644 --- a/internal/credentials/access_error_test.go +++ b/internal/credentials/access_error_test.go @@ -14,7 +14,7 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" ) -var _ Credentials = customCredentials{} +var _ Credentials = customCredentials{token: ""} type customCredentials struct { token string diff --git a/internal/credentials/static.go b/internal/credentials/static.go index 56e80277d..c23bc466f 100644 --- a/internal/credentials/static.go +++ b/internal/credentials/static.go @@ -44,6 +44,10 @@ func NewStaticCredentials(user, password, endpoint string, opts ...StaticCredent user: user, password: password, endpoint: endpoint, + opts: []grpc.DialOption{}, + token: "", + requestAt: time.Time{}, + mu: sync.Mutex{}, sourceInfo: stack.Record(1), } for _, opt := range opts { From 7b7836fdba0abbc87870a0beace45eeaa7f96dc1 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Thu, 7 Mar 2024 00:13:55 +0500 Subject: [PATCH 09/57] add explicit initialization of fileds of structures in internal/grpcwrapper --- internal/allocator/allocator.go | 3 ++- internal/bind/params_test.go | 16 +++++++------- internal/grpcwrapper/rawtopic/alter_topic.go | 4 ++++ .../rawtopic/controlplane_types.go | 1 + internal/grpcwrapper/rawtopic/create_topic.go | 21 ++++++++++--------- .../grpcwrapper/rawtopic/describe_topic.go | 3 ++- .../rawtopic/rawtopicreader/messages.go | 20 ++++++++++-------- .../rawtopic/rawtopicreader/rawtopicreader.go | 14 ++++++------- .../rawtopic/rawtopicwriter/messages.go | 10 +++++++-- .../rawtopicwriter/streamwriter_test.go | 4 ++++ .../grpcwrapper/rawydb/operation_params.go | 9 +++++--- 11 files changed, 64 insertions(+), 41 deletions(-) diff --git a/internal/allocator/allocator.go b/internal/allocator/allocator.go index e8e0a7475..932899fc6 100644 --- a/internal/allocator/allocator.go +++ b/internal/allocator/allocator.go @@ -2,11 +2,12 @@ package allocator import ( "sync" + + "google.golang.org/protobuf/types/known/structpb" "github.com/ydb-platform/ydb-go-genproto/protos/Ydb" "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Query" "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Table" - "google.golang.org/protobuf/types/known/structpb" ) type ( diff --git a/internal/bind/params_test.go b/internal/bind/params_test.go index 8ff0ee6c5..a636bd6da 100644 --- a/internal/bind/params_test.go +++ b/internal/bind/params_test.go @@ -411,18 +411,18 @@ func TestArgsToParams(t *testing.T) { }, { args: []interface{}{ - ¶ms.Parameters{ + ¶ms.Parameters{ params.Named("$p0", types.Int32Value(1)), params.Named("$p1", types.Uint64Value(2)), params.Named("$p2", types.TextValue("3")), - }, + }, ¶ms.Parameters{ params.Named("$p0", types.Int32Value(1)), params.Named("$p1", types.Uint64Value(2)), params.Named("$p2", types.TextValue("3")), - }, + }, }, - params: []*params.Parameter, + params: []*params.Parameter{}, err: errMultipleQueryParameters, }, { @@ -492,11 +492,11 @@ func TestArgsToParams(t *testing.T) { }, { args: []interface{}{ - driver.NamedValue{Name: "", Ordinal: 0, Value: ¶ms.Parameters{ + driver.NamedValue{Name: "", Ordinal: 0, Value: ¶ms.Parameters{ params.Named("$p0", types.Int32Value(1)), params.Named("$p1", types.Uint64Value(2)), params.Named("$p2", types.TextValue("3")), - }}, + }}, }, params: []*params.Parameter{ params.Named("$p0", types.Int32Value(1)), @@ -511,11 +511,11 @@ func TestArgsToParams(t *testing.T) { params.Named("$p0", types.Int32Value(1)), params.Named("$p1", types.Uint64Value(2)), params.Named("$p2", types.TextValue("3")), - }}, + }}, driver.NamedValue{Name: "$p1", Ordinal: 0, Value: params.Named("$p1", types.Uint64Value(2))}, driver.NamedValue{Name: "$p2", Ordinal: 0, Value: params.Named("$p2", types.TextValue("3"))}, }, - params: []*params.Parameter, + params: []*params.Parameter{}, err: errMultipleQueryParameters, }, } { diff --git a/internal/grpcwrapper/rawtopic/alter_topic.go b/internal/grpcwrapper/rawtopic/alter_topic.go index d7db57d74..c78f307ab 100644 --- a/internal/grpcwrapper/rawtopic/alter_topic.go +++ b/internal/grpcwrapper/rawtopic/alter_topic.go @@ -34,9 +34,13 @@ func (req *AlterTopicRequest) ToProto() *Ydb_Topic.AlterTopicRequest { AlterPartitioningSettings: req.AlterPartitionSettings.ToProto(), SetRetentionPeriod: req.SetRetentionPeriod.ToProto(), SetRetentionStorageMb: req.SetRetentionStorageMB.ToProto(), + SetSupportedCodecs: req.SetSupportedCodecsValue.ToProto(), SetPartitionWriteSpeedBytesPerSecond: req.SetPartitionWriteSpeedBytesPerSecond.ToProto(), SetPartitionWriteBurstBytes: req.SetPartitionWriteBurstBytes.ToProto(), AlterAttributes: req.AlterAttributes, + AddConsumers: []*Ydb_Topic.Consumer{}, + DropConsumers: []string{}, + AlterConsumers: []*Ydb_Topic.AlterConsumer{}, SetMeteringMode: Ydb_Topic.MeteringMode(req.SetMeteringMode), } diff --git a/internal/grpcwrapper/rawtopic/controlplane_types.go b/internal/grpcwrapper/rawtopic/controlplane_types.go index 6df4322fb..6940958d1 100644 --- a/internal/grpcwrapper/rawtopic/controlplane_types.go +++ b/internal/grpcwrapper/rawtopic/controlplane_types.go @@ -35,6 +35,7 @@ func (c *Consumer) ToProto() *Ydb_Topic.Consumer { ReadFrom: c.ReadFrom.ToProto(), SupportedCodecs: c.SupportedCodecs.ToProto(), Attributes: c.Attributes, + ConsumerStats: new(Ydb_Topic.Consumer_ConsumerStats), } } diff --git a/internal/grpcwrapper/rawtopic/create_topic.go b/internal/grpcwrapper/rawtopic/create_topic.go index fd17da84e..e23035eae 100644 --- a/internal/grpcwrapper/rawtopic/create_topic.go +++ b/internal/grpcwrapper/rawtopic/create_topic.go @@ -27,26 +27,27 @@ type CreateTopicRequest struct { func (req *CreateTopicRequest) ToProto() *Ydb_Topic.CreateTopicRequest { proto := &Ydb_Topic.CreateTopicRequest{ - Path: req.Path, - PartitioningSettings: req.PartitionSettings.ToProto(), + OperationParams: req.OperationParams.ToProto(), + Path: req.Path, + PartitioningSettings: req.PartitionSettings.ToProto(), + RetentionPeriod: new(durationpb.Duration), + RetentionStorageMb: req.RetentionStorageMB, + SupportedCodecs: req.SupportedCodecs.ToProto(), + PartitionWriteSpeedBytesPerSecond: req.PartitionWriteSpeedBytesPerSecond, + PartitionWriteBurstBytes: req.PartitionWriteBurstBytes, + Attributes: req.Attributes, + Consumers: make([]*Ydb_Topic.Consumer, len(req.Consumers)), + MeteringMode: Ydb_Topic.MeteringMode(req.MeteringMode), } if req.RetentionPeriod != 0 { proto.RetentionPeriod = durationpb.New(req.RetentionPeriod) } - proto.RetentionStorageMb = req.RetentionStorageMB - proto.SupportedCodecs = req.SupportedCodecs.ToProto() - proto.PartitionWriteSpeedBytesPerSecond = req.PartitionWriteSpeedBytesPerSecond - proto.PartitionWriteBurstBytes = req.PartitionWriteBurstBytes - proto.Attributes = req.Attributes - proto.Consumers = make([]*Ydb_Topic.Consumer, len(req.Consumers)) for i := range proto.GetConsumers() { proto.Consumers[i] = req.Consumers[i].ToProto() } - proto.MeteringMode = Ydb_Topic.MeteringMode(req.MeteringMode) - return proto } diff --git a/internal/grpcwrapper/rawtopic/describe_topic.go b/internal/grpcwrapper/rawtopic/describe_topic.go index a1c3d4838..9d040e04f 100644 --- a/internal/grpcwrapper/rawtopic/describe_topic.go +++ b/internal/grpcwrapper/rawtopic/describe_topic.go @@ -22,6 +22,7 @@ func (req *DescribeTopicRequest) ToProto() *Ydb_Topic.DescribeTopicRequest { return &Ydb_Topic.DescribeTopicRequest{ OperationParams: req.OperationParams.ToProto(), Path: req.Path, + IncludeStats: false, } } @@ -46,7 +47,7 @@ func (res *DescribeTopicResult) FromProto(protoResponse *Ydb_Topic.DescribeTopic return err } - protoResult := &Ydb_Topic.DescribeTopicResult{} + protoResult := new(Ydb_Topic.DescribeTopicResult) if err := protoResponse.GetOperation().GetResult().UnmarshalTo(protoResult); err != nil { return xerrors.WithStackTrace(fmt.Errorf("ydb: describe topic result failed on unmarshal grpc result: %w", err)) } diff --git a/internal/grpcwrapper/rawtopic/rawtopicreader/messages.go b/internal/grpcwrapper/rawtopic/rawtopicreader/messages.go index 5a34477ee..ead95a1f3 100644 --- a/internal/grpcwrapper/rawtopic/rawtopicreader/messages.go +++ b/internal/grpcwrapper/rawtopic/rawtopicreader/messages.go @@ -111,13 +111,14 @@ type InitRequest struct { func (r *InitRequest) toProto() *Ydb_Topic.StreamReadMessage_InitRequest { p := &Ydb_Topic.StreamReadMessage_InitRequest{ - Consumer: r.Consumer, + Consumer: r.Consumer, + TopicsReadSettings: make([]*Ydb_Topic.StreamReadMessage_InitRequest_TopicReadSettings, len(r.TopicsReadSettings)), + ReaderName: "", } - p.TopicsReadSettings = make([]*Ydb_Topic.StreamReadMessage_InitRequest_TopicReadSettings, len(r.TopicsReadSettings)) for topicSettingsIndex := range r.TopicsReadSettings { srcTopicSettings := &r.TopicsReadSettings[topicSettingsIndex] - dstTopicSettings := &Ydb_Topic.StreamReadMessage_InitRequest_TopicReadSettings{} + dstTopicSettings := new(Ydb_Topic.StreamReadMessage_InitRequest_TopicReadSettings) p.TopicsReadSettings[topicSettingsIndex] = dstTopicSettings dstTopicSettings.Path = srcTopicSettings.Path @@ -301,20 +302,21 @@ type CommitOffsetRequest struct { } func (r *CommitOffsetRequest) toProto() *Ydb_Topic.StreamReadMessage_CommitOffsetRequest { - res := &Ydb_Topic.StreamReadMessage_CommitOffsetRequest{} - res.CommitOffsets = make( - []*Ydb_Topic.StreamReadMessage_CommitOffsetRequest_PartitionCommitOffset, - len(r.CommitOffsets), - ) + res := &Ydb_Topic.StreamReadMessage_CommitOffsetRequest{ + CommitOffsets: make( + []*Ydb_Topic.StreamReadMessage_CommitOffsetRequest_PartitionCommitOffset, + len(r.CommitOffsets), + ), + } for sessionIndex := range r.CommitOffsets { srcPartitionCommitOffset := &r.CommitOffsets[sessionIndex] dstCommitOffset := &Ydb_Topic.StreamReadMessage_CommitOffsetRequest_PartitionCommitOffset{ PartitionSessionId: srcPartitionCommitOffset.PartitionSessionID.ToInt64(), + Offsets: make([]*Ydb_Topic.OffsetsRange, len(srcPartitionCommitOffset.Offsets)), } res.CommitOffsets[sessionIndex] = dstCommitOffset - dstCommitOffset.Offsets = make([]*Ydb_Topic.OffsetsRange, len(srcPartitionCommitOffset.Offsets)) for offsetIndex := range srcPartitionCommitOffset.Offsets { dstCommitOffset.Offsets[offsetIndex] = srcPartitionCommitOffset.Offsets[offsetIndex].ToProto() } diff --git a/internal/grpcwrapper/rawtopic/rawtopicreader/rawtopicreader.go b/internal/grpcwrapper/rawtopic/rawtopicreader/rawtopicreader.go index 17ccc026e..db2a7f461 100644 --- a/internal/grpcwrapper/rawtopic/rawtopicreader/rawtopicreader.go +++ b/internal/grpcwrapper/rawtopic/rawtopicreader/rawtopicreader.go @@ -52,13 +52,13 @@ func (s StreamReader) Recv() (ServerMessage, error) { switch m := grpcMess.GetServerMessage().(type) { case *Ydb_Topic.StreamReadMessage_FromServer_InitResponse: - resp := &InitResponse{} + resp := new(InitResponse) resp.ServerMessageMetadata = meta resp.fromProto(m.InitResponse) return resp, nil case *Ydb_Topic.StreamReadMessage_FromServer_ReadResponse: - resp := &ReadResponse{} + resp := new(ReadResponse) resp.ServerMessageMetadata = meta if err = resp.fromProto(m.ReadResponse); err != nil { return nil, err @@ -66,7 +66,7 @@ func (s StreamReader) Recv() (ServerMessage, error) { return resp, nil case *Ydb_Topic.StreamReadMessage_FromServer_StartPartitionSessionRequest: - resp := &StartPartitionSessionRequest{} + resp := new(StartPartitionSessionRequest) resp.ServerMessageMetadata = meta if err = resp.fromProto(m.StartPartitionSessionRequest); err != nil { return nil, err @@ -74,7 +74,7 @@ func (s StreamReader) Recv() (ServerMessage, error) { return resp, nil case *Ydb_Topic.StreamReadMessage_FromServer_StopPartitionSessionRequest: - req := &StopPartitionSessionRequest{} + req := new(StopPartitionSessionRequest) req.ServerMessageMetadata = meta if err = req.fromProto(m.StopPartitionSessionRequest); err != nil { return nil, err @@ -82,7 +82,7 @@ func (s StreamReader) Recv() (ServerMessage, error) { return req, nil case *Ydb_Topic.StreamReadMessage_FromServer_CommitOffsetResponse: - resp := &CommitOffsetResponse{} + resp := new(CommitOffsetResponse) resp.ServerMessageMetadata = meta if err = resp.fromProto(m.CommitOffsetResponse); err != nil { return nil, err @@ -90,7 +90,7 @@ func (s StreamReader) Recv() (ServerMessage, error) { return resp, nil case *Ydb_Topic.StreamReadMessage_FromServer_PartitionSessionStatusResponse: - resp := &PartitionSessionStatusResponse{} + resp := new(PartitionSessionStatusResponse) resp.ServerMessageMetadata = meta if err = resp.fromProto(m.PartitionSessionStatusResponse); err != nil { return nil, err @@ -98,7 +98,7 @@ func (s StreamReader) Recv() (ServerMessage, error) { return resp, nil case *Ydb_Topic.StreamReadMessage_FromServer_UpdateTokenResponse: - resp := &UpdateTokenResponse{} + resp := new(UpdateTokenResponse) resp.ServerMessageMetadata = meta resp.MustFromProto(m.UpdateTokenResponse) diff --git a/internal/grpcwrapper/rawtopic/rawtopicwriter/messages.go b/internal/grpcwrapper/rawtopic/rawtopicwriter/messages.go index 774c1fd87..eb13a8405 100644 --- a/internal/grpcwrapper/rawtopic/rawtopicwriter/messages.go +++ b/internal/grpcwrapper/rawtopic/rawtopicwriter/messages.go @@ -37,6 +37,7 @@ func (r *InitRequest) toProto() (*Ydb_Topic.StreamWriteMessage_InitRequest, erro ProducerId: r.ProducerID, WriteSessionMeta: r.WriteSessionMeta, GetLastSeqNo: r.GetLastSeqNo, + Partitioning: nil, } err := r.Partitioning.setToProtoInitRequest(res) @@ -60,13 +61,15 @@ func NewPartitioningMessageGroup(messageGroupID string) Partitioning { return Partitioning{ Type: PartitioningMessageGroupID, MessageGroupID: messageGroupID, + PartitionID: 0, } } func NewPartitioningPartitionID(partitionID int64) Partitioning { return Partitioning{ - Type: PartitioningPartitionID, - PartitionID: partitionID, + Type: PartitioningPartitionID, + MessageGroupID: "", + PartitionID: partitionID, } } @@ -160,6 +163,7 @@ func (r *WriteRequest) toProto() (p *Ydb_Topic.StreamWriteMessage_FromClient_Wri WriteRequest: &Ydb_Topic.StreamWriteMessage_WriteRequest{ Messages: messages, Codec: int32(r.Codec.ToProto()), + Tx: new(Ydb_Topic.TransactionIdentity), }, } @@ -181,6 +185,8 @@ func (d *MessageData) ToProto() (*Ydb_Topic.StreamWriteMessage_WriteRequest_Mess CreatedAt: timestamppb.New(d.CreatedAt), Data: d.Data, UncompressedSize: d.UncompressedSize, + Partitioning: nil, + MetadataItems: []*Ydb_Topic.MetadataItem{}, } err := d.Partitioning.setToProtoMessage(res) if err != nil { diff --git a/internal/grpcwrapper/rawtopic/rawtopicwriter/streamwriter_test.go b/internal/grpcwrapper/rawtopic/rawtopicwriter/streamwriter_test.go index f076adab9..f986eb0d5 100644 --- a/internal/grpcwrapper/rawtopic/rawtopicwriter/streamwriter_test.go +++ b/internal/grpcwrapper/rawtopic/rawtopicwriter/streamwriter_test.go @@ -19,6 +19,7 @@ func TestSendWriteRequest(t *testing.T) { SeqNo: 1, }, }, + Tx: new(Ydb_Topic.TransactionIdentity), }, } @@ -48,6 +49,7 @@ func TestSendWriteRequest(t *testing.T) { SeqNo: 3, }, }, + Tx: new(Ydb_Topic.TransactionIdentity), } split1 := &Ydb_Topic.StreamWriteMessage_WriteRequest{ @@ -57,6 +59,7 @@ func TestSendWriteRequest(t *testing.T) { SeqNo: 1, }, }, + Tx: new(Ydb_Topic.TransactionIdentity), } split2 := &Ydb_Topic.StreamWriteMessage_WriteRequest{ @@ -69,6 +72,7 @@ func TestSendWriteRequest(t *testing.T) { SeqNo: 3, }, }, + Tx: new(Ydb_Topic.TransactionIdentity), } getWriteRequest := func(req *Ydb_Topic.StreamWriteMessage_FromClient) *Ydb_Topic.StreamWriteMessage_WriteRequest { diff --git a/internal/grpcwrapper/rawydb/operation_params.go b/internal/grpcwrapper/rawydb/operation_params.go index 21d80eba1..c80bb99b5 100644 --- a/internal/grpcwrapper/rawydb/operation_params.go +++ b/internal/grpcwrapper/rawydb/operation_params.go @@ -1,6 +1,7 @@ package rawydb import ( + "github.com/ydb-platform/ydb-go-genproto/protos/Ydb" "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Operations" "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawoptional" @@ -15,10 +16,12 @@ type OperationParams struct { func (p *OperationParams) ToProto() *Ydb_Operations.OperationParams { res := &Ydb_Operations.OperationParams{ - OperationMode: p.OperationMode.ToProto(), + OperationMode: p.OperationMode.ToProto(), + OperationTimeout: p.OperationTimeout.ToProto(), + CancelAfter: p.CancelAfter.ToProto(), + Labels: make(map[string]string), + ReportCostInfo: Ydb.FeatureFlag_STATUS_UNSPECIFIED, } - res.OperationTimeout = p.OperationTimeout.ToProto() - res.CancelAfter = p.CancelAfter.ToProto() return res } From 6f7731555334aeb51053fdb6737fc327a863e19c Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Mon, 11 Mar 2024 00:26:48 +0500 Subject: [PATCH 10/57] add explicit initialization of fileds of structures in internal/meta --- internal/meta/meta.go | 9 ++++++--- internal/meta/test/meta_test.go | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/meta/meta.go b/internal/meta/meta.go index 4f1564732..ed77e05ef 100644 --- a/internal/meta/meta.go +++ b/internal/meta/meta.go @@ -20,9 +20,12 @@ func New( opts ...Option, ) *Meta { m := &Meta{ - trace: trace, - credentials: credentials, - database: database, + trace: trace, + credentials: credentials, + database: database, + requestsType: "", + userAgents: []string{}, + capabilities: []string{}, } for _, o := range opts { if o != nil { diff --git a/internal/meta/test/meta_test.go b/internal/meta/test/meta_test.go index e077b7f6b..3f2314b9b 100644 --- a/internal/meta/test/meta_test.go +++ b/internal/meta/test/meta_test.go @@ -18,7 +18,7 @@ func TestMetaRequiredHeaders(t *testing.T) { m := internal.New( "database", credentials.NewAccessTokenCredentials("token"), - &trace.Driver{}, + new(trace.Driver), internal.WithRequestTypeOption("requestType"), internal.WithUserAgentOption("user-agent"), ) From eae4e543b4e5ca99d65dcd7fc6db8f63dd755313 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Tue, 26 Mar 2024 19:23:07 +0500 Subject: [PATCH 11/57] switch off the exhaustruct linter for tests --- .golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yml b/.golangci.yml index 57b714c7d..5eb0b201b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -299,6 +299,7 @@ issues: - unused - unparam - gocritic + - exhaustruct - path: topic/topicreader/reader_example_test.go linters: - staticcheck From 6f63136e188394ba75d800049385bd6353a48404 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Fri, 5 Apr 2024 17:46:00 +0500 Subject: [PATCH 12/57] again fixes in internal/meta --- internal/meta/meta.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/meta/meta.go b/internal/meta/meta.go index 8f856379d..ccf244c8e 100644 --- a/internal/meta/meta.go +++ b/internal/meta/meta.go @@ -24,10 +24,13 @@ func New( opts ...Option, ) *Meta { m := &Meta{ - pid: strconv.Itoa(pid), - trace: trace, - credentials: credentials, - database: database, + pid: strconv.Itoa(pid), + trace: trace, + credentials: credentials, + database: database, + requestsType: "", + applicationName: "", + capabilities: nil, } for _, opt := range opts { if opt != nil { From 80b050f65a4aeafc949da9278ae8f9780a2554e4 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Fri, 5 Apr 2024 17:53:57 +0500 Subject: [PATCH 13/57] add explicit initialization of fields of structures in internal/operation --- internal/operation/params.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/operation/params.go b/internal/operation/params.go index 03d342e9a..915a0b3a7 100644 --- a/internal/operation/params.go +++ b/internal/operation/params.go @@ -4,6 +4,7 @@ import ( "context" "time" + "github.com/ydb-platform/ydb-go-genproto/protos/Ydb" "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Operations" ) @@ -30,5 +31,7 @@ func Params( OperationMode: mode.toYDB(), OperationTimeout: timeoutParam(timeout), CancelAfter: timeoutParam(cancelAfter), + Labels: nil, + ReportCostInfo: Ydb.FeatureFlag_STATUS_UNSPECIFIED, } } From b27a4acb7aba0223f6b04483a30c655b1831b165 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Fri, 5 Apr 2024 18:35:16 +0500 Subject: [PATCH 14/57] add explicit initialization of fields of structures in internal/params --- internal/params/dict.go | 3 ++- internal/params/parameters.go | 10 ++++++++++ internal/params/variant.go | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/internal/params/dict.go b/internal/params/dict.go index d772f659e..e9128325e 100644 --- a/internal/params/dict.go +++ b/internal/params/dict.go @@ -23,7 +23,8 @@ type ( func (d *dict) Add() *dictPair { return &dictPair{ - parent: d, + parent: d, + keyValue: nil, } } diff --git a/internal/params/parameters.go b/internal/params/parameters.go index aae4e38d0..4508da16d 100644 --- a/internal/params/parameters.go +++ b/internal/params/parameters.go @@ -26,6 +26,9 @@ type ( func Named(name string, value value.Value) *Parameter { return &Parameter{ + parent: Builder{ + params: nil, + }, name: name, value: value, } @@ -99,6 +102,7 @@ func (p *Parameter) BeginOptional() *optional { return &optional{ parent: p.parent, name: p.name, + value: p.value, } } @@ -106,6 +110,7 @@ func (p *Parameter) BeginList() *list { return &list{ parent: p.parent, name: p.name, + values: nil, } } @@ -117,6 +122,7 @@ func (p *Parameter) BeginSet() *set { return &set{ parent: p.parent, name: p.name, + values: nil, } } @@ -124,6 +130,7 @@ func (p *Parameter) BeginDict() *dict { return &dict{ parent: p.parent, name: p.name, + values: nil, } } @@ -131,6 +138,7 @@ func (p *Parameter) BeginTuple() *tuple { return &tuple{ parent: p.parent, name: p.name, + values: nil, } } @@ -138,6 +146,7 @@ func (p *Parameter) BeginStruct() *structure { return &structure{ parent: p.parent, name: p.name, + values: nil, } } @@ -145,6 +154,7 @@ func (p *Parameter) BeginVariant() *variant { return &variant{ parent: p.parent, name: p.name, + value: p.value, } } diff --git a/internal/params/variant.go b/internal/params/variant.go index 16815e38e..fbe3ff543 100644 --- a/internal/params/variant.go +++ b/internal/params/variant.go @@ -27,11 +27,17 @@ func (vb *variantBuilder) EndVariant() Builder { func (v *variant) BeginTuple() *variantTuple { return &variantTuple{ parent: v, + types: nil, + index: 0, + value: v.value, } } func (v *variant) BeginStruct() *variantStruct { return &variantStruct{ parent: v, + fields: nil, + name: "", + value: v.value, } } From 4b7d44c5b69002cb5e40a7e1c2e35cf113bd39f2 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Sat, 6 Apr 2024 23:30:03 +0500 Subject: [PATCH 15/57] add explicit initialization of fields of structures in internal/pool --- internal/pool/pool.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/internal/pool/pool.go b/internal/pool/pool.go index b7a5e8a3f..7fb3c5e9b 100644 --- a/internal/pool/pool.go +++ b/internal/pool/pool.go @@ -2,6 +2,7 @@ package pool import ( "context" + "sync" "time" "github.com/ydb-platform/ydb-go-sdk/v3/internal/pool/stats" @@ -145,14 +146,20 @@ func New[PT Item[T], T any]( opts ...option[PT, T], ) *Pool[PT, T] { p := &Pool[PT, T]{ - trace: defaultTrace, - limit: DefaultLimit, + trace: defaultTrace, + limit: DefaultLimit, + createTimeout: time.Duration(0), + closeTimeout: time.Duration(0), + mu: xsync.Mutex{Mutex: sync.Mutex{}}, + idle: nil, + index: nil, createItem: func(ctx context.Context) (PT, error) { var item T return &item, nil }, - done: make(chan struct{}), + done: make(chan struct{}), + stats: nil, } for _, opt := range opts { @@ -250,7 +257,8 @@ func New[PT Item[T], T any]( p.idle = make([]PT, 0, p.limit) p.index = make(map[PT]struct{}, p.limit) p.stats = &safeStats{ - v: stats.Stats{Limit: p.limit}, + mu: xsync.RWMutex{RWMutex: sync.RWMutex{}}, + v: stats.Stats{Limit: p.limit, Index: 0, Idle: 0, InUse: 0}, onChange: p.trace.OnChange, } From 2a19aad524ee7602635e2dfb42e84efcbefcd3f1 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Sat, 6 Apr 2024 23:51:55 +0500 Subject: [PATCH 16/57] add explicit initialization of fields of structures in internal/query --- internal/query/client.go | 1 + internal/query/config/config.go | 3 ++- internal/query/options/execute.go | 12 ++++++++---- internal/query/options/retry.go | 9 +++++---- internal/query/result.go | 5 +++-- internal/query/result_set.go | 2 +- internal/query/session.go | 3 +++ 7 files changed, 23 insertions(+), 12 deletions(-) diff --git a/internal/query/client.go b/internal/query/client.go index 3019e83cd..a501a43a9 100644 --- a/internal/query/client.go +++ b/internal/query/client.go @@ -175,6 +175,7 @@ func New(ctx context.Context, balancer balancer, cfg *config.Config) *Client { client := &Client{ config: cfg, grpcClient: Ydb_Query_V1.NewQueryServiceClient(balancer), + pool: nil, done: make(chan struct{}), } diff --git a/internal/query/config/config.go b/internal/query/config/config.go index 7adb08242..8aca2ed3e 100644 --- a/internal/query/config/config.go +++ b/internal/query/config/config.go @@ -38,10 +38,11 @@ func New(opts ...Option) *Config { func defaults() *Config { return &Config{ + Common: config.Common{}, poolLimit: DefaultPoolMaxSize, sessionCreateTimeout: DefaultSessionCreateTimeout, sessionDeleteTimeout: DefaultSessionDeleteTimeout, - trace: &trace.Query{}, + trace: new(trace.Query), } } diff --git a/internal/query/options/execute.go b/internal/query/options/execute.go index 6a306c26d..7352fedc6 100644 --- a/internal/query/options/execute.go +++ b/internal/query/options/execute.go @@ -112,15 +112,18 @@ const ( func defaultCommonExecuteSettings() commonExecuteSettings { return commonExecuteSettings{ - syntax: SyntaxYQL, - execMode: ExecModeExecute, - statsMode: StatsModeNone, + syntax: SyntaxYQL, + params: params.Parameters{}, + execMode: ExecModeExecute, + statsMode: StatsModeNone, + callOptions: nil, } } func ExecuteSettings(opts ...ExecuteOption) (settings *Execute) { settings = &Execute{ commonExecuteSettings: defaultCommonExecuteSettings(), + txControl: nil, } settings.commonExecuteSettings = defaultCommonExecuteSettings() settings.txControl = tx.DefaultTxControl() @@ -168,6 +171,7 @@ func (s *commonExecuteSettings) Params() *params.Parameters { func TxExecuteSettings(id string, opts ...TxExecuteOption) (settings *txExecuteSettings) { settings = &txExecuteSettings{ ExecuteSettings: ExecuteSettings(WithTxControl(tx.NewControl(tx.WithTxID(id)))), + commitTx: false, } for _, opt := range opts { if opt != nil { @@ -190,7 +194,7 @@ var ( _ TxExecuteOption = ExecMode(0) _ TxExecuteOption = StatsMode(0) _ TxExecuteOption = txCommitOption{} - _ ExecuteOption = TxControlOption{} + _ ExecuteOption = TxControlOption{txControl: nil} ) func WithCommit() txCommitOption { diff --git a/internal/query/options/retry.go b/internal/query/options/retry.go index b604152e3..54ab40c06 100644 --- a/internal/query/options/retry.go +++ b/internal/query/options/retry.go @@ -9,12 +9,12 @@ import ( var ( _ DoOption = idempotentOption{} _ DoOption = labelOption("") - _ DoOption = traceOption{} + _ DoOption = traceOption{t: nil} _ DoTxOption = idempotentOption{} _ DoTxOption = labelOption("") - _ DoTxOption = traceOption{} - _ DoTxOption = doTxSettingsOption{} + _ DoTxOption = traceOption{t: nil} + _ DoTxOption = doTxSettingsOption{txSettings: tx.Settings{}} ) type ( @@ -108,7 +108,8 @@ func WithTrace(t *trace.Query) traceOption { func ParseDoOpts(t *trace.Query, opts ...DoOption) (s *doSettings) { s = &doSettings{ - trace: t, + retryOpts: nil, + trace: t, } for _, opt := range opts { diff --git a/internal/query/result.go b/internal/query/result.go index 78478610d..e34f14937 100644 --- a/internal/query/result.go +++ b/internal/query/result.go @@ -34,7 +34,7 @@ func newResult( closeResult context.CancelFunc, ) (_ *result, txID string, err error) { if t == nil { - t = &trace.Query{} + t = new(trace.Query) } if closeResult == nil { closeResult = func() {} @@ -74,6 +74,7 @@ func newResult( lastPart: part, closed: closed, closeOnce: closeOnce, + errs: nil, trace: t, }, part.GetTxMeta().GetId(), nil } @@ -85,7 +86,7 @@ func nextPart( t *trace.Query, ) (_ *Ydb_Query.ExecuteQueryResponsePart, finalErr error) { if t == nil { - t = &trace.Query{} + t = new(trace.Query) } onDone := trace.QueryOnResultNextPart(t, &ctx, diff --git a/internal/query/result_set.go b/internal/query/result_set.go index 47d90301f..6b9daeea1 100644 --- a/internal/query/result_set.go +++ b/internal/query/result_set.go @@ -32,7 +32,7 @@ func newResultSet( t *trace.Query, ) *resultSet { if t == nil { - t = &trace.Query{} + t = new(trace.Query) } return &resultSet{ diff --git a/internal/query/session.go b/internal/query/session.go index 708b36df6..bbee57ce5 100644 --- a/internal/query/session.go +++ b/internal/query/session.go @@ -45,8 +45,11 @@ func createSession( ) (s *Session, finalErr error) { s = &Session{ cfg: cfg, + id: "", + nodeID: 0, grpcClient: client, statusCode: statusUnknown, + closeOnce: nil, checks: []func(*Session) bool{ func(s *Session) bool { switch s.status() { From ddaede2e59a4e9c135f864b7b4345753f7c980ff Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Sun, 7 Apr 2024 00:00:39 +0500 Subject: [PATCH 17/57] add explicit initialization of fields of structures in internal/ratelimiter --- internal/ratelimiter/client.go | 4 ++++ internal/ratelimiter/config/config.go | 3 ++- internal/ratelimiter/options/acquire.go | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/ratelimiter/client.go b/internal/ratelimiter/client.go index eec07b118..de4213600 100644 --- a/internal/ratelimiter/client.go +++ b/internal/ratelimiter/client.go @@ -299,6 +299,10 @@ func (c *Client) describeResource( resource := &ratelimiter.Resource{ ResourcePath: result.GetResource().GetResourcePath(), + HierarchicalDrr: ratelimiter.HierarchicalDrrSettings{ + MaxUnitsPerSecond: 0, MaxBurstSizeCoefficient: 0, + PrefetchCoefficient: 0, PrefetchWatermark: 0, + }, } if result.GetResource().GetHierarchicalDrr() != nil { diff --git a/internal/ratelimiter/config/config.go b/internal/ratelimiter/config/config.go index d0761f779..4a73236e3 100644 --- a/internal/ratelimiter/config/config.go +++ b/internal/ratelimiter/config/config.go @@ -35,7 +35,8 @@ func With(config config.Common) Option { func New(opts ...Option) Config { c := Config{ - trace: &trace.Ratelimiter{}, + Common: config.Common{}, + trace: &trace.Ratelimiter{}, } for _, opt := range opts { if opt != nil { diff --git a/internal/ratelimiter/options/acquire.go b/internal/ratelimiter/options/acquire.go index 1febf3e63..d502c01b8 100644 --- a/internal/ratelimiter/options/acquire.go +++ b/internal/ratelimiter/options/acquire.go @@ -72,7 +72,9 @@ func WithOperationCancelAfter(operationCancelAfter time.Duration) AcquireOption func NewAcquire(opts ...AcquireOption) Acquire { h := &acquireOptionsHolder{ - acquireType: AcquireTypeDefault, + acquireType: AcquireTypeDefault, + operationTimeout: time.Duration(0), + operationCancelAfter: time.Duration(0), } for _, opt := range opts { if opt != nil { From c3eedbbf45ca31e64e9881ebbfe1270dfd5deab6 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Mon, 8 Apr 2024 22:21:48 +0500 Subject: [PATCH 18/57] add explicit initialization of fields of structures in internal/repeater --- internal/repeater/repeater.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/repeater/repeater.go b/internal/repeater/repeater.go index 8cb2fb0c0..ebd73b5b1 100644 --- a/internal/repeater/repeater.go +++ b/internal/repeater/repeater.go @@ -100,12 +100,13 @@ func New( r := &repeater{ interval: interval, + name: "", + trace: new(trace.Driver), task: task, cancel: cancel, stopped: make(chan struct{}), force: make(chan struct{}, 1), clock: clockwork.NewRealClock(), - trace: &trace.Driver{}, } for _, opt := range opts { From e83898ee1d1064dd145a95d42508e8bfeda762a1 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Mon, 8 Apr 2024 22:33:24 +0500 Subject: [PATCH 19/57] add explicit initialization of fields of structures in internal/scheme --- internal/scheme/client.go | 1 + internal/scheme/config/config.go | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/scheme/client.go b/internal/scheme/client.go index 6f46ed736..c4c977cbb 100644 --- a/internal/scheme/client.go +++ b/internal/scheme/client.go @@ -284,6 +284,7 @@ func (c *Client) modifyPermissions(ctx context.Context, path string, desc permis c.config.OperationCancelAfter(), operation.ModeSync, ), + Inheritance: nil, }, ) if err != nil { diff --git a/internal/scheme/config/config.go b/internal/scheme/config/config.go index a684fc83e..f2f9a75c1 100644 --- a/internal/scheme/config/config.go +++ b/internal/scheme/config/config.go @@ -48,7 +48,9 @@ func With(config config.Common) Option { func New(opts ...Option) Config { c := Config{ - trace: &trace.Scheme{}, + Common: config.Common{}, + databaseName: "", + trace: new(trace.Scheme), } for _, opt := range opts { if opt != nil { From 985c5333e53b136d2208ea6dcc63c09c2cf672ae Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Mon, 8 Apr 2024 22:44:36 +0500 Subject: [PATCH 20/57] add explicit initialization of fields of structures in internal/scripting --- internal/scripting/client.go | 13 +++++++++++-- internal/scripting/config/config.go | 3 ++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/scripting/client.go b/internal/scripting/client.go index a8ecc18bb..11f2360f5 100644 --- a/internal/scripting/client.go +++ b/internal/scripting/client.go @@ -7,6 +7,7 @@ import ( "github.com/ydb-platform/ydb-go-genproto/Ydb_Scripting_V1" "github.com/ydb-platform/ydb-go-genproto/protos/Ydb" "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Scripting" + "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Table" "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_TableStats" "google.golang.org/grpc" @@ -85,8 +86,12 @@ func (c *Client) execute( c.config.OperationCancelAfter(), operation.ModeSync, ), + CollectStats: Ydb_Table.QueryStatsCollection_STATS_COLLECTION_UNSPECIFIED, + } + result = Ydb_Scripting.ExecuteYqlResult{ + ResultSets: nil, + QueryStats: nil, } - result = Ydb_Scripting.ExecuteYqlResult{} response *Ydb_Scripting.ExecuteYqlResponse ) defer func() { @@ -165,7 +170,10 @@ func (c *Client) explain( ), } response *Ydb_Scripting.ExplainYqlResponse - result = Ydb_Scripting.ExplainYqlResult{} + result = Ydb_Scripting.ExplainYqlResult{ + ParametersTypes: nil, + Plan: "", + } ) defer func() { onDone(e.Explanation.Plan, err) @@ -238,6 +246,7 @@ func (c *Client) streamExecute( c.config.OperationCancelAfter(), operation.ModeSync, ), + CollectStats: Ydb_Table.QueryStatsCollection_STATS_COLLECTION_UNSPECIFIED, } ) defer func() { diff --git a/internal/scripting/config/config.go b/internal/scripting/config/config.go index 35f90651d..010161412 100644 --- a/internal/scripting/config/config.go +++ b/internal/scripting/config/config.go @@ -34,7 +34,8 @@ func With(config config.Common) Option { func New(opts ...Option) Config { c := Config{ - trace: &trace.Scripting{}, + Common: config.Common{}, + trace: new(trace.Scripting), } for _, opt := range opts { if opt != nil { From e9064ef50a675fe034a35935cf6fdd66867a363c Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Mon, 8 Apr 2024 22:48:14 +0500 Subject: [PATCH 21/57] add explicit initialization of fields of structures in internal/stack --- internal/stack/record.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/stack/record.go b/internal/stack/record.go index efe5e9db6..243872b35 100644 --- a/internal/stack/record.go +++ b/internal/stack/record.go @@ -62,7 +62,7 @@ func PackagePath(b bool) recordOption { } } -var _ Caller = call{} +var _ Caller = call{function: 0, file: "", line: 0} type call struct { function uintptr From a85a73784a7aa76f5db2d77e981a3e44fce4330a Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Mon, 15 Apr 2024 19:52:35 +0500 Subject: [PATCH 22/57] add explicit initialization of fields of structures in internal/table --- internal/table/client.go | 27 +++++---- internal/table/config/config.go | 4 +- internal/table/retry.go | 7 ++- internal/table/scanner/result.go | 41 ++++++++++++- internal/table/scanner/scan_raw.go | 41 ++++++++----- internal/table/scanner/scanner.go | 23 ++++++-- internal/table/scanner/stats.go | 5 +- internal/table/session.go | 94 ++++++++++++++++++++++++------ internal/table/transaction.go | 1 + internal/table/ttl.go | 1 + 10 files changed, 189 insertions(+), 55 deletions(-) diff --git a/internal/table/client.go b/internal/table/client.go index 041112034..257165524 100644 --- a/internal/table/client.go +++ b/internal/table/client.go @@ -54,15 +54,17 @@ func newClient( config *config.Config, ) *Client { c := &Client{ - clock: config.Clock(), - config: config, - cc: balancer, - nodeChecker: balancer, - build: builder, - index: make(map[*session]sessionInfo), - idle: list.New(), - waitQ: list.New(), - limit: config.SizeLimit(), + clock: config.Clock(), + config: config, + cc: balancer, + nodeChecker: balancer, + build: builder, + mu: xsync.Mutex{Mutex: sync.Mutex{}}, + index: make(map[*session]sessionInfo), + createInProgress: 0, + idle: list.New(), + waitQ: list.New(), + limit: config.SizeLimit(), waitChPool: sync.Pool{ New: func() interface{} { ch := make(chan *session) @@ -70,7 +72,9 @@ func newClient( return &ch }, }, - done: make(chan struct{}), + testHookGetWaitCh: nil, + wg: sync.WaitGroup{}, + done: make(chan struct{}), } if idleThreshold := config.IdleThreshold(); idleThreshold > 0 { c.wg.Add(1) @@ -123,7 +127,7 @@ func withCreateSessionOnClose(onClose func(s *session)) createSessionOption { } func (c *Client) createSession(ctx context.Context, opts ...createSessionOption) (s *session, err error) { - options := createSessionOptions{} + options := createSessionOptions{onCreate: nil, onClose: nil} for _, opt := range opts { if opt != nil { opt(&options) @@ -320,6 +324,7 @@ func (c *Client) internalPoolCreateSession(ctx context.Context) (s *session, err withCreateSessionOnCreate(func(s *session) { c.mu.WithLock(func() { c.index[s] = sessionInfo{ + idle: nil, touched: c.clock.Now(), } trace.TableOnPoolSessionAdd(c.config.Trace(), s) diff --git a/internal/table/config/config.go b/internal/table/config/config.go index de94fb3e6..3ec5f605c 100644 --- a/internal/table/config/config.go +++ b/internal/table/config/config.go @@ -235,11 +235,13 @@ func (c *Config) DeleteTimeout() time.Duration { func defaults() *Config { return &Config{ + Common: config.Common{}, sizeLimit: DefaultSessionPoolSizeLimit, createSessionTimeout: DefaultSessionPoolCreateSessionTimeout, deleteTimeout: DefaultSessionPoolDeleteTimeout, idleThreshold: DefaultSessionPoolIdleThreshold, clock: clockwork.NewRealClock(), - trace: &trace.Table{}, + ignoreTruncated: false, + trace: new(trace.Table), } } diff --git a/internal/table/retry.go b/internal/table/retry.go index d6577d7ad..6454a71eb 100644 --- a/internal/table/retry.go +++ b/internal/table/retry.go @@ -93,10 +93,13 @@ func retryBackoff( func (c *Client) retryOptions(opts ...table.Option) *table.Options { options := &table.Options{ - Trace: c.config.Trace(), + Label: "", + Idempotent: false, + Trace: c.config.Trace(), TxSettings: table.TxSettings( table.WithSerializableReadWrite(), ), + TxCommitOptions: nil, RetryOptions: []retry.Option{ retry.WithTrace(c.config.TraceRetry()), }, @@ -107,7 +110,7 @@ func (c *Client) retryOptions(opts ...table.Option) *table.Options { } } if options.Trace == nil { - options.Trace = &trace.Table{} + options.Trace = new(trace.Table) } return options diff --git a/internal/table/scanner/result.go b/internal/table/scanner/result.go index 1cbc88eb6..62068c4e6 100644 --- a/internal/table/scanner/result.go +++ b/internal/table/scanner/result.go @@ -4,6 +4,7 @@ import ( "context" "errors" "io" + "sync" "sync/atomic" "github.com/ydb-platform/ydb-go-genproto/protos/Ydb" @@ -113,6 +114,25 @@ func NewStream( opts ...option, ) (StreamResult, error) { r := &streamResult{ + baseResult: baseResult{ + valueScanner: valueScanner{ + set: nil, + row: nil, + converter: nil, + stack: scanStack{v: nil, p: 0, scanItem: item{name: "", i: 0, t: nil, v: nil}}, + nextRow: 0, + nextItem: 0, + ignoreTruncated: false, + markTruncatedAsRetryable: false, + columnIndexes: nil, + errMtx: xsync.RWMutex{RWMutex: sync.RWMutex{}}, + err: nil, + }, + nextResultSetCounter: atomic.Uint64{}, + statsMtx: xsync.RWMutex{RWMutex: sync.RWMutex{}}, + stats: nil, + closed: atomic.Bool{}, + }, recv: recv, close: onClose, } @@ -131,9 +151,26 @@ func NewStream( func NewUnary(sets []*Ydb.ResultSet, stats *Ydb_TableStats.QueryStats, opts ...option) UnaryResult { r := &unaryResult{ baseResult: baseResult{ - stats: stats, + valueScanner: valueScanner{ + set: nil, + row: nil, + converter: nil, + stack: scanStack{v: nil, p: 0, scanItem: item{name: "", i: 0, t: nil, v: nil}}, + nextRow: 0, + nextItem: 0, + ignoreTruncated: false, + markTruncatedAsRetryable: false, + columnIndexes: nil, + errMtx: xsync.RWMutex{RWMutex: sync.RWMutex{}}, + err: nil, + }, + nextResultSetCounter: atomic.Uint64{}, + statsMtx: xsync.RWMutex{RWMutex: sync.RWMutex{}}, + stats: stats, + closed: atomic.Bool{}, }, - sets: sets, + sets: sets, + nextSet: 0, } for _, opt := range opts { if opt != nil { diff --git a/internal/table/scanner/scan_raw.go b/internal/table/scanner/scan_raw.go index 7c0782f3c..a494c9d08 100644 --- a/internal/table/scanner/scan_raw.go +++ b/internal/table/scanner/scan_raw.go @@ -344,9 +344,10 @@ func (s *rawConverter) ListItem(i int) { } if t := s.assertTypeList(p.t); t != nil { s.stack.set(item{ - i: i, - t: t.ListType.GetItem(), - v: p.v.GetItems()[i], + name: "", + i: i, + t: t.ListType.GetItem(), + v: p.v.GetItems()[i], }) } } @@ -383,9 +384,10 @@ func (s *rawConverter) TupleItem(i int) { } if t := s.assertTypeTuple(p.t); t != nil { s.stack.set(item{ - i: i, - t: t.TupleType.GetElements()[i], - v: p.v.GetItems()[i], + name: "", + i: i, + t: t.TupleType.GetElements()[i], + v: p.v.GetItems()[i], }) } } @@ -466,9 +468,10 @@ func (s *rawConverter) DictKey(i int) { } if t := s.assertTypeDict(p.t); t != nil { s.stack.set(item{ - i: i, - t: t.DictType.GetKey(), - v: p.v.GetPairs()[i].GetKey(), + name: "", + i: i, + t: t.DictType.GetKey(), + v: p.v.GetPairs()[i].GetKey(), }) } } @@ -483,9 +486,10 @@ func (s *rawConverter) DictPayload(i int) { } if t := s.assertTypeDict(p.t); t != nil { s.stack.set(item{ - i: i, - t: t.DictType.GetPayload(), - v: p.v.GetPairs()[i].GetPayload(), + name: "", + i: i, + t: t.DictType.GetPayload(), + v: p.v.GetPairs()[i].GetPayload(), }) } } @@ -541,6 +545,7 @@ func (s *rawConverter) Unwrap() { s.stack.enter() s.stack.set(item{ name: "*", + i: 0, t: t.OptionalType.GetItem(), v: v, }) @@ -560,12 +565,20 @@ func (s *rawConverter) Decimal(t types.Type) (v [16]byte) { func (s *rawConverter) UnwrapDecimal() decimal.Decimal { if s.Err() != nil { - return decimal.Decimal{} + return decimal.Decimal{ + Bytes: [16]byte{}, + Precision: 0, + Scale: 0, + } } s.unwrap() d := s.assertTypeDecimal(s.stack.current().t) if d == nil { - return decimal.Decimal{} + return decimal.Decimal{ + Bytes: [16]byte{}, + Precision: 0, + Scale: 0, + } } return decimal.Decimal{ diff --git a/internal/table/scanner/scanner.go b/internal/table/scanner/scanner.go index f541a1235..6ef084d03 100644 --- a/internal/table/scanner/scanner.go +++ b/internal/table/scanner/scanner.go @@ -56,8 +56,9 @@ func (s *valueScanner) Columns(it func(options.Column)) { } for _, m := range s.set.GetColumns() { it(options.Column{ - Name: m.GetName(), - Type: internalTypes.TypeFromYDB(m.GetType()), + Name: m.GetName(), + Type: internalTypes.TypeFromYDB(m.GetType()), + Family: "", }) } } @@ -511,12 +512,20 @@ func (s *valueScanner) unwrapValue() (v *Ydb.Value) { func (s *valueScanner) unwrapDecimal() decimal.Decimal { if s.Err() != nil { - return decimal.Decimal{} + return decimal.Decimal{ + Bytes: [16]byte{}, + Precision: 0, + Scale: 0, + } } s.unwrap() d := s.assertTypeDecimal(s.stack.current().t) if d == nil { - return decimal.Decimal{} + return decimal.Decimal{ + Bytes: [16]byte{}, + Precision: 0, + Scale: 0, + } } return decimal.Decimal{ @@ -1131,7 +1140,11 @@ func (s *valueScanner) setDefaultValue(dst interface{}) { case *value.Value: *v = s.value() case *decimal.Decimal: - *v = decimal.Decimal{} + *v = decimal.Decimal{ + Bytes: [16]byte{}, + Precision: 0, + Scale: 0, + } case sql.Scanner: err := v.Scan(nil) if err != nil { diff --git a/internal/table/scanner/stats.go b/internal/table/scanner/stats.go index d9772e34c..a4f583022 100644 --- a/internal/table/scanner/stats.go +++ b/internal/table/scanner/stats.go @@ -116,7 +116,10 @@ func (q *queryPhase) IsLiteralPhase() bool { func initOperationStats(x *Ydb_TableStats.OperationStats) stats.OperationStats { if x == nil { - return stats.OperationStats{} + return stats.OperationStats{ + Rows: 0, + Bytes: 0, + } } return stats.OperationStats{ diff --git a/internal/table/session.go b/internal/table/session.go index 3c9fe585c..54eb2790d 100644 --- a/internal/table/session.go +++ b/internal/table/session.go @@ -145,14 +145,7 @@ func newSession(ctx context.Context, cc grpc.ClientConnInterface, config *config return nil, xerrors.WithStackTrace(err) } - s = &session{ - id: result.GetSessionId(), - config: config, - status: table.SessionReady, - } - s.lastUsage.Store(time.Now().Unix()) - - s.tableService = Ydb_Table_V1.NewTableServiceClient( + tableService := Ydb_Table_V1.NewTableServiceClient( conn.WithBeforeFunc( conn.WithContextModifier(cc, func(ctx context.Context) context.Context { return meta.WithTrailerCallback(balancerContext.WithEndpoint(ctx, s), s.checkCloseHint) @@ -163,6 +156,19 @@ func newSession(ctx context.Context, cc grpc.ClientConnInterface, config *config ), ) + s = &session{ + onClose: nil, + id: result.GetSessionId(), + tableService: tableService, + config: config, + status: table.SessionReady, + lastUsage: atomic.Int64{}, + statusMtx: sync.RWMutex{}, + closeOnce: sync.Once{}, + nodeID: atomic.Uint32{}, + } + s.lastUsage.Store(time.Now().Unix()) + return s, nil } @@ -279,14 +285,28 @@ func (s *session) CreateTable( ) (err error) { var ( request = Ydb_Table.CreateTableRequest{ - SessionId: s.id, - Path: path, + SessionId: s.id, + Path: path, + Columns: nil, + PrimaryKey: nil, + Profile: nil, OperationParams: operation.Params( ctx, s.config.OperationTimeout(), s.config.OperationCancelAfter(), operation.ModeSync, ), + Indexes: nil, + TtlSettings: nil, + StorageSettings: nil, + ColumnFamilies: nil, + Attributes: nil, + CompactionPolicy: "", + Partitions: nil, + PartitioningSettings: nil, + KeyBloomFilter: Ydb.FeatureFlag_STATUS_UNSPECIFIED, + ReadReplicasSettings: nil, + Tiering: "", } a = allocator.New() ) @@ -323,6 +343,9 @@ func (s *session) DescribeTable( s.config.OperationCancelAfter(), operation.ModeSync, ), + IncludeShardKeyBounds: false, + IncludeTableStats: false, + IncludePartitionStats: false, } for _, opt := range opts { if opt != nil { @@ -500,14 +523,32 @@ func (s *session) AlterTable( ) (err error) { var ( request = Ydb_Table.AlterTableRequest{ - SessionId: s.id, - Path: path, + SessionId: s.id, + Path: path, + AddColumns: nil, + DropColumns: nil, OperationParams: operation.Params( ctx, s.config.OperationTimeout(), s.config.OperationCancelAfter(), operation.ModeSync, ), + AlterColumns: nil, + TtlAction: nil, + AddIndexes: nil, + DropIndexes: nil, + AlterStorageSettings: nil, + AddColumnFamilies: nil, + AlterColumnFamilies: nil, + AlterAttributes: nil, + SetCompactionPolicy: "", + AlterPartitioningSettings: nil, + SetKeyBloomFilter: Ydb.FeatureFlag_STATUS_UNSPECIFIED, + SetReadReplicasSettings: nil, + AddChangefeeds: nil, + DropChangefeeds: nil, + RenameIndexes: nil, + TieringAction: nil, } a = allocator.New() ) @@ -572,6 +613,7 @@ func copyTables( operationCancelAfter, operation.ModeSync, ), + Tables: nil, } for _, opt := range opts { if opt != nil { @@ -773,8 +815,10 @@ func (s *session) executeQueryResult( table.Transaction, result.Result, error, ) { tx := &transaction{ - id: res.GetTxMeta().GetId(), - s: s, + id: res.GetTxMeta().GetId(), + s: s, + control: nil, + state: txState{rawVal: atomic.Uint32{}}, } if txControl.GetCommitTx() { tx.state.Store(txStateCommitted) @@ -991,8 +1035,15 @@ func (s *session) StreamReadTable( s, ) request = Ydb_Table.ReadTableRequest{ - SessionId: s.id, - Path: path, + SessionId: s.id, + Path: path, + KeyRange: nil, + Columns: nil, + Ordered: false, + RowLimit: 0, + UseSnapshot: Ydb.FeatureFlag_STATUS_UNSPECIFIED, + BatchLimitBytes: 0, + BatchLimitRows: 0, } stream Ydb_Table_V1.TableService_StreamReadTableClient a = allocator.New() @@ -1059,6 +1110,7 @@ func (s *session) ReadRows( SessionId: s.id, Path: path, Keys: value.ToYDB(keys, a), + Columns: nil, } response *Ydb_Table.ReadRowsResponse ) @@ -1110,9 +1162,10 @@ func (s *session) StreamExecuteScanQuery( s, q, parameters, ) request = Ydb_Table.ExecuteScanQueryRequest{ - Query: q.toYDB(a), - Parameters: parameters.ToYDB(a), - Mode: Ydb_Table.ExecuteScanQueryRequest_MODE_EXEC, // set default + Query: q.toYDB(a), + Parameters: parameters.ToYDB(a), + Mode: Ydb_Table.ExecuteScanQueryRequest_MODE_EXEC, // set default + CollectStats: Ydb_Table.QueryStatsCollection_STATS_COLLECTION_UNSPECIFIED, } stream Ydb_Table_V1.TableService_StreamExecuteScanQueryClient callOptions []grpc.CallOption @@ -1202,6 +1255,8 @@ func (s *session) BulkUpsert(ctx context.Context, table string, rows value.Value s.config.OperationCancelAfter(), operation.ModeSync, ), + DataFormat: nil, + Data: nil, }, callOptions..., ) @@ -1254,6 +1309,7 @@ func (s *session) BeginTransaction( id: result.GetTxMeta().GetId(), s: s, control: table.TxControl(table.WithTxID(result.GetTxMeta().GetId())), + state: txState{rawVal: atomic.Uint32{}}, } tx.state.Store(txStateInitialized) diff --git a/internal/table/transaction.go b/internal/table/transaction.go index a07576196..cf7de7bac 100644 --- a/internal/table/transaction.go +++ b/internal/table/transaction.go @@ -156,6 +156,7 @@ func (tx *transaction) CommitTx( tx.s.config.OperationCancelAfter(), operation.ModeSync, ), + CollectStats: Ydb_Table.QueryStatsCollection_STATS_COLLECTION_UNSPECIFIED, } response *Ydb_Table.CommitTransactionResponse result = new(Ydb_Table.CommitTransactionResult) diff --git a/internal/table/ttl.go b/internal/table/ttl.go index fd3ad945e..45baf260e 100644 --- a/internal/table/ttl.go +++ b/internal/table/ttl.go @@ -16,6 +16,7 @@ func NewTimeToLiveSettings(settings *Ydb_Table.TtlSettings) *options.TimeToLiveS ColumnName: mode.DateTypeColumn.GetColumnName(), ExpireAfterSeconds: mode.DateTypeColumn.GetExpireAfterSeconds(), Mode: options.TimeToLiveModeDateType, + ColumnUnit: nil, } case *Ydb_Table.TtlSettings_ValueSinceUnixEpoch: From 2970590c6159e0a67a4d0f70b404ea8d924fbd1d Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Mon, 15 Apr 2024 23:41:27 +0500 Subject: [PATCH 23/57] add explicit initialization of fields of structures in internal/types --- internal/types/types.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/types/types.go b/internal/types/types.go index 4942cd787..592c8a83d 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/ydb-platform/ydb-go-genproto/protos/Ydb" + "google.golang.org/protobuf/types/known/structpb" "github.com/ydb-platform/ydb-go-sdk/v3/internal/allocator" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xstring" @@ -487,7 +488,9 @@ func (v PgType) ToYDB(a *allocator.Allocator) *Ydb.Type { // TODO: make allocator return &Ydb.Type{Type: &Ydb.Type_PgType{ PgType: &Ydb.PgType{ - Oid: v.OID, + Oid: v.OID, + Typlen: 0, + Typmod: 0, }, }} } @@ -902,7 +905,9 @@ func (v Void) Yql() string { } var _voidType = &Ydb.Type{ - Type: &Ydb.Type_VoidType{}, + Type: &Ydb.Type_VoidType{ + VoidType: structpb.NullValue_NULL_VALUE, + }, } func (v Void) equalsTo(rhs Type) bool { @@ -930,7 +935,9 @@ func (v Null) Yql() string { } var _nullType = &Ydb.Type{ - Type: &Ydb.Type_NullType{}, + Type: &Ydb.Type_NullType{ + NullType: structpb.NullValue_NULL_VALUE, + }, } func (v Null) equalsTo(rhs Type) bool { From bf696146425a0de381a9e6a89bb96b82dfcf4ec2 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Mon, 15 Apr 2024 23:51:04 +0500 Subject: [PATCH 24/57] add explicit initialization of fields of structures in internal/value --- internal/value/value.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/internal/value/value.go b/internal/value/value.go index 14a8b43f7..d89e61d3f 100644 --- a/internal/value/value.go +++ b/internal/value/value.go @@ -1260,6 +1260,10 @@ func (v pgValue) toYDB(_ *allocator.Allocator) *Ydb.Value { Value: &Ydb.Value_TextValue{ TextValue: v.val, }, + Items: nil, + Pairs: nil, + VariantIndex: 0, + High_128: 0, } } @@ -2227,7 +2231,11 @@ func (v voidValue) Yql() string { var ( _voidValueType = types.Void{} _voidValue = &Ydb.Value{ - Value: new(Ydb.Value_NullFlagValue), + Value: new(Ydb.Value_NullFlagValue), + Items: nil, + Pairs: nil, + VariantIndex: 0, + High_128: 0, } ) @@ -2382,19 +2390,23 @@ func ZeroValue(t types.Type) Value { case *types.List, *types.EmptyList: return &listValue{ - t: t, + t: t, + items: nil, } case *types.Set: return &setValue{ - t: t, + t: t, + items: nil, } case *types.Dict: return &dictValue{ - t: t.ValueType(), + t: t.ValueType(), + values: nil, } case *types.EmptyDict: return &dictValue{ - t: t, + t: t, + values: nil, } case *types.Tuple: return TupleValue(func() []Value { From 14511ab58d50b07d8f5a2fe5c23fee30bba8ed6d Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Mon, 15 Apr 2024 23:55:52 +0500 Subject: [PATCH 25/57] add explicit initialization of fields of structures in internal/xcontext --- internal/xcontext/context_with_cancel.go | 4 ++++ internal/xcontext/context_with_timeout.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/internal/xcontext/context_with_cancel.go b/internal/xcontext/context_with_cancel.go index 1deeac4bb..52a3fbe7d 100644 --- a/internal/xcontext/context_with_cancel.go +++ b/internal/xcontext/context_with_cancel.go @@ -9,6 +9,10 @@ import ( func WithCancel(ctx context.Context) (context.Context, context.CancelFunc) { childCtx := &cancelCtx{ parentCtx: ctx, + ctx: nil, + ctxCancel: nil, + m: sync.Mutex{}, + err: nil, } childCtx.ctx, childCtx.ctxCancel = context.WithCancel(ctx) diff --git a/internal/xcontext/context_with_timeout.go b/internal/xcontext/context_with_timeout.go index 5342798fe..067d132a7 100644 --- a/internal/xcontext/context_with_timeout.go +++ b/internal/xcontext/context_with_timeout.go @@ -11,7 +11,11 @@ import ( func WithTimeout(ctx context.Context, t time.Duration) (context.Context, context.CancelFunc) { childCtx := &timeoutCtx{ parentCtx: ctx, + ctx: nil, + ctxCancel: nil, from: stack.Record(1), + m: sync.Mutex{}, + err: nil, } childCtx.ctx, childCtx.ctxCancel = context.WithTimeout(ctx, t) From 4140b143807a2a116d8f16aba0348ee68f90aedc Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Tue, 16 Apr 2024 00:14:46 +0500 Subject: [PATCH 26/57] add explicit initialization of fields of structures in internal/xerrors --- internal/xerrors/issues.go | 1 + internal/xerrors/operation.go | 11 ++++++++--- internal/xerrors/retryable.go | 1 + internal/xerrors/stacktrace.go | 2 +- internal/xerrors/transport.go | 18 ++++++++++++------ 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/internal/xerrors/issues.go b/internal/xerrors/issues.go index 066bb94eb..c52f04be4 100644 --- a/internal/xerrors/issues.go +++ b/internal/xerrors/issues.go @@ -59,6 +59,7 @@ func (ii issues) String() string { func NewWithIssues(text string, issues ...error) error { err := &withIssuesError{ reason: text, + issues: nil, } for i := range issues { if issues[i] != nil { diff --git a/internal/xerrors/operation.go b/internal/xerrors/operation.go index 7020e4f42..4e6073b12 100644 --- a/internal/xerrors/operation.go +++ b/internal/xerrors/operation.go @@ -84,8 +84,10 @@ func (e *operationOption) applyToOperationError(oe *operationError) { // FromOperation must use as `Operation(FromOperation(operation.Status))` func FromOperation(operation operation.Status) *operationOption { return &operationOption{ - code: operation.GetStatus(), - issues: operation.GetIssues(), + code: operation.GetStatus(), + issues: operation.GetIssues(), + address: "", + traceID: "", } } @@ -95,7 +97,10 @@ type oeOpt interface { func Operation(opts ...oeOpt) error { oe := &operationError{ - code: Ydb.StatusIds_STATUS_CODE_UNSPECIFIED, + code: Ydb.StatusIds_STATUS_CODE_UNSPECIFIED, + issues: nil, + address: "", + traceID: "", } for _, opt := range opts { if opt != nil { diff --git a/internal/xerrors/retryable.go b/internal/xerrors/retryable.go index 1c3141e8f..7253f4880 100644 --- a/internal/xerrors/retryable.go +++ b/internal/xerrors/retryable.go @@ -68,6 +68,7 @@ func Retryable(err error, opts ...RetryableErrorOption) error { re = &retryableError{ err: err, name: "CUSTOM", + backoffType: backoff.TypeNoBackoff, code: -1, isRetryObjectValid: true, } diff --git a/internal/xerrors/stacktrace.go b/internal/xerrors/stacktrace.go index 3140547d5..9c7e9b0cd 100644 --- a/internal/xerrors/stacktrace.go +++ b/internal/xerrors/stacktrace.go @@ -23,7 +23,7 @@ func WithStackTrace(err error, opts ...withStackTraceOption) error { if err == nil { return nil } - options := withStackTraceOptions{} + options := withStackTraceOptions{skipDepth: 0} for _, opt := range opts { if opt != nil { opt(&options) diff --git a/internal/xerrors/transport.go b/internal/xerrors/transport.go index b66f7735c..9650968d9 100644 --- a/internal/xerrors/transport.go +++ b/internal/xerrors/transport.go @@ -145,13 +145,17 @@ func Transport(err error, opts ...teOpt) error { } if s, ok := grpcStatus.FromError(err); ok { te = &transportError{ - status: s, - err: err, + status: s, + err: err, + address: "", + traceID: "", } } else { te = &transportError{ - status: grpcStatus.New(grpcCodes.Unknown, stack.Record(1)), - err: err, + status: grpcStatus.New(grpcCodes.Unknown, stack.Record(1)), + err: err, + address: "", + traceID: "", } } for _, opt := range opts { @@ -194,8 +198,10 @@ func TransportError(err error) Error { } if s, ok := grpcStatus.FromError(err); ok { return &transportError{ - status: s, - err: err, + status: s, + err: err, + address: "", + traceID: "", } } From 2db1efb03df6fbe877875a1509a6bf8b61f34879 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Tue, 16 Apr 2024 00:17:47 +0500 Subject: [PATCH 27/57] add explicit initialization of fields of structures in internal/xrand --- internal/xrand/xrand.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/xrand/xrand.go b/internal/xrand/xrand.go index 2f8ed0021..890fc0b87 100644 --- a/internal/xrand/xrand.go +++ b/internal/xrand/xrand.go @@ -33,6 +33,7 @@ func WithSeed(seed int64) option { func New(opts ...option) Rand { r := &r{ + m: &sync.Mutex{}, r: rand.New(rand.NewSource(time.Now().Unix())), //nolint:gosec } for _, opt := range opts { From f0406f653a7a7221e389a4977bd437f87fce11cf Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Tue, 16 Apr 2024 20:05:47 +0500 Subject: [PATCH 28/57] add explicit initialization of fields of structures in internal/xsql --- internal/xsql/conn.go | 48 ++++++++++++++++++++++++-------------- internal/xsql/connector.go | 28 +++++++++++++++------- internal/xsql/rows.go | 14 +++++------ internal/xsql/stmt.go | 6 ++--- internal/xsql/tx.go | 14 ++++++----- internal/xsql/tx_fake.go | 13 ++++++----- 6 files changed, 75 insertions(+), 48 deletions(-) diff --git a/internal/xsql/conn.go b/internal/xsql/conn.go index c5d670517..d3f66dec9 100644 --- a/internal/xsql/conn.go +++ b/internal/xsql/conn.go @@ -8,6 +8,7 @@ import ( "io" "path" "strings" + "sync" "sync/atomic" "time" @@ -115,23 +116,32 @@ func (resultNoRows) LastInsertId() (int64, error) { return 0, ErrUnsupported } func (resultNoRows) RowsAffected() (int64, error) { return 0, ErrUnsupported } var ( - _ driver.Conn = &conn{} - _ driver.ConnPrepareContext = &conn{} - _ driver.ConnBeginTx = &conn{} - _ driver.ExecerContext = &conn{} - _ driver.QueryerContext = &conn{} - _ driver.Pinger = &conn{} - _ driver.Validator = &conn{} - _ driver.NamedValueChecker = &conn{} + _ driver.Conn = new(conn) + _ driver.ConnPrepareContext = new(conn) + _ driver.ConnBeginTx = new(conn) + _ driver.ExecerContext = new(conn) + _ driver.QueryerContext = new(conn) + _ driver.Pinger = new(conn) + _ driver.Validator = new(conn) + _ driver.NamedValueChecker = new(conn) _ driver.Result = resultNoRows{} ) func newConn(ctx context.Context, c *Connector, s table.ClosableSession, opts ...connOption) *conn { cc := &conn{ - openConnCtx: ctx, - connector: c, - session: s, + openConnCtx: ctx, + connector: c, + trace: nil, + session: s, + beginTxFuncs: nil, + closed: atomic.Bool{}, + lastUsage: atomic.Int64{}, + defaultQueryMode: DefaultQueryMode, + defaultTxControl: nil, + dataOpts: nil, + scanOpts: nil, + currentTx: nil, } cc.beginTxFuncs = map[QueryMode]beginTxFunc{ DataQueryMode: cc.beginTx, @@ -334,8 +344,9 @@ func (c *conn) queryContext(ctx context.Context, query string, args []driver.Nam } return &rows{ - conn: c, - result: res, + conn: c, + result: res, + nextSet: sync.Once{}, }, nil case ScanQueryMode: normalizedQuery, parameters, err := c.normalize(query, args...) @@ -353,8 +364,9 @@ func (c *conn) queryContext(ctx context.Context, query string, args []driver.Nam } return &rows{ - conn: c, - result: res, + conn: c, + result: res, + nextSet: sync.Once{}, }, nil case ExplainQueryMode: normalizedQuery, _, err := c.normalize(query, args...) @@ -371,6 +383,7 @@ func (c *conn) queryContext(ctx context.Context, query string, args []driver.Nam sql.Named("AST", exp.AST), sql.Named("Plan", exp.Plan), }, + readAll: false, }, nil case ScriptingQueryMode: normalizedQuery, parameters, err := c.normalize(query, args...) @@ -386,8 +399,9 @@ func (c *conn) queryContext(ctx context.Context, query string, args []driver.Nam } return &rows{ - conn: c, - result: res, + conn: c, + result: res, + nextSet: sync.Once{}, }, nil default: return nil, fmt.Errorf("unsupported query mode '%s' on conn query", m) diff --git a/internal/xsql/connector.go b/internal/xsql/connector.go index 8009f66d1..88b95d40a 100644 --- a/internal/xsql/connector.go +++ b/internal/xsql/connector.go @@ -197,13 +197,23 @@ type ydbDriver interface { func Open(parent ydbDriver, opts ...ConnectorOption) (_ *Connector, err error) { c := &Connector{ - parent: parent, - clock: clockwork.NewRealClock(), - conns: make(map[*conn]struct{}), - defaultTxControl: table.DefaultTxControl(), - defaultQueryMode: DefaultQueryMode, - pathNormalizer: bind.TablePathPrefix(parent.Name()), - trace: &trace.DatabaseSQL{}, + parent: parent, + clock: clockwork.NewRealClock(), + Bindings: bind.Bindings{}, + fakeTxModes: nil, + onClose: nil, + conns: make(map[*conn]struct{}), + connsMtx: sync.RWMutex{}, + idleStopper: nil, + defaultTxControl: table.DefaultTxControl(), + defaultQueryMode: DefaultQueryMode, + defaultDataQueryOpts: nil, + defaultScanQueryOpts: nil, + disableServerBalancer: false, + idleThreshold: time.Duration(0), + pathNormalizer: bind.TablePathPrefix(parent.Name()), + trace: nil, + traceRetry: nil, } for _, opt := range opts { if opt != nil { @@ -253,8 +263,8 @@ type Connector struct { } var ( - _ driver.Connector = &Connector{} - _ io.Closer = &Connector{} + _ driver.Connector = nil + _ io.Closer = nil ) func (c *Connector) idleCloser() (idleStopper func()) { diff --git a/internal/xsql/rows.go b/internal/xsql/rows.go index a9bb1572e..d4f9d3cb5 100644 --- a/internal/xsql/rows.go +++ b/internal/xsql/rows.go @@ -17,13 +17,13 @@ import ( ) var ( - _ driver.Rows = &rows{} - _ driver.RowsNextResultSet = &rows{} - _ driver.RowsColumnTypeDatabaseTypeName = &rows{} - _ driver.RowsColumnTypeNullable = &rows{} - _ driver.Rows = &single{} + _ driver.Rows = &rows{conn: nil, result: nil, nextSet: sync.Once{}} + _ driver.RowsNextResultSet = &rows{conn: nil, result: nil, nextSet: sync.Once{}} + _ driver.RowsColumnTypeDatabaseTypeName = &rows{conn: nil, result: nil, nextSet: sync.Once{}} + _ driver.RowsColumnTypeNullable = &rows{conn: nil, result: nil, nextSet: sync.Once{}} + _ driver.Rows = &single{values: nil, readAll: false} - _ scanner.Scanner = &valuer{} + _ scanner.Scanner = &valuer{v: nil} ignoreColumnPrefixName = "__discard_column_" ) @@ -122,7 +122,7 @@ func (r *rows) Next(dst []driver.Value) error { } values := make([]indexed.RequiredOrOptional, len(dst)) for i := range dst { - values[i] = &valuer{} + values[i] = &valuer{v: nil} } if err = r.result.Scan(values...); err != nil { return badconn.Map(xerrors.WithStackTrace(err)) diff --git a/internal/xsql/stmt.go b/internal/xsql/stmt.go index 75b571acd..a0dab1378 100644 --- a/internal/xsql/stmt.go +++ b/internal/xsql/stmt.go @@ -24,9 +24,9 @@ type stmt struct { } var ( - _ driver.Stmt = &stmt{} - _ driver.StmtQueryContext = &stmt{} - _ driver.StmtExecContext = &stmt{} + _ driver.Stmt = &stmt{conn: nil, processor: nil, query: "", stmtCtx: nil, trace: nil} + _ driver.StmtQueryContext = &stmt{conn: nil, processor: nil, query: "", stmtCtx: nil, trace: nil} + _ driver.StmtExecContext = &stmt{conn: nil, processor: nil, query: "", stmtCtx: nil, trace: nil} ) func (s *stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (_ driver.Rows, finalErr error) { diff --git a/internal/xsql/tx.go b/internal/xsql/tx.go index d67813437..9a3573951 100644 --- a/internal/xsql/tx.go +++ b/internal/xsql/tx.go @@ -4,6 +4,7 @@ import ( "context" "database/sql/driver" "fmt" + "sync" "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" @@ -20,10 +21,10 @@ type tx struct { } var ( - _ driver.Tx = &tx{} - _ driver.ExecerContext = &tx{} - _ driver.QueryerContext = &tx{} - _ table.TransactionIdentifier = &tx{} + _ driver.Tx = &tx{conn: nil, txCtx: nil, tx: nil} + _ driver.ExecerContext = &tx{conn: nil, txCtx: nil, tx: nil} + _ driver.QueryerContext = &tx{conn: nil, txCtx: nil, tx: nil} + _ table.TransactionIdentifier = &tx{conn: nil, txCtx: nil, tx: nil} ) func (c *conn) beginTx(ctx context.Context, txOptions driver.TxOptions) (currentTx, error) { @@ -153,8 +154,9 @@ func (tx *tx) QueryContext(ctx context.Context, query string, args []driver.Name } return &rows{ - conn: tx.conn, - result: res, + conn: tx.conn, + result: res, + nextSet: sync.Once{}, }, nil } diff --git a/internal/xsql/tx_fake.go b/internal/xsql/tx_fake.go index 459aba718..85369e3e8 100644 --- a/internal/xsql/tx_fake.go +++ b/internal/xsql/tx_fake.go @@ -39,16 +39,17 @@ func (tx *txFake) PrepareContext(ctx context.Context, query string) (_ driver.St } var ( - _ driver.Tx = &txFake{} - _ driver.ExecerContext = &txFake{} - _ driver.QueryerContext = &txFake{} - _ table.TransactionIdentifier = &txFake{} + _ driver.Tx = &txFake{beginCtx: nil, conn: nil, ctx: nil} + _ driver.ExecerContext = &txFake{beginCtx: nil, conn: nil, ctx: nil} + _ driver.QueryerContext = &txFake{beginCtx: nil, conn: nil, ctx: nil} + _ table.TransactionIdentifier = &txFake{beginCtx: nil, conn: nil, ctx: nil} ) func (c *conn) beginTxFake(ctx context.Context, txOptions driver.TxOptions) (currentTx, error) { return &txFake{ - conn: c, - ctx: ctx, + beginCtx: nil, + conn: c, + ctx: ctx, }, nil } From a1b0e00d6b79890682eb67ad3ce14b0cb37c3475 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Tue, 16 Apr 2024 20:08:24 +0500 Subject: [PATCH 29/57] add explicit initialization of fields of structures in internal/xstring --- internal/xstring/buffer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/xstring/buffer.go b/internal/xstring/buffer.go index acd4dbc01..4bc22534d 100644 --- a/internal/xstring/buffer.go +++ b/internal/xstring/buffer.go @@ -10,7 +10,7 @@ type buffer struct { } var buffersPool = sync.Pool{New: func() interface{} { - return &buffer{} + return &buffer{Buffer: bytes.Buffer{}} }} func (b *buffer) Free() { From a711da6b46581ff9b0f5c0dcb5d5910baf9d5bb3 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Tue, 16 Apr 2024 20:15:28 +0500 Subject: [PATCH 30/57] add explicit initialization of fields of structures in internal/xsync --- internal/xsync/once.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/xsync/once.go b/internal/xsync/once.go index 35f5ed0aa..76431c460 100644 --- a/internal/xsync/once.go +++ b/internal/xsync/once.go @@ -27,7 +27,7 @@ type Once[T closer.Closer] struct { } func OnceValue[T closer.Closer](f func() T) *Once[T] { - return &Once[T]{f: f} + return &Once[T]{f: f, t: f(), once: sync.Once{}, mutex: sync.RWMutex{}} } func (v *Once[T]) Close(ctx context.Context) (err error) { From 377162ec61625fc2359b486a8390e4455ec49e26 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Tue, 16 Apr 2024 20:28:08 +0500 Subject: [PATCH 31/57] add explicit initialization of fields of structures in internal/xtest --- internal/xtest/logger.go | 1 + internal/xtest/manytimes.go | 5 ++++- internal/xtest/ydb_grpc_mocks.go | 18 +++++++++++------- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/internal/xtest/logger.go b/internal/xtest/logger.go index 62bdfbe21..39fda1ea2 100644 --- a/internal/xtest/logger.go +++ b/internal/xtest/logger.go @@ -7,6 +7,7 @@ import ( func MakeSyncedTest(t testing.TB) *SyncedTest { return &SyncedTest{ + m: sync.Mutex{}, TB: t, } } diff --git a/internal/xtest/manytimes.go b/internal/xtest/manytimes.go index 4dc7f1ccb..b5b21b3a8 100644 --- a/internal/xtest/manytimes.go +++ b/internal/xtest/manytimes.go @@ -64,7 +64,10 @@ func runTest(t testing.TB, test TestFunc) { t.Helper() tw := &testWrapper{ - TB: t, + TB: t, + m: sync.Mutex{}, + logs: nil, + cleanup: nil, } defer tw.doCleanup() diff --git a/internal/xtest/ydb_grpc_mocks.go b/internal/xtest/ydb_grpc_mocks.go index d3816feca..207c21651 100644 --- a/internal/xtest/ydb_grpc_mocks.go +++ b/internal/xtest/ydb_grpc_mocks.go @@ -39,7 +39,7 @@ func GrpcMockTopicConnString(e fixenv.Env, topicServiceImpl Ydb_Topic_V1.TopicSe return fixenv.NewGenericResultWithCleanup(connString, clean), nil } - return fixenv.CacheResult(e, f, fixenv.CacheOptions{CacheKey: addr}) + return fixenv.CacheResult(e, f, fixenv.CacheOptions{Scope: 0, CacheKey: addr}) } type grpcMock struct { @@ -95,8 +95,9 @@ type mockDiscoveryService struct { func newMockDiscoveryService(host string, port uint32) *mockDiscoveryService { return &mockDiscoveryService{ - host: host, - port: port, + UnimplementedDiscoveryServiceServer: Ydb_Discovery_V1.UnimplementedDiscoveryServiceServer{}, + host: host, + port: port, } } @@ -121,10 +122,13 @@ func (m mockDiscoveryService) ListEndpoints( } resp := &Ydb_Discovery.ListEndpointsResponse{ Operation: &Ydb_Operations.Operation{ - Id: "test-list-operation", - Ready: true, - Status: Ydb.StatusIds_SUCCESS, - Result: &anypb.Any{}, + Id: "test-list-operation", + Ready: true, + Status: Ydb.StatusIds_SUCCESS, + Issues: nil, + Result: &anypb.Any{TypeUrl: "", Value: nil}, + Metadata: &anypb.Any{TypeUrl: "", Value: nil}, + CostInfo: nil, }, } err := resp.GetOperation().GetResult().MarshalFrom(res) From 18b64b7c0488839d90311c174b635623ff4c95e9 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Fri, 19 Apr 2024 16:17:42 +0500 Subject: [PATCH 32/57] add explicit initialization of fields of structures in internal/background --- internal/background/worker.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/background/worker.go b/internal/background/worker.go index 91c0d1686..df7af2083 100644 --- a/internal/background/worker.go +++ b/internal/background/worker.go @@ -33,7 +33,17 @@ type Worker struct { type CallbackFunc func(ctx context.Context) func NewWorker(parent context.Context) *Worker { - w := Worker{} + w := Worker{ + ctx: context.Background(), + workers: sync.WaitGroup{}, + closeReason: nil, + tasksCompleted: nil, + tasks: nil, + stop: nil, + onceInit: sync.Once{}, + m: xsync.Mutex{Mutex: sync.Mutex{}}, + closed: false, + } w.ctx, w.stop = xcontext.WithCancel(parent) return &w From 33bb8e5cc37efe2b5ce839ad66f0d8eb8d3ffa6e Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Fri, 19 Apr 2024 19:29:58 +0500 Subject: [PATCH 33/57] add explicit initialization of fields of structures in internal/cmd --- internal/cmd/gtrace/main.go | 39 ++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/internal/cmd/gtrace/main.go b/internal/cmd/gtrace/main.go index 99f2bf98a..e6023b9ad 100644 --- a/internal/cmd/gtrace/main.go +++ b/internal/cmd/gtrace/main.go @@ -16,6 +16,7 @@ import ( "os" "path/filepath" "strings" + "sync" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" ) @@ -82,11 +83,25 @@ func main() { writers = append(writers, &Writer{ Context: buildCtx, Output: f, + once: sync.Once{}, + bw: nil, + atEOL: false, + depth: 0, + scope: nil, + pkg: nil, + std: make(map[string]bool), }) } else { writers = append(writers, &Writer{ Context: buildCtx, Output: os.Stdout, + once: sync.Once{}, + bw: nil, + atEOL: false, + depth: 0, + scope: nil, + pkg: nil, + std: make(map[string]bool), }) } @@ -129,14 +144,25 @@ func main() { } } info := &types.Info{ - Types: make(map[ast.Expr]types.TypeAndValue), - Defs: make(map[*ast.Ident]types.Object), - Uses: make(map[*ast.Ident]types.Object), + Types: make(map[ast.Expr]types.TypeAndValue), + Defs: make(map[*ast.Ident]types.Object), + Uses: make(map[*ast.Ident]types.Object), + Instances: make(map[*ast.Ident]types.Instance), + Implicits: make(map[ast.Node]types.Object), + Selections: make(map[*ast.SelectorExpr]*types.Selection), + Scopes: make(map[ast.Node]*types.Scope), + InitOrder: nil, + FileVersions: make(map[*ast.File]string), } conf := types.Config{ IgnoreFuncBodies: true, DisableUnusedImportCheck: true, Importer: importer.ForCompiler(fset, "source", nil), + Context: nil, + GoVersion: "", + FakeImportC: false, + Error: nil, + Sizes: nil, } pkg, err := conf.Check(".", fset, astFiles, info) if err != nil { @@ -179,7 +205,7 @@ func main() { for _, c := range v.List { if strings.Contains(strings.TrimPrefix(c.Text, "//"), "gtrace:gen") { if item == nil { - item = &GenItem{} + item = &GenItem{Ident: nil, StructType: nil} } } } @@ -202,11 +228,14 @@ func main() { p := Package{ Package: pkg, BuildConstraints: buildConstraints, + Traces: nil, } traces := make(map[string]*Trace) for _, item := range items { t := &Trace{ - Name: item.Ident.Name, + Name: item.Ident.Name, + Hooks: nil, + Nested: false, } p.Traces = append(p.Traces, t) traces[item.Ident.Name] = t From 447e72a117937570a8ffbdf9b48f67367b7c14af Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Fri, 19 Apr 2024 21:35:15 +0500 Subject: [PATCH 34/57] add explicit initialization of fields of structures in internal/balancer --- internal/balancer/balancer.go | 19 ++++++++++++++++++- internal/balancer/connections_state.go | 3 +++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/internal/balancer/balancer.go b/internal/balancer/balancer.go index f69ec11e2..c2ba1e20e 100644 --- a/internal/balancer/balancer.go +++ b/internal/balancer/balancer.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "sort" + "sync" "google.golang.org/grpc" @@ -258,6 +259,17 @@ func New( driverConfig: driverConfig, pool: pool, localDCDetector: detectLocalDC, + config: balancerConfig.Config{ + Filter: nil, + AllowFallback: false, + SingleConn: false, + DetectLocalDC: false, + }, + discoveryClient: nil, + discoveryRepeater: nil, + mu: xsync.RWMutex{RWMutex: sync.RWMutex{}}, + connectionsState: nil, + onApplyDiscoveredEndpoints: nil, } d := internalDiscovery.New(ctx, pool.Get( endpoint.New(driverConfig.Endpoint()), @@ -266,7 +278,12 @@ func New( b.discoveryClient = d if config := driverConfig.Balancer(); config == nil { - b.config = balancerConfig.Config{} + b.config = balancerConfig.Config{ + Filter: nil, + AllowFallback: false, + SingleConn: false, + DetectLocalDC: false, + } } else { b.config = *config } diff --git a/internal/balancer/connections_state.go b/internal/balancer/connections_state.go index e9196ead7..9a1ea8abc 100644 --- a/internal/balancer/connections_state.go +++ b/internal/balancer/connections_state.go @@ -27,6 +27,9 @@ func newConnectionsState( res := &connectionsState{ connByNodeID: connsToNodeIDMap(conns), rand: xrand.New(xrand.WithLock()), + prefer: nil, + fallback: nil, + all: nil, } res.prefer, res.fallback = sortPreferConnections(conns, filter, info, allowFallback) From 6c43dee12361b8cc29a0f85fcc8b5767e0cbb8f5 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Fri, 19 Apr 2024 21:48:42 +0500 Subject: [PATCH 35/57] add explicit initialization of fields of structures in internal/conn --- internal/conn/conn.go | 22 ++++++++++++++++------ internal/conn/last_usage.go | 2 ++ internal/conn/pool.go | 1 + 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/internal/conn/conn.go b/internal/conn/conn.go index 66278bb94..6a9d5bdda 100644 --- a/internal/conn/conn.go +++ b/internal/conn/conn.go @@ -490,10 +490,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: newLastUsage(nil), + mtx: sync.RWMutex{}, + cc: nil, + closed: false, + state: atomic.Uint32{}, + onClose: nil, + onTransportErrors: nil, } c.state.Store(uint32(Created)) for _, opt := range opts { @@ -536,7 +542,9 @@ type ctxHandleRPCKey struct{} var rpcKey = ctxHandleRPCKey{} func markContext(ctx context.Context) (context.Context, *modificationMark) { - mark := &modificationMark{} + mark := &modificationMark{ + dirty: atomic.Bool{}, + } return context.WithValue(ctx, rpcKey, mark), mark } @@ -544,7 +552,9 @@ func markContext(ctx context.Context) (context.Context, *modificationMark) { func getContextMark(ctx context.Context) *modificationMark { v := ctx.Value(rpcKey) if v == nil { - return &modificationMark{} + return &modificationMark{ + dirty: atomic.Bool{}, + } } return v.(*modificationMark) diff --git a/internal/conn/last_usage.go b/internal/conn/last_usage.go index b0ca293a9..e70e215ef 100644 --- a/internal/conn/last_usage.go +++ b/internal/conn/last_usage.go @@ -21,6 +21,8 @@ func newLastUsage(clock clockwork.Clock) *lastUsage { now := clock.Now() usage := &lastUsage{ clock: clock, + locks: atomic.Int64{}, + t: atomic.Pointer[time.Time]{}, } usage.t.Store(&now) diff --git a/internal/conn/pool.go b/internal/conn/pool.go index 6115c612f..01b0d0716 100644 --- a/internal/conn/pool.go +++ b/internal/conn/pool.go @@ -243,6 +243,7 @@ func NewPool(ctx context.Context, config Config) *Pool { opts: config.GrpcDialOptions(), conns: make(map[connsKey]*conn), done: make(chan struct{}), + mtx: xsync.RWMutex{RWMutex: sync.RWMutex{}}, } if ttl := config.ConnectionTTL(); ttl > 0 { From 17091a9ad45b11088466dfc27bdaf94b5a992788 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Sat, 20 Apr 2024 22:34:02 +0500 Subject: [PATCH 36/57] add explicit initialization of fields of structures in internal/coordination --- internal/coordination/client.go | 1 + internal/coordination/config/config.go | 3 +- .../coordination/conversation/conversation.go | 11 ++++++- internal/coordination/session.go | 29 ++++++++++++++----- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/internal/coordination/client.go b/internal/coordination/client.go index 70322f702..857399cff 100644 --- a/internal/coordination/client.go +++ b/internal/coordination/client.go @@ -44,6 +44,7 @@ func New(ctx context.Context, cc grpc.ClientConnInterface, config config.Config) config: config, client: Ydb_Coordination_V1.NewCoordinationServiceClient(cc), sessions: make(map[*session]struct{}), + mutex: sync.Mutex{}, } } diff --git a/internal/coordination/config/config.go b/internal/coordination/config/config.go index 692777a43..d473f4e7d 100644 --- a/internal/coordination/config/config.go +++ b/internal/coordination/config/config.go @@ -35,7 +35,8 @@ func With(config config.Common) Option { func New(opts ...Option) Config { c := Config{ - trace: &trace.Coordination{}, + Common: config.Common{}, + trace: new(trace.Coordination), } for _, opt := range opts { if opt != nil { diff --git a/internal/coordination/conversation/conversation.go b/internal/coordination/conversation/conversation.go index c3c8e1863..f2053a272 100644 --- a/internal/coordination/conversation/conversation.go +++ b/internal/coordination/conversation/conversation.go @@ -137,6 +137,9 @@ func NewController() *Controller { return &Controller{ notifyChan: make(chan struct{}, 1), conflicts: make(map[string]struct{}), + mutex: sync.Mutex{}, + queue: nil, + closed: false, } } @@ -195,7 +198,13 @@ type Option func(c *Conversation) // NewConversation creates a new conversation that starts with a specified message. func NewConversation(request func() *Ydb_Coordination.SessionRequest, opts ...Option) *Conversation { - conversation := Conversation{message: request} + conversation := Conversation{ + message: request, responseFilter: nil, acknowledgeFilter: nil, + cancelMessage: nil, cancelFilter: nil, + conflictKey: "", responseErr: nil, done: nil, + requestSent: nil, cancelRequestSent: nil, response: nil, + idempotent: false, canceled: false, + } for _, o := range opts { if o != nil { o(&conversation) diff --git a/internal/coordination/session.go b/internal/coordination/session.go index af10c064c..95bf0bb21 100644 --- a/internal/coordination/session.go +++ b/internal/coordination/session.go @@ -49,12 +49,16 @@ func createSession( ) (*session, error) { sessionCtx, cancel := xcontext.WithCancel(xcontext.ValueOnly(ctx)) s := session{ - options: opts, - client: client, - ctx: sessionCtx, - cancel: cancel, - sessionClosedChan: make(chan struct{}), - controller: conversation.NewController(), + options: opts, + client: client, + ctx: sessionCtx, + cancel: cancel, + sessionClosedChan: make(chan struct{}), + controller: conversation.NewController(), + sessionID: 0, + mutex: sync.Mutex{}, + lastGoodResponseTime: time.Time{}, + cancelStream: nil, } client.sessionCreated(&s) @@ -548,6 +552,7 @@ func (s *session) CreateSemaphore( ReqId: newReqID(), Name: name, Limit: limit, + Data: nil, } for _, o := range opts { if o != nil { @@ -590,6 +595,7 @@ func (s *session) UpdateSemaphore( updateSemaphore := Ydb_Coordination.SessionRequest_UpdateSemaphore{ ReqId: newReqID(), Name: name, + Data: nil, } for _, o := range opts { if o != nil { @@ -634,6 +640,7 @@ func (s *session) DeleteSemaphore( deleteSemaphore := Ydb_Coordination.SessionRequest_DeleteSemaphore{ ReqId: newReqID(), Name: name, + Force: false, } for _, o := range opts { if o != nil { @@ -675,8 +682,12 @@ func (s *session) DescribeSemaphore( req := conversation.NewConversation( func() *Ydb_Coordination.SessionRequest { describeSemaphore := Ydb_Coordination.SessionRequest_DescribeSemaphore{ - ReqId: newReqID(), - Name: name, + ReqId: newReqID(), + Name: name, + IncludeOwners: false, + IncludeWaiters: false, + WatchData: false, + WatchOwners: false, } for _, o := range opts { if o != nil { @@ -778,6 +789,8 @@ func (s *session) AcquireSemaphore( Name: name, Count: count, TimeoutMillis: math.MaxUint64, + Data: nil, + Ephemeral: false, } for _, o := range opts { if o != nil { From 0916f1b26a776c88a7d1392866f660b0a66d299d Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Sat, 20 Apr 2024 22:42:01 +0500 Subject: [PATCH 37/57] add explicit initialization of fields of structures in internal/discovery --- internal/discovery/config/config.go | 7 ++++++- internal/discovery/discovery.go | 7 ++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/discovery/config/config.go b/internal/discovery/config/config.go index 782f3b6b2..e9ad9a3eb 100644 --- a/internal/discovery/config/config.go +++ b/internal/discovery/config/config.go @@ -27,7 +27,12 @@ type Config struct { func New(opts ...Option) *Config { c := &Config{ interval: DefaultInterval, - trace: &trace.Discovery{}, + trace: new(trace.Discovery), + Common: config.Common{}, + endpoint: "", + database: "", + secure: false, + meta: nil, } for _, opt := range opts { if opt != nil { diff --git a/internal/discovery/discovery.go b/internal/discovery/discovery.go index dfda2660c..edcacab02 100644 --- a/internal/discovery/discovery.go +++ b/internal/discovery/discovery.go @@ -27,7 +27,7 @@ func New(ctx context.Context, cc grpc.ClientConnInterface, config *config.Config } } -var _ discovery.Client = &Client{} +var _ discovery.Client = &Client{config: nil, cc: nil, client: nil} type Client struct { config *config.Config @@ -45,6 +45,7 @@ func (c *Client) Discover(ctx context.Context) (endpoints []endpoint.Endpoint, e ) request = Ydb_Discovery.ListEndpointsRequest{ Database: c.config.Database(), + Service: nil, } response *Ydb_Discovery.ListEndpointsResponse result Ydb_Discovery.ListEndpointsResult @@ -102,7 +103,7 @@ func (c *Client) WhoAmI(ctx context.Context) (whoAmI *discovery.WhoAmI, err erro onDone = trace.DiscoveryOnWhoAmI(c.config.Trace(), &ctx, stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/discovery.(*Client).WhoAmI"), ) - request = Ydb_Discovery.WhoAmIRequest{} + request = Ydb_Discovery.WhoAmIRequest{IncludeGroups: false} response *Ydb_Discovery.WhoAmIResponse whoAmIResultResult Ydb_Discovery.WhoAmIResult ) @@ -134,7 +135,7 @@ func (c *Client) WhoAmI(ctx context.Context) (whoAmI *discovery.WhoAmI, err erro result := response.GetOperation().GetResult() if result == nil { - return &discovery.WhoAmI{}, nil + return &discovery.WhoAmI{User: "", Groups: nil}, nil } err = response.GetOperation().GetResult().UnmarshalTo(&whoAmIResultResult) From 2f525ee3d2c748e906d8f20f69eef6123d9c5e77 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Mon, 22 Apr 2024 01:46:06 +0500 Subject: [PATCH 38/57] add explicit initialization of fields of structures in internal/topic --- internal/topic/topicclientinternal/client.go | 19 +++++++-- internal/topic/topicreaderinternal/batch.go | 9 ++-- internal/topic/topicreaderinternal/batcher.go | 37 ++++++++++++----- .../topic/topicreaderinternal/commit_range.go | 3 +- .../topic/topicreaderinternal/committer.go | 17 +++++--- .../topicreaderinternal/grpc_synced_stream.go | 2 +- internal/topic/topicreaderinternal/message.go | 41 ++++++++++++++----- .../message_content_pool.go | 2 +- .../topicreaderinternal/one_time_reader.go | 1 + .../topicreaderinternal/partition_session.go | 18 ++++---- internal/topic/topicreaderinternal/reader.go | 2 +- .../topicreaderinternal/stream_reader_impl.go | 41 ++++++++++++++----- .../topicreaderinternal/stream_reconnector.go | 26 ++++++++---- .../topic/topicwriterinternal/encoders.go | 3 ++ internal/topic/topicwriterinternal/message.go | 15 ++++++- internal/topic/topicwriterinternal/queue.go | 18 +++++--- .../topicwriterinternal/writer_reconnector.go | 27 +++++++++++- .../writer_single_stream.go | 21 +++++++++- 18 files changed, 229 insertions(+), 73 deletions(-) diff --git a/internal/topic/topicclientinternal/client.go b/internal/topic/topicclientinternal/client.go index 2318d97b1..42232d530 100644 --- a/internal/topic/topicclientinternal/client.go +++ b/internal/topic/topicclientinternal/client.go @@ -2,11 +2,14 @@ package topicclientinternal import ( "context" + "time" "github.com/ydb-platform/ydb-go-genproto/Ydb_Topic_V1" "google.golang.org/grpc" "github.com/ydb-platform/ydb-go-sdk/v3/credentials" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/config" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawoptional" "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic" "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawydb" "github.com/ydb-platform/ydb-go-sdk/v3/internal/topic" @@ -50,7 +53,8 @@ func New( func newTopicConfig(opts ...topicoptions.TopicOption) topic.Config { c := topic.Config{ - Trace: &trace.Topic{}, + Common: config.Common{}, + Trace: new(trace.Topic), } for _, opt := range opts { if opt != nil { @@ -68,7 +72,7 @@ func (c *Client) Close(_ context.Context) error { // Alter topic options func (c *Client) Alter(ctx context.Context, path string, opts ...topicoptions.AlterOption) error { - req := &rawtopic.AlterTopicRequest{} + req := new(rawtopic.AlterTopicRequest) req.OperationParams = c.defaultOperationParams req.Path = path for _, opt := range opts { @@ -99,7 +103,7 @@ func (c *Client) Create( path string, opts ...topicoptions.CreateOption, ) error { - req := &rawtopic.CreateTopicRequest{} + req := new(rawtopic.CreateTopicRequest) req.OperationParams = c.defaultOperationParams req.Path = path @@ -172,7 +176,14 @@ func (c *Client) Describe( // Drop topic func (c *Client) Drop(ctx context.Context, path string, opts ...topicoptions.DropOption) error { - req := rawtopic.DropTopicRequest{} + req := rawtopic.DropTopicRequest{ + OperationParams: rawydb.OperationParams{ + OperationMode: rawydb.OperationParamsModeUnspecified, + OperationTimeout: rawoptional.Duration{Value: time.Duration(0), HasValue: false}, + CancelAfter: rawoptional.Duration{Value: time.Duration(0), HasValue: false}, + }, + Path: "", + } req.OperationParams = c.defaultOperationParams req.Path = path diff --git a/internal/topic/topicreaderinternal/batch.go b/internal/topic/topicreaderinternal/batch.go index e8e00ad01..73d99eb64 100644 --- a/internal/topic/topicreaderinternal/batch.go +++ b/internal/topic/topicreaderinternal/batch.go @@ -45,7 +45,9 @@ func newBatch(session *partitionSession, messages []*PublicMessage) (*PublicBatc } offset := commitRange{ - partitionSession: session, + commitOffsetStart: rawtopicreader.Offset(0), + commitOffsetEnd: rawtopicreader.Offset(0), + partitionSession: session, } if len(messages) > 0 { offset.commitOffsetStart = messages[0].commitRange.commitOffsetStart @@ -55,6 +57,7 @@ func newBatch(session *partitionSession, messages []*PublicMessage) (*PublicBatc return &PublicBatch{ Messages: messages, commitRange: offset, + DoNotCopy: empty.DoNotCopy{}, }, nil } @@ -68,7 +71,7 @@ func newBatchFromStream( for i := range sb.MessageData { sMess := &sb.MessageData[i] - dstMess := &PublicMessage{} + dstMess := new(PublicMessage) messages[i] = dstMess dstMess.CreatedAt = sMess.CreatedAt dstMess.MessageGroupID = sMess.MessageGroupID @@ -128,7 +131,7 @@ func (m *PublicBatch) getCommitRange() PublicCommitRange { func (m *PublicBatch) append(b *PublicBatch) (*PublicBatch, error) { var res *PublicBatch if m == nil { - res = &PublicBatch{} + res = new(PublicBatch) } else { res = m } diff --git a/internal/topic/topicreaderinternal/batcher.go b/internal/topic/topicreaderinternal/batcher.go index 8eaa5eb6b..fd853b06b 100644 --- a/internal/topic/topicreaderinternal/batcher.go +++ b/internal/topic/topicreaderinternal/batcher.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "sync" "sync/atomic" "github.com/ydb-platform/ydb-go-sdk/v3/internal/empty" @@ -29,9 +30,16 @@ type batcher struct { func newBatcher() *batcher { return &batcher{ - messages: make(batcherMessagesMap), - closeChan: make(empty.Chan), + popInFlight: 0, + closeErr: nil, hasNewMessages: make(empty.Chan, 1), + + m: xsync.Mutex{Mutex: sync.Mutex{}}, + + forceIgnoreMinRestrictionsOnNextMessagesBatch: false, + closed: false, + closeChan: make(empty.Chan), + messages: make(batcherMessagesMap), } } @@ -108,7 +116,7 @@ func (o batcherGetOptions) cutBatchItemsHead(items batcherMessageOrderItems) ( ok bool, ) { notFound := func() (batcherMessageOrderItem, batcherMessageOrderItems, bool) { - return batcherMessageOrderItem{}, batcherMessageOrderItems{}, false + return batcherMessageOrderItem{Batch: nil, RawMessage: nil}, batcherMessageOrderItems{}, false } if len(items) == 0 { return notFound() @@ -231,19 +239,26 @@ func newBatcherResultCandidate( ok bool, ) batcherResultCandidate { return batcherResultCandidate{ - Key: key, - Result: result, - Rest: rest, - Ok: ok, + Key: key, + Result: result, + Rest: rest, + Ok: ok, + WaiterIndex: 0, } } func (b *batcher) findNeedLock(filter batcherGetOptions) batcherResultCandidate { if len(b.messages) == 0 { - return batcherResultCandidate{} + return batcherResultCandidate{ + Key: nil, + Result: batcherMessageOrderItem{Batch: nil, RawMessage: nil}, + Rest: batcherMessageOrderItems{}, + Ok: false, + WaiterIndex: 0, + } } - rawMessageOpts := batcherGetOptions{rawMessagesOnly: true} + rawMessageOpts := batcherGetOptions{MinCount: 0, MaxCount: 0, rawMessagesOnly: true} var batchResult batcherResultCandidate needBatchResult := true @@ -344,11 +359,11 @@ type batcherMessageOrderItem struct { } func newBatcherItemBatch(b *PublicBatch) batcherMessageOrderItem { - return batcherMessageOrderItem{Batch: b} + return batcherMessageOrderItem{Batch: b, RawMessage: nil} } func newBatcherItemRawMessage(b rawtopicreader.ServerMessage) batcherMessageOrderItem { - return batcherMessageOrderItem{RawMessage: b} + return batcherMessageOrderItem{Batch: nil, RawMessage: b} } func (item *batcherMessageOrderItem) IsBatch() bool { diff --git a/internal/topic/topicreaderinternal/commit_range.go b/internal/topic/topicreaderinternal/commit_range.go index c744cd49b..191ba44c7 100644 --- a/internal/topic/topicreaderinternal/commit_range.go +++ b/internal/topic/topicreaderinternal/commit_range.go @@ -41,7 +41,7 @@ func NewCommitRangesWithCapacity(capacity int) CommitRanges { } func NewCommitRangesFromPublicCommits(ranges []PublicCommitRange) CommitRanges { - res := CommitRanges{} + res := CommitRanges{ranges: nil} res.ranges = make([]commitRange, len(ranges)) for i := 0; i < len(res.ranges); i++ { res.ranges[i] = ranges[i].priv @@ -133,6 +133,7 @@ func (r *CommitRanges) toRawPartitionCommitOffset() []rawtopicreader.PartitionCo newPartition := func(id rawtopicreader.PartitionSessionID) rawtopicreader.PartitionCommitOffset { return rawtopicreader.PartitionCommitOffset{ PartitionSessionID: id, + Offsets: nil, } } diff --git a/internal/topic/topicreaderinternal/committer.go b/internal/topic/topicreaderinternal/committer.go index 6c35916d8..1f46c0108 100644 --- a/internal/topic/topicreaderinternal/committer.go +++ b/internal/topic/topicreaderinternal/committer.go @@ -3,6 +3,7 @@ package topicreaderinternal import ( "context" "errors" + "sync" "sync/atomic" "time" @@ -54,11 +55,17 @@ type committer struct { func newCommitter(tracer *trace.Topic, lifeContext context.Context, mode PublicCommitMode, send sendMessageToServerFunc) *committer { //nolint:lll,revive res := &committer{ - mode: mode, - clock: clockwork.NewRealClock(), - send: send, - backgroundWorker: *background.NewWorker(lifeContext), - tracer: tracer, + mode: mode, + clock: clockwork.NewRealClock(), + send: send, + backgroundWorker: *background.NewWorker(lifeContext), + tracer: tracer, + BufferTimeLagTrigger: time.Duration(0), + BufferCountTrigger: 0, + commitLoopSignal: nil, + m: xsync.Mutex{Mutex: sync.Mutex{}}, + waiters: nil, + commits: CommitRanges{ranges: nil}, } res.initChannels() res.start() diff --git a/internal/topic/topicreaderinternal/grpc_synced_stream.go b/internal/topic/topicreaderinternal/grpc_synced_stream.go index 0a573ee57..b192de67f 100644 --- a/internal/topic/topicreaderinternal/grpc_synced_stream.go +++ b/internal/topic/topicreaderinternal/grpc_synced_stream.go @@ -6,7 +6,7 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic/rawtopicreader" ) -var _ RawTopicReaderStream = &syncedStream{} +var _ RawTopicReaderStream = &syncedStream{m: sync.Mutex{}, stream: nil} type syncedStream struct { m sync.Mutex diff --git a/internal/topic/topicreaderinternal/message.go b/internal/topic/topicreaderinternal/message.go index 13cc98f0c..6985ed623 100644 --- a/internal/topic/topicreaderinternal/message.go +++ b/internal/topic/topicreaderinternal/message.go @@ -9,6 +9,7 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/internal/empty" "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic/rawtopiccommon" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic/rawtopicreader" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" ) @@ -107,7 +108,7 @@ type PublicMessageBuilder struct { } func NewPublicMessageBuilder() *PublicMessageBuilder { - res := &PublicMessageBuilder{} + res := &PublicMessageBuilder{mess: nil} res.initMessage() return res @@ -115,15 +116,33 @@ func NewPublicMessageBuilder() *PublicMessageBuilder { func (pmb *PublicMessageBuilder) initMessage() { pmb.mess = &PublicMessage{ - commitRange: commitRange{partitionSession: newPartitionSession( - context.Background(), - "", - 0, - 0, - "", - 0, - 0, - )}, + DoNotCopy: empty.DoNotCopy{}, + SeqNo: 0, + CreatedAt: time.Time{}, + MessageGroupID: "", + WriteSessionMetadata: nil, + Offset: 0, + WrittenAt: time.Time{}, + ProducerID: "", + Metadata: nil, + commitRange: commitRange{ + commitOffsetStart: rawtopicreader.Offset(0), + commitOffsetEnd: rawtopicreader.Offset(0), + partitionSession: newPartitionSession( + context.Background(), + "", + 0, + 0, + "", + 0, + 0, + ), + }, + data: oneTimeReader{err: nil, reader: nil}, + rawDataLen: 0, + bufferBytesAccount: 0, + UncompressedSize: 0, + dataConsumed: false, } } @@ -189,7 +208,7 @@ func (pmb *PublicMessageBuilder) ProducerID(producerID string) *PublicMessageBui func (pmb *PublicMessageBuilder) DataAndUncompressedSize(data []byte) *PublicMessageBuilder { copyData := make([]byte, len(data)) copy(copyData, data) - pmb.mess.data = oneTimeReader{reader: bytes.NewReader(data)} + pmb.mess.data = oneTimeReader{err: nil, reader: bytes.NewReader(data)} pmb.mess.dataConsumed = false pmb.mess.rawDataLen = len(copyData) pmb.mess.UncompressedSize = len(copyData) diff --git a/internal/topic/topicreaderinternal/message_content_pool.go b/internal/topic/topicreaderinternal/message_content_pool.go index 73b561cae..fd3da1959 100644 --- a/internal/topic/topicreaderinternal/message_content_pool.go +++ b/internal/topic/topicreaderinternal/message_content_pool.go @@ -27,7 +27,7 @@ const ( maxInitialBufferSize = 1024 * 1024 * 50 // protection from bad UncompressedSize from stream ) -var globalReadMessagePool = &sync.Pool{} +var globalReadMessagePool = new(sync.Pool) func callbackOnReaderContent( p Pool, diff --git a/internal/topic/topicreaderinternal/one_time_reader.go b/internal/topic/topicreaderinternal/one_time_reader.go index 4a54d6f7a..3646b4d28 100644 --- a/internal/topic/topicreaderinternal/one_time_reader.go +++ b/internal/topic/topicreaderinternal/one_time_reader.go @@ -11,6 +11,7 @@ type oneTimeReader struct { func newOneTimeReader(reader io.Reader) oneTimeReader { return oneTimeReader{ + err: nil, reader: reader, } } diff --git a/internal/topic/topicreaderinternal/partition_session.go b/internal/topic/topicreaderinternal/partition_session.go index 9e23c5495..ae65e8af8 100644 --- a/internal/topic/topicreaderinternal/partition_session.go +++ b/internal/topic/topicreaderinternal/partition_session.go @@ -44,13 +44,15 @@ func newPartitionSession( partitionContext, cancel := xcontext.WithCancel(partitionContext) res := &partitionSession{ - Topic: topic, - PartitionID: partitionID, - readerID: readerID, - connectionID: connectionID, - ctx: partitionContext, - ctxCancel: cancel, - partitionSessionID: partitionSessionID, + Topic: topic, + PartitionID: partitionID, + readerID: readerID, + connectionID: connectionID, + ctx: partitionContext, + ctxCancel: cancel, + partitionSessionID: partitionSessionID, + lastReceivedOffsetEndVal: atomic.Int64{}, + committedOffsetVal: atomic.Int64{}, } res.committedOffsetVal.Store(committedOffset.ToInt64()) res.lastReceivedOffsetEndVal.Store(committedOffset.ToInt64() - 1) @@ -114,7 +116,7 @@ func (c *partitionSessionStorage) Add(session *partitionSession) error { if _, ok := c.sessions[session.partitionSessionID]; ok { return xerrors.WithStackTrace(fmt.Errorf("session id already existed: %v", session.partitionSessionID)) } - c.sessions[session.partitionSessionID] = &sessionInfo{Session: session} + c.sessions[session.partitionSessionID] = &sessionInfo{Session: session, RemovedIndex: 0, RemoveTime: time.Time{}} return nil } diff --git a/internal/topic/topicreaderinternal/reader.go b/internal/topic/topicreaderinternal/reader.go index b499221d1..f60371c2c 100644 --- a/internal/topic/topicreaderinternal/reader.go +++ b/internal/topic/topicreaderinternal/reader.go @@ -59,7 +59,7 @@ func (o ReadMessageBatchOptions) clone() ReadMessageBatchOptions { } func newReadMessageBatchOptions() ReadMessageBatchOptions { - return ReadMessageBatchOptions{} + return ReadMessageBatchOptions{batcherGetOptions: batcherGetOptions{MinCount: 0, MaxCount: 0, rawMessagesOnly: false}} } // PublicReadBatchOption для различных пожеланий к батчу вроде WithMaxMessages(int) diff --git a/internal/topic/topicreaderinternal/stream_reader_impl.go b/internal/topic/topicreaderinternal/stream_reader_impl.go index 381ccd690..f393383fd 100644 --- a/internal/topic/topicreaderinternal/stream_reader_impl.go +++ b/internal/topic/topicreaderinternal/stream_reader_impl.go @@ -9,6 +9,7 @@ import ( "math/big" "reflect" "runtime/pprof" + "sync" "sync/atomic" "time" @@ -72,20 +73,25 @@ type topicStreamReaderConfig struct { func newTopicStreamReaderConfig() topicStreamReaderConfig { return topicStreamReaderConfig{ - BaseContext: context.Background(), - BufferSizeProtoBytes: 1024 * 1024, - Cred: credentials.NewAnonymousCredentials(), - CredUpdateInterval: time.Hour, - CommitMode: CommitModeAsync, - CommitterBatchTimeLag: time.Second, - Decoders: newDecoderMap(), - Trace: &trace.Topic{}, + BaseContext: context.Background(), + BufferSizeProtoBytes: 1024 * 1024, + Cred: credentials.NewAnonymousCredentials(), + CredUpdateInterval: time.Hour, + CommitMode: CommitModeAsync, + CommitterBatchTimeLag: time.Second, + Decoders: newDecoderMap(), + Trace: new(trace.Topic), + CommitterBatchCounterTrigger: 0, + Consumer: "", + ReadSelectors: nil, + GetPartitionStartOffsetCallback: nil, } } func (cfg *topicStreamReaderConfig) initMessage() *rawtopicreader.InitRequest { res := &rawtopicreader.InitRequest{ - Consumer: cfg.Consumer, + Consumer: cfg.Consumer, + TopicsReadSettings: nil, } res.TopicsReadSettings = make([]rawtopicreader.TopicReadSettings, len(cfg.ReadSelectors)) @@ -145,13 +151,26 @@ func newTopicStreamReaderStopped( cfg: cfg, ctx: stopPump, freeBytes: make(chan int, 1), - stream: &syncedStream{stream: stream}, + stream: &syncedStream{m: sync.Mutex{}, stream: stream}, cancel: cancel, batcher: newBatcher(), backgroundWorkers: *background.NewWorker(stopPump), readConnectionID: "preinitID-" + readerConnectionID.String(), readerID: readerID, rawMessagesFromBuffer: make(chan rawtopicreader.ServerMessage, 1), + restBufferSizeBytes: atomic.Int64{}, + sessionController: partitionSessionStorage{ + m: sync.RWMutex{}, + sessions: nil, + removeIndex: 0, + lastCompactedTime: time.Time{}, + lastCompactedRemoveIndex: 0, + }, + committer: nil, + m: xsync.RWMutex{RWMutex: sync.RWMutex{}}, + err: nil, + started: false, + closed: false, } res.committer = newCommitter(cfg.Trace, labeledContext, cfg.CommitMode, res.send) @@ -777,6 +796,8 @@ func (r *topicStreamReaderImpl) onStartPartitionSessionRequestFromBuffer( respMessage := &rawtopicreader.StartPartitionSessionResponse{ PartitionSessionID: session.partitionSessionID, + ReadOffset: rawtopicreader.OptionalOffset{Offset: rawtopicreader.Offset(0), HasValue: false}, + CommitOffset: rawtopicreader.OptionalOffset{Offset: rawtopicreader.Offset(0), HasValue: false}, } var forceOffset *int64 diff --git a/internal/topic/topicreaderinternal/stream_reconnector.go b/internal/topic/topicreaderinternal/stream_reconnector.go index ec601ba67..7e1823585 100644 --- a/internal/topic/topicreaderinternal/stream_reconnector.go +++ b/internal/topic/topicreaderinternal/stream_reconnector.go @@ -59,14 +59,24 @@ func newReaderReconnector( baseContext context.Context, ) *readerReconnector { res := &readerReconnector{ - readerID: readerID, - clock: clockwork.NewRealClock(), - readerConnect: connector, - streamErr: errUnconnected, - connectTimeout: connectTimeout, - tracer: tracer, - baseContext: baseContext, - retrySettings: retrySettings, + readerID: readerID, + clock: clockwork.NewRealClock(), + readerConnect: connector, + streamErr: errUnconnected, + connectTimeout: connectTimeout, + tracer: tracer, + baseContext: baseContext, + retrySettings: retrySettings, + background: background.Worker{}, + streamVal: nil, + closedErr: nil, + initErr: nil, + reconnectFromBadStream: nil, + streamConnectionInProgress: nil, + initDoneCh: nil, + m: xsync.RWMutex{RWMutex: sync.RWMutex{}}, + closeOnce: sync.Once{}, + initDone: false, } if res.connectTimeout == 0 { diff --git a/internal/topic/topicwriterinternal/encoders.go b/internal/topic/topicwriterinternal/encoders.go index 7ae89d534..285cade25 100644 --- a/internal/topic/topicwriterinternal/encoders.go +++ b/internal/topic/topicwriterinternal/encoders.go @@ -104,6 +104,9 @@ func NewEncoderSelector( tracer: tracer, writerReconnectorID: writerReconnectorID, sessionID: sessionID, + allowedCodecs: rawtopiccommon.SupportedCodecs{}, + lastSelectedCodec: 0, + batchCounter: 0, } res.ResetAllowedCodecs(allowedCodecs) diff --git a/internal/topic/topicwriterinternal/message.go b/internal/topic/topicwriterinternal/message.go index 5c618e631..24956ec5e 100644 --- a/internal/topic/topicwriterinternal/message.go +++ b/internal/topic/topicwriterinternal/message.go @@ -44,11 +44,14 @@ func (p PublicFuturePartitioning) ToRaw() rawtopicwriter.Partitioning { func NewPartitioningWithMessageGroupID(id string) PublicFuturePartitioning { return PublicFuturePartitioning{ messageGroupID: id, + partitionID: 0, + hasPartitionID: false, } } func NewPartitioningWithPartitionID(id int64) PublicFuturePartitioning { return PublicFuturePartitioning{ + messageGroupID: "", partitionID: id, hasPartitionID: true, } @@ -219,7 +222,15 @@ func newMessageDataWithContent( encoders *EncoderMap, ) messageWithDataContent { return messageWithDataContent{ - PublicMessage: message, - encoders: encoders, + PublicMessage: message, + encoders: encoders, + dataWasRead: false, + hasRawContent: false, + hasEncodedContent: false, + metadataCached: false, + bufCodec: 0, + bufEncoded: bytes.Buffer{}, + rawBuf: bytes.Buffer{}, + BufUncompressedSize: 0, } } diff --git a/internal/topic/topicwriterinternal/queue.go b/internal/topic/topicwriterinternal/queue.go index 25ff072d3..16c1243f2 100644 --- a/internal/topic/topicwriterinternal/queue.go +++ b/internal/topic/topicwriterinternal/queue.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "sort" + "sync" "github.com/ydb-platform/ydb-go-sdk/v3/internal/empty" "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic/rawtopicwriter" @@ -48,11 +49,18 @@ type messageQueue struct { func newMessageQueue() messageQueue { return messageQueue{ - messagesByOrder: make(map[int]messageWithDataContent), - seqNoToOrderID: make(map[int64]int), - hasNewMessages: make(empty.Chan, 1), - closedChan: make(empty.Chan), - lastSeqNo: -1, + messagesByOrder: make(map[int]messageWithDataContent), + seqNoToOrderID: make(map[int64]int), + hasNewMessages: make(empty.Chan, 1), + closedChan: make(empty.Chan), + lastSeqNo: -1, + OnAckReceived: nil, + closedErr: nil, + acksReceivedEvent: xsync.EventBroadcast{}, + m: xsync.RWMutex{RWMutex: sync.RWMutex{}}, + closed: false, + lastWrittenIndex: 0, + lastSentIndex: 0, } } diff --git a/internal/topic/topicwriterinternal/writer_reconnector.go b/internal/topic/topicwriterinternal/writer_reconnector.go index 93f1ccaf4..beac7fa90 100644 --- a/internal/topic/topicwriterinternal/writer_reconnector.go +++ b/internal/topic/topicwriterinternal/writer_reconnector.go @@ -8,6 +8,7 @@ import ( "math" "math/big" "runtime" + "sync" "sync/atomic" "time" @@ -80,7 +81,16 @@ func newWriterReconnectorConfig(options ...PublicWriterOption) WriterReconnector credUpdateInterval: time.Hour, clock: clockwork.NewRealClock(), compressorCount: runtime.NumCPU(), - tracer: &trace.Topic{}, + tracer: new(trace.Topic), + producerID: "", + topic: "", + writerMeta: nil, + defaultPartitioning: rawtopicwriter.Partitioning{ + Type: rawtopicwriter.PartitioningUndefined, + MessageGroupID: "", + PartitionID: 0, + }, + forceCodec: rawtopiccommon.CodecUNSPECIFIED, }, AutoSetSeqNo: true, AutoSetCreatedTime: true, @@ -88,7 +98,14 @@ func newWriterReconnectorConfig(options ...PublicWriterOption) WriterReconnector MaxQueueLen: 1000, RetrySettings: topic.RetrySettings{ StartTimeout: topic.DefaultStartTimeout, + CheckError: nil, }, + Common: config.Common{}, + AdditionalEncoders: nil, + Connect: nil, + WaitServerAck: false, + OnWriterInitResponseCallback: nil, + connectTimeout: time.Duration(0), } if cfg.compressorCount == 0 { cfg.compressorCount = 1 @@ -155,6 +172,13 @@ func newWriterReconnectorStopped( encodersMap: NewEncoderMap(), writerInstanceID: writerInstanceID.String(), retrySettings: cfg.RetrySettings, + background: background.Worker{}, + sessionID: "", + initDoneCh: nil, + initInfo: InitialInfo{LastSeqNum: 0}, + m: xsync.RWMutex{RWMutex: sync.RWMutex{}}, + firstConnectionHandled: atomic.Bool{}, + initDone: false, } res.queue.OnAckReceived = res.onAckReceived @@ -538,6 +562,7 @@ func (w *WriterReconnector) onWriterInitCallbackHandler(writerStream *SingleStre SessionID: w.sessionID, PartitionID: writerStream.PartitionID, CodecsFromServer: createPublicCodecsFromRaw(writerStream.CodecsFromServer), + AllowedCodecs: nil, } if err := w.cfg.OnWriterInitResponseCallback(info); err != nil { diff --git a/internal/topic/topicwriterinternal/writer_single_stream.go b/internal/topic/topicwriterinternal/writer_single_stream.go index 4f01c56d1..9b7e807b7 100644 --- a/internal/topic/topicwriterinternal/writer_single_stream.go +++ b/internal/topic/topicwriterinternal/writer_single_stream.go @@ -85,6 +85,25 @@ func newSingleStreamWriterStopped( cfg: cfg, background: *background.NewWorker(xcontext.ValueOnly(ctxForPProfLabelsOnly)), closeCompleted: make(empty.Chan), + Encoder: EncoderSelector{ + m: nil, + tracer: nil, + writerReconnectorID: "", + sessionID: "", + allowedCodecs: rawtopiccommon.SupportedCodecs{}, + lastSelectedCodec: 0, + parallelCompressors: 0, + batchCounter: 0, + measureIntervalBatches: 0, + }, + CodecsFromServer: rawtopiccommon.SupportedCodecs{}, + allowedCodecs: rawtopiccommon.SupportedCodecs{}, + SessionID: "", + closeReason: nil, + ReceivedLastSeqNum: 0, + PartitionID: 0, + closed: atomic.Bool{}, + LastSeqNumRequested: false, } } @@ -279,7 +298,7 @@ func (w *SingleStreamWriter) sendUpdateToken(ctx context.Context) (err error) { return nil } - req := &rawtopicwriter.UpdateTokenRequest{} + req := new(rawtopicwriter.UpdateTokenRequest) req.Token = token return stream.Send(req) From 9df7a9fbe60e4a3be6570fa8d13cbe0fbfc48017 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Mon, 22 Apr 2024 19:20:09 +0500 Subject: [PATCH 39/57] add explicit initialization of fields of structures in balancers/ --- balancers/balancers.go | 19 ++++++++++++++++--- balancers/config.go | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/balancers/balancers.go b/balancers/balancers.go index c73c8f503..34961dc34 100644 --- a/balancers/balancers.go +++ b/balancers/balancers.go @@ -11,16 +11,29 @@ import ( // Deprecated: RoundRobin is RandomChoice now func RoundRobin() *balancerConfig.Config { - return &balancerConfig.Config{} + return &balancerConfig.Config{ + Filter: nil, + AllowFallback: false, + SingleConn: false, + DetectLocalDC: false, + } } func RandomChoice() *balancerConfig.Config { - return &balancerConfig.Config{} + return &balancerConfig.Config{ + Filter: nil, + AllowFallback: false, + SingleConn: false, + DetectLocalDC: false, + } } func SingleConn() *balancerConfig.Config { return &balancerConfig.Config{ - SingleConn: true, + Filter: nil, + AllowFallback: false, + SingleConn: true, + DetectLocalDC: false, } } diff --git a/balancers/config.go b/balancers/config.go index 8bc38199c..a79c2cde1 100644 --- a/balancers/config.go +++ b/balancers/config.go @@ -112,6 +112,7 @@ func FromConfig(config string, opts ...fromConfigOption) *balancerConfig.Config var ( h = fromConfigOptionsHolder{ fallbackBalancer: Default(), + errorHandler: nil, } b *balancerConfig.Config err error From 64786cabf7a03305011a5743f7011ad443c4c74e Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Mon, 22 Apr 2024 19:25:50 +0500 Subject: [PATCH 40/57] add explicit initialization of fields of structures in config/ --- config/defaults.go | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/config/defaults.go b/config/defaults.go index e63867808..c0a35523b 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -12,6 +12,7 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/balancers" "github.com/ydb-platform/ydb-go-sdk/v3/credentials" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/config" "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xresolver" "github.com/ydb-platform/ydb-go-sdk/v3/trace" @@ -78,10 +79,12 @@ func certPool() *x509.CertPool { } func defaultTLSConfig() *tls.Config { - return &tls.Config{ - MinVersion: tls.VersionTLS12, - RootCAs: certPool(), - } + config := new(tls.Config) + + config.MinVersion = tls.VersionTLS12 + config.RootCAs = certPool() + + return config } func defaultConfig() (c *Config) { @@ -89,9 +92,18 @@ func defaultConfig() (c *Config) { credentials: credentials.NewAnonymousCredentials( credentials.WithSourceInfo(stack.Record(0)), ), - balancerConfig: balancers.Default(), - tlsConfig: defaultTLSConfig(), - dialTimeout: DefaultDialTimeout, - trace: &trace.Driver{}, + balancerConfig: balancers.Default(), + tlsConfig: defaultTLSConfig(), + dialTimeout: DefaultDialTimeout, + trace: new(trace.Driver), + Common: config.Common{}, + connectionTTL: time.Duration(0), + secure: false, + endpoint: "", + database: "", + metaOptions: nil, + grpcOptions: nil, + meta: nil, + excludeGRPCCodesForPessimization: nil, } } From 04e685003204647124baf56f1b414c71ad6ce218 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Tue, 23 Apr 2024 20:26:06 +0500 Subject: [PATCH 41/57] add explicit initialization of fields of structures in log/ --- log/driver.go | 5 +++++ log/field.go | 18 ++++++++++++++++++ log/logger.go | 4 +++- log/query.go | 1 + 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/log/driver.go b/log/driver.go index fb9c8b1a1..d9b882dbf 100644 --- a/log/driver.go +++ b/log/driver.go @@ -498,5 +498,10 @@ func internalDriver(l Logger, d trace.Detailer) trace.Driver { //nolint:gocyclo } } }, + OnWith: nil, + OnPoolNew: nil, + OnPoolRelease: nil, + OnConnPark: nil, + OnBalancerClusterDiscoveryAttempt: nil, } } diff --git a/log/field.go b/log/field.go index af6f65598..245116f63 100644 --- a/log/field.go +++ b/log/field.go @@ -192,6 +192,8 @@ func String(k, v string) Field { ftype: StringType, key: k, vstr: v, + vint: 0, + vany: nil, } } @@ -201,6 +203,8 @@ func Int(k string, v int) Field { ftype: IntType, key: k, vint: int64(v), + vstr: "", + vany: nil, } } @@ -209,6 +213,8 @@ func Int64(k string, v int64) Field { ftype: Int64Type, key: k, vint: v, + vstr: "", + vany: nil, } } @@ -225,6 +231,8 @@ func Bool(key string, value bool) Field { ftype: BoolType, key: key, vint: vint, + vstr: "", + vany: nil, } } @@ -234,6 +242,8 @@ func Duration(key string, value time.Duration) Field { ftype: DurationType, key: key, vint: value.Nanoseconds(), + vstr: "", + vany: nil, } } @@ -243,6 +253,8 @@ func Strings(key string, value []string) Field { ftype: StringsType, key: key, vany: value, + vint: 0, + vstr: "", } } @@ -252,6 +264,8 @@ func NamedError(key string, value error) Field { ftype: ErrorType, key: key, vany: value, + vint: 0, + vstr: "", } } @@ -266,6 +280,8 @@ func Any(key string, value interface{}) Field { ftype: AnyType, key: key, vany: value, + vint: 0, + vstr: "", } } @@ -280,6 +296,8 @@ func Stringer(key string, value fmt.Stringer) Field { ftype: StringerType, key: key, vany: value, + vint: 0, + vstr: "", } } diff --git a/log/logger.go b/log/logger.go index 8caf7229a..84ccf6f86 100644 --- a/log/logger.go +++ b/log/logger.go @@ -29,6 +29,7 @@ type simpleLoggerOption interface { func Default(w io.Writer, opts ...simpleLoggerOption) *defaultLogger { l := &defaultLogger{ coloring: false, + logQuery: false, minLevel: INFO, clock: clockwork.NewRealClock(), w: w, @@ -104,7 +105,8 @@ type wrapper struct { func wrapLogger(l Logger, opts ...Option) *wrapper { ll := &wrapper{ - logger: l, + logQuery: false, + logger: l, } for _, opt := range opts { if opt != nil { diff --git a/log/query.go b/log/query.go index e44e9e3ac..f964c9301 100644 --- a/log/query.go +++ b/log/query.go @@ -649,5 +649,6 @@ func internalQuery( } } }, + OnPoolChange: nil, } } From d87408ac4b72b030f4eb06d8e11b274b49129817 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Tue, 23 Apr 2024 20:34:22 +0500 Subject: [PATCH 42/57] add explicit initialization of fields of structures in retry/ --- retry/retry.go | 20 ++++++++++++-------- retry/sql.go | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/retry/retry.go b/retry/retry.go index 16b1050bf..a2e3a189e 100644 --- a/retry/retry.go +++ b/retry/retry.go @@ -101,7 +101,7 @@ func WithStackTrace() stackTraceOption { return stackTraceOption{} } -var _ Option = traceOption{} +var _ Option = traceOption{t: nil} type traceOption struct { t *trace.Retry @@ -145,7 +145,7 @@ func WithIdempotent(idempotent bool) idempotentOption { return idempotentOption(idempotent) } -var _ Option = fastBackoffOption{} +var _ Option = fastBackoffOption{backoff: nil} type fastBackoffOption struct { backoff backoff.Backoff @@ -170,7 +170,7 @@ func WithFastBackoff(b backoff.Backoff) fastBackoffOption { return fastBackoffOption{backoff: b} } -var _ Option = slowBackoffOption{} +var _ Option = slowBackoffOption{backoff: nil} type slowBackoffOption struct { backoff backoff.Backoff @@ -195,7 +195,7 @@ func WithSlowBackoff(b backoff.Backoff) slowBackoffOption { return slowBackoffOption{backoff: b} } -var _ Option = panicCallbackOption{} +var _ Option = panicCallbackOption{callback: nil} type panicCallbackOption struct { callback func(e interface{}) @@ -232,10 +232,14 @@ func WithPanicCallback(panicCallback func(e interface{})) panicCallbackOption { // If you need to retry your op func on some logic errors - you must return RetryableError() from retryOperation func Retry(ctx context.Context, op retryOperation, opts ...Option) (finalErr error) { options := &retryOptions{ - call: stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/retry.Retry"), - trace: &trace.Retry{}, - fastBackoff: backoff.Fast, - slowBackoff: backoff.Slow, + call: stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/retry.Retry"), + trace: new(trace.Retry), + fastBackoff: backoff.Fast, + slowBackoff: backoff.Slow, + label: "", + idempotent: false, + stackTrace: false, + panicCallback: nil, } for _, opt := range opts { if opt != nil { diff --git a/retry/sql.go b/retry/sql.go index affde98e2..fb4ae096d 100644 --- a/retry/sql.go +++ b/retry/sql.go @@ -107,7 +107,7 @@ func WithDoTxRetryOptions(opts ...Option) doTxRetryOptionsOption { return opts } -var _ doTxOption = txOptionsOption{} +var _ doTxOption = txOptionsOption{txOptions: nil} type txOptionsOption struct { txOptions *sql.TxOptions From 6187a25180feb990b0d00cd6f966f74dc3a6323b Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Tue, 23 Apr 2024 20:42:37 +0500 Subject: [PATCH 43/57] add explicit initialization of fields of structures in scheme/ --- scheme/scheme.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scheme/scheme.go b/scheme/scheme.go index 1aeac9777..cd335c66c 100644 --- a/scheme/scheme.go +++ b/scheme/scheme.go @@ -171,7 +171,13 @@ func (p Permissions) To(y *Ydb_Scheme.Permissions) { } func InnerConvertEntry(y *Ydb_Scheme.Entry) *Entry { - res := &Entry{} + res := &Entry{ + Name: "", + Owner: "", + Type: EntryTypeUnknown, + Permissions: nil, + EffectivePermissions: nil, + } res.From(y) return res From b6ad7b89b1ef7b8bf4e9874a032cf9a10dd33800 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Tue, 23 Apr 2024 20:51:07 +0500 Subject: [PATCH 44/57] add explicit initialization of fields of structures in sugar/ --- sugar/dsn.go | 15 +++++++++++---- sugar/result.go | 4 +++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/sugar/dsn.go b/sugar/dsn.go index b94e5fc57..fd3c0219a 100644 --- a/sugar/dsn.go +++ b/sugar/dsn.go @@ -13,10 +13,17 @@ func DSN(endpoint, database string, secure bool) (s string) { qp := url.Values{} dsn := url.URL{ - Scheme: "grpc", - Host: endpoint, - Path: database, - RawQuery: qp.Encode(), + Scheme: "grpc", + Host: endpoint, + Path: database, + RawQuery: qp.Encode(), + Opaque: "", + User: nil, + RawPath: "", + OmitHost: false, + ForceQuery: false, + Fragment: "", + RawFragment: "", } if secure { diff --git a/sugar/result.go b/sugar/result.go index 33c2339d9..a0dd225df 100644 --- a/sugar/result.go +++ b/sugar/result.go @@ -78,6 +78,8 @@ func (r *result) Close() error { // Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. func Result(r query.Result) *result { return &result{ - r: r, + r: r, + rs: nil, + row: nil, } } From 137ff0ea4f9367d802d9cc54ce5d0e0dff18d89f Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Wed, 24 Apr 2024 14:03:56 +0500 Subject: [PATCH 45/57] add explicit initialization of fields of structures in table/ --- table/options/models.go | 8 +++++++- table/options/options.go | 37 +++++++++++++++++++++++-------------- table/table.go | 4 ++-- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/table/options/models.go b/table/options/models.go index 4692d9d4a..7881a60b7 100644 --- a/table/options/models.go +++ b/table/options/models.go @@ -258,6 +258,7 @@ func (ps PartitioningSettings) toYDB() *Ydb_Table.PartitioningSettings { PartitioningByLoad: ps.PartitioningByLoad.ToYDB(), MinPartitionsCount: ps.MinPartitionsCount, MaxPartitionsCount: ps.MaxPartitionsCount, + PartitionBy: nil, } } @@ -449,7 +450,10 @@ const ( func NewTTLSettings() TimeToLiveSettings { return TimeToLiveSettings{ - Mode: TimeToLiveModeDateType, + Mode: TimeToLiveModeDateType, + ColumnName: "", + ExpireAfterSeconds: 0, + ColumnUnit: nil, } } @@ -516,6 +520,7 @@ func (ttl *TimeToLiveSettings) ToYDB() *Ydb_Table.TtlSettings { ExpireAfterSeconds: ttl.ExpireAfterSeconds, }, }, + RunIntervalSeconds: 0, } default: // currently use TimeToLiveModeDateType mode as default return &Ydb_Table.TtlSettings{ @@ -525,6 +530,7 @@ func (ttl *TimeToLiveSettings) ToYDB() *Ydb_Table.TtlSettings { ExpireAfterSeconds: ttl.ExpireAfterSeconds, }, }, + RunIntervalSeconds: 0, } } } diff --git a/table/options/options.go b/table/options/options.go index db85556a7..c417d8339 100644 --- a/table/options/options.go +++ b/table/options/options.go @@ -58,15 +58,17 @@ type column struct { func (c column) ApplyAlterTableOption(d *AlterTableDesc, a *allocator.Allocator) { d.AddColumns = append(d.AddColumns, &Ydb_Table.ColumnMeta{ - Name: c.name, - Type: types.TypeToYDB(c.typ, a), + Name: c.name, + Type: types.TypeToYDB(c.typ, a), + Family: "", }) } func (c column) ApplyCreateTableOption(d *CreateTableDesc, a *allocator.Allocator) { d.Columns = append(d.Columns, &Ydb_Table.ColumnMeta{ - Name: c.name, - Type: types.TypeToYDB(c.typ, a), + Name: c.name, + Type: types.TypeToYDB(c.typ, a), + Family: "", }) } @@ -158,7 +160,10 @@ type index struct { func (i index) ApplyAlterTableOption(d *AlterTableDesc, a *allocator.Allocator) { x := &Ydb_Table.TableIndex{ - Name: i.name, + Name: i.name, + IndexColumns: nil, + Type: nil, + DataColumns: nil, } for _, opt := range i.opts { if opt != nil { @@ -170,7 +175,10 @@ func (i index) ApplyAlterTableOption(d *AlterTableDesc, a *allocator.Allocator) func (i index) ApplyCreateTableOption(d *CreateTableDesc, a *allocator.Allocator) { x := &Ydb_Table.TableIndex{ - Name: i.name, + Name: i.name, + IndexColumns: nil, + Type: nil, + DataColumns: nil, } for _, opt := range i.opts { if opt != nil { @@ -595,7 +603,7 @@ func WithPartitioningSettingsObject(ps PartitioningSettings) CreateTableOption { type partitioningSettings []PartitioningSettingsOption func (opts partitioningSettings) ApplyCreateTableOption(d *CreateTableDesc, a *allocator.Allocator) { - settings := &ydbPartitioningSettings{} + settings := new(ydbPartitioningSettings) for _, opt := range opts { if opt != nil { opt.ApplyPartitioningSettingsOption(settings) @@ -728,7 +736,8 @@ func WithAddAttribute(key, value string) AlterTableOption { // WithDropAttribute drops attribute from table in AlterTable request func WithDropAttribute(key string) AlterTableOption { return attribute{ - key: key, + key: key, + value: "", } } @@ -778,7 +787,7 @@ func WithSetTimeToLiveSettings(settings TimeToLiveSettings) AlterTableOption { type dropTimeToLive struct{} func (dropTimeToLive) ApplyAlterTableOption(d *AlterTableDesc, a *allocator.Allocator) { - d.TtlAction = &Ydb_Table.AlterTableRequest_DropTtlSettings{} + d.TtlAction = &Ydb_Table.AlterTableRequest_DropTtlSettings{DropTtlSettings: nil} } // WithDropTimeToLive drops TTL settings in AlterTable request @@ -1017,11 +1026,11 @@ func WithExecuteScanQueryStats(stats ExecuteScanQueryStatsType) ExecuteScanQuery var ( _ ReadRowsOption = readColumnsOption{} _ ReadTableOption = readOrderedOption{} - _ ReadTableOption = readKeyRangeOption{} - _ ReadTableOption = readGreaterOrEqualOption{} - _ ReadTableOption = readLessOrEqualOption{} - _ ReadTableOption = readLessOption{} - _ ReadTableOption = readGreaterOption{} + _ ReadTableOption = readKeyRangeOption{From: nil, To: nil} + _ ReadTableOption = readGreaterOrEqualOption{Value: nil} + _ ReadTableOption = readLessOrEqualOption{Value: nil} + _ ReadTableOption = readLessOption{Value: nil} + _ ReadTableOption = readGreaterOption{Value: nil} _ ReadTableOption = readRowLimitOption(0) ) diff --git a/table/table.go b/table/table.go index 6d2305a1e..cba38cd5b 100644 --- a/table/table.go +++ b/table/table.go @@ -531,7 +531,7 @@ func WithIdempotent() idempotentOption { return idempotentOption{} } -var _ Option = txSettingsOption{} +var _ Option = txSettingsOption{txSettings: nil} type txSettingsOption struct { txSettings *TransactionSettings @@ -557,7 +557,7 @@ func WithTxCommitOptions(opts ...options.CommitTransactionOption) txCommitOption return opts } -var _ Option = traceOption{} +var _ Option = traceOption{t: nil} type traceOption struct { t *trace.Table From afc8ce6b9346b541534455d07ebb01a11390564f Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Wed, 24 Apr 2024 14:15:40 +0500 Subject: [PATCH 46/57] add explicit initialization of fields of structures in testutil/ --- testutil/driver.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/testutil/driver.go b/testutil/driver.go index 48b82d4ca..a14c1151b 100644 --- a/testutil/driver.go +++ b/testutil/driver.go @@ -6,6 +6,7 @@ import ( "reflect" "strings" + "github.com/ydb-platform/ydb-go-genproto/protos/Ydb" "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Operations" "google.golang.org/grpc" "google.golang.org/grpc/metadata" @@ -173,6 +174,7 @@ func (b *balancerStub) Get(context.Context) (conn grpc.ClientConnInterface, err cc := &clientConn{ onInvoke: b.onInvoke, onNewStream: b.onNewStream, + onAddress: nil, } return cc, nil @@ -217,7 +219,13 @@ func WithInvokeHandlers(invokeHandlers InvokeHandlers) balancerOption { "Operation", reply, &Ydb_Operations.Operation{ - Result: anyResult, + Result: anyResult, + Id: "", + Ready: false, + Status: Ydb.StatusIds_STATUS_CODE_UNSPECIFIED, + Issues: nil, + Metadata: nil, + CostInfo: nil, }, ) @@ -247,7 +255,7 @@ func WithNewStreamHandlers(newStreamHandlers NewStreamHandlers) balancerOption { } func NewBalancer(opts ...balancerOption) *balancerStub { - c := &balancerStub{} + c := &balancerStub{onInvoke: nil, onNewStream: nil} for _, opt := range opts { if opt != nil { opt(c) From 0e8696d55f7c375d1efc873e2766b52635349b37 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Wed, 24 Apr 2024 14:33:19 +0500 Subject: [PATCH 47/57] add explicit initialization of fields of structures in topic/ --- topic/topicoptions/topicoptions_alter.go | 10 +++++++++- topic/topicoptions/topicoptions_reader.go | 2 +- topic/topicreader/reader.go | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/topic/topicoptions/topicoptions_alter.go b/topic/topicoptions/topicoptions_alter.go index 52700a7f4..b119319c8 100644 --- a/topic/topicoptions/topicoptions_alter.go +++ b/topic/topicoptions/topicoptions_alter.go @@ -4,7 +4,9 @@ import ( "sort" "time" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawoptional" "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic/rawtopiccommon" "github.com/ydb-platform/ydb-go-sdk/v3/topic/topictypes" ) @@ -126,7 +128,13 @@ func ensureAlterConsumer( return consumers, i } } - consumers = append(consumers, rawtopic.AlterConsumer{Name: name}) + consumers = append(consumers, rawtopic.AlterConsumer{ + Name: name, + SetImportant: rawoptional.Bool{Value: false, HasValue: false}, + SetReadFrom: rawoptional.Time{Value: time.Time{}, HasValue: false}, + SetSupportedCodecs: rawtopiccommon.SupportedCodecs{}, + AlterAttributes: nil, + }) return consumers, len(consumers) - 1 } diff --git a/topic/topicoptions/topicoptions_reader.go b/topic/topicoptions/topicoptions_reader.go index 549211688..2a7dc4cdf 100644 --- a/topic/topicoptions/topicoptions_reader.go +++ b/topic/topicoptions/topicoptions_reader.go @@ -18,7 +18,7 @@ type ReadSelectors []ReadSelector // ReadTopic create simple selector for read topics, if no need special settings. func ReadTopic(path string) ReadSelectors { - return ReadSelectors{{Path: path}} + return ReadSelectors{{Path: path, Partitions: nil, ReadFrom: time.Time{}, MaxTimeLag: time.Duration(0)}} } // ReaderOption options for topic reader diff --git a/topic/topicreader/reader.go b/topic/topicreader/reader.go index 9c50d4a51..566f5380b 100644 --- a/topic/topicreader/reader.go +++ b/topic/topicreader/reader.go @@ -28,7 +28,7 @@ type Reader struct { // NewReader // create new reader, used internally only. func NewReader(internalReader topicreaderinternal.Reader) *Reader { - return &Reader{reader: internalReader} + return &Reader{reader: internalReader, readInFlyght: atomic.Bool{}, commitInFlyght: atomic.Bool{}} } // WaitInit waits until the reader is initialized From f4da3761634964fe399dfd53f330a992cc5df15d Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Wed, 24 Apr 2024 14:37:17 +0500 Subject: [PATCH 48/57] add explicit initialization of fields of structures in trace/ --- trace/details.go | 1 + trace/traceutil.go | 1 + 2 files changed, 2 insertions(+) diff --git a/trace/details.go b/trace/details.go index 124885135..992a8661b 100644 --- a/trace/details.go +++ b/trace/details.go @@ -199,6 +199,7 @@ func MatchDetails(pattern string, opts ...matchDetailsOption) (d Details) { var ( h = &matchDetailsOptionsHolder{ defaultDetails: defaultDetails, + posixMatch: false, } re *regexp.Regexp err error diff --git a/trace/traceutil.go b/trace/traceutil.go index 8ad52bfb6..7d5e3b0ef 100644 --- a/trace/traceutil.go +++ b/trace/traceutil.go @@ -9,6 +9,7 @@ import ( func Stub(x interface{}, f func(name string, args ...interface{})) { (FieldStubber{ OnCall: f, + OnStub: nil, }).Stub(reflect.ValueOf(x)) } From 85b78ecdbb0210af1b665db085618d2867d98923 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Wed, 24 Apr 2024 14:48:16 +0500 Subject: [PATCH 49/57] fix marks from exhaustruct linter for driver.go --- driver.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/driver.go b/driver.go index 7adfab361..19388c806 100644 --- a/driver.go +++ b/driver.go @@ -108,7 +108,7 @@ func (d *Driver) trace() *trace.Driver { return d.config.Trace() } - return &trace.Driver{} + return new(trace.Driver) } // Close closes Driver and clear resources @@ -309,11 +309,10 @@ func newConnectionFromOptions(ctx context.Context, opts ...Option) (_ *Driver, e } }() - d := &Driver{ - children: make(map[uint64]*Driver), - ctx: ctx, - ctxCancel: driverCtxCancel, - } + d := new(Driver) + d.children = make(map[uint64]*Driver) + d.ctx = ctx + d.ctxCancel = driverCtxCancel if caFile, has := os.LookupEnv("YDB_SSL_ROOT_CERTIFICATES_FILE"); has { d.opts = append(d.opts, From 3282efff4cc361dc7bc9f5387b2bcca069ad2374 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Wed, 24 Apr 2024 14:54:50 +0500 Subject: [PATCH 50/57] add explicit initialization of fields of structures in sql.go --- sql.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sql.go b/sql.go index 0db01dd72..03b220972 100644 --- a/sql.go +++ b/sql.go @@ -5,6 +5,7 @@ import ( "database/sql" "database/sql/driver" "fmt" + "sync" "github.com/ydb-platform/ydb-go-sdk/v3/internal/bind" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" @@ -15,7 +16,10 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/trace" ) -var d = &sqlDriver{connectors: make(map[*xsql.Connector]*Driver)} //nolint:gochecknoglobals +var d = &sqlDriver{ + connectors: make(map[*xsql.Connector]*Driver), + connectorsMtx: xsync.RWMutex{RWMutex: sync.RWMutex{}}, +} //nolint:gochecknoglobals func init() { //nolint:gochecknoinits sql.Register("ydb", d) @@ -28,8 +32,8 @@ type sqlDriver struct { } var ( - _ driver.Driver = &sqlDriver{} - _ driver.DriverContext = &sqlDriver{} + _ driver.Driver = &sqlDriver{connectors: nil, connectorsMtx: xsync.RWMutex{RWMutex: sync.RWMutex{}}} + _ driver.DriverContext = &sqlDriver{connectors: nil, connectorsMtx: xsync.RWMutex{RWMutex: sync.RWMutex{}}} ) func (d *sqlDriver) Close() error { From 06032b3a288a51f88f27473eaa0a9071f155f48a Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Wed, 24 Apr 2024 19:45:16 +0500 Subject: [PATCH 51/57] add explicit initialization of fields of structures in examples/basic --- examples/basic/gorm/data.go | 446 ++++++++++++++++++++++++------------ examples/basic/gorm/main.go | 31 ++- examples/basic/xorm/data.go | 1 + examples/basic/xorm/main.go | 24 +- 4 files changed, 345 insertions(+), 157 deletions(-) diff --git a/examples/basic/gorm/data.go b/examples/basic/gorm/data.go index b5b72f269..905f45c73 100644 --- a/examples/basic/gorm/data.go +++ b/examples/basic/gorm/data.go @@ -4,361 +4,523 @@ import "time" var data = []Series{ { - Title: "IT Crowd", + ID: "", + Comment: "", + Title: "IT Crowd", Info: "" + "The IT Crowd is a British sitcom produced by Channel 4, written by Graham Linehan, produced by " + "Ash Atalla and starring Chris O'Dowd, Richard Ayoade, Katherine Parkinson, and Matt Berry.", ReleaseDate: date("2006-02-03"), Seasons: []Season{ { + ID: "", + SeriesID: "", Title: "Season 1", FirstAired: date("2006-02-03"), LastAired: date("2006-03-03"), Episodes: []Episode{ { - Title: "Yesterday's Jam", - AirDate: date("2006-02-03"), + ID: "", + SeasonID: "", + Title: "Yesterday's Jam", + AirDate: date("2006-02-03"), }, { - Title: "Calamity Jen", - AirDate: date("2006-02-03"), + ID: "", + SeasonID: "", + Title: "Calamity Jen", + AirDate: date("2006-02-03"), }, { - Title: "Fifty-Fifty", - AirDate: date("2006-02-10"), + ID: "", + SeasonID: "", + Title: "Fifty-Fifty", + AirDate: date("2006-02-10"), }, { - Title: "The Red Door", - AirDate: date("2006-02-17"), + ID: "", + SeasonID: "", + Title: "The Red Door", + AirDate: date("2006-02-17"), }, { - Title: "The Haunting of Bill Crouse", - AirDate: date("2006-02-24"), + ID: "", + SeasonID: "", + Title: "The Haunting of Bill Crouse", + AirDate: date("2006-02-24"), }, { - Title: "Aunt Irma Visits", - AirDate: date("2006-03-03"), + ID: "", + SeasonID: "", + Title: "Aunt Irma Visits", + AirDate: date("2006-03-03"), }, }, }, { + ID: "", + SeriesID: "", Title: "Season 2", FirstAired: date("2007-08-24"), LastAired: date("2007-09-28"), Episodes: []Episode{ { - Title: "The Work Outing", - AirDate: date("2006-08-24"), + ID: "", + SeasonID: "", + Title: "The Work Outing", + AirDate: date("2006-08-24"), }, { - Title: "Return of the Golden Child", - AirDate: date("2007-08-31"), + ID: "", + SeasonID: "", + Title: "Return of the Golden Child", + AirDate: date("2007-08-31"), }, { - Title: "Moss and the German", - AirDate: date("2007-09-07"), + ID: "", + SeasonID: "", + Title: "Moss and the German", + AirDate: date("2007-09-07"), }, { - Title: "The Dinner Party", - AirDate: date("2007-09-14"), + ID: "", + SeasonID: "", + Title: "The Dinner Party", + AirDate: date("2007-09-14"), }, { - Title: "Smoke and Mirrors", - AirDate: date("2007-09-21"), + ID: "", + SeasonID: "", + Title: "Smoke and Mirrors", + AirDate: date("2007-09-21"), }, { - Title: "Men Without Women", - AirDate: date("2007-09-28"), + ID: "", + SeasonID: "", + Title: "Men Without Women", + AirDate: date("2007-09-28"), }, }, }, { + ID: "", + SeriesID: "", Title: "Season 3", FirstAired: date("2008-11-21"), LastAired: date("2008-12-26"), Episodes: []Episode{ { - Title: "From Hell", - AirDate: date("2008-11-21"), + ID: "", + SeasonID: "", + Title: "From Hell", + AirDate: date("2008-11-21"), }, { - Title: "Are We Not Men?", - AirDate: date("2008-11-28"), + ID: "", + SeasonID: "", + Title: "Are We Not Men?", + AirDate: date("2008-11-28"), }, { - Title: "Tramps Like Us", - AirDate: date("2008-12-05"), + ID: "", + SeasonID: "", + Title: "Tramps Like Us", + AirDate: date("2008-12-05"), }, { - Title: "The Speech", - AirDate: date("2008-12-12"), + ID: "", + SeasonID: "", + Title: "The Speech", + AirDate: date("2008-12-12"), }, { - Title: "Friendface", - AirDate: date("2008-12-19"), + ID: "", + SeasonID: "", + Title: "Friendface", + AirDate: date("2008-12-19"), }, { - Title: "Calendar Geeks", - AirDate: date("2008-12-26"), + ID: "", + SeasonID: "", + Title: "Calendar Geeks", + AirDate: date("2008-12-26"), }, }, }, { + ID: "", + SeriesID: "", Title: "Season 4", FirstAired: date("2010-06-25"), LastAired: date("2010-07-30"), Episodes: []Episode{ { - Title: "Jen The Fredo", - AirDate: date("2010-06-25"), + ID: "", + SeasonID: "", + Title: "Jen The Fredo", + AirDate: date("2010-06-25"), }, { - Title: "The Final Countdown", - AirDate: date("2010-07-02"), + ID: "", + SeasonID: "", + Title: "The Final Countdown", + AirDate: date("2010-07-02"), }, { - Title: "Something Happened", - AirDate: date("2010-07-09"), + ID: "", + SeasonID: "", + Title: "Something Happened", + AirDate: date("2010-07-09"), }, { - Title: "Italian For Beginners", - AirDate: date("2010-07-16"), + ID: "", + SeasonID: "", + Title: "Italian For Beginners", + AirDate: date("2010-07-16"), }, { - Title: "Bad Boys", - AirDate: date("2010-07-23"), + ID: "", + SeasonID: "", + Title: "Bad Boys", + AirDate: date("2010-07-23"), }, { - Title: "Reynholm vs Reynholm", - AirDate: date("2010-07-30"), + ID: "", + SeasonID: "", + Title: "Reynholm vs Reynholm", + AirDate: date("2010-07-30"), }, }, }, }, }, { - Title: "Silicon Valley", + ID: "", + Comment: "", + Title: "Silicon Valley", Info: "" + "Silicon Valley is an American comedy television series created by Mike Judge, John Altschuler and " + "Dave Krinsky. The series focuses on five young men who founded a startup company in Silicon Valley.", ReleaseDate: date("2014-04-06"), Seasons: []Season{ { + ID: "", + SeriesID: "", Title: "Season 1", FirstAired: date("2006-02-03"), LastAired: date("2006-03-03"), Episodes: []Episode{ { - Title: "Minimum Viable Product", - AirDate: date("2014-04-06"), + ID: "", + SeasonID: "", + Title: "Minimum Viable Product", + AirDate: date("2014-04-06"), }, { - Title: "The Cap Table", - AirDate: date("2014-04-13"), + ID: "", + SeasonID: "", + Title: "The Cap Table", + AirDate: date("2014-04-13"), }, { - Title: "Articles of Incorporation", - AirDate: date("2014-04-20"), + ID: "", + SeasonID: "", + Title: "Articles of Incorporation", + AirDate: date("2014-04-20"), }, { - Title: "Fiduciary Duties", - AirDate: date("2014-04-27"), + ID: "", + SeasonID: "", + Title: "Fiduciary Duties", + AirDate: date("2014-04-27"), }, { - Title: "Signaling Risk", - AirDate: date("2014-05-04"), + ID: "", + SeasonID: "", + Title: "Signaling Risk", + AirDate: date("2014-05-04"), }, { - Title: "Third Party Insourcing", - AirDate: date("2014-05-11"), + ID: "", + SeasonID: "", + Title: "Third Party Insourcing", + AirDate: date("2014-05-11"), }, { - Title: "Proof of Concept", - AirDate: date("2014-05-18"), + ID: "", + SeasonID: "", + Title: "Proof of Concept", + AirDate: date("2014-05-18"), }, { - Title: "Optimal Tip-to-Tip Efficiency", - AirDate: date("2014-06-01"), + ID: "", + SeasonID: "", + Title: "Optimal Tip-to-Tip Efficiency", + AirDate: date("2014-06-01"), }, }, }, { + ID: "", + SeriesID: "", Title: "Season 2", FirstAired: date("2007-08-24"), LastAired: date("2007-09-28"), Episodes: []Episode{ { - Title: "Sand Hill Shuffle", - AirDate: date("2015-04-12"), + ID: "", + SeasonID: "", + Title: "Sand Hill Shuffle", + AirDate: date("2015-04-12"), }, { - Title: "Runaway Devaluation", - AirDate: date("2015-04-19"), + ID: "", + SeasonID: "", + Title: "Runaway Devaluation", + AirDate: date("2015-04-19"), }, { - Title: "Bad Money", - AirDate: date("2015-04-26"), + ID: "", + SeasonID: "", + Title: "Bad Money", + AirDate: date("2015-04-26"), }, { - Title: "The Lady", - AirDate: date("2015-05-03"), + ID: "", + SeasonID: "", + Title: "The Lady", + AirDate: date("2015-05-03"), }, { - Title: "Server Space", - AirDate: date("2015-05-10"), + ID: "", + SeasonID: "", + Title: "Server Space", + AirDate: date("2015-05-10"), }, { - Title: "Homicide", - AirDate: date("2015-05-17"), + ID: "", + SeasonID: "", + Title: "Homicide", + AirDate: date("2015-05-17"), }, { - Title: "Adult Content", - AirDate: date("2015-05-24"), + ID: "", + SeasonID: "", + Title: "Adult Content", + AirDate: date("2015-05-24"), }, { - Title: "White Hat/Black Hat", - AirDate: date("2015-05-31"), + ID: "", + SeasonID: "", + Title: "White Hat/Black Hat", + AirDate: date("2015-05-31"), }, { - Title: "Binding Arbitration", - AirDate: date("2015-06-07"), + ID: "", + SeasonID: "", + Title: "Binding Arbitration", + AirDate: date("2015-06-07"), }, { - Title: "Two Days of the Condor", - AirDate: date("2015-06-14"), + ID: "", + SeasonID: "", + Title: "Two Days of the Condor", + AirDate: date("2015-06-14"), }, }, }, { + ID: "", + SeriesID: "", Title: "Season 3", FirstAired: date("2008-11-21"), LastAired: date("2008-12-26"), Episodes: []Episode{ { - Title: "Founder Friendly", - AirDate: date("2016-04-24"), + ID: "", + SeasonID: "", + Title: "Founder Friendly", + AirDate: date("2016-04-24"), }, { - Title: "Two in the Box", - AirDate: date("2016-05-01"), + ID: "", + SeasonID: "", + Title: "Two in the Box", + AirDate: date("2016-05-01"), }, { - Title: "Meinertzhagen's Haversack", - AirDate: date("2016-05-08"), + ID: "", + SeasonID: "", + Title: "Meinertzhagen's Haversack", + AirDate: date("2016-05-08"), }, { - Title: "Maleant Data Systems Solutions", - AirDate: date("2016-05-15"), + ID: "", + SeasonID: "", + Title: "Maleant Data Systems Solutions", + AirDate: date("2016-05-15"), }, { - Title: "The Empty Chair", - AirDate: date("2016-05-22"), + ID: "", + SeasonID: "", + Title: "The Empty Chair", + AirDate: date("2016-05-22"), }, { - Title: "Bachmanity Insanity", - AirDate: date("2016-05-29"), + ID: "", + SeasonID: "", + Title: "Bachmanity Insanity", + AirDate: date("2016-05-29"), }, { - Title: "To Build a Better Beta", - AirDate: date("2016-06-05"), + ID: "", + SeasonID: "", + Title: "To Build a Better Beta", + AirDate: date("2016-06-05"), }, { - Title: "Bachman's Earnings Over-Ride", - AirDate: date("2016-06-12"), + ID: "", + SeasonID: "", + Title: "Bachman's Earnings Over-Ride", + AirDate: date("2016-06-12"), }, { - Title: "Daily Active Users", - AirDate: date("2016-06-19"), + ID: "", + SeasonID: "", + Title: "Daily Active Users", + AirDate: date("2016-06-19"), }, { - Title: "The Uptick", - AirDate: date("2016-06-26"), + ID: "", + SeasonID: "", + Title: "The Uptick", + AirDate: date("2016-06-26"), }, }, }, { + ID: "", + SeriesID: "", Title: "Season 4", FirstAired: date("2010-06-25"), LastAired: date("2010-07-30"), Episodes: []Episode{ { - Title: "Success Failure", - AirDate: date("2017-04-23"), + ID: "", + SeasonID: "", + Title: "Success Failure", + AirDate: date("2017-04-23"), }, { - Title: "Terms of Service", - AirDate: date("2017-04-30"), + ID: "", + SeasonID: "", + Title: "Terms of Service", + AirDate: date("2017-04-30"), }, { - Title: "Intellectual Property", - AirDate: date("2017-05-07"), + ID: "", + SeasonID: "", + Title: "Intellectual Property", + AirDate: date("2017-05-07"), }, { - Title: "Teambuilding Exercise", - AirDate: date("2017-05-14"), + ID: "", + SeasonID: "", + Title: "Teambuilding Exercise", + AirDate: date("2017-05-14"), }, { - Title: "The Blood Boy", - AirDate: date("2017-05-21"), + ID: "", + SeasonID: "", + Title: "The Blood Boy", + AirDate: date("2017-05-21"), }, { - Title: "Customer Service", - AirDate: date("2017-05-28"), + ID: "", + SeasonID: "", + Title: "Customer Service", + AirDate: date("2017-05-28"), }, { - Title: "The Patent Troll", - AirDate: date("2017-06-04"), + ID: "", + SeasonID: "", + Title: "The Patent Troll", + AirDate: date("2017-06-04"), }, { - Title: "The Keenan Vortex", - AirDate: date("2017-06-11"), + ID: "", + SeasonID: "", + Title: "The Keenan Vortex", + AirDate: date("2017-06-11"), }, { - Title: "Hooli-Con", - AirDate: date("2017-06-18"), + ID: "", + SeasonID: "", + Title: "Hooli-Con", + AirDate: date("2017-06-18"), }, { - Title: "Server Error", - AirDate: date("2017-06-25"), + ID: "", + SeasonID: "", + Title: "Server Error", + AirDate: date("2017-06-25"), }, }, }, { + ID: "", + SeriesID: "", Title: "Season 5", FirstAired: date("2018-03-25"), LastAired: date("2018-05-13"), Episodes: []Episode{ { - Title: "Grow Fast or Die Slow", - AirDate: date("2018-03-25"), + ID: "", + SeasonID: "", + Title: "Grow Fast or Die Slow", + AirDate: date("2018-03-25"), }, { - Title: "Reorientation", - AirDate: date("2018-04-01"), + ID: "", + SeasonID: "", + Title: "Reorientation", + AirDate: date("2018-04-01"), }, { - Title: "Chief Operating Officer", - AirDate: date("2018-04-08"), + ID: "", + SeasonID: "", + Title: "Chief Operating Officer", + AirDate: date("2018-04-08"), }, { - Title: "Tech Evangelist", - AirDate: date("2018-04-15"), + ID: "", + SeasonID: "", + Title: "Tech Evangelist", + AirDate: date("2018-04-15"), }, { - Title: "Facial Recognition", - AirDate: date("2018-04-22"), + ID: "", + SeasonID: "", + Title: "Facial Recognition", + AirDate: date("2018-04-22"), }, { - Title: "Artificial Emotional Intelligence", - AirDate: date("2018-04-29"), + ID: "", + SeasonID: "", + Title: "Artificial Emotional Intelligence", + AirDate: date("2018-04-29"), }, { - Title: "Initial Coin Offering", - AirDate: date("2018-05-06"), + ID: "", + SeasonID: "", + Title: "Initial Coin Offering", + AirDate: date("2018-05-06"), }, { - Title: "Fifty-One Percent", - AirDate: date("2018-05-13"), + ID: "", + SeasonID: "", + Title: "Fifty-One Percent", + AirDate: date("2018-05-13"), }, }, }, diff --git a/examples/basic/gorm/main.go b/examples/basic/gorm/main.go index 725032216..48aabcadb 100644 --- a/examples/basic/gorm/main.go +++ b/examples/basic/gorm/main.go @@ -26,9 +26,8 @@ func main() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() - cfg := &gorm.Config{ - Logger: logger.Default.LogMode(logger.Error), - } + cfg := new(gorm.Config) + cfg.Logger = logger.Default.LogMode(logger.Error) // connect var db *gorm.DB @@ -79,17 +78,17 @@ func main() { func prepareScheme(db *gorm.DB) error { if err := db.Migrator().DropTable( - &Series{}, - &Season{}, - &Episode{}, + &Series{ID: "", Title: "", Info: "", Comment: "", ReleaseDate: time.Time{}, Seasons: nil}, + &Season{ID: "", SeriesID: "", Title: "", FirstAired: time.Time{}, LastAired: time.Time{}, Episodes: nil}, + &Episode{ID: "", SeasonID: "", Title: "", AirDate: time.Time{}}, ); err != nil { return err } return db.AutoMigrate( - &Series{}, - &Season{}, - &Episode{}, + &Series{ID: "", Title: "", Info: "", Comment: "", ReleaseDate: time.Time{}, Seasons: nil}, + &Season{ID: "", SeriesID: "", Title: "", FirstAired: time.Time{}, LastAired: time.Time{}, Episodes: nil}, + &Episode{ID: "", SeasonID: "", Title: "", AirDate: time.Time{}}, ) } @@ -139,13 +138,23 @@ func findEpisodesByTitle(db *gorm.DB, fragment string) error { log.Println("all episodes with title with word 'bad':") for i := range episodes { ss := Season{ - ID: episodes[i].SeasonID, + ID: episodes[i].SeasonID, + SeriesID: "", + Title: "", + FirstAired: time.Time{}, + LastAired: time.Time{}, + Episodes: nil, } if err := db.Take(&ss).Error; err != nil { return err } s := Series{ - ID: ss.SeriesID, + ID: ss.SeriesID, + Title: "", + Info: "", + Comment: "", + ReleaseDate: time.Time{}, + Seasons: nil, } if err := db.Take(&s).Error; err != nil { return err diff --git a/examples/basic/xorm/data.go b/examples/basic/xorm/data.go index c6cfbb3fe..a343db4ee 100644 --- a/examples/basic/xorm/data.go +++ b/examples/basic/xorm/data.go @@ -32,6 +32,7 @@ func episodeData(seasonID, episodeID, title string, date time.Time) *Episodes { SeasonID: seasonID, Title: title, AirDate: date, + Views: 0, } } diff --git a/examples/basic/xorm/main.go b/examples/basic/xorm/main.go index 8a0961af5..fef70bf5b 100644 --- a/examples/basic/xorm/main.go +++ b/examples/basic/xorm/main.go @@ -70,12 +70,20 @@ func main() { } func prepareScheme(db *xorm.Engine) error { - err := db.DropTables(&Series{}, &Seasons{}, &Episodes{}) + err := db.DropTables( + &Series{ID: "", Title: "", Info: "", Comment: "", ReleaseDate: time.Time{}}, + &Seasons{ID: "", SeriesID: "", Title: "", FirstAired: time.Time{}, LastAired: time.Time{}}, + &Episodes{ID: "", SeasonID: "", Title: "", AirDate: time.Time{}, Views: 0}, + ) if err != nil { return err } - err = db.CreateTables(&Series{}, &Seasons{}, &Episodes{}) + err = db.CreateTables( + &Series{ID: "", Title: "", Info: "", Comment: "", ReleaseDate: time.Time{}}, + &Seasons{ID: "", SeriesID: "", Title: "", FirstAired: time.Time{}, LastAired: time.Time{}}, + &Episodes{ID: "", SeasonID: "", Title: "", AirDate: time.Time{}, Views: 0}, + ) return err } @@ -154,14 +162,22 @@ func findEpisodesByTitle(db *xorm.Engine, fragment string) error { log.Println("all episodes with title with word 'bad':") for _, e := range episodes { ss := Seasons{ - ID: e.SeasonID, + ID: e.SeasonID, + SeriesID: "", + Title: "", + FirstAired: time.Time{}, + LastAired: time.Time{}, } if _, err := session.Get(&ss); err != nil { return err } s := Series{ - ID: ss.SeriesID, + ID: ss.SeriesID, + Title: "", + Info: "", + Comment: "", + ReleaseDate: time.Time{}, } if _, err := session.Get(&s); err != nil { return err From 2cf5b70530d88902e673f2716aab67f147b1af8e Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Wed, 24 Apr 2024 19:48:47 +0500 Subject: [PATCH 52/57] add explicit initialization of fields of structures in examples/read_table --- examples/read_table/orders.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/read_table/orders.go b/examples/read_table/orders.go index c9e007193..a61205aa4 100644 --- a/examples/read_table/orders.go +++ b/examples/read_table/orders.go @@ -148,7 +148,7 @@ func readTable(ctx context.Context, c table.Client, path string, opts ...options defer func() { _ = res.Close() }() - r := row{} + r := row{id: 0, orderID: 0, date: time.Time{}, description: ""} for res.NextResultSet(ctx) { for res.NextRow() { if res.CurrentResultSet().ColumnCount() == 4 { From 90ca7de90997ed12090e347bfff48dabfa9ef610 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Wed, 24 Apr 2024 20:11:31 +0500 Subject: [PATCH 53/57] add explicit initialization of fields of structures in examples/serverless --- examples/serverless/healthcheck/main.go | 2 +- examples/serverless/healthcheck/service.go | 15 ++++++---- examples/serverless/url_shortener/main.go | 16 +++++++++-- examples/serverless/url_shortener/service.go | 29 +++++++++++++++----- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/examples/serverless/healthcheck/main.go b/examples/serverless/healthcheck/main.go index 5e828aa31..ca28d6d2b 100644 --- a/examples/serverless/healthcheck/main.go +++ b/examples/serverless/healthcheck/main.go @@ -16,7 +16,7 @@ var ( prefix string count int interval time.Duration - urls = URLs{} + urls = URLs{urls: nil} ) // URLs is a flag.Value implementation which holds URL's as string slice diff --git a/examples/serverless/healthcheck/service.go b/examples/serverless/healthcheck/service.go index 7e5ecb486..f8b5812cf 100644 --- a/examples/serverless/healthcheck/service.go +++ b/examples/serverless/healthcheck/service.go @@ -29,14 +29,17 @@ var once sync.Once func getService(ctx context.Context, dsn string, opts ...ydb.Option) (s *service, err error) { once.Do(func() { + transport := new(http.Transport) + transport.TLSClientConfig = new(tls.Config) + transport.TLSClientConfig.InsecureSkipVerify = true + s = &service{ + db: nil, client: &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: &tls.Config{ - InsecureSkipVerify: true, //nolint:gosec - }, - }, - Timeout: time.Second * 10, + Transport: transport, + CheckRedirect: nil, + Jar: nil, + Timeout: time.Second * 10, }, } s.db, err = ydb.Open(ctx, dsn, opts...) diff --git a/examples/serverless/url_shortener/main.go b/examples/serverless/url_shortener/main.go index 7e8ad0919..467f287f6 100644 --- a/examples/serverless/url_shortener/main.go +++ b/examples/serverless/url_shortener/main.go @@ -99,8 +99,20 @@ func main() { defer s.Close(ctx) server := &http.Server{ //nolint:gosec - Addr: ":" + strconv.Itoa(port), - Handler: s.router, + Addr: ":" + strconv.Itoa(port), + Handler: s.router, + DisableGeneralOptionsHandler: false, + TLSConfig: nil, + ReadTimeout: time.Duration(0), + ReadHeaderTimeout: time.Duration(0), + WriteTimeout: time.Duration(0), + IdleTimeout: time.Duration(0), + MaxHeaderBytes: 0, + TLSNextProto: nil, + ConnState: nil, + ErrorLog: nil, + BaseContext: nil, + ConnContext: nil, } defer func() { _ = server.Shutdown(ctx) diff --git a/examples/serverless/url_shortener/service.go b/examples/serverless/url_shortener/service.go index 041c55d9d..5aa0745e7 100644 --- a/examples/serverless/url_shortener/service.go +++ b/examples/serverless/url_shortener/service.go @@ -88,9 +88,11 @@ func getService(ctx context.Context, dsn string, opts ...ydb.Option) (s *service var ( registry = prometheus.NewRegistry() calls = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: "app", - Name: "calls", - Help: "application calls counter", + Namespace: "app", + Name: "calls", + Help: "application calls counter", + Subsystem: "", + ConstLabels: nil, }, []string{ "method", "success", @@ -110,14 +112,18 @@ func getService(ctx context.Context, dsn string, opts ...ydb.Option) (s *service (5000 * time.Millisecond).Seconds(), (10000 * time.Millisecond).Seconds(), }, + Subsystem: "", + ConstLabels: nil, }, []string{ "success", "method", }) callsErrors = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: "app", - Name: "errors", - Help: "application errors counter", + Namespace: "app", + Name: "errors", + Help: "application errors counter", + Subsystem: "", + ConstLabels: nil, }, []string{ "method", }) @@ -139,6 +145,7 @@ func getService(ctx context.Context, dsn string, opts ...ydb.Option) (s *service ) s = &service{ + db: nil, registry: registry, router: mux.NewRouter(), @@ -155,7 +162,15 @@ func getService(ctx context.Context, dsn string, opts ...ydb.Option) (s *service } s.router.Handle("/metrics", promhttp.InstrumentMetricHandler( - registry, promhttp.HandlerFor(registry, promhttp.HandlerOpts{}), + registry, promhttp.HandlerFor(registry, promhttp.HandlerOpts{ + ErrorLog: nil, + ErrorHandling: 0, + Registry: nil, + DisableCompression: false, + MaxRequestsInFlight: 0, + Timeout: time.Duration(0), + EnableOpenMetrics: false, + }), )) s.router.HandleFunc("/", s.handleIndex).Methods(http.MethodGet) s.router.HandleFunc("/shorten", s.handleShorten).Methods(http.MethodPost) From 01ea3c020b30dda497509786ca92a7be1c305786 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Wed, 24 Apr 2024 20:33:35 +0500 Subject: [PATCH 54/57] add explicit initialization of fields of structures in examples/topic --- .../topic/cdc-cache-bus-freeseats/balancer.go | 1 + .../topic/cdc-cache-bus-freeseats/cache.go | 6 +- .../topic/cdc-cache-bus-freeseats/database.go | 6 +- .../cdc-cache-bus-freeseats/webserver.go | 8 ++- .../cdc-cache-bus-freeseats/webserver_cdc.go | 6 +- .../topic/cdc-fill-and-read/cdc-reader.go | 6 +- examples/topic/cdc-fill-and-read/main.go | 6 +- .../topic/topicreader/topicreader_simple.go | 2 +- .../topic/topicreader/topicreader_trace.go | 61 +++++++++++++++++++ examples/topic/topicwriter/topicwriter.go | 7 ++- 10 files changed, 95 insertions(+), 14 deletions(-) diff --git a/examples/topic/cdc-cache-bus-freeseats/balancer.go b/examples/topic/cdc-cache-bus-freeseats/balancer.go index 6fba494e0..989d13819 100644 --- a/examples/topic/cdc-cache-bus-freeseats/balancer.go +++ b/examples/topic/cdc-cache-bus-freeseats/balancer.go @@ -13,6 +13,7 @@ type balancer struct { func newBalancer(handlers ...http.Handler) *balancer { return &balancer{ handlers: handlers, + counter: 0, } } diff --git a/examples/topic/cdc-cache-bus-freeseats/cache.go b/examples/topic/cdc-cache-bus-freeseats/cache.go index 4e67084f6..077e42ec7 100644 --- a/examples/topic/cdc-cache-bus-freeseats/cache.go +++ b/examples/topic/cdc-cache-bus-freeseats/cache.go @@ -15,8 +15,10 @@ type Cache struct { func NewCache(timeout time.Duration) *Cache { return &Cache{ - timeout: timeout, - values: make(map[string]CacheItem), + timeout: timeout, + values: make(map[string]CacheItem), + m: sync.Mutex{}, + setCounter: 0, } } diff --git a/examples/topic/cdc-cache-bus-freeseats/database.go b/examples/topic/cdc-cache-bus-freeseats/database.go index 43ad188ce..2b44a5b55 100644 --- a/examples/topic/cdc-cache-bus-freeseats/database.go +++ b/examples/topic/cdc-cache-bus-freeseats/database.go @@ -67,7 +67,11 @@ UPSERT INTO bus (id, freeSeats) VALUES ("bus1", 40), ("bus2", 60); func createCosumers(ctx context.Context, db *ydb.Driver, consumersCount int) error { for i := 0; i < consumersCount; i++ { err := db.Topic().Alter(ctx, "bus/updates", topicoptions.AlterWithAddConsumers(topictypes.Consumer{ - Name: consumerName(i), + Name: consumerName(i), + Important: false, + SupportedCodecs: nil, + ReadFrom: time.Time{}, + Attributes: nil, })) if err != nil { return err diff --git a/examples/topic/cdc-cache-bus-freeseats/webserver.go b/examples/topic/cdc-cache-bus-freeseats/webserver.go index 3825fabce..b10ffd42d 100644 --- a/examples/topic/cdc-cache-bus-freeseats/webserver.go +++ b/examples/topic/cdc-cache-bus-freeseats/webserver.go @@ -27,9 +27,11 @@ type server struct { func newServer(id int, db *ydb.Driver, cacheTimeout time.Duration, useCDC bool) *server { res := &server{ - cache: NewCache(cacheTimeout), - db: db, - id: id, + cache: NewCache(cacheTimeout), + db: db, + id: id, + mux: http.ServeMux{}, + dbCounter: 0, } res.mux.HandleFunc("/", res.IndexPageHandler) diff --git a/examples/topic/cdc-cache-bus-freeseats/webserver_cdc.go b/examples/topic/cdc-cache-bus-freeseats/webserver_cdc.go index 70f4a1f22..96bcebe06 100644 --- a/examples/topic/cdc-cache-bus-freeseats/webserver_cdc.go +++ b/examples/topic/cdc-cache-bus-freeseats/webserver_cdc.go @@ -14,8 +14,10 @@ func (s *server) cdcLoop() { consumer := consumerName(s.id) reader, err := s.db.Topic().StartReader(consumer, topicoptions.ReadSelectors{ { - Path: "bus/updates", - ReadFrom: time.Now(), + Path: "bus/updates", + ReadFrom: time.Now(), + Partitions: nil, + MaxTimeLag: time.Duration(0), }, }, ) diff --git a/examples/topic/cdc-fill-and-read/cdc-reader.go b/examples/topic/cdc-fill-and-read/cdc-reader.go index b3771009d..50bf3b4cb 100644 --- a/examples/topic/cdc-fill-and-read/cdc-reader.go +++ b/examples/topic/cdc-fill-and-read/cdc-reader.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log" + "time" "github.com/ydb-platform/ydb-go-sdk/v3" "github.com/ydb-platform/ydb-go-sdk/v3/topic/topicoptions" @@ -14,7 +15,10 @@ func cdcRead(ctx context.Context, db *ydb.Driver, consumerName, topicPath string // Connect to changefeed log.Println("Start cdc read") - reader, err := db.Topic().StartReader(consumerName, []topicoptions.ReadSelector{{Path: topicPath}}) + reader, err := db.Topic().StartReader( + consumerName, + []topicoptions.ReadSelector{{Path: topicPath, Partitions: nil, ReadFrom: time.Time{}, MaxTimeLag: time.Duration(0)}}, + ) if err != nil { log.Fatal("failed to start read feed", err) } diff --git a/examples/topic/cdc-fill-and-read/main.go b/examples/topic/cdc-fill-and-read/main.go index d0cfdbe47..175395655 100644 --- a/examples/topic/cdc-fill-and-read/main.go +++ b/examples/topic/cdc-fill-and-read/main.go @@ -103,7 +103,11 @@ func prepareTableWithCDC(ctx context.Context, db *ydb.Driver, prefix, tableName, log.Println("Create consumer") err = db.Topic().Alter(ctx, topicPath, topicoptions.AlterWithAddConsumers(topictypes.Consumer{ - Name: consumerName, + Name: consumerName, + Important: false, + SupportedCodecs: nil, + ReadFrom: time.Time{}, + Attributes: nil, })) if err != nil { panic(fmt.Errorf("failed to create feed consumer: %w", err)) diff --git a/examples/topic/topicreader/topicreader_simple.go b/examples/topic/topicreader/topicreader_simple.go index 6fb568037..c58a5e1eb 100644 --- a/examples/topic/topicreader/topicreader_simple.go +++ b/examples/topic/topicreader/topicreader_simple.go @@ -44,7 +44,7 @@ func UnmarshalMessageContentToJSONStruct(msg *topicreader.Message) { // UnmarshalMessageContentToProtobufStruct is example for effective way for unmarshal protobuf message content to value func UnmarshalMessageContentToProtobufStruct(msg *topicreader.Message) { - v := &firestore.BundledDocumentMetadata{} // protobuf type + v := new(firestore.BundledDocumentMetadata) // protobuf type _ = topicsugar.ProtoUnmarshal(msg, v) } diff --git a/examples/topic/topicreader/topicreader_trace.go b/examples/topic/topicreader/topicreader_trace.go index 28ab11427..461f8dc9e 100644 --- a/examples/topic/topicreader/topicreader_trace.go +++ b/examples/topic/topicreader/topicreader_trace.go @@ -17,6 +17,27 @@ func CommitNotify(ctx context.Context, db *ydb.Driver) { // called when receive commit notify from server fmt.Println(info.Topic, info.PartitionID, info.CommittedOffset) }, + OnReaderStart: nil, + OnReaderReconnect: nil, + OnReaderReconnectRequest: nil, + OnReaderPartitionReadStartResponse: nil, + OnReaderPartitionReadStopResponse: nil, + OnReaderCommit: nil, + OnReaderSendCommitMessage: nil, + OnReaderClose: nil, + OnReaderInit: nil, + OnReaderError: nil, + OnReaderUpdateToken: nil, + OnReaderSentDataRequest: nil, + OnReaderReceiveDataResponse: nil, + OnReaderReadMessages: nil, + OnReaderUnknownGrpcMessage: nil, + OnWriterReconnect: nil, + OnWriterInitStream: nil, + OnWriterClose: nil, + OnWriterCompressMessages: nil, + OnWriterSendMessages: nil, + OnWriterReadUnknownGrpcMessage: nil, }, ), ) @@ -61,6 +82,26 @@ func ExplicitPartitionStartStopHandler(ctx context.Context, db *ydb.Driver) { return nil }, + OnReaderStart: nil, + OnReaderReconnect: nil, + OnReaderReconnectRequest: nil, + OnReaderCommit: nil, + OnReaderSendCommitMessage: nil, + OnReaderCommittedNotify: nil, + OnReaderClose: nil, + OnReaderInit: nil, + OnReaderError: nil, + OnReaderUpdateToken: nil, + OnReaderSentDataRequest: nil, + OnReaderReceiveDataResponse: nil, + OnReaderReadMessages: nil, + OnReaderUnknownGrpcMessage: nil, + OnWriterReconnect: nil, + OnWriterInitStream: nil, + OnWriterClose: nil, + OnWriterCompressMessages: nil, + OnWriterSendMessages: nil, + OnWriterReadUnknownGrpcMessage: nil, }, ), ) @@ -135,6 +176,26 @@ func PartitionStartStopHandlerAndOwnReadProgressStorage(ctx context.Context, db trace.Topic{ OnReaderPartitionReadStartResponse: onPartitionStart, OnReaderPartitionReadStopResponse: onPartitionStop, + OnReaderStart: nil, + OnReaderReconnect: nil, + OnReaderReconnectRequest: nil, + OnReaderCommit: nil, + OnReaderSendCommitMessage: nil, + OnReaderCommittedNotify: nil, + OnReaderClose: nil, + OnReaderInit: nil, + OnReaderError: nil, + OnReaderUpdateToken: nil, + OnReaderSentDataRequest: nil, + OnReaderReceiveDataResponse: nil, + OnReaderReadMessages: nil, + OnReaderUnknownGrpcMessage: nil, + OnWriterReconnect: nil, + OnWriterInitStream: nil, + OnWriterClose: nil, + OnWriterCompressMessages: nil, + OnWriterSendMessages: nil, + OnWriterReadUnknownGrpcMessage: nil, }, ), ) diff --git a/examples/topic/topicwriter/topicwriter.go b/examples/topic/topicwriter/topicwriter.go index a378f8a90..ca864c573 100644 --- a/examples/topic/topicwriter/topicwriter.go +++ b/examples/topic/topicwriter/topicwriter.go @@ -3,6 +3,7 @@ package topicwriter import ( "bytes" "context" + "time" "github.com/ydb-platform/ydb-go-sdk/v3" "github.com/ydb-platform/ydb-go-sdk/v3/topic/topicoptions" @@ -30,15 +31,15 @@ func ConnectSelectCodec(ctx context.Context, db *ydb.Driver) *topicwriter.Writer func SendMessagesOneByOne(ctx context.Context, w *topicwriter.Writer) { data := []byte{1, 2, 3} - mess := topicwriter.Message{Data: bytes.NewReader(data)} + mess := topicwriter.Message{Data: bytes.NewReader(data), SeqNo: 0, CreatedAt: time.Time{}, Metadata: nil} _ = w.Write(ctx, mess) } func SendGroupOfMessages(ctx context.Context, w *topicwriter.Writer) { data1 := []byte{1, 2, 3} data2 := []byte{4, 5, 6} - mess1 := topicwriter.Message{Data: bytes.NewReader(data1)} - mess2 := topicwriter.Message{Data: bytes.NewReader(data2)} + mess1 := topicwriter.Message{Data: bytes.NewReader(data1), SeqNo: 0, CreatedAt: time.Time{}, Metadata: nil} + mess2 := topicwriter.Message{Data: bytes.NewReader(data2), SeqNo: 0, CreatedAt: time.Time{}, Metadata: nil} _ = w.Write(ctx, mess1, mess2) } From c5058c4d9681ba6516cceb445512f64d068935ca Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Wed, 24 Apr 2024 23:24:27 +0500 Subject: [PATCH 55/57] add explicit initialization of fields of structures in tests/slo --- tests/slo/database/sql/storage.go | 3 ++ tests/slo/gorm/storage.go | 39 ++++++++++++++---- tests/slo/internal/config/config.go | 4 +- tests/slo/internal/generator/generator.go | 4 ++ tests/slo/internal/metrics/metrics.go | 50 ++++++++++++++++++----- tests/slo/native/query/storage.go | 50 ++++++++++++++++++++++- tests/slo/native/table/storage.go | 50 ++++++++++++++++++++++- tests/slo/xorm/storage.go | 12 +++++- 8 files changed, 186 insertions(+), 26 deletions(-) diff --git a/tests/slo/database/sql/storage.go b/tests/slo/database/sql/storage.go index 6468764f0..f8cc3fc1b 100755 --- a/tests/slo/database/sql/storage.go +++ b/tests/slo/database/sql/storage.go @@ -87,6 +87,9 @@ func NewStorage(ctx context.Context, cfg *config.Config, poolSize int) (s *Stora dropQuery: fmt.Sprintf(dropTemplate, cfg.Table), upsertQuery: fmt.Sprintf(upsertTemplate, cfg.Table), selectQuery: fmt.Sprintf(selectTemplate, cfg.Table), + cc: nil, + c: nil, + db: nil, } s.cc, err = ydb.Open( diff --git a/tests/slo/gorm/storage.go b/tests/slo/gorm/storage.go index b2cf92211..4b177d71e 100644 --- a/tests/slo/gorm/storage.go +++ b/tests/slo/gorm/storage.go @@ -53,6 +53,7 @@ func NewStorage(cfg *config.Config, poolSize int) (*Storage, error) { cfg: cfg, tableOptions: fmt.Sprintf(optionsTemplate, cfg.PartitionSize, cfg.MinPartitionsCount, cfg.MaxPartitionsCount, cfg.MinPartitionsCount), + db: nil, } var err error @@ -64,7 +65,25 @@ func NewStorage(cfg *config.Config, poolSize int) (*Storage, error) { ydb.WithTablePathPrefix(label), ), &gorm.Config{ - Logger: gormLogger.Default.LogMode(gormLogger.Warn), + Logger: gormLogger.Default.LogMode(gormLogger.Warn), + SkipDefaultTransaction: false, + NamingStrategy: nil, + FullSaveAssociations: false, + NowFunc: nil, + DryRun: false, + PrepareStmt: false, + DisableAutomaticPing: false, + DisableForeignKeyConstraintWhenMigrating: false, + IgnoreRelationshipsWhenMigrating: false, + DisableNestedTransaction: false, + AllowGlobalUpdate: false, + QueryFields: false, + CreateBatchSize: 0, + TranslateError: false, + ClauseBuilders: nil, + ConnPool: nil, + Dialector: nil, + Plugins: nil, }, ) if err != nil { @@ -93,11 +112,12 @@ func (s *Storage) Read(ctx context.Context, id generator.RowID) (r generator.Row return err } - err = s.db.WithContext(ctx).Scopes(addTableToScope(s.cfg.Table)).Model(&generator.Row{}). + err = s.db.WithContext(ctx).Scopes(addTableToScope(s.cfg.Table)).Model(new(generator.Row)). First(&r, "hash = ? AND id = ?", clause.Expr{ - SQL: "Digest::NumericHash(?)", - Vars: []interface{}{id}, + SQL: "Digest::NumericHash(?)", + Vars: []interface{}{id}, + WithoutParentheses: false, }, id, ).Error @@ -141,11 +161,12 @@ func (s *Storage) Write(ctx context.Context, row generator.Row) (attempts int, e return err } - return s.db.WithContext(ctx).Scopes(addTableToScope(s.cfg.Table)).Model(&generator.Row{}). + return s.db.WithContext(ctx).Scopes(addTableToScope(s.cfg.Table)).Model(new(generator.Row)). Create(map[string]interface{}{ "Hash": clause.Expr{ - SQL: "Digest::NumericHash(?)", - Vars: []interface{}{row.ID}, + SQL: "Digest::NumericHash(?)", + Vars: []interface{}{row.ID}, + WithoutParentheses: false, }, "ID": row.ID, "PayloadStr": row.PayloadStr, @@ -177,7 +198,7 @@ func (s *Storage) createTable(ctx context.Context) error { defer cancel() return s.db.WithContext(ctx).Scopes(addTableToScope(s.cfg.Table)). - Set("gorm:table_options", s.tableOptions).AutoMigrate(&generator.Row{}) + Set("gorm:table_options", s.tableOptions).AutoMigrate(new(generator.Row)) } func (s *Storage) dropTable(ctx context.Context) error { @@ -188,7 +209,7 @@ func (s *Storage) dropTable(ctx context.Context) error { ctx, cancel := context.WithTimeout(ctx, time.Duration(s.cfg.WriteTimeout)*time.Millisecond) defer cancel() - return s.db.WithContext(ctx).Scopes(addTableToScope(s.cfg.Table)).Migrator().DropTable(&generator.Row{}) + return s.db.WithContext(ctx).Scopes(addTableToScope(s.cfg.Table)).Migrator().DropTable(new(generator.Row)) } func (s *Storage) close(ctx context.Context) error { diff --git a/tests/slo/internal/config/config.go b/tests/slo/internal/config/config.go index b858d27b8..af274da0f 100644 --- a/tests/slo/internal/config/config.go +++ b/tests/slo/internal/config/config.go @@ -36,7 +36,7 @@ type Config struct { } func New() (*Config, error) { - cfg := &Config{} + cfg := new(Config) if len(os.Args) < 2 { fmt.Print(mainHelp) @@ -44,7 +44,7 @@ func New() (*Config, error) { return nil, ErrWrongArgs } - fs := flag.FlagSet{} + fs := flag.FlagSet{Usage: nil} switch os.Args[1] { case "create": diff --git a/tests/slo/internal/generator/generator.go b/tests/slo/internal/generator/generator.go index 275ccd41c..3bc90fdf8 100755 --- a/tests/slo/internal/generator/generator.go +++ b/tests/slo/internal/generator/generator.go @@ -21,6 +21,7 @@ type Generator struct { func New(id RowID) *Generator { return &Generator{ currentID: id, + mu: sync.Mutex{}, } } @@ -33,6 +34,9 @@ func (g *Generator) Generate() (Row, error) { ID: id, PayloadDouble: func(a float64) *float64 { return &a }(rand.Float64()), //nolint:gosec // speed more important PayloadTimestamp: func(a time.Time) *time.Time { return &a }(time.Now()), + Hash: 0, + PayloadStr: nil, + PayloadHash: 0, } var err error diff --git a/tests/slo/internal/metrics/metrics.go b/tests/slo/internal/metrics/metrics.go index ee7778152..4cfbf67d5 100644 --- a/tests/slo/internal/metrics/metrics.go +++ b/tests/slo/internal/metrics/metrics.go @@ -30,27 +30,42 @@ type ( func New(url, label, jobName string) (*Metrics, error) { m := &Metrics{ - label: label, + label: label, + oks: nil, + notOks: nil, + inflight: nil, + latencies: nil, + attempts: nil, + p: nil, } m.oks = prometheus.NewGaugeVec( prometheus.GaugeOpts{ - Name: "oks", - Help: "amount of OK requests", + Name: "oks", + Help: "amount of OK requests", + Namespace: "", + Subsystem: "", + ConstLabels: nil, }, []string{"jobName"}, ) m.notOks = prometheus.NewGaugeVec( prometheus.GaugeOpts{ - Name: "not_oks", - Help: "amount of not OK requests", + Name: "not_oks", + Help: "amount of not OK requests", + Namespace: "", + Subsystem: "", + ConstLabels: nil, }, []string{"jobName"}, ) m.inflight = prometheus.NewGaugeVec( prometheus.GaugeOpts{ - Name: "inflight", - Help: "amount of requests in flight", + Name: "inflight", + Help: "amount of requests in flight", + Namespace: "", + Subsystem: "", + ConstLabels: nil, }, []string{"jobName"}, ) @@ -63,15 +78,28 @@ func New(url, label, jobName string) (*Metrics, error) { 0.99: 0, 1.0: 0, }, - MaxAge: 15 * time.Second, + MaxAge: 15 * time.Second, + Namespace: "", + Subsystem: "", + ConstLabels: nil, + AgeBuckets: 0, + BufCap: 0, }, []string{"status", "jobName"}, ) m.attempts = prometheus.NewHistogramVec( prometheus.HistogramOpts{ - Name: "attempts", - Help: "summary of amount for request", - Buckets: prometheus.LinearBuckets(1, 1, 10), + Name: "attempts", + Help: "summary of amount for request", + Buckets: prometheus.LinearBuckets(1, 1, 10), + Namespace: "", + Subsystem: "", + ConstLabels: nil, + NativeHistogramBucketFactor: 0, + NativeHistogramZeroThreshold: 0, + NativeHistogramMaxBucketNumber: 0, + NativeHistogramMinResetDuration: 0, + NativeHistogramMaxZeroThreshold: 0, }, []string{"status", "jobName"}, ) diff --git a/tests/slo/native/query/storage.go b/tests/slo/native/query/storage.go index 89377d012..f237222b4 100755 --- a/tests/slo/native/query/storage.go +++ b/tests/slo/native/query/storage.go @@ -97,7 +97,7 @@ func (s *Storage) Read(ctx context.Context, entryID generator.RowID) (_ generato ctx, cancel := context.WithTimeout(ctx, time.Duration(s.cfg.ReadTimeout)*time.Millisecond) defer cancel() - e := generator.Row{} + e := generator.Row{Hash: 0, ID: 0, PayloadStr: nil, PayloadDouble: nil, PayloadTimestamp: nil, PayloadHash: 0} err := s.db.Query().Do(ctx, func(ctx context.Context, session query.Session) (err error) { @@ -156,6 +156,30 @@ func (s *Storage) Read(ctx context.Context, entryID generator.RowID) (_ generato attempts = info.Attempts } }, + OnNew: nil, + OnClose: nil, + OnPoolNew: nil, + OnPoolClose: nil, + OnPoolTry: nil, + OnPoolWith: nil, + OnPoolPut: nil, + OnPoolGet: nil, + OnPoolChange: nil, + OnDoTx: nil, + OnSessionCreate: nil, + OnSessionAttach: nil, + OnSessionDelete: nil, + OnSessionExecute: nil, + OnSessionBegin: nil, + OnTxExecute: nil, + OnResultNew: nil, + OnResultNextPart: nil, + OnResultNextResultSet: nil, + OnResultClose: nil, + OnResultSetNextRow: nil, + OnRowScan: nil, + OnRowScanNamed: nil, + OnRowScanStruct: nil, }), query.WithLabel("READ"), ) @@ -205,6 +229,30 @@ func (s *Storage) Write(ctx context.Context, e generator.Row) (attempts int, fin attempts = info.Attempts } }, + OnNew: nil, + OnClose: nil, + OnPoolNew: nil, + OnPoolClose: nil, + OnPoolTry: nil, + OnPoolWith: nil, + OnPoolPut: nil, + OnPoolGet: nil, + OnPoolChange: nil, + OnDoTx: nil, + OnSessionCreate: nil, + OnSessionAttach: nil, + OnSessionDelete: nil, + OnSessionExecute: nil, + OnSessionBegin: nil, + OnTxExecute: nil, + OnResultNew: nil, + OnResultNextPart: nil, + OnResultNextResultSet: nil, + OnResultClose: nil, + OnResultSetNextRow: nil, + OnRowScan: nil, + OnRowScanNamed: nil, + OnRowScanStruct: nil, }), query.WithLabel("WRITE"), ) diff --git a/tests/slo/native/table/storage.go b/tests/slo/native/table/storage.go index b31f72a0e..f5d3ad71e 100755 --- a/tests/slo/native/table/storage.go +++ b/tests/slo/native/table/storage.go @@ -98,7 +98,7 @@ func (s *Storage) Read(ctx context.Context, entryID generator.RowID) (_ generato ctx, cancel := context.WithTimeout(ctx, time.Duration(s.cfg.ReadTimeout)*time.Millisecond) defer cancel() - e := generator.Row{} + e := generator.Row{Hash: 0, ID: 0, PayloadStr: nil, PayloadDouble: nil, PayloadTimestamp: nil, PayloadHash: 0} err = s.db.Table().Do(ctx, func(ctx context.Context, session table.Session) (err error) { @@ -147,6 +147,30 @@ func (s *Storage) Read(ctx context.Context, entryID generator.RowID) (_ generato attempts = info.Attempts } }, + OnInit: nil, + OnClose: nil, + OnDoTx: nil, + OnCreateSession: nil, + OnSessionNew: nil, + OnSessionDelete: nil, + OnSessionKeepAlive: nil, + OnSessionBulkUpsert: nil, + OnSessionQueryPrepare: nil, + OnSessionQueryExecute: nil, + OnSessionQueryExplain: nil, + OnSessionQueryStreamExecute: nil, + OnSessionQueryStreamRead: nil, + OnTxBegin: nil, + OnTxExecute: nil, + OnTxExecuteStatement: nil, + OnTxCommit: nil, + OnTxRollback: nil, + OnPoolStateChange: nil, + OnPoolSessionAdd: nil, + OnPoolSessionRemove: nil, + OnPoolPut: nil, + OnPoolGet: nil, + OnPoolWait: nil, }), ) @@ -193,6 +217,30 @@ func (s *Storage) Write(ctx context.Context, e generator.Row) (attempts int, _ e attempts = info.Attempts } }, + OnInit: nil, + OnClose: nil, + OnDoTx: nil, + OnCreateSession: nil, + OnSessionNew: nil, + OnSessionDelete: nil, + OnSessionKeepAlive: nil, + OnSessionBulkUpsert: nil, + OnSessionQueryPrepare: nil, + OnSessionQueryExecute: nil, + OnSessionQueryExplain: nil, + OnSessionQueryStreamExecute: nil, + OnSessionQueryStreamRead: nil, + OnTxBegin: nil, + OnTxExecute: nil, + OnTxExecuteStatement: nil, + OnTxCommit: nil, + OnTxRollback: nil, + OnPoolStateChange: nil, + OnPoolSessionAdd: nil, + OnPoolSessionRemove: nil, + OnPoolPut: nil, + OnPoolGet: nil, + OnPoolWait: nil, }), ) diff --git a/tests/slo/xorm/storage.go b/tests/slo/xorm/storage.go index 4550374c9..7d6da8104 100644 --- a/tests/slo/xorm/storage.go +++ b/tests/slo/xorm/storage.go @@ -65,6 +65,10 @@ type Storage struct { func NewStorage(ctx context.Context, cfg *config.Config, poolSize int) (_ *Storage, err error) { s := &Storage{ cfg: cfg, + cc: nil, + c: nil, + db: nil, + x: nil, } dsn := s.cfg.Endpoint + s.cfg.DB @@ -195,7 +199,9 @@ func (s *Storage) createTable(ctx context.Context) error { defer cancel() return retry.Do(ctx, s.x.DB().DB, func(ctx context.Context, _ *sql.Conn) error { - return s.x.Context(ctx).CreateTable(generator.Row{}) + return s.x.Context(ctx).CreateTable(generator.Row{ + Hash: 0, ID: 0, PayloadStr: nil, PayloadDouble: nil, PayloadTimestamp: nil, PayloadHash: 0, + }) }) } @@ -208,7 +214,9 @@ func (s *Storage) dropTable(ctx context.Context) error { defer cancel() return retry.Do(ctx, s.x.DB().DB, func(ctx context.Context, _ *sql.Conn) error { - return s.x.Context(ctx).DropTable(generator.Row{}) + return s.x.Context(ctx).DropTable(generator.Row{ + Hash: 0, ID: 0, PayloadStr: nil, PayloadDouble: nil, PayloadTimestamp: nil, PayloadHash: 0, + }) }) } From 299daa423d6f1e7375916fd66f31bdbbf81931a7 Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Sun, 5 May 2024 19:15:20 +0500 Subject: [PATCH 56/57] add explicit initialization of fields of structures in internal/; log/; retry/ --- internal/conn/conn.go | 1 + internal/credentials/oauth2.go | 46 +++++++++++++++++---- internal/table/session.go | 1 + internal/topic/topicwriterinternal/queue.go | 25 +++++------ internal/xcontext/cancels_quard.go | 1 + internal/xsql/connector.go | 1 + internal/xsync/last_usage_guard.go | 2 + log/driver.go | 1 + retry/budget/budget.go | 6 ++- retry/retry.go | 2 +- 10 files changed, 63 insertions(+), 23 deletions(-) diff --git a/internal/conn/conn.go b/internal/conn/conn.go index e0e6793a4..7fe18cfcf 100644 --- a/internal/conn/conn.go +++ b/internal/conn/conn.go @@ -432,6 +432,7 @@ func (c *conn) NewStream( s := &grpcClientStream{ parentConn: c, + stream: nil, streamCtx: ctx, streamCancel: cancel, wrapping: useWrapping, diff --git a/internal/credentials/oauth2.go b/internal/credentials/oauth2.go index f49826127..a001836cb 100644 --- a/internal/credentials/oauth2.go +++ b/internal/credentials/oauth2.go @@ -179,12 +179,14 @@ func (tokenSource *tokenSourceOption) ApplyOauth2CredentialsOption(c *oauth2Toke func WithSubjectToken(subjectToken TokenSource) *tokenSourceOption { return &tokenSourceOption{ source: subjectToken, + createFunc: nil, tokenSourceType: SubjectTokenSourceType, } } func WithFixedSubjectToken(token, tokenType string) *tokenSourceOption { return &tokenSourceOption{ + source: nil, createFunc: func() (TokenSource, error) { return NewFixedTokenSource(token, tokenType), nil }, @@ -194,6 +196,7 @@ func WithFixedSubjectToken(token, tokenType string) *tokenSourceOption { func WithJWTSubjectToken(opts ...JWTTokenSourceOption) *tokenSourceOption { return &tokenSourceOption{ + source: nil, createFunc: func() (TokenSource, error) { return NewJWTTokenSource(opts...) }, @@ -205,12 +208,14 @@ func WithJWTSubjectToken(opts ...JWTTokenSourceOption) *tokenSourceOption { func WithActorToken(actorToken TokenSource) *tokenSourceOption { return &tokenSourceOption{ source: actorToken, + createFunc: nil, tokenSourceType: ActorTokenSourceType, } } func WithFixedActorToken(token, tokenType string) *tokenSourceOption { return &tokenSourceOption{ + source: nil, createFunc: func() (TokenSource, error) { return NewFixedTokenSource(token, tokenType), nil }, @@ -220,6 +225,7 @@ func WithFixedActorToken(token, tokenType string) *tokenSourceOption { func WithJWTActorToken(opts ...JWTTokenSourceOption) *tokenSourceOption { return &tokenSourceOption{ + source: nil, createFunc: func() (TokenSource, error) { return NewJWTTokenSource(opts...) }, @@ -265,10 +271,21 @@ 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), + tokenEndpoint: "", + grantType: "urn:ietf:params:oauth:grant-type:token-exchange", + resource: "", + audience: nil, + scope: nil, + requestedTokenType: "urn:ietf:params:oauth:token-type:access_token", + subjectTokenSource: nil, + actorTokenSource: nil, + requestTimeout: defaultRequestTimeout, + receivedToken: "", + updateTokenTime: time.Time{}, + receivedTokenExpireTime: time.Time{}, + mutex: sync.RWMutex{}, + updating: atomic.Bool{}, + sourceInfo: stack.Record(1), } var err error @@ -452,8 +469,10 @@ func (provider *oauth2TokenExchange) exchangeToken(ctx context.Context, now time req.Close = true client := http.Client{ - Transport: http.DefaultTransport, - Timeout: provider.requestTimeout, + Transport: http.DefaultTransport, + CheckRedirect: nil, + Jar: nil, + Timeout: provider.requestTimeout, } result, err := client.Do(req) @@ -756,7 +775,14 @@ func WithRSAPrivateKeyPEMFile(path string) *rsaPrivateKeyPemFileOption { func NewJWTTokenSource(opts ...JWTTokenSourceOption) (*jwtTokenSource, error) { s := &jwtTokenSource{ - tokenTTL: defaultJWTTokenTTL, + signingMethod: nil, + keyID: "", + privateKey: nil, + issuer: "", + subject: "", + audience: nil, + id: "", + tokenTTL: defaultJWTTokenTTL, } var err error @@ -801,6 +827,8 @@ func (s *jwtTokenSource) Token() (Token, error) { err error ) t := jwt.Token{ + Raw: "", + Method: s.signingMethod, Header: map[string]interface{}{ "typ": "JWT", "alg": s.signingMethod.Alg(), @@ -812,9 +840,11 @@ func (s *jwtTokenSource) Token() (Token, error) { IssuedAt: issued, Audience: s.audience, ExpiresAt: expire, + NotBefore: nil, ID: s.id, }, - Method: s.signingMethod, + Signature: "", + Valid: false, } var token Token diff --git a/internal/table/session.go b/internal/table/session.go index db660143e..9e1675f2d 100644 --- a/internal/table/session.go +++ b/internal/table/session.go @@ -664,6 +664,7 @@ func renameTables( operationCancelAfter, operation.ModeSync, ), + Tables: nil, } for _, opt := range opts { if opt != nil { diff --git a/internal/topic/topicwriterinternal/queue.go b/internal/topic/topicwriterinternal/queue.go index f7d097a18..69f872f46 100644 --- a/internal/topic/topicwriterinternal/queue.go +++ b/internal/topic/topicwriterinternal/queue.go @@ -51,18 +51,19 @@ type messageQueue struct { func newMessageQueue() messageQueue { return messageQueue{ - messagesByOrder: make(map[int]messageWithDataContent), - seqNoToOrderID: make(map[int64]int), - hasNewMessages: make(empty.Chan, 1), - closedChan: make(empty.Chan), - lastSeqNo: -1, - OnAckReceived: nil, - closedErr: nil, - acksReceivedEvent: xsync.EventBroadcast{}, - m: xsync.RWMutex{RWMutex: sync.RWMutex{}}, - closed: false, - lastWrittenIndex: 0, - lastSentIndex: 0, + messagesByOrder: make(map[int]messageWithDataContent), + seqNoToOrderID: make(map[int64]int), + hasNewMessages: make(empty.Chan, 1), + closedChan: make(empty.Chan), + lastSeqNo: -1, + OnAckReceived: nil, + closedErr: nil, + acksReceivedEvent: xsync.EventBroadcast{}, + m: xsync.RWMutex{RWMutex: sync.RWMutex{}}, + stopReceiveMessagesReason: nil, + closed: false, + lastWrittenIndex: 0, + lastSentIndex: 0, } } diff --git a/internal/xcontext/cancels_quard.go b/internal/xcontext/cancels_quard.go index b2743e656..e9514b99d 100644 --- a/internal/xcontext/cancels_quard.go +++ b/internal/xcontext/cancels_quard.go @@ -14,6 +14,7 @@ type ( func NewCancelsGuard() *CancelsGuard { return &CancelsGuard{ + mu: sync.Mutex{}, cancels: make(map[*context.CancelFunc]struct{}), } } diff --git a/internal/xsql/connector.go b/internal/xsql/connector.go index 5124ed1d2..237ebea0d 100644 --- a/internal/xsql/connector.go +++ b/internal/xsql/connector.go @@ -229,6 +229,7 @@ func Open(parent ydbDriver, opts ...ConnectorOption) (_ *Connector, err error) { pathNormalizer: bind.TablePathPrefix(parent.Name()), trace: nil, traceRetry: nil, + retryBudget: nil, } for _, opt := range opts { if opt != nil { diff --git a/internal/xsync/last_usage_guard.go b/internal/xsync/last_usage_guard.go index f11d5ba49..6a30bb73e 100644 --- a/internal/xsync/last_usage_guard.go +++ b/internal/xsync/last_usage_guard.go @@ -29,6 +29,8 @@ func WithClock(clock clockwork.Clock) lastUsageOption { func NewLastUsage(opts ...lastUsageOption) *lastUsage { lastUsage := &lastUsage{ + locks: atomic.Int64{}, + t: atomic.Pointer[time.Time]{}, clock: clockwork.NewRealClock(), } for _, opt := range opts { diff --git a/log/driver.go b/log/driver.go index 57a95484d..db66137a2 100644 --- a/log/driver.go +++ b/log/driver.go @@ -503,5 +503,6 @@ func internalDriver(l Logger, d trace.Detailer) trace.Driver { //nolint:gocyclo OnPoolRelease: nil, OnConnPark: nil, OnBalancerClusterDiscoveryAttempt: nil, + OnConnStreamFinish: nil, } } diff --git a/retry/budget/budget.go b/retry/budget/budget.go index 2f2625178..94d78e9e3 100644 --- a/retry/budget/budget.go +++ b/retry/budget/budget.go @@ -39,8 +39,10 @@ func withFixedBudgetClock(clock clockwork.Clock) fixedBudgetOption { // Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental func Limited(attemptsPerSecond int, opts ...fixedBudgetOption) *fixedBudget { q := &fixedBudget{ - clock: clockwork.NewRealClock(), - done: make(chan struct{}), + clock: clockwork.NewRealClock(), + ticker: nil, + quota: nil, + done: make(chan struct{}), } for _, opt := range opts { opt(q) diff --git a/retry/retry.go b/retry/retry.go index 1a2304689..b5b8cdaab 100644 --- a/retry/retry.go +++ b/retry/retry.go @@ -126,7 +126,7 @@ func WithTrace(t *trace.Retry) traceOption { return traceOption{t: t} } -var _ Option = budgetOption{} +var _ Option = budgetOption{b: nil} type budgetOption struct { b budget.Budget From a5cc73cc2493cf05528eee84c315d53cbdbaa72a Mon Sep 17 00:00:00 2001 From: kozyrev-m Date: Sun, 5 May 2024 20:10:58 +0500 Subject: [PATCH 57/57] fix import in internal/allocator/allocator.go --- internal/allocator/allocator.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/internal/allocator/allocator.go b/internal/allocator/allocator.go index 77a661eb7..a1bbb5d5e 100644 --- a/internal/allocator/allocator.go +++ b/internal/allocator/allocator.go @@ -3,8 +3,6 @@ package allocator import ( "sync" - "google.golang.org/protobuf/types/known/structpb" - "github.com/ydb-platform/ydb-go-genproto/protos/Ydb" "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Query" "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Table" @@ -347,7 +345,7 @@ func (a *nullFlagAllocator) NullFlag() (v *Ydb.Value_NullFlagValue) { func (a *nullFlagAllocator) free() { for _, v := range a.allocations { - *v = Ydb.Value_NullFlagValue{NullFlagValue: structpb.NullValue_NULL_VALUE} + *v = Ydb.Value_NullFlagValue{NullFlagValue: 0} nullFlagPool.Put(v) } a.allocations = a.allocations[:0] @@ -534,7 +532,7 @@ func (a *typeEmptyListAllocator) TypeEmptyList() (v *Ydb.Type_EmptyListType) { func (a *typeEmptyListAllocator) free() { for _, v := range a.allocations { - *v = Ydb.Type_EmptyListType{EmptyListType: structpb.NullValue_NULL_VALUE} + *v = Ydb.Type_EmptyListType{EmptyListType: 0} typeEmptyListPool.Put(v) } a.allocations = a.allocations[:0] @@ -553,7 +551,7 @@ func (a *typeEmptyDictAllocator) TypeEmptyDict() (v *Ydb.Type_EmptyDictType) { func (a *typeEmptyDictAllocator) free() { for _, v := range a.allocations { - *v = Ydb.Type_EmptyDictType{EmptyDictType: structpb.NullValue_NULL_VALUE} + *v = Ydb.Type_EmptyDictType{EmptyDictType: 0} typeEmptyDictPool.Put(v) } a.allocations = a.allocations[:0]