@@ -14,36 +14,7 @@ import (
1414 "github.com/ydb-platform/ydb-go-sdk/v3/trace"
1515)
1616
17- type Pool interface {
18- Getter
19- Taker
20- Releaser
21- Pessimizer
22- }
23-
24- type Getter interface {
25- Get (endpoint endpoint.Endpoint ) Conn
26- }
27-
28- type Taker interface {
29- Take (ctx context.Context ) error
30- }
31-
32- type Releaser interface {
33- Release (ctx context.Context ) error
34- }
35-
36- type Pessimizer interface {
37- Pessimize (ctx context.Context , cc Conn , cause error )
38- Unpessimize (ctx context.Context , cc Conn )
39- }
40-
41- type PoolConfig interface {
42- ConnectionTTL () time.Duration
43- GrpcDialOptions () []grpc.DialOption
44- }
45-
46- type pool struct {
17+ type Pool struct {
4718 usages int64
4819 config Config
4920 mtx sync.RWMutex
@@ -52,7 +23,7 @@ type pool struct {
5223 done chan struct {}
5324}
5425
55- func (p * pool ) Get (endpoint endpoint.Endpoint ) Conn {
26+ func (p * Pool ) Get (endpoint endpoint.Endpoint ) Conn {
5627 p .mtx .Lock ()
5728 defer p .mtx .Unlock ()
5829
@@ -73,13 +44,13 @@ func (p *pool) Get(endpoint endpoint.Endpoint) Conn {
7344 return cc
7445}
7546
76- func (p * pool ) remove (c * conn ) {
47+ func (p * Pool ) remove (c * conn ) {
7748 p .mtx .Lock ()
7849 defer p .mtx .Unlock ()
7950 delete (p .conns , c .Endpoint ().Address ())
8051}
8152
82- func (p * pool ) Pessimize (ctx context.Context , cc Conn , cause error ) {
53+ func (p * Pool ) Ban (ctx context.Context , cc Conn , cause error ) {
8354 e := cc .Endpoint ().Copy ()
8455
8556 p .mtx .RLock ()
@@ -90,7 +61,7 @@ func (p *pool) Pessimize(ctx context.Context, cc Conn, cause error) {
9061 return
9162 }
9263
93- trace .DriverOnPessimizeNode (
64+ trace .DriverOnConnBan (
9465 p .config .Trace (),
9566 & ctx ,
9667 e ,
@@ -99,7 +70,7 @@ func (p *pool) Pessimize(ctx context.Context, cc Conn, cause error) {
9970 )(cc .SetState (Banned ))
10071}
10172
102- func (p * pool ) Unpessimize (ctx context.Context , cc Conn ) {
73+ func (p * Pool ) Allow (ctx context.Context , cc Conn ) {
10374 e := cc .Endpoint ().Copy ()
10475
10576 p .mtx .RLock ()
@@ -110,19 +81,19 @@ func (p *pool) Unpessimize(ctx context.Context, cc Conn) {
11081 return
11182 }
11283
113- trace .DriverOnUnpessimizeNode (p .config .Trace (),
84+ trace .DriverOnConnAllow (p .config .Trace (),
11485 & ctx ,
11586 e ,
11687 cc .GetState (),
11788 )(cc .SetState (Online ))
11889}
11990
120- func (p * pool ) Take (context.Context ) error {
91+ func (p * Pool ) Take (context.Context ) error {
12192 atomic .AddInt64 (& p .usages , 1 )
12293 return nil
12394}
12495
125- func (p * pool ) Release (ctx context.Context ) error {
96+ func (p * Pool ) Release (ctx context.Context ) error {
12697 if atomic .AddInt64 (& p .usages , - 1 ) > 0 {
12798 return nil
12899 }
@@ -150,7 +121,7 @@ func (p *pool) Release(ctx context.Context) error {
150121 return nil
151122}
152123
153- func (p * pool ) connParker (ctx context.Context , ttl , interval time.Duration ) {
124+ func (p * Pool ) connParker (ctx context.Context , ttl , interval time.Duration ) {
154125 ticker := time .NewTicker (interval )
155126 defer ticker .Stop ()
156127 for {
@@ -172,7 +143,7 @@ func (p *pool) connParker(ctx context.Context, ttl, interval time.Duration) {
172143 }
173144}
174145
175- func (p * pool ) collectConns () []* conn {
146+ func (p * Pool ) collectConns () []* conn {
176147 p .mtx .RLock ()
177148 defer p .mtx .RUnlock ()
178149 conns := make ([]* conn , 0 , len (p .conns ))
@@ -185,8 +156,8 @@ func (p *pool) collectConns() []*conn {
185156func NewPool (
186157 ctx context.Context ,
187158 config Config ,
188- ) Pool {
189- p := & pool {
159+ ) * Pool {
160+ p := & Pool {
190161 usages : 1 ,
191162 config : config ,
192163 opts : config .GrpcDialOptions (),
0 commit comments