Skip to content

Commit

Permalink
Keep priority on scanner's subsequent scans
Browse files Browse the repository at this point in the history
If a scanner needs to scan multiple times ensure all scanners get the
priority set in the initial hrpc.Scan.

Updated baseQuery.Priority to return a uint32 rather than a *uint32 to
be less weird.
  • Loading branch information
aaronbee authored and dethi committed Aug 15, 2024
1 parent e08f807 commit 9f5d859
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 30 deletions.
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

0 comments on commit 9f5d859

Please sign in to comment.