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 CanBatch and GetPriority helpers #269

Merged
merged 1 commit into from
Aug 27, 2024
Merged
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
7 changes: 7 additions & 0 deletions hrpc/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ func SkipBatch() func(Call) error {
}
}

// CanBatch returns true if this RPC can be included in a batch/multi
// request.
func CanBatch(c Call) bool {
b, ok := c.(Batchable)
return ok && !b.SkipBatch()
}

// hasQueryOptions is interface that needs to be implemented by calls
// that allow to provide Families and Filters options.
type hasQueryOptions interface {
Expand Down
10 changes: 10 additions & 0 deletions hrpc/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ func (bq *baseQuery) Priority() uint32 {
return bq.priority
}

// GetPriority returns the priority of a Call. Returns 0 for calls
// that don't have a priority set or don't support setting a priority.
func GetPriority(c Call) uint32 {
p, ok := c.(interface{ Priority() uint32 })
if !ok {
return 0
}
return p.Priority()
}

// Families option adds families constraint to a Scan or Get request.
func Families(f map[string][]string) func(Call) error {
return func(hc Call) error {
Expand Down
8 changes: 3 additions & 5 deletions region/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ type client struct {

// QueueRPC will add an rpc call to the queue for processing by the writer goroutine
func (c *client) QueueRPC(rpc hrpc.Call) {
if b, ok := rpc.(hrpc.Batchable); ok && c.rpcQueueSize > 1 && !b.SkipBatch() {
if c.rpcQueueSize > 1 && hrpc.CanBatch(rpc) {
c.QueueBatch(rpc.Context(), []hrpc.Call{rpc})
} else {
select {
Expand Down Expand Up @@ -687,10 +687,8 @@ func marshalProto(rpc hrpc.Call, callID uint32, request proto.Message,
header.MethodName = proto.String(rpc.Name())
header.RequestParam = pbTrue
header.CallId = &callID
if p, ok := rpc.(interface{ Priority() uint32 }); ok {
if p := p.Priority(); p > 0 {
header.Priority = &p
}
if p := hrpc.GetPriority(rpc); p > 0 {
header.Priority = &p
}

if cellblocksLen > 0 {
Expand Down
2 changes: 1 addition & 1 deletion rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (c *client) SendBatch(ctx context.Context, batch []hrpc.Call) (
res[i].Error = fmt.Errorf("multiple tables in batch request: %q and %q",
string(table), string(rpc.Table()))
allOK = false
} else if b, batchable := rpc.(hrpc.Batchable); !batchable || b.SkipBatch() {
} else if !hrpc.CanBatch(rpc) {
res[i].Error = errors.New("non-batchable call passed to SendBatch")
allOK = false
}
Expand Down
Loading