44 "container/list"
55 "context"
66 "fmt"
7- "github.com/ydb-platform/ydb-go-sdk/v3/internal/endpoint"
8- "math"
9- "sort"
107 "sync"
118 "sync/atomic"
129 "time"
@@ -49,14 +46,13 @@ func newClient(
4946 onDone = trace .TableOnInit (config .Trace (), & ctx )
5047 )
5148 c := & Client {
52- config : config ,
53- cc : cc ,
54- build : builder ,
55- index : make (map [* session ]sessionInfo ),
56- nodeLoading : make (map [uint32 ]int ),
57- idle : list .New (),
58- waitq : list .New (),
59- limit : config .SizeLimit (),
49+ config : config ,
50+ cc : cc ,
51+ build : builder ,
52+ index : make (map [* session ]sessionInfo ),
53+ idle : list .New (),
54+ waitq : list .New (),
55+ limit : config .SizeLimit (),
6056 waitChPool : sync.Pool {
6157 New : func () interface {} {
6258 ch := make (chan * session )
@@ -83,11 +79,10 @@ type Client struct {
8379 cc grpc.ClientConnInterface
8480 config config.Config
8581 index map [* session ]sessionInfo
86- createInProgress int // KIKIMR-9163: in-create-process counter
87- limit int // Upper bound for Client size.
88- idle * list.List // list<table.session>
89- waitq * list.List // list<*chan table.session>
90- nodeLoading map [uint32 ]int
82+ createInProgress int // KIKIMR-9163: in-create-process counter
83+ limit int // Upper bound for Client size.
84+ idle * list.List // list<table.session>
85+ waitq * list.List // list<*chan table.session>
9186 keeperWake chan struct {} // Set by internalPoolKeeper.
9287 keeperStop chan struct {}
9388 keeperDone chan struct {}
@@ -127,8 +122,6 @@ func (c *Client) CreateSession(ctx context.Context, opts ...table.Option) (_ tab
127122 defer cancel ()
128123 }
129124
130- createSessionCtx = balancer .WithNodeID (createSessionCtx , c .nextNodeID ())
131-
132125 s , err = c .build (createSessionCtx )
133126
134127 select {
@@ -161,21 +154,6 @@ func (c *Client) CreateSession(ctx context.Context, opts ...table.Option) (_ tab
161154 }
162155 }
163156 var s * session
164- defer func () {
165- if s != nil {
166- c .mu .WithLock (func () {
167- c .nodeLoading [s .NodeID ()]++
168- })
169- s .onClose = append (s .onClose , func (s * session ) {
170- c .mu .WithLock (func () {
171- nodeID := s .NodeID ()
172- if _ , has := c .nodeLoading [nodeID ]; has {
173- c .nodeLoading [nodeID ]--
174- }
175- })
176- })
177- }
178- }()
179157 if ! c .config .AutoRetry () {
180158 s , err = createSession (ctx )
181159 if err != nil {
@@ -219,28 +197,10 @@ func (c *Client) isClosed() bool {
219197 return atomic .LoadUint32 (& c .closed ) != 0
220198}
221199
222- func (c * Client ) nextNodeID () (nodeID uint32 ) {
223- nodeID = math .MaxUint32
224- c .mu .WithLock (func () {
225- min := math .MaxInt
226- for id , count := range c .nodeLoading {
227- if count < min {
228- min = count
229- nodeID = id
230- }
231- }
232- fmt .Println ("nextNodeID =" , nodeID , "min =" , min )
233- })
234- return nodeID
235- }
236-
237200// c.mu must NOT be held.
238201func (c * Client ) internalPoolCreateSession (ctx context.Context ) (s * session , err error ) {
239202 defer func () {
240203 if s != nil {
241- c .mu .WithLock (func () {
242- c .nodeLoading [s .NodeID ()]++
243- })
244204 s .onClose = append (s .onClose , func (s * session ) {
245205 c .spawnedGoroutines .Start ("onClose" , func (ctx context.Context ) {
246206 c .mu .WithLock (func () {
@@ -259,11 +219,6 @@ func (c *Client) internalPoolCreateSession(ctx context.Context) (s *session, err
259219 if info .idle != nil {
260220 c .idle .Remove (info .idle )
261221 }
262-
263- nodeID := s .NodeID ()
264- if _ , has := c .nodeLoading [nodeID ]; has {
265- c .nodeLoading [nodeID ]--
266- }
267222 })
268223 })
269224 })
@@ -308,8 +263,6 @@ func (c *Client) internalPoolCreateSession(ctx context.Context) (s *session, err
308263 defer cancel ()
309264 }
310265
311- createSessionCtx = balancer .WithNodeID (createSessionCtx , c .nextNodeID ())
312-
313266 s , err = c .build (createSessionCtx )
314267 if s == nil && err == nil {
315268 panic ("ydb: abnormal result of session build" )
@@ -321,8 +274,6 @@ func (c *Client) internalPoolCreateSession(ctx context.Context) (s *session, err
321274 c .index [s ] = sessionInfo {}
322275 trace .TableOnPoolSessionAdd (c .config .Trace (), s )
323276 trace .TableOnPoolStateChange (c .config .Trace (), len (c .index ), "append" )
324- c .nodeLoading [s .NodeID ()]++
325- fmt .Printf ("c.nodeLoading: %v" , c .nodeLoading )
326277 }
327278 })
328279
@@ -356,28 +307,6 @@ func (c *Client) internalPoolCreateSession(ctx context.Context) (s *session, err
356307 }
357308}
358309
359- func (c * Client ) UpdateNodes (nodes []endpoint.Info ) {
360- sort .Slice (nodes , func (i , j int ) bool {
361- return nodes [i ].NodeID () < nodes [j ].NodeID ()
362- })
363- c .mu .WithLock (func () {
364- for _ , node := range nodes {
365- nodeID := node .NodeID ()
366- if _ , has := c .nodeLoading [nodeID ]; ! has {
367- c .nodeLoading [nodeID ] = 0
368- }
369- }
370- nodeLoading := c .nodeLoading
371- for nodeID := range nodeLoading {
372- if sort .Search (len (nodes ), func (i int ) bool {
373- return nodes [i ].NodeID () <= nodeID
374- }) < len (nodes ) {
375- delete (c .nodeLoading , nodeID )
376- }
377- }
378- })
379- }
380-
381310type getOptions struct {
382311 t trace.Table
383312}
0 commit comments