Skip to content

Commit b117bb2

Browse files
committed
* Renamed db.Coordination().CreateSession() to db.Coordination().Session() for compatibility with protos
1 parent 8bc29cd commit b117bb2

File tree

12 files changed

+156
-57
lines changed

12 files changed

+156
-57
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Renamed `db.Coordination().CreateSession()` to `db.Coordination().Session()` for compatibility with protos
2+
13
## v3.61.0
24
* Added `Tuple` support for `Variant` in `ydb.ParamsBuilder()`
35

coordination/coordination.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type Client interface {
1616
DropNode(ctx context.Context, path string) (err error)
1717
DescribeNode(ctx context.Context, path string) (_ *scheme.Entry, _ *NodeConfig, err error)
1818

19-
// CreateSession starts a new session. This method blocks until the server session is created. The context provided
19+
// Session starts a new session. This method blocks until the server session is created. The context provided
2020
// may be used to cancel the invocation. If the method completes successfully, the session remains alive even if
2121
// the context is canceled.
2222
//
@@ -29,7 +29,7 @@ type Client interface {
2929
// # Experimental
3030
//
3131
// Notice: This API is EXPERIMENTAL and may be changed or removed in a later release.
32-
CreateSession(ctx context.Context, path string, opts ...options.CreateSessionOption) (Session, error)
32+
Session(ctx context.Context, path string, opts ...options.SessionOption) (Session, error)
3333
}
3434

3535
const (

coordination/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func Example_semaphore() {
8181
}
8282
fmt.Printf("node description: %+v\nnode config: %+v\n", e, c)
8383

84-
s, err := db.Coordination().CreateSession(ctx, "/local/test")
84+
s, err := db.Coordination().Session(ctx, "/local/test")
8585
if err != nil {
8686
fmt.Printf("failed to create session: %v\n", err)
8787

coordination/options/options.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,70 +7,70 @@ import (
77
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Coordination"
88
)
99

10-
// WithDescription returns an CreateSessionOption that specifies a user-defined description that may be used to describe
10+
// WithDescription returns an SessionOption that specifies a user-defined description that may be used to describe
1111
// the client.
12-
func WithDescription(description string) CreateSessionOption {
12+
func WithDescription(description string) SessionOption {
1313
return func(c *CreateSessionOptions) {
1414
c.Description = description
1515
}
1616
}
1717

18-
// WithSessionTimeout returns an CreateSessionOption that specifies the timeout during which client may restore a
18+
// WithSessionTimeout returns an SessionOption that specifies the timeout during which client may restore a
1919
// detached session. The client is forced to terminate the session if the last successful session request occurred
2020
// earlier than this time.
2121
//
2222
// If this is not set, the client uses the default 5 seconds.
23-
func WithSessionTimeout(timeout time.Duration) CreateSessionOption {
23+
func WithSessionTimeout(timeout time.Duration) SessionOption {
2424
return func(c *CreateSessionOptions) {
2525
c.SessionTimeout = timeout
2626
}
2727
}
2828

29-
// WithSessionStartTimeout returns an CreateSessionOption that specifies the time that the client should wait for a
29+
// WithSessionStartTimeout returns an SessionOption that specifies the time that the client should wait for a
3030
// response to the StartSession request from the server before it terminates the gRPC stream and tries to reconnect.
3131
//
3232
// If this is not set, the client uses the default time 1 second.
33-
func WithSessionStartTimeout(timeout time.Duration) CreateSessionOption {
33+
func WithSessionStartTimeout(timeout time.Duration) SessionOption {
3434
return func(c *CreateSessionOptions) {
3535
c.SessionStartTimeout = timeout
3636
}
3737
}
3838

39-
// WithSessionStopTimeout returns an CreateSessionOption that specifies the time that the client should wait for a
39+
// WithSessionStopTimeout returns an SessionOption that specifies the time that the client should wait for a
4040
// response to the StopSession request from the server before it terminates the gRPC stream and tries to reconnect.
4141
//
4242
// If this is not set, the client uses the default time 1 second.
43-
func WithSessionStopTimeout(timeout time.Duration) CreateSessionOption {
43+
func WithSessionStopTimeout(timeout time.Duration) SessionOption {
4444
return func(c *CreateSessionOptions) {
4545
c.SessionStartTimeout = timeout
4646
}
4747
}
4848

49-
// WithSessionKeepAliveTimeout returns an CreateSessionOption that specifies the time that the client will wait before
49+
// WithSessionKeepAliveTimeout returns an SessionOption that specifies the time that the client will wait before
5050
// it terminates the gRPC stream and tries to reconnect if no successful responses have been received from the server.
5151
//
5252
// If this is not set, the client uses the default time 10 seconds.
53-
func WithSessionKeepAliveTimeout(timeout time.Duration) CreateSessionOption {
53+
func WithSessionKeepAliveTimeout(timeout time.Duration) SessionOption {
5454
return func(c *CreateSessionOptions) {
5555
c.SessionKeepAliveTimeout = timeout
5656
}
5757
}
5858

59-
// WithSessionReconnectDelay returns an CreateSessionOption that specifies the time that the client will wait before it
59+
// WithSessionReconnectDelay returns an SessionOption that specifies the time that the client will wait before it
6060
// tries to reconnect the underlying gRPC stream in case of error.
6161
//
6262
// If this is not set, the client uses the default time 500 milliseconds.
63-
func WithSessionReconnectDelay(delay time.Duration) CreateSessionOption {
63+
func WithSessionReconnectDelay(delay time.Duration) SessionOption {
6464
return func(c *CreateSessionOptions) {
6565
c.SessionReconnectDelay = delay
6666
}
6767
}
6868

69-
// CreateSessionOption configures how we create a new session.
70-
type CreateSessionOption func(c *CreateSessionOptions)
69+
// SessionOption configures how we create a new session.
70+
type SessionOption func(c *CreateSessionOptions)
7171

72-
// CreateSessionOptions configure an CreateSession call. CreateSessionOptions are set by the CreateSessionOption values
73-
// passed to the CreateSession function.
72+
// CreateSessionOptions configure an Session call. CreateSessionOptions are set by the SessionOption values
73+
// passed to the Session function.
7474
type CreateSessionOptions struct {
7575
Description string
7676
SessionTimeout time.Duration

examples/coordination/lock/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func main() {
9191
for {
9292
fmt.Println("waiting for a lock...")
9393

94-
session, err := db.Coordination().CreateSession(ctx, path)
94+
session, err := db.Coordination().Session(ctx, path)
9595
if err != nil {
9696
fmt.Println("failed to open session", err)
9797

examples/coordination/workers/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func main() {
110110

111111
fmt.Println("starting tasks")
112112
for {
113-
session, err := db.Coordination().CreateSession(ctx, path)
113+
session, err := db.Coordination().Session(ctx, path)
114114
if err != nil {
115115
fmt.Println("failed to open session", err)
116116

internal/coordination/client.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func describeNode(
299299
}, nil
300300
}
301301

302-
func newCreateSessionConfig(opts ...options.CreateSessionOption) *options.CreateSessionOptions {
302+
func newCreateSessionConfig(opts ...options.SessionOption) *options.CreateSessionOptions {
303303
c := defaultCreateSessionConfig()
304304
for _, o := range opts {
305305
if o != nil {
@@ -344,17 +344,17 @@ func defaultCreateSessionConfig() *options.CreateSessionOptions {
344344
}
345345
}
346346

347-
func (c *Client) CreateSession(
347+
func (c *Client) Session(
348348
ctx context.Context,
349349
path string,
350-
opts ...options.CreateSessionOption,
350+
opts ...options.SessionOption,
351351
) (_ coordination.Session, finalErr error) {
352352
if c == nil {
353353
return nil, xerrors.WithStackTrace(errNilClient)
354354
}
355355

356-
onDone := trace.CoordinationOnCreateSession(c.config.Trace(), &ctx,
357-
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/coordination.(*Client).CreateSession"),
356+
onDone := trace.CoordinationOnSession(c.config.Trace(), &ctx,
357+
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/coordination.(*Client).Session"),
358358
path,
359359
)
360360
defer func() {
@@ -364,17 +364,20 @@ func (c *Client) CreateSession(
364364
return createSession(ctx, c, path, newCreateSessionConfig(opts...))
365365
}
366366

367-
func (c *Client) Close(ctx context.Context) error {
367+
func (c *Client) Close(ctx context.Context) (finalErr error) {
368368
if c == nil {
369369
return xerrors.WithStackTrace(errNilClient)
370370
}
371371

372-
c.closeSessions(ctx)
372+
onDone := trace.CoordinationOnClose(c.config.Trace(), &ctx,
373+
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/coordination.(*Client).Close"),
374+
)
375+
defer func() {
376+
onDone(finalErr)
377+
}()
373378

374-
return c.close(ctx)
375-
}
379+
c.closeSessions(ctx)
376380

377-
func (c *Client) close(context.Context) error {
378381
return nil
379382
}
380383

internal/coordination/session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package coordination
33
import (
44
"context"
55
"encoding/binary"
6-
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
76
"math"
87
"math/rand"
98
"sync"
@@ -16,6 +15,7 @@ import (
1615
"github.com/ydb-platform/ydb-go-sdk/v3/coordination"
1716
"github.com/ydb-platform/ydb-go-sdk/v3/coordination/options"
1817
"github.com/ydb-platform/ydb-go-sdk/v3/internal/coordination/conversation"
18+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
1919
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
2020
)
2121

log/coordination.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,36 @@ func internalCoordination(
125125
}
126126
}
127127
},
128-
OnCreateSession: func(info trace.CoordinationCreateSessionStartInfo) func(trace.CoordinationCreateSessionDoneInfo) {
128+
OnSession: func(info trace.CoordinationSessionStartInfo) func(trace.CoordinationSessionDoneInfo) {
129129
if d.Details()&trace.CoordinationEvents == 0 {
130130
return nil
131131
}
132132
ctx := with(*info.Context, TRACE, "ydb", "coordination", "node", "describe")
133133
l.Log(ctx, "start")
134134
start := time.Now()
135135

136-
return func(info trace.CoordinationCreateSessionDoneInfo) {
136+
return func(info trace.CoordinationSessionDoneInfo) {
137+
if info.Error == nil {
138+
l.Log(WithLevel(ctx, INFO), "done",
139+
latencyField(start),
140+
)
141+
} else {
142+
l.Log(WithLevel(ctx, ERROR), "fail",
143+
latencyField(start),
144+
versionField(),
145+
)
146+
}
147+
}
148+
},
149+
OnClose: func(info trace.CoordinationCloseStartInfo) func(trace.CoordinationCloseDoneInfo) {
150+
if d.Details()&trace.CoordinationEvents == 0 {
151+
return nil
152+
}
153+
ctx := with(*info.Context, TRACE, "ydb", "coordination", "close")
154+
l.Log(ctx, "start")
155+
start := time.Now()
156+
157+
return func(info trace.CoordinationCloseDoneInfo) {
137158
if info.Error == nil {
138159
l.Log(WithLevel(ctx, INFO), "done",
139160
latencyField(start),

tests/integration/coordination_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestCoordinationSemaphore(t *testing.T) {
5353
}
5454
fmt.Printf("node description: %+v\nnode config: %+v\n", e, c)
5555

56-
s, err := db.Coordination().CreateSession(ctx, nodePath)
56+
s, err := db.Coordination().Session(ctx, nodePath)
5757
if err != nil {
5858
t.Fatalf("failed to create session: %v\n", err)
5959
}

0 commit comments

Comments
 (0)