Skip to content

Commit eed2391

Browse files
authored
Merge branch 'slack-22.0' into tanjin-scatter-update-limit-optout
2 parents 2373013 + a20d887 commit eed2391

18 files changed

Lines changed: 487 additions & 36 deletions

File tree

go/flags/endtoend/vtcombo.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Flags:
4444
--config-path strings Paths to search for config files in. (default [{{ .Workdir }}])
4545
--config-persistence-min-interval duration minimum interval between persisting dynamic config changes back to disk (if no change has occurred, nothing is done). (default 1s)
4646
--config-type string Config file type (omit to infer config type from file extension).
47+
--consolidator-cache-proto3-rows If true, the consolidation leader pre-caches proto3-encoded rows so that waiters avoid redundant encoding work.
4748
--consolidator-query-waiter-cap int Configure the maximum number of clients allowed to wait on the consolidator.
4849
--consolidator-query-waiter-cap-method string Configure the method when consolidator waiter cap is exceeded. Options: fallthrough, reject. (default "fallthrough")
4950
--consolidator-stream-query-size int Configure the stream consolidator query size in bytes. Setting to 0 disables the stream consolidator. (default 2097152)
@@ -295,20 +296,23 @@ Flags:
295296
--queryserver-config-query-cache-memory int query server query cache size in bytes, maximum amount of memory to be used for caching. vttablet analyzes every incoming query and generate a query plan, these plans are being cached in a lru cache. This config controls the capacity of the lru cache. (default 33554432)
296297
--queryserver-config-query-pool-max-idle-count int query server query pool - maximum number of idle connections to retain in the pool. Use this to balance between faster response times during traffic bursts and resource efficiency during low-traffic periods.
297298
--queryserver-config-query-pool-timeout duration query server query pool timeout, it is how long vttablet waits for a connection from the query pool. If set to 0 (default) then the overall query timeout is used instead.
299+
--queryserver-config-query-pool-waiter-cap uint query server query pool waiter cap is the maximum number of queries allowed to wait for a connection from the pool. If set to 0 (default) then there is no limit.
298300
--queryserver-config-query-timeout duration query server query timeout, this is the query timeout in vttablet side. If a query takes more than this timeout, it will be killed. (default 30s)
299301
--queryserver-config-schema-change-signal query server schema signal, will signal connected vtgates that schema has changed whenever this is detected. VTGates will need to have -schema_change_signal enabled for this to work (default true)
300302
--queryserver-config-schema-reload-time duration query server schema reload time, how often vttablet reloads schemas from underlying MySQL instance. vttablet keeps table schemas in its own memory and periodically refreshes it from MySQL. This config controls the reload time. (default 30m0s)
301303
--queryserver-config-stream-buffer-size int query server stream buffer size, the maximum number of bytes sent from vttablet for each stream call. It's recommended to keep this value in sync with vtgate's stream_buffer_size. (default 32768)
302304
--queryserver-config-stream-pool-max-idle-count int query server stream pool - maximum number of idle connections to retain in the pool. Use this to balance between faster response times during traffic bursts and resource efficiency during low-traffic periods.
303305
--queryserver-config-stream-pool-size int query server stream connection pool size, stream pool is used by stream queries: queries that return results to client in a streaming fashion (default 200)
304306
--queryserver-config-stream-pool-timeout duration query server stream pool timeout, it is how long vttablet waits for a connection from the stream pool. If set to 0 (default) then there is no timeout.
307+
--queryserver-config-stream-pool-waiter-cap uint query server stream pool waiter cap is the maximum number of streaming queries allowed to wait for a connection from the pool. If set to 0 (default) then there is no limit.
305308
--queryserver-config-strict-table-acl only allow queries that pass table acl checks
306309
--queryserver-config-terse-errors prevent bind vars from escaping in client error messages
307310
--queryserver-config-transaction-cap int query server transaction cap is the maximum number of transactions allowed to happen at any given point of a time for a single vttablet. E.g. by setting transaction cap to 100, there are at most 100 transactions will be processed by a vttablet and the 101th transaction will be blocked (and fail if it cannot get connection within specified timeout) (default 20)
308311
--queryserver-config-transaction-timeout duration query server transaction timeout, a transaction will be killed if it takes longer than this value (default 30s)
309312
--queryserver-config-truncate-error-len int truncate errors sent to client if they are longer than this value (0 means do not truncate)
310313
--queryserver-config-txpool-max-idle-count int query server transaction pool - maximum number of idle connections to retain in the pool. Use this to balance between faster response times during traffic bursts and resource efficiency during low-traffic periods.
311314
--queryserver-config-txpool-timeout duration query server transaction pool timeout, it is how long vttablet waits if tx pool is full (default 1s)
315+
--queryserver-config-txpool-waiter-cap uint query server transaction pool waiter cap is the maximum number of transactions allowed to wait for a connection from the pool. If set to 0 (default) then there is no limit.
312316
--queryserver-config-warn-result-size int query server result size warning threshold, warn if number of rows returned from vttablet for non-streaming queries exceeds this
313317
--queryserver-enable-views Enable views support in vttablet.
314318
--queryserver_enable_online_ddl Enable online DDL. (default true)

