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

hrpc: add an option to skip retry #263

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 25 additions & 0 deletions hrpc/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type Call interface {
ResultChan() chan RPCResult
Description() string // Used for tracing and metrics
Context() context.Context
SkipRetry() bool
}

type withOptions interface {
Expand Down Expand Up @@ -90,6 +91,20 @@ func SkipBatch() func(Call) error {
}
}

func SkipRetry() func(Call) error {
return func(c Call) error {
if b, ok := c.(canSetSkipRetry); ok {
b.setSkipRetry(true)
return nil
}
return errors.New("'SkipRetry' is not implemented for this call")
}
}

type canSetSkipRetry interface {
setSkipRetry(v bool)
}

// hasQueryOptions is interface that needs to be implemented by calls
// that allow to provide Families and Filters options.
type hasQueryOptions interface {
Expand Down Expand Up @@ -119,12 +134,22 @@ type base struct {

region RegionInfo
resultch chan RPCResult

skipRetry bool
}

func (b *base) Context() context.Context {
return b.ctx
}

func (b *base) SkipRetry() bool {
return b.skipRetry
}

func (b *base) setSkipRetry() {
b.skipRetry = true
}

func (b *base) Region() RegionInfo {
return b.region
}
Expand Down
5 changes: 5 additions & 0 deletions region/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ func (m *multi) Context() context.Context {
return context.Background()
}

// SkipRetry always returns false for Multi.
func (m *multi) SkipRetry() bool {
return false
}

// String returns a description of this call
func (m *multi) String() string {
return "MULTI"
Expand Down
20 changes: 11 additions & 9 deletions rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,18 @@ func (c *client) SendRPC(rpc hrpc.Call) (msg proto.Message, err error) {
return nil, err
}
msg, err = c.sendRPCToRegionClient(ctx, rpc, rc)
switch err.(type) {
case region.RetryableError:
sp.AddEvent("retrySleep")
backoff, err = sleepAndIncreaseBackoff(ctx, backoff)
if err != nil {
return msg, err
if !rpc.SkipRetry() {
switch err.(type) {
case region.RetryableError:
sp.AddEvent("retrySleep")
backoff, err = sleepAndIncreaseBackoff(ctx, backoff)
if err != nil {
return msg, err
}
continue // retry
case region.ServerError, region.NotServingRegionError:
continue // retry
}
continue // retry
case region.ServerError, region.NotServingRegionError:
continue // retry
}
return msg, err
}
Expand Down
1 change: 1 addition & 0 deletions rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func TestSendRPCSanity(t *testing.T) {
expMsg := &pb.ScanResponse{}
result <- hrpc.RPCResult{Msg: expMsg}
mockCall.EXPECT().ResultChan().Return(result).Times(1)
mockCall.EXPECT().SkipRetry().Return(false)
msg, err := c.SendRPC(mockCall)
if err != nil {
t.Fatal(err)
Expand Down
16 changes: 7 additions & 9 deletions scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,22 +337,20 @@ func (s *scanner) closeRegionScanner() {
return
}
if !s.rpc.IsClosing() {
// Not closed at server side
// if we are closing in the middle of scanning a region,
// send a close scanner request
// TODO: add a deadline
// Not closed at server side if we are closing in the middle of scanning
// a region, so send a close scanner request. This is a fire-and-forget
// call, as if we fail the scanner lease will expire and be closed
// automatically by HBase.
rpc, err := hrpc.NewScanRange(context.Background(),
s.rpc.Table(), s.startRow, nil,
hrpc.ScannerID(s.curRegionScannerID),
hrpc.CloseScanner(),
hrpc.NumberOfRows(0))
hrpc.NumberOfRows(0),
hrpc.SkipRetry(),
)
if err != nil {
panic(fmt.Sprintf("should not happen: %s", err))
}

// If the request fails, the scanner lease will be expired
// and it will be closed automatically by hbase.
// No need to bother clients about that.
go s.SendRPC(rpc)
}
s.curRegionScannerID = noScannerID
Expand Down
14 changes: 14 additions & 0 deletions test/mock/call.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading