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

Keep priority on scanner's subsequent scans #268

Merged
merged 1 commit into from
Aug 15, 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: 2 additions & 5 deletions hrpc/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,8 @@ func (bq *baseQuery) setConsistency(consistency ConsistencyType) {
func (bq *baseQuery) setPriority(priority uint32) {
bq.priority = priority
}
func (bq *baseQuery) Priority() *uint32 {
if bq.priority == 0 {
return nil
}
return &bq.priority
func (bq *baseQuery) Priority() uint32 {
return bq.priority
}

// Families option adds families constraint to a Scan or Get request.
Expand Down
35 changes: 13 additions & 22 deletions hrpc/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,43 +214,34 @@ func TestPriority(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if got := get.Priority(); got != nil {
t.Errorf("expected nil, got %v", got)
}
get, err = NewGet(nil, nil, nil, Priority(0))
if err != nil {
t.Fatal(err)
}
if got := get.Priority(); got != nil {
t.Errorf("expected nil, got %v", got)
if got := get.Priority(); got != 0 {
t.Errorf("expected 0, got %d", got)
}
get, err = NewGet(nil, nil, nil, Priority(5))
if err != nil {
t.Fatal(err)
}
if got := get.Priority(); *got != 5 {
t.Errorf("expected priority 5, got %v", got)
if got := get.Priority(); got != 5 {
t.Errorf("expected priority 5, got %d", got)
}

scan, err := NewScan(nil, nil)
if err != nil {
t.Fatal(err)
}
if got := scan.Priority(); got != nil {
t.Errorf("expected nil, got %v", got)
}
scan, err = NewScan(nil, nil, Priority(0))
if err != nil {
t.Fatal(err)
}
if got := scan.Priority(); got != nil {
t.Errorf("expected nil, got %v", got)
if got := scan.Priority(); got != 0 {
t.Errorf("expected 0, got %d", got)
}
scan, err = NewScan(nil, nil, Priority(5))
if err != nil {
t.Fatal(err)
}
if got := scan.Priority(); *got != 5 {
t.Errorf("expected priority 5, got %v", got)
if got := scan.Priority(); got != 5 {
t.Errorf("expected priority 5, got %d", got)
}

_, err = NewPut(nil, nil, nil, nil, Priority(5))
if err == nil {
t.Errorf("expected error when creating Put with Priority, but got none")
}
}
6 changes: 4 additions & 2 deletions region/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,10 @@ 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 {
header.Priority = p.Priority()
if p, ok := rpc.(interface{ Priority() uint32 }); ok {
if p := p.Priority(); p > 0 {
header.Priority = &p
}
}

if cellblocksLen > 0 {
Expand Down
4 changes: 3 additions & 1 deletion scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ func (s *scanner) request() (*pb.ScanResponse, hrpc.RegionInfo, error) {
s.startRow,
nil,
hrpc.ScannerID(s.curRegionScannerID),
hrpc.NumberOfRows(s.rpc.NumberOfRows()))
hrpc.NumberOfRows(s.rpc.NumberOfRows()),
hrpc.Priority(s.rpc.Priority()),
)
}
if err != nil {
return nil, nil, err
Expand Down
Loading