go/flags/endtoend/vttablet.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Flags:
7878
--config-path strings Paths to search for config files in. (default [{{ .Workdir }}])
7979
--config-persistence-min-interval duration minimum interval between persisting dynamic config changes back to disk (if no change has occurred, nothing is done). (default 1s)
8080
--config-type string Config file type (omit to infer config type from file extension).
81+
--consolidator-cache-proto3-rows If true, the consolidation leader pre-caches proto3-encoded rows so that waiters avoid redundant encoding work.
8182
--consolidator-query-waiter-cap int Configure the maximum number of clients allowed to wait on the consolidator.
8283
--consolidator-query-waiter-cap-method string Configure the method when consolidator waiter cap is exceeded. Options: fallthrough, reject. (default "fallthrough")
8384
--consolidator-stream-query-size int Configure the stream consolidator query size in bytes. Setting to 0 disables the stream consolidator. (default 2097152)
@@ -287,20 +288,23 @@ Flags:
287288
--queryserver-config-query-cache-memory int query server query cache size in bytes, maximum amount of memory to be used for caching. vttablet analyzes every incoming query and generate a query plan, these plans are being cached in a lru cache. This config controls the capacity of the lru cache. (default 33554432)
288289
--queryserver-config-query-pool-max-idle-count int query server query pool - maximum number of idle connections to retain in the pool. Use this to balance between faster response times during traffic bursts and resource efficiency during low-traffic periods.
289290
--queryserver-config-query-pool-timeout duration query server query pool timeout, it is how long vttablet waits for a connection from the query pool. If set to 0 (default) then the overall query timeout is used instead.
291+
--queryserver-config-query-pool-waiter-cap uint query server query pool waiter cap is the maximum number of queries allowed to wait for a connection from the pool. If set to 0 (default) then there is no limit.
290292
--queryserver-config-query-timeout duration query server query timeout, this is the query timeout in vttablet side. If a query takes more than this timeout, it will be killed. (default 30s)
291293
--queryserver-config-schema-change-signal query server schema signal, will signal connected vtgates that schema has changed whenever this is detected. VTGates will need to have -schema_change_signal enabled for this to work (default true)
292294
--queryserver-config-schema-reload-time duration query server schema reload time, how often vttablet reloads schemas from underlying MySQL instance. vttablet keeps table schemas in its own memory and periodically refreshes it from MySQL. This config controls the reload time. (default 30m0s)
293295
--queryserver-config-stream-buffer-size int query server stream buffer size, the maximum number of bytes sent from vttablet for each stream call. It's recommended to keep this value in sync with vtgate's stream_buffer_size. (default 32768)
294296
--queryserver-config-stream-pool-max-idle-count int query server stream pool - maximum number of idle connections to retain in the pool. Use this to balance between faster response times during traffic bursts and resource efficiency during low-traffic periods.
295297
--queryserver-config-stream-pool-size int query server stream connection pool size, stream pool is used by stream queries: queries that return results to client in a streaming fashion (default 200)
296298
--queryserver-config-stream-pool-timeout duration query server stream pool timeout, it is how long vttablet waits for a connection from the stream pool. If set to 0 (default) then there is no timeout.
299+
--queryserver-config-stream-pool-waiter-cap uint query server stream pool waiter cap is the maximum number of streaming queries allowed to wait for a connection from the pool. If set to 0 (default) then there is no limit.
297300
--queryserver-config-strict-table-acl only allow queries that pass table acl checks
298301
--queryserver-config-terse-errors prevent bind vars from escaping in client error messages
299302
--queryserver-config-transaction-cap int query server transaction cap is the maximum number of transactions allowed to happen at any given point of a time for a single vttablet. E.g. by setting transaction cap to 100, there are at most 100 transactions will be processed by a vttablet and the 101th transaction will be blocked (and fail if it cannot get connection within specified timeout) (default 20)
300303
--queryserver-config-transaction-timeout duration query server transaction timeout, a transaction will be killed if it takes longer than this value (default 30s)
301304
--queryserver-config-truncate-error-len int truncate errors sent to client if they are longer than this value (0 means do not truncate)
302305
--queryserver-config-txpool-max-idle-count int query server transaction pool - maximum number of idle connections to retain in the pool. Use this to balance between faster response times during traffic bursts and resource efficiency during low-traffic periods.
303306
--queryserver-config-txpool-timeout duration query server transaction pool timeout, it is how long vttablet waits if tx pool is full (default 1s)
307+
--queryserver-config-txpool-waiter-cap uint query server transaction pool waiter cap is the maximum number of transactions allowed to wait for a connection from the pool. If set to 0 (default) then there is no limit.
304308
--queryserver-config-warn-result-size int query server result size warning threshold, warn if number of rows returned from vttablet for non-streaming queries exceeds this
305309
--queryserver-enable-views Enable views support in vttablet.
306310
--queryserver_enable_online_ddl Enable online DDL. (default true)

