Skip to content

Commit

Permalink
prevent keyspace client from panic
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Mar 8, 2024
1 parent 46c8a6f commit cbfbb3a
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions client/keyspace_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/opentracing/opentracing-go"
"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/keyspacepb"
"github.com/tikv/pd/client/errs"
)

// KeyspaceClient manages keyspace metadata.
Expand Down Expand Up @@ -56,7 +57,12 @@ func (c *client) LoadKeyspace(ctx context.Context, name string) (*keyspacepb.Key
Header: c.requestHeader(),
Name: name,
}
resp, err := c.keyspaceClient().LoadKeyspace(ctx, req)
protoClient := c.keyspaceClient()
if protoClient == nil {
cancel()
return nil, errs.ErrClientGetProtoClient

Check warning on line 63 in client/keyspace_client.go

View check run for this annotation

Codecov / codecov/patch

client/keyspace_client.go#L62-L63

Added lines #L62 - L63 were not covered by tests
}
resp, err := protoClient.LoadKeyspace(ctx, req)
cancel()

if err != nil {
Expand Down Expand Up @@ -96,7 +102,12 @@ func (c *client) UpdateKeyspaceState(ctx context.Context, id uint32, state keysp
Id: id,
State: state,
}
resp, err := c.keyspaceClient().UpdateKeyspaceState(ctx, req)
protoClient := c.keyspaceClient()
if protoClient == nil {
cancel()
return nil, errs.ErrClientGetProtoClient

Check warning on line 108 in client/keyspace_client.go

View check run for this annotation

Codecov / codecov/patch

client/keyspace_client.go#L107-L108

Added lines #L107 - L108 were not covered by tests
}
resp, err := protoClient.UpdateKeyspaceState(ctx, req)
cancel()

if err != nil {
Expand Down Expand Up @@ -135,7 +146,12 @@ func (c *client) GetAllKeyspaces(ctx context.Context, startID uint32, limit uint
StartId: startID,
Limit: limit,
}
resp, err := c.keyspaceClient().GetAllKeyspaces(ctx, req)
protoClient := c.keyspaceClient()
if protoClient == nil {
cancel()
return nil, errs.ErrClientGetProtoClient

Check warning on line 152 in client/keyspace_client.go

View check run for this annotation

Codecov / codecov/patch

client/keyspace_client.go#L151-L152

Added lines #L151 - L152 were not covered by tests
}
resp, err := protoClient.GetAllKeyspaces(ctx, req)
cancel()

if err != nil {
Expand Down

0 comments on commit cbfbb3a

Please sign in to comment.