-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-28443 Return too slow when scanning a table with non-existing REGION_REPLICA_ID #5767
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
Open
guluo2016
wants to merge
3
commits into
apache:master
Choose a base branch
from
guluo2016:hbase_HBASE-28443
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+234
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
207 changes: 207 additions & 0 deletions
207
.../src/test/java/org/apache/hadoop/hbase/client/TestScanOrGetWithReplicationFromClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| /* | ||
| * 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.assertEquals; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.junit.Assert.fail; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import org.apache.hadoop.hbase.DoNotRetryIOException; | ||
| import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
| import org.apache.hadoop.hbase.HBaseTestingUtil; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.filter.PrefixFilter; | ||
| import org.apache.hadoop.hbase.regionserver.HRegion; | ||
| import org.apache.hadoop.hbase.testclassification.ClientTests; | ||
| import org.apache.hadoop.hbase.testclassification.MediumTests; | ||
| import org.apache.hadoop.hbase.util.Bytes; | ||
| import org.apache.hadoop.io.IOUtils; | ||
| import org.junit.After; | ||
| import org.junit.AfterClass; | ||
| import org.junit.Before; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
| import org.junit.rules.TestName; | ||
|
|
||
| @Category({ MediumTests.class, ClientTests.class }) | ||
| public class TestScanOrGetWithReplicationFromClient { | ||
| @ClassRule | ||
| public static final HBaseClassTestRule CLASS_RULE = | ||
| HBaseClassTestRule.forClass(TestScanOrGetWithReplicationFromClient.class); | ||
|
|
||
| @Rule | ||
| public TestName name = new TestName(); | ||
|
|
||
| private final static HBaseTestingUtil UTIL = new HBaseTestingUtil(); | ||
| private static final String ROW = "r1"; | ||
| private static final byte[] FAMILY = Bytes.toBytes("info"); | ||
| private static final int REGION_REPLICATION_COUNT = 2; | ||
| // region replica id starts from 0 | ||
| private static final int NON_EXISTING_REGION_REPLICA_ID = REGION_REPLICATION_COUNT; | ||
| private static Connection connection; | ||
| private static Admin admin; | ||
| private TableName tableName; | ||
|
|
||
| @BeforeClass | ||
| public static void setUpBeforeClass() throws Exception { | ||
| UTIL.startMiniCluster(1); | ||
| connection = UTIL.getConnection(); | ||
| admin = UTIL.getAdmin(); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void tearDownAfterClass() throws Exception { | ||
| IOUtils.cleanup(null, admin); | ||
| IOUtils.cleanup(null, connection); | ||
| UTIL.shutdownMiniCluster(); | ||
| } | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| tableName = TableName.valueOf(name.getMethodName()); | ||
| ColumnFamilyDescriptor columnFamilyDescriptor = | ||
| ColumnFamilyDescriptorBuilder.newBuilder(FAMILY).build(); | ||
| TableDescriptor tableDescriptor = | ||
| TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(columnFamilyDescriptor) | ||
| .setRegionReplication(REGION_REPLICATION_COUNT).build(); | ||
| admin.createTable(tableDescriptor); | ||
| UTIL.waitTableAvailable(tableName); | ||
| assertTrue(admin.tableExists(tableName)); | ||
| assertEquals(REGION_REPLICATION_COUNT, tableDescriptor.getRegionReplication()); | ||
|
|
||
| List<HRegion> regions = UTIL.getHBaseCluster().getRegions(tableName); | ||
| assertEquals(REGION_REPLICATION_COUNT, regions.size()); | ||
|
|
||
| Table table = connection.getTable(tableName); | ||
| Put put = new Put(Bytes.toBytes(ROW)).addColumn(FAMILY, Bytes.toBytes("q"), | ||
| Bytes.toBytes("test_value")); | ||
| table.put(put); | ||
| admin.flush(tableName); | ||
|
|
||
| Scan scan = new Scan(); | ||
| ResultScanner rs = table.getScanner(scan); | ||
| rs.forEach(r -> assertEquals(ROW, Bytes.toString(r.getRow()))); | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() throws Exception { | ||
| UTIL.deleteTable(tableName); | ||
| } | ||
|
|
||
| @Test | ||
| public void testScanMetaWithRegionReplicaId() throws IOException { | ||
| Table metaTable = connection.getTable(TableName.META_TABLE_NAME); | ||
| Scan scan = new Scan(); | ||
| scan.setFilter(new PrefixFilter(tableName.getName())); | ||
| scan.setReplicaId(RegionReplicaUtil.DEFAULT_REPLICA_ID); | ||
| scan.setConsistency(Consistency.TIMELINE); | ||
| ResultScanner rs = metaTable.getScanner(scan); | ||
| rs.forEach(r -> assertTrue(Bytes.toString(r.getRow()).contains(tableName.getNameAsString()))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testScanMetaWithNonExistingRegionReplicaId() throws IOException { | ||
| Table metaTable = connection.getTable(TableName.META_TABLE_NAME); | ||
| Scan scan = new Scan(); | ||
| scan.setReplicaId(NON_EXISTING_REGION_REPLICA_ID); | ||
| scan.setConsistency(Consistency.TIMELINE); | ||
| ResultScanner rs = metaTable.getScanner(scan); | ||
| try { | ||
| rs.forEach(r -> Bytes.toString(r.getRow())); | ||
| fail("Should not reach here"); | ||
| } catch (Exception e) { | ||
| Throwable throwable = e.getCause(); | ||
| assertTrue(throwable instanceof DoNotRetryIOException); | ||
| String message = "The specified region replica id " + NON_EXISTING_REGION_REPLICA_ID | ||
| + " does not exist, the REGION_REPLICATION of this table " | ||
| + TableName.META_TABLE_NAME.getNameAsString() + " is " | ||
| + TableDescriptorBuilder.DEFAULT_REGION_REPLICATION + ", " | ||
| + "this means that the maximum region replica id you can specify is " | ||
| + (TableDescriptorBuilder.DEFAULT_REGION_REPLICATION - 1) + "."; | ||
| assertEquals(message, throwable.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testScanTableWithRegionReplicaId() throws IOException { | ||
| Table table = connection.getTable(tableName); | ||
| Scan scan = new Scan(); | ||
| scan.setReplicaId(RegionReplicaUtil.DEFAULT_REPLICA_ID); | ||
| scan.setConsistency(Consistency.TIMELINE); | ||
| ResultScanner rs = table.getScanner(scan); | ||
| rs.forEach(r -> assertEquals(ROW, Bytes.toString(r.getRow()))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testScanTableWithNonExistingRegionReplicaId() throws IOException { | ||
| Table table = connection.getTable(tableName); | ||
| Scan scan = new Scan(); | ||
| scan.setReplicaId(NON_EXISTING_REGION_REPLICA_ID); | ||
| scan.setConsistency(Consistency.TIMELINE); | ||
| ResultScanner rs = table.getScanner(scan); | ||
| try { | ||
| rs.forEach(r -> Bytes.toString(r.getRow())); | ||
| fail("Should not reach here"); | ||
| } catch (Exception e) { | ||
| Throwable throwable = e.getCause(); | ||
| assertTrue(throwable instanceof DoNotRetryIOException); | ||
| String message = "The specified region replica id " + NON_EXISTING_REGION_REPLICA_ID | ||
| + " does not exist, the REGION_REPLICATION of this table " + tableName.getNameAsString() | ||
| + " is " + REGION_REPLICATION_COUNT + ", " | ||
| + "this means that the maximum region replica id you can specify is " | ||
| + (REGION_REPLICATION_COUNT - 1) + "."; | ||
| assertEquals(message, throwable.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetTableWithRegionReplicaId() throws IOException { | ||
| Table table = connection.getTable(tableName); | ||
| Get get = new Get(Bytes.toBytes(ROW)).setConsistency(Consistency.TIMELINE) | ||
| .setReplicaId(RegionReplicaUtil.DEFAULT_REPLICA_ID); | ||
| Result result = table.get(get); | ||
| assertEquals(ROW, Bytes.toString(result.getRow())); | ||
| String value = Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("q"))); | ||
| assertEquals("test_value", value); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetTableWithNonExistingRegionReplicaId() throws IOException { | ||
| Table table = connection.getTable(tableName); | ||
| Get get = new Get(Bytes.toBytes(ROW)).setConsistency(Consistency.TIMELINE) | ||
| .setReplicaId(NON_EXISTING_REGION_REPLICA_ID); | ||
| try { | ||
| Result result = table.get(get); | ||
| result.getValue(FAMILY, Bytes.toBytes("q")); | ||
| fail("Should not reach here"); | ||
| } catch (Exception e) { | ||
| assertTrue(e instanceof DoNotRetryIOException); | ||
| String message = "The specified region replica id " + NON_EXISTING_REGION_REPLICA_ID | ||
| + " does not exist, the REGION_REPLICATION of this table " + tableName.getNameAsString() | ||
| + " is " + REGION_REPLICATION_COUNT + ", " | ||
| + "this means that the maximum region replica id you can specify is " | ||
| + (REGION_REPLICATION_COUNT - 1) + "."; | ||
| assertEquals(message, e.getMessage()); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test should fail if no exception is thrown.
So I will update it.