go/pools/smartconnpool/pool.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package smartconnpool
1818

1919
import (
2020
"context"
21+
"errors"
2122
"math/rand/v2"
2223
"sync"
2324
"sync/atomic"
@@ -39,6 +40,9 @@ var (
3940
// ErrConnPoolClosed is returned when trying to get a connection from a closed conn pool
4041
ErrConnPoolClosed = vterrors.New(vtrpcpb.Code_INTERNAL, "connection pool is closed")
4142

43+
// ErrPoolWaiterCapReached is returned when the waiter cap has been reached
44+
ErrPoolWaiterCapReached = vterrors.New(vtrpcpb.Code_RESOURCE_EXHAUSTED, "connection pool waiter cap reached")
45+
4246
// PoolCloseTimeout is how long to wait for all connections to be returned to the pool during close
4347
PoolCloseTimeout = 10 * time.Second
4448
)
@@ -52,6 +56,7 @@ type Metrics struct {
5256
idleClosed atomic.Int64
5357
diffSetting atomic.Int64
5458
resetSetting atomic.Int64
59+
waiterCapRejected atomic.Int64
5560
}
5661

5762
func (m *Metrics) MaxLifetimeClosed() int64 {
@@ -86,6 +91,10 @@ func (m *Metrics) ResetSettingCount() int64 {
8691
return m.resetSetting.Load()
8792
}
8893

94+
func (m *Metrics) WaiterCapRejected() int64 {
95+
return m.waiterCapRejected.Load()
96+
}
97+
8998
type Connector[C Connection] func(ctx context.Context) (C, error)
9099
type RefreshCheck func() (bool, error)
91100

@@ -95,6 +104,7 @@ type Config[C Connection] struct {
95104
IdleTimeout time.Duration
96105
MaxLifetime time.Duration
97106
RefreshInterval time.Duration
107+
MaxWaiters uint
98108
LogWait func(time.Time)
99109
}
100110

@@ -149,6 +159,9 @@ type ConnPool[C Connection] struct {
149159
refreshInterval atomic.Int64
150160
// logWait is called every time a client must block waiting for a connection
151161
logWait func(time.Time)
162+
// maxWaiters is the maximum number of clients that can be waiting for a connection;
163+
// 0 means unlimited
164+
maxWaiters uint
152165
}
153166

154167
Metrics Metrics
@@ -165,7 +178,14 @@ func NewPool[C Connection](config *Config[C]) *ConnPool[C] {
165178
pool.config.idleTimeout.Store(config.IdleTimeout.Nanoseconds())
166179
pool.config.refreshInterval.Store(config.RefreshInterval.Nanoseconds())
167180
pool.config.logWait = config.LogWait
181+
pool.config.maxWaiters = config.MaxWaiters
168182
pool.wait.init()
183+
pool.wait.onWait = func() {
184+
pool.Metrics.waitCount.Add(1)
185+
}
186+
pool.wait.onWaiterCapReached = func() {
187+
pool.Metrics.waiterCapRejected.Add(1)
188+
}
169189

170190
return pool
171191
}
@@ -374,8 +394,7 @@ func (pool *ConnPool[D]) RefreshInterval() time.Duration {
374394
return time.Duration(pool.config.refreshInterval.Load())
375395
}
376396

377-
func (pool *ConnPool[C]) recordWait(start time.Time) {
378-
pool.Metrics.waitCount.Add(1)
397+
func (pool *ConnPool[C]) recordWaitDuration(start time.Time) {
379398
pool.Metrics.waitTime.Add(time.Since(start).Nanoseconds())
380399
if pool.config.logWait != nil {
381400
pool.config.logWait(start)
@@ -612,11 +631,14 @@ func (pool *ConnPool[C]) get(ctx context.Context) (*Pooled[C], error) {
612631
return nil, ErrConnPoolClosed
613632
}
614633

615-
conn, err = pool.wait.waitForConn(ctx, nil, *closeChan)
634+
conn, err = pool.wait.waitForConn(ctx, nil, *closeChan, pool.config.maxWaiters)
616635
if err != nil {
636+
if errors.Is(err, ErrPoolWaiterCapReached) {
637+
return nil, err
638+
}
617639
return nil, ErrTimeout
618640
}
619-
pool.recordWait(start)
641+
pool.recordWaitDuration(start)
620642
}
621643
// no connections available and no connections to wait for (pool is closed)
622644
if conn == nil {
@@ -675,11 +697,14 @@ func (pool *ConnPool[C]) getWithSetting(ctx context.Context, setting *Setting) (
675697
return nil, ErrConnPoolClosed
676698
}
677699

678-
conn, err = pool.wait.waitForConn(ctx, setting, *closeChan)
700+
conn, err = pool.wait.waitForConn(ctx, setting, *closeChan, pool.config.maxWaiters)
679701
if err != nil {
702+
if errors.Is(err, ErrPoolWaiterCapReached) {
703+
return nil, err
704+
}
680705
return nil, ErrTimeout
681706
}
682-
pool.recordWait(start)
707+
pool.recordWaitDuration(start)
683708
}
684709
// no connections available and no connections to wait for (pool is closed)
685710
if conn == nil {
@@ -920,6 +945,9 @@ func (pool *ConnPool[C]) RegisterStats(stats *servenv.Exporter, name string) {
920945
stats.NewCounterFunc(name+"GetSetting", "Tablet server conn pool get with setting count", func() int64 {
921946
return pool.Metrics.GetSettingCount()
922947
})
948+
stats.NewCounterFunc(name+"WaiterCapRejected", "Tablet server conn pool waiter cap rejected", func() int64 {
949+
return pool.Metrics.WaiterCapRejected()
950+
})
923951
stats.NewCounterFunc(name+"DiffSetting", "Number of times pool applied different setting", func() int64 {
924952
return pool.Metrics.DiffSettingCount()
925953
})

0 commit comments

Comments
 (0)