Skip to content

Commit

Permalink
scanner: don't send scanner close request when region was exhausted
Browse files Browse the repository at this point in the history
HBase server already close the region scanner[1] when there is no more
results to be send from that region. Therefore, it is useless to send
one more request to close the scanner.

[1] https://github.com/apache/hbase/blob/master/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java#L3698
  • Loading branch information
dethi committed Jul 5, 2024
1 parent e059f8c commit 1fab40d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 37 deletions.
2 changes: 1 addition & 1 deletion scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (s *scanner) update(resp *pb.ScanResponse, region hrpc.RegionInfo) {
}
if !resp.GetMoreResultsInRegion() {
// we are done with this region, prepare scan for next region
s.closeRegionScanner()
s.curRegionScannerID = noScannerID

// Normal Scan
if !s.rpc.Reversed() {
Expand Down
37 changes: 1 addition & 36 deletions scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,12 @@ func testCallClose(scan *hrpc.Scan, c *mock.MockRPCClient, scannerID uint64,
group.Done()
}).Return(&pb.ScanResponse{}, nil).Times(1)
}

func TestScanner(t *testing.T) {
ctrl := test.NewController(t)
defer ctrl.Finish()
c := mock.NewMockRPCClient(ctrl)

var wg sync.WaitGroup
wg.Add(3)
defer wg.Wait()

scan, err := hrpc.NewScan(context.Background(), table, hrpc.NumberOfRows(2))
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -152,8 +149,6 @@ func TestScanner(t *testing.T) {
Results: dup(resultsPB[1:2]),
}, nil).Times(1)

// added call to close scanner
testCallClose(scan, c, scannerID, &wg, t)
scannerID++

s, err = hrpc.NewScanRange(scan.Context(), table,
Expand All @@ -168,11 +163,6 @@ func TestScanner(t *testing.T) {
Results: dup(resultsPB[2:3]),
}, nil).Times(1)

// added call to close scanner
testCallClose(scan, c, scannerID, &wg, t)
if err != nil {
t.Fatal(err)
}
scannerID++

s, err = hrpc.NewScanRange(scan.Context(), table, []byte("foo"), nil,
Expand All @@ -188,9 +178,6 @@ func TestScanner(t *testing.T) {
MoreResults: proto.Bool(false),
}, nil).Times(1)

// added call to close scanner
testCallClose(scan, c, scannerID, &wg, t)

var rs []*hrpc.Result
for {
r, err := scanner.Next()
Expand Down Expand Up @@ -600,10 +587,6 @@ func testPartialResults(t *testing.T, scan *hrpc.Scan, expected []*hrpc.Result)
defer ctrl.Finish()
c := mock.NewMockRPCClient(ctrl)

var wg sync.WaitGroup
wg.Add(3)
defer wg.Wait()

tcase := []struct {
region hrpc.RegionInfo
results []*pb.Result
Expand Down Expand Up @@ -680,11 +663,6 @@ func testPartialResults(t *testing.T, scan *hrpc.Scan, expected []*hrpc.Result)
MoreResultsInRegion: &partial.moreResultsInRegion,
Results: partial.results,
}, nil).Times(1)

if partial.scanFromID {
// added call to close scanner
testCallClose(scan, c, scannerID, &wg, t)
}
}

var rs []*hrpc.Result
Expand All @@ -709,10 +687,6 @@ func TestReversedScanner(t *testing.T) {
defer ctrl.Finish()
c := mock.NewMockRPCClient(ctrl)

var wg sync.WaitGroup
wg.Add(3)
defer wg.Wait()

ctx := context.Background()
scan, err := hrpc.NewScan(ctx, table, hrpc.Reversed())
if err != nil {
Expand All @@ -734,9 +708,6 @@ func TestReversedScanner(t *testing.T) {
Results: dup(resultsPB[3:4]),
}, nil).Times(1)

// added call to close scanner
testCallClose(scan, c, scannerID, &wg, t)

s, err = hrpc.NewScanRange(ctx, table,
append([]byte("fon"), rowPadding...), nil, hrpc.Reversed())
if err != nil {
Expand All @@ -749,9 +720,6 @@ func TestReversedScanner(t *testing.T) {
Results: dup(resultsPB[2:3]),
}, nil).Times(1)

// added call to close scanner
testCallClose(scan, c, scannerID, &wg, t)

s, err = hrpc.NewScanRange(ctx, table,
append([]byte("baq"), rowPadding...), nil, hrpc.Reversed())
if err != nil {
Expand All @@ -777,9 +745,6 @@ func TestReversedScanner(t *testing.T) {
Results: dup(resultsPB[:1]),
}, nil).Times(1)

// added call to close scanner
testCallClose(scan, c, scannerID, &wg, t)

var rs []*hrpc.Result
for {
r, err := scanner.Next()
Expand Down

0 comments on commit 1fab40d

Please sign in to comment.