Skip to content

Commit d2a5acb

Browse files
committed
* Fixed bug with fail cast of grpc response to operation.{Response,Status}
1 parent b8f9bed commit d2a5acb

File tree

6 files changed

+33
-47
lines changed

6 files changed

+33
-47
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Fixed bug with fail cast of grpc response to `operation.{Response,Status}`
2+
13
## v3.74.3
24
* Removed check the node is available for query and table service sessions
35
* Refactored the `balancers.PreferLocations()` function - it is a clean/pure function

internal/conn/conn.go

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
"github.com/ydb-platform/ydb-go-sdk/v3/internal/endpoint"
1717
"github.com/ydb-platform/ydb-go-sdk/v3/internal/meta"
18-
"github.com/ydb-platform/ydb-go-sdk/v3/internal/response"
18+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/operation"
1919
"github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
2020
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
2121
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
@@ -364,35 +364,36 @@ func (c *conn) Invoke(
364364
return err
365365
}
366366

367-
err = c.handleResponse(res, &opID, &issues, traceID, useWrapping)
368-
if err != nil {
369-
return err
370-
}
371-
372-
return err
373-
}
374-
375-
func (c *conn) handleResponse(
376-
res interface{},
377-
opID *string,
378-
issues *[]trace.Issue,
379-
traceID string,
380-
useWrapping bool,
381-
) error {
382-
if o, ok := res.(response.Response); ok {
383-
*opID = o.GetOperation().GetId()
384-
for _, issue := range o.GetOperation().GetIssues() {
385-
*issues = append(*issues, issue)
367+
switch t := res.(type) {
368+
case operation.Response:
369+
opID = t.GetOperation().GetId()
370+
for _, issue := range t.GetOperation().GetIssues() {
371+
issues = append(issues, issue)
386372
}
387373
if useWrapping {
388374
switch {
389-
case !o.GetOperation().GetReady():
375+
case !t.GetOperation().GetReady():
390376
return c.wrapError(errOperationNotReady)
391377

392-
case o.GetOperation().GetStatus() != Ydb.StatusIds_SUCCESS:
378+
case t.GetOperation().GetStatus() != Ydb.StatusIds_SUCCESS:
379+
return c.wrapError(
380+
xerrors.Operation(
381+
xerrors.FromOperation(t.GetOperation()),
382+
xerrors.WithAddress(c.Address()),
383+
xerrors.WithTraceID(traceID),
384+
),
385+
)
386+
}
387+
}
388+
case operation.Status:
389+
for _, issue := range t.GetIssues() {
390+
issues = append(issues, issue)
391+
}
392+
if useWrapping {
393+
if t.GetStatus() != Ydb.StatusIds_SUCCESS {
393394
return c.wrapError(
394395
xerrors.Operation(
395-
xerrors.FromOperation(o.GetOperation()),
396+
xerrors.FromOperation(t),
396397
xerrors.WithAddress(c.Address()),
397398
xerrors.WithTraceID(traceID),
398399
),

internal/conn/grpc_client_stream.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"google.golang.org/grpc/metadata"
1010

1111
"github.com/ydb-platform/ydb-go-sdk/v3/internal/meta"
12+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/operation"
1213
"github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
13-
"github.com/ydb-platform/ydb-go-sdk/v3/internal/wrap"
1414
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
1515
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
1616
)
@@ -173,7 +173,7 @@ func (s *grpcClientStream) RecvMsg(m interface{}) (err error) {
173173
}
174174

175175
if s.wrapping {
176-
if operation, ok := m.(wrap.StreamOperationResponse); ok {
176+
if operation, ok := m.(operation.Status); ok {
177177
if status := operation.GetStatus(); status != Ydb.StatusIds_SUCCESS {
178178
return s.wrapError(
179179
xerrors.Operation(

internal/grpcwrapper/rawtopic/describe_topic.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawscheme"
1111
"github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic/rawtopiccommon"
1212
"github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawydb"
13+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/operation"
1314
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
1415
)
1516

@@ -41,13 +42,13 @@ type DescribeTopicResult struct {
4142
MeteringMode MeteringMode
4243
}
4344

44-
func (res *DescribeTopicResult) FromProto(protoResponse *Ydb_Topic.DescribeTopicResponse) error {
45-
if err := res.Operation.FromProtoWithStatusCheck(protoResponse.GetOperation()); err != nil {
45+
func (res *DescribeTopicResult) FromProto(response operation.Response) error {
46+
if err := res.Operation.FromProtoWithStatusCheck(response.GetOperation()); err != nil {
4647
return err
4748
}
4849

4950
protoResult := &Ydb_Topic.DescribeTopicResult{}
50-
if err := protoResponse.GetOperation().GetResult().UnmarshalTo(protoResult); err != nil {
51+
if err := response.GetOperation().GetResult().UnmarshalTo(protoResult); err != nil {
5152
return xerrors.WithStackTrace(fmt.Errorf("ydb: describe topic result failed on unmarshal grpc result: %w", err))
5253
}
5354

internal/response/response.go renamed to internal/operation/response.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package response
1+
package operation
22

33
import "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Operations"
44

internal/wrap/wrap.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)