Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* Fixed bug with fail cast of grpc response to operation.{Response,Status} #1300

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Fixed bug with fail cast of grpc response to `operation.{Response,Status}`

## v3.74.3
* Removed check the node is available for query and table service sessions
* Refactored the `balancers.PreferLocations()` function - it is a clean/pure function
Expand Down
47 changes: 24 additions & 23 deletions internal/conn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"github.com/ydb-platform/ydb-go-sdk/v3/internal/endpoint"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/meta"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/response"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/operation"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
Expand Down Expand Up @@ -364,35 +364,36 @@ func (c *conn) Invoke(
return err
}

err = c.handleResponse(res, &opID, &issues, traceID, useWrapping)
if err != nil {
return err
}

return err
}

func (c *conn) handleResponse(
res interface{},
opID *string,
issues *[]trace.Issue,
traceID string,
useWrapping bool,
) error {
if o, ok := res.(response.Response); ok {
*opID = o.GetOperation().GetId()
for _, issue := range o.GetOperation().GetIssues() {
*issues = append(*issues, issue)
switch t := res.(type) {
case operation.Response:
opID = t.GetOperation().GetId()
for _, issue := range t.GetOperation().GetIssues() {
issues = append(issues, issue)
}
if useWrapping {
switch {
case !o.GetOperation().GetReady():
case !t.GetOperation().GetReady():
return c.wrapError(errOperationNotReady)

case o.GetOperation().GetStatus() != Ydb.StatusIds_SUCCESS:
case t.GetOperation().GetStatus() != Ydb.StatusIds_SUCCESS:
return c.wrapError(
xerrors.Operation(
xerrors.FromOperation(t.GetOperation()),
xerrors.WithAddress(c.Address()),
xerrors.WithTraceID(traceID),
),
)
}
}
case operation.Status:
for _, issue := range t.GetIssues() {
issues = append(issues, issue)
}
if useWrapping {
if t.GetStatus() != Ydb.StatusIds_SUCCESS {
return c.wrapError(
xerrors.Operation(
xerrors.FromOperation(o.GetOperation()),
xerrors.FromOperation(t),
xerrors.WithAddress(c.Address()),
xerrors.WithTraceID(traceID),
),
Expand Down
4 changes: 2 additions & 2 deletions internal/conn/grpc_client_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"google.golang.org/grpc/metadata"

"github.com/ydb-platform/ydb-go-sdk/v3/internal/meta"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/operation"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/wrap"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
)
Expand Down Expand Up @@ -173,7 +173,7 @@ func (s *grpcClientStream) RecvMsg(m interface{}) (err error) {
}

if s.wrapping {
if operation, ok := m.(wrap.StreamOperationResponse); ok {
if operation, ok := m.(operation.Status); ok {
if status := operation.GetStatus(); status != Ydb.StatusIds_SUCCESS {
return s.wrapError(
xerrors.Operation(
Expand Down
7 changes: 4 additions & 3 deletions internal/grpcwrapper/rawtopic/describe_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawscheme"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic/rawtopiccommon"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawydb"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/operation"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
)

Expand Down Expand Up @@ -41,13 +42,13 @@ type DescribeTopicResult struct {
MeteringMode MeteringMode
}

func (res *DescribeTopicResult) FromProto(protoResponse *Ydb_Topic.DescribeTopicResponse) error {
if err := res.Operation.FromProtoWithStatusCheck(protoResponse.GetOperation()); err != nil {
func (res *DescribeTopicResult) FromProto(response operation.Response) error {
if err := res.Operation.FromProtoWithStatusCheck(response.GetOperation()); err != nil {
return err
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package response
package operation

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

Expand Down
18 changes: 0 additions & 18 deletions internal/wrap/wrap.go

This file was deleted.

Loading