Skip to content

Commit 836562e

Browse files
authored
Merge pull request #1142 from ydb-platform/trace-query-transaction
Query service fixes
2 parents fa39a0b + 82f75c0 commit 836562e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+919
-1404
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
* Added support of `TzDate`,`TzDateTime`,`TzTimestamp` types in `ydb.ParamsBuilder()`
2+
* Added `trace.Query.OnTransactionExecute` event
3+
* Added query pool metrics
4+
* Fixed logic of query session pool
5+
* Changed initialization of internal driver clients to lazy
6+
* Disabled the logic of background grpc-connection parking
27

38
## v3.58.2
49
* Added `trace.Query.OnSessionBegin` event

config/config.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ type Config struct {
2121

2222
trace *trace.Driver
2323
dialTimeout time.Duration
24-
connectionTTL time.Duration
2524
balancerConfig *balancerConfig.Config
2625
secure bool
2726
endpoint string
@@ -57,13 +56,6 @@ func (c *Config) Meta() *meta.Meta {
5756
return c.meta
5857
}
5958

60-
// ConnectionTTL defines interval for parking grpc connections.
61-
//
62-
// If ConnectionTTL is zero - connections are not park.
63-
func (c *Config) ConnectionTTL() time.Duration {
64-
return c.connectionTTL
65-
}
66-
6759
// Secure is a flag for secure connection
6860
func (c *Config) Secure() bool {
6961
return c.secure
@@ -177,12 +169,6 @@ func WithUserAgent(userAgent string) Option {
177169
}
178170
}
179171

180-
func WithConnectionTTL(ttl time.Duration) Option {
181-
return func(c *Config) {
182-
c.connectionTTL = ttl
183-
}
184-
}
185-
186172
func WithCredentials(credentials credentials.Credentials) Option {
187173
return func(c *Config) {
188174
c.credentials = credentials

driver.go

Lines changed: 130 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,28 @@ type Driver struct {
6565
config *config.Config
6666
options []config.Option
6767

68-
discovery *internalDiscovery.Client
68+
discovery *xsync.Once[*internalDiscovery.Client]
6969
discoveryOptions []discoveryConfig.Option
7070

71-
table *internalTable.Client
71+
table *xsync.Once[*internalTable.Client]
7272
tableOptions []tableConfig.Option
7373

74-
query *internalQuery.Client
74+
query *xsync.Once[*internalQuery.Client]
7575
queryOptions []queryConfig.Option
7676

77-
scripting *internalScripting.Client
77+
scripting *xsync.Once[*internalScripting.Client]
7878
scriptingOptions []scriptingConfig.Option
7979

80-
scheme *internalScheme.Client
80+
scheme *xsync.Once[*internalScheme.Client]
8181
schemeOptions []schemeConfig.Option
8282

83-
coordination *internalCoordination.Client
83+
coordination *xsync.Once[*internalCoordination.Client]
8484
coordinationOptions []coordinationConfig.Option
8585

86-
ratelimiter *internalRatelimiter.Client
86+
ratelimiter *xsync.Once[*internalRatelimiter.Client]
8787
ratelimiterOptions []ratelimiterConfig.Option
8888

89-
topic *topicclientinternal.Client
89+
topic *xsync.Once[*topicclientinternal.Client]
9090
topicOptions []topicoptions.TopicOption
9191

9292
databaseSQLOptions []xsql.ConnectorOption
@@ -184,7 +184,7 @@ func (d *Driver) Secure() bool {
184184

185185
// Table returns table client
186186
func (d *Driver) Table() table.Client {
187-
return d.table
187+
return d.table.Get()
188188
}
189189

190190
// Query returns query client
@@ -193,37 +193,37 @@ func (d *Driver) Table() table.Client {
193193
//
194194
// Notice: This API is EXPERIMENTAL and may be changed or removed in a later release.
195195
func (d *Driver) Query() query.Client {
196-
return d.query
196+
return d.query.Get()
197197
}
198198

199199
// Scheme returns scheme client
200200
func (d *Driver) Scheme() scheme.Client {
201-
return d.scheme
201+
return d.scheme.Get()
202202
}
203203

204204
// Coordination returns coordination client
205205
func (d *Driver) Coordination() coordination.Client {
206-
return d.coordination
206+
return d.coordination.Get()
207207
}
208208

209209
// Ratelimiter returns ratelimiter client
210210
func (d *Driver) Ratelimiter() ratelimiter.Client {
211-
return d.ratelimiter
211+
return d.ratelimiter.Get()
212212
}
213213

214214
// Discovery returns discovery client
215215
func (d *Driver) Discovery() discovery.Client {
216-
return d.discovery
216+
return d.discovery.Get()
217217
}
218218

219219
// Scripting returns scripting client
220220
func (d *Driver) Scripting() scripting.Client {
221-
return d.scripting
221+
return d.scripting.Get()
222222
}
223223

224224
// Topic returns topic client
225225
func (d *Driver) Topic() topic.Client {
226-
return d.topic
226+
return d.topic.Get()
227227
}
228228

229229
// Open connects to database by DSN and return driver runtime holder
@@ -400,138 +400,133 @@ func (d *Driver) connect(ctx context.Context) (err error) {
400400
return xerrors.WithStackTrace(err)
401401
}
402402

403-
d.table, err = internalTable.New(ctx,
404-
d.balancer,
405-
tableConfig.New(
406-
append(
407-
// prepend common params from root config
408-
[]tableConfig.Option{
409-
tableConfig.With(d.config.Common),
410-
},
411-
d.tableOptions...,
412-
)...,
413-
),
414-
)
415-
if err != nil {
416-
return xerrors.WithStackTrace(err)
417-
}
403+
d.table = xsync.OnceValue(func() *internalTable.Client {
404+
return internalTable.New(xcontext.WithoutDeadline(ctx),
405+
d.balancer,
406+
tableConfig.New(
407+
append(
408+
// prepend common params from root config
409+
[]tableConfig.Option{
410+
tableConfig.With(d.config.Common),
411+
},
412+
d.tableOptions...,
413+
)...,
414+
),
415+
)
416+
})
418417

419-
d.query, err = internalQuery.New(ctx,
420-
d.balancer,
421-
queryConfig.New(
422-
append(
423-
// prepend common params from root config
424-
[]queryConfig.Option{
425-
queryConfig.With(d.config.Common),
426-
},
427-
d.queryOptions...,
428-
)...,
429-
),
430-
)
418+
d.query = xsync.OnceValue(func() *internalQuery.Client {
419+
return internalQuery.New(xcontext.WithoutDeadline(ctx),
420+
d.balancer,
421+
queryConfig.New(
422+
append(
423+
// prepend common params from root config
424+
[]queryConfig.Option{
425+
queryConfig.With(d.config.Common),
426+
},
427+
d.queryOptions...,
428+
)...,
429+
),
430+
)
431+
})
431432
if err != nil {
432433
return xerrors.WithStackTrace(err)
433434
}
434435

435-
d.scheme, err = internalScheme.New(ctx,
436-
d.balancer,
437-
schemeConfig.New(
438-
append(
439-
// prepend common params from root config
440-
[]schemeConfig.Option{
441-
schemeConfig.WithDatabaseName(d.Name()),
442-
schemeConfig.With(d.config.Common),
443-
},
444-
d.schemeOptions...,
445-
)...,
446-
),
447-
)
448-
if err != nil {
449-
return xerrors.WithStackTrace(err)
450-
}
436+
d.scheme = xsync.OnceValue(func() *internalScheme.Client {
437+
return internalScheme.New(xcontext.WithoutDeadline(ctx),
438+
d.balancer,
439+
schemeConfig.New(
440+
append(
441+
// prepend common params from root config
442+
[]schemeConfig.Option{
443+
schemeConfig.WithDatabaseName(d.Name()),
444+
schemeConfig.With(d.config.Common),
445+
},
446+
d.schemeOptions...,
447+
)...,
448+
),
449+
)
450+
})
451451

452-
d.coordination, err = internalCoordination.New(ctx,
453-
d.balancer,
454-
coordinationConfig.New(
455-
append(
456-
// prepend common params from root config
457-
[]coordinationConfig.Option{
458-
coordinationConfig.With(d.config.Common),
459-
},
460-
d.coordinationOptions...,
461-
)...,
462-
),
463-
)
464-
if err != nil {
465-
return xerrors.WithStackTrace(err)
466-
}
452+
d.coordination = xsync.OnceValue(func() *internalCoordination.Client {
453+
return internalCoordination.New(xcontext.WithoutDeadline(ctx),
454+
d.balancer,
455+
coordinationConfig.New(
456+
append(
457+
// prepend common params from root config
458+
[]coordinationConfig.Option{
459+
coordinationConfig.With(d.config.Common),
460+
},
461+
d.coordinationOptions...,
462+
)...,
463+
),
464+
)
465+
})
467466

468-
d.ratelimiter, err = internalRatelimiter.New(ctx,
469-
d.balancer,
470-
ratelimiterConfig.New(
471-
append(
472-
// prepend common params from root config
473-
[]ratelimiterConfig.Option{
474-
ratelimiterConfig.With(d.config.Common),
475-
},
476-
d.ratelimiterOptions...,
477-
)...,
478-
),
479-
)
480-
if err != nil {
481-
return xerrors.WithStackTrace(err)
482-
}
467+
d.ratelimiter = xsync.OnceValue(func() *internalRatelimiter.Client {
468+
return internalRatelimiter.New(xcontext.WithoutDeadline(ctx),
469+
d.balancer,
470+
ratelimiterConfig.New(
471+
append(
472+
// prepend common params from root config
473+
[]ratelimiterConfig.Option{
474+
ratelimiterConfig.With(d.config.Common),
475+
},
476+
d.ratelimiterOptions...,
477+
)...,
478+
),
479+
)
480+
})
483481

484-
d.discovery, err = internalDiscovery.New(ctx,
485-
d.pool.Get(endpoint.New(d.config.Endpoint())),
486-
discoveryConfig.New(
487-
append(
488-
// prepend common params from root config
489-
[]discoveryConfig.Option{
490-
discoveryConfig.With(d.config.Common),
491-
discoveryConfig.WithEndpoint(d.Endpoint()),
492-
discoveryConfig.WithDatabase(d.Name()),
493-
discoveryConfig.WithSecure(d.Secure()),
494-
discoveryConfig.WithMeta(d.config.Meta()),
495-
},
496-
d.discoveryOptions...,
497-
)...,
498-
),
499-
)
500-
if err != nil {
501-
return xerrors.WithStackTrace(err)
502-
}
482+
d.discovery = xsync.OnceValue(func() *internalDiscovery.Client {
483+
return internalDiscovery.New(xcontext.WithoutDeadline(ctx),
484+
d.pool.Get(endpoint.New(d.config.Endpoint())),
485+
discoveryConfig.New(
486+
append(
487+
// prepend common params from root config
488+
[]discoveryConfig.Option{
489+
discoveryConfig.With(d.config.Common),
490+
discoveryConfig.WithEndpoint(d.Endpoint()),
491+
discoveryConfig.WithDatabase(d.Name()),
492+
discoveryConfig.WithSecure(d.Secure()),
493+
discoveryConfig.WithMeta(d.config.Meta()),
494+
},
495+
d.discoveryOptions...,
496+
)...,
497+
),
498+
)
499+
})
500+
501+
d.scripting = xsync.OnceValue(func() *internalScripting.Client {
502+
return internalScripting.New(xcontext.WithoutDeadline(ctx),
503+
d.balancer,
504+
scriptingConfig.New(
505+
append(
506+
// prepend common params from root config
507+
[]scriptingConfig.Option{
508+
scriptingConfig.With(d.config.Common),
509+
},
510+
d.scriptingOptions...,
511+
)...,
512+
),
513+
)
514+
})
503515

504-
d.scripting, err = internalScripting.New(ctx,
505-
d.balancer,
506-
scriptingConfig.New(
516+
d.topic = xsync.OnceValue(func() *topicclientinternal.Client {
517+
return topicclientinternal.New(xcontext.WithoutDeadline(ctx),
518+
d.balancer,
519+
d.config.Credentials(),
507520
append(
508521
// prepend common params from root config
509-
[]scriptingConfig.Option{
510-
scriptingConfig.With(d.config.Common),
522+
[]topicoptions.TopicOption{
523+
topicoptions.WithOperationTimeout(d.config.OperationTimeout()),
524+
topicoptions.WithOperationCancelAfter(d.config.OperationCancelAfter()),
511525
},
512-
d.scriptingOptions...,
526+
d.topicOptions...,
513527
)...,
514-
),
515-
)
516-
if err != nil {
517-
return xerrors.WithStackTrace(err)
518-
}
519-
520-
d.topic, err = topicclientinternal.New(ctx,
521-
d.balancer,
522-
d.config.Credentials(),
523-
append(
524-
// prepend common params from root config
525-
[]topicoptions.TopicOption{
526-
topicoptions.WithOperationTimeout(d.config.OperationTimeout()),
527-
topicoptions.WithOperationCancelAfter(d.config.OperationCancelAfter()),
528-
},
529-
d.topicOptions...,
530-
)...,
531-
)
532-
if err != nil {
533-
return xerrors.WithStackTrace(err)
534-
}
528+
)
529+
})
535530

536531
return nil
537532
}

0 commit comments

Comments
 (0)