Repository: hbase Updated Branches: refs/heads/branch-1 737b489ed -> 408645c4e refs/heads/branch-1.3 2ddb30c57 -> 6545b45b1 refs/heads/master 7d819eb72 -> e99ed99be
HBASE-18000 Make sure we always return the scanner id with ScanResponse Signed-off-by: Andrew Purtell <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/e99ed99b Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/e99ed99b Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/e99ed99b Branch: refs/heads/master Commit: e99ed99bee66b9719ffb3127710fda486f952048 Parents: 7d819eb Author: zhangduo <[email protected]> Authored: Fri May 5 14:46:17 2017 +0800 Committer: Andrew Purtell <[email protected]> Committed: Fri May 5 11:38:34 2017 -0700 ---------------------------------------------------------------------- .../hbase/regionserver/RSRpcServices.java | 3 + .../hbase/client/TestAlwaysSetScannerId.java | 104 +++++++++++++++++++ 2 files changed, 107 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/e99ed99b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java index 8d4ea4d..2d4d0e9 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java @@ -3008,6 +3008,9 @@ public class RSRpcServices implements HBaseRPCErrorHandler, try { if (request.hasScannerId()) { rsh = getRegionScanner(request); + // The downstream projects such as AsyncHBase in OpenTSDB need this value. See HBASE-18000 + // for more details. + builder.setScannerId(request.getScannerId()); } else { rsh = newRegionScanner(request, builder); } http://git-wip-us.apache.org/repos/asf/hbase/blob/e99ed99b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAlwaysSetScannerId.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAlwaysSetScannerId.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAlwaysSetScannerId.java new file mode 100644 index 0000000..d9f226f --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAlwaysSetScannerId.java @@ -0,0 +1,104 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.client; + +import static org.junit.Assert.*; + +import java.io.IOException; + +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HRegionInfo; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException; +import org.apache.hadoop.hbase.shaded.protobuf.RequestConverter; +import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos; +import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest; +import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanResponse; +import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.apache.hadoop.hbase.testclassification.RegionServerTests; +import org.apache.hadoop.hbase.util.Bytes; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +/** + * Testcase to make sure that we always set scanner id in ScanResponse. See HBASE-18000. + */ +@Category({ RegionServerTests.class, MediumTests.class }) +public class TestAlwaysSetScannerId { + + private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); + + private static final TableName TABLE_NAME = TableName.valueOf("test"); + + private static final byte[] CF = Bytes.toBytes("cf"); + + private static final byte[] CQ = Bytes.toBytes("cq"); + + private static final int COUNT = 10; + + private static HRegionInfo HRI; + + private static ClientProtos.ClientService.BlockingInterface STUB; + + @BeforeClass + public static void setUp() throws Exception { + UTIL.startMiniCluster(1); + try (Table table = UTIL.createTable(TABLE_NAME, CF)) { + for (int i = 0; i < COUNT; i++) { + table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i))); + } + } + HRI = UTIL.getAdmin().getTableRegions(TABLE_NAME).get(0); + STUB = ((ConnectionImplementation) UTIL.getConnection()) + .getClient(UTIL.getHBaseCluster().getRegionServer(0).getServerName()); + } + + @AfterClass + public static void tearDown() throws Exception { + UTIL.shutdownMiniCluster(); + } + + @Test + public void test() throws ServiceException, IOException { + Scan scan = new Scan(); + ScanRequest req = RequestConverter.buildScanRequest(HRI.getRegionName(), scan, 1, false); + ScanResponse resp = STUB.scan(null, req); + assertTrue(resp.hasScannerId()); + long scannerId = resp.getScannerId(); + int nextCallSeq = 0; + // test next + for (int i = 0; i < 5; i++) { + req = RequestConverter.buildScanRequest(scannerId, 1, false, nextCallSeq++, false, false, -1); + resp = STUB.scan(null, req); + assertTrue(resp.hasScannerId()); + assertEquals(scannerId, resp.getScannerId()); + } + // test renew + req = RequestConverter.buildScanRequest(scannerId, 0, false, nextCallSeq++, false, true, -1); + resp = STUB.scan(null, req); + assertTrue(resp.hasScannerId()); + assertEquals(scannerId, resp.getScannerId()); + // test close + req = RequestConverter.buildScanRequest(scannerId, 0, true, false); + resp = STUB.scan(null, req); + assertTrue(resp.hasScannerId()); + assertEquals(scannerId, resp.getScannerId()); + } +}
