github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/query/config/config.go (about) 1 package config 2 3 import ( 4 "time" 5 6 "github.com/jonboulle/clockwork" 7 8 "github.com/ydb-platform/ydb-go-sdk/v3/internal/config" 9 "github.com/ydb-platform/ydb-go-sdk/v3/trace" 10 ) 11 12 const ( 13 DefaultPoolDeleteTimeout = 500 * time.Millisecond 14 DefaultPoolCreateSessionTimeout = 5 * time.Second 15 DefaultPoolMaxSize = 50 16 ) 17 18 type Config struct { 19 config.Common 20 21 sizeLimit int 22 23 createSessionTimeout time.Duration 24 deleteTimeout time.Duration 25 26 trace *trace.Query 27 28 clock clockwork.Clock 29 } 30 31 func New(opts ...Option) *Config { 32 c := defaults() 33 for _, o := range opts { 34 if o != nil { 35 o(c) 36 } 37 } 38 39 return c 40 } 41 42 func defaults() *Config { 43 return &Config{ 44 sizeLimit: DefaultPoolMaxSize, 45 createSessionTimeout: DefaultPoolCreateSessionTimeout, 46 deleteTimeout: DefaultPoolDeleteTimeout, 47 clock: clockwork.NewRealClock(), 48 trace: &trace.Query{}, 49 } 50 } 51 52 // Trace defines trace over table client calls 53 func (c *Config) Trace() *trace.Query { 54 return c.trace 55 } 56 57 // Clock defines clock 58 func (c *Config) Clock() clockwork.Clock { 59 return c.clock 60 } 61 62 // PoolMaxSize is an upper bound of pooled sessions. 63 // If PoolMaxSize is less than or equal to zero then the 64 // DefaultPoolMaxSize variable is used as a limit. 65 func (c *Config) PoolMaxSize() int { 66 return c.sizeLimit 67 } 68 69 // CreateSessionTimeout limits maximum time spent on Create session request 70 func (c *Config) CreateSessionTimeout() time.Duration { 71 return c.createSessionTimeout 72 } 73 74 // DeleteTimeout limits maximum time spent on Delete request 75 // 76 // If DeleteTimeout is less than or equal to zero then the DefaultPoolDeleteTimeout is used. 77 func (c *Config) DeleteTimeout() time.Duration { 78 return c.deleteTimeout 79 }