Skip to content

Commit 13b0904

Browse files
committed
switched internal/table.Client from container/list to internal/xlist
1 parent f9d7a12 commit 13b0904

File tree

2 files changed

+16
-32
lines changed

2 files changed

+16
-32
lines changed

internal/table/client.go

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package table
22

33
import (
4-
"container/list"
54
"context"
65
"fmt"
76
"sync"
@@ -15,6 +14,7 @@ import (
1514
"github.com/ydb-platform/ydb-go-sdk/v3/internal/table/config"
1615
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
1716
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
17+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xlist"
1818
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsync"
1919
"github.com/ydb-platform/ydb-go-sdk/v3/meta"
2020
"github.com/ydb-platform/ydb-go-sdk/v3/retry"
@@ -50,8 +50,8 @@ func newClient(
5050
cc: cc,
5151
build: builder,
5252
index: make(map[*session]sessionInfo),
53-
idle: list.New(),
54-
waitQ: list.New(),
53+
idle: xlist.New[*session](),
54+
waitQ: xlist.New[*chan *session](),
5555
limit: config.SizeLimit(),
5656
waitChPool: sync.Pool{
5757
New: func() interface{} {
@@ -82,10 +82,10 @@ type Client struct {
8282
// read-write fields
8383
mu xsync.Mutex
8484
index map[*session]sessionInfo
85-
createInProgress int // KIKIMR-9163: in-create-process counter
86-
limit int // Upper bound for Client size.
87-
idle *list.List // list<*session>
88-
waitQ *list.List // list<*chan *session>
85+
createInProgress int // KIKIMR-9163: in-create-process counter
86+
limit int // Upper bound for Client size.
87+
idle *xlist.List[*session]
88+
waitQ *xlist.List[*chan *session]
8989
waitChPool sync.Pool
9090
testHookGetWaitCh func() // nil except some tests.
9191
wg sync.WaitGroup
@@ -484,7 +484,7 @@ func (c *Client) Get(ctx context.Context) (s *session, err error) {
484484
func (c *Client) internalPoolWaitFromCh(ctx context.Context, t *trace.Table) (s *session, err error) {
485485
var (
486486
ch *chan *session
487-
el *list.Element // Element in the wait queue.
487+
el *xlist.Element[*chan *session] // Element in the wait queue.
488488
ok bool
489489
)
490490

@@ -626,18 +626,11 @@ func (c *Client) Close(ctx context.Context) (err error) {
626626
c.limit = 0
627627

628628
for el := c.waitQ.Front(); el != nil; el = el.Next() {
629-
ch, ok := el.Value.(*chan *session)
630-
if !ok {
631-
panic(fmt.Sprintf("unsupported type conversion from %T to *chan *session", ch))
632-
}
633-
close(*ch)
629+
close(*el.Value)
634630
}
635631

636632
for e := c.idle.Front(); e != nil; e = e.Next() {
637-
s, ok := e.Value.(*session)
638-
if !ok {
639-
panic(fmt.Sprintf("unsupported type conversion from %T to *session", s))
640-
}
633+
s := e.Value
641634
s.SetStatus(table.SessionClosing)
642635
c.wg.Add(1)
643636
go func() {
@@ -765,10 +758,7 @@ func (c *Client) internalPoolGCTick(ctx context.Context, idleThreshold time.Dura
765758
return
766759
}
767760
for e := c.idle.Front(); e != nil; e = e.Next() {
768-
s, ok := e.Value.(*session)
769-
if !ok {
770-
panic(fmt.Sprintf("unsupported type conversion from %T to *session", s))
771-
}
761+
s := e.Value
772762
info, has := c.index[s]
773763
if !has {
774764
panic("session not found in pool")
@@ -841,10 +831,7 @@ func (c *Client) internalPoolPeekFirstIdle() (s *session, touched time.Time) {
841831
if el == nil {
842832
return
843833
}
844-
s, ok := el.Value.(*session)
845-
if !ok {
846-
panic(fmt.Sprintf("unsupported type conversion from %T to *session", s))
847-
}
834+
s = el.Value
848835
info, has := c.index[s]
849836
if !has || el != info.idle {
850837
panic("inconsistent session client index")
@@ -883,10 +870,7 @@ func (c *Client) internalPoolNotify(s *session) (notified bool) {
883870
// missed something and may want to retry (especially for case (3)).
884871
//
885872
// After that we taking a next waiter and repeat the same.
886-
ch, ok := c.waitQ.Remove(el).(*chan *session)
887-
if !ok {
888-
panic(fmt.Sprintf("unsupported type conversion from %T to *chan *session", ch))
889-
}
873+
ch := c.waitQ.Remove(el)
890874
select {
891875
case *ch <- s:
892876
// Case (1).
@@ -933,7 +917,7 @@ func (c *Client) internalPoolPushIdle(s *session, now time.Time) {
933917
}
934918

935919
// c.mu must be held.
936-
func (c *Client) internalPoolHandlePushIdle(s *session, now time.Time, el *list.Element) {
920+
func (c *Client) internalPoolHandlePushIdle(s *session, now time.Time, el *xlist.Element[*session]) {
937921
info, has := c.index[s]
938922
if !has {
939923
panic("trying to store session created outside of the client")
@@ -948,6 +932,6 @@ func (c *Client) internalPoolHandlePushIdle(s *session, now time.Time, el *list.
948932
}
949933

950934
type sessionInfo struct {
951-
idle *list.Element
935+
idle *xlist.Element[*session]
952936
touched time.Time
953937
}

internal/table/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ func (s *StubBuilder) createSession(ctx context.Context) (session *session, err
912912
func (c *Client) debug() {
913913
fmt.Print("head ")
914914
for el := c.idle.Front(); el != nil; el = el.Next() {
915-
s := el.Value.(*session)
915+
s := el.Value
916916
x := c.index[s]
917917
fmt.Printf("<-> %s(%d) ", s.ID(), x.touched.Unix())
918918
}

0 commit comments

Comments
 (0)