Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,13 @@ private boolean tryComplete(LocateRequest req, CompletableFuture<RegionLocations
this.locatePrefetchLimit =
conn.getConfiguration().getInt(LOCATE_PREFETCH_LIMIT, DEFAULT_LOCATE_PREFETCH_LIMIT);

boolean useMetaReplicas =
conn.getConfiguration().getBoolean(USE_META_REPLICAS, DEFAULT_USE_META_REPLICAS);
// Get the region locator's meta replica mode.
this.metaReplicaMode = CatalogReplicaMode.fromString(
conn.getConfiguration().get(LOCATOR_META_REPLICAS_MODE, CatalogReplicaMode.NONE.toString()));
this.metaReplicaMode = useMetaReplicas ?
CatalogReplicaMode.fromString(conn.getConfiguration()
.get(LOCATOR_META_REPLICAS_MODE, CatalogReplicaMode.NONE.toString())) :
CatalogReplicaMode.NONE;

switch (this.metaReplicaMode) {
case LOAD_BALANCE:
Expand All @@ -244,8 +248,6 @@ private boolean tryComplete(LocateRequest req, CompletableFuture<RegionLocations
break;
case NONE:
// If user does not configure LOCATOR_META_REPLICAS_MODE, let's check the legacy config.
boolean useMetaReplicas =
conn.getConfiguration().getBoolean(USE_META_REPLICAS, DEFAULT_USE_META_REPLICAS);
if (useMetaReplicas) {
this.metaReplicaMode = CatalogReplicaMode.HEDGED_READ;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
*/
package org.apache.hadoop.hbase.client;

import static org.apache.hadoop.hbase.client.RegionLocator.LOCATOR_META_REPLICAS_MODE;
import static org.junit.Assert.assertArrayEquals;

import java.io.IOException;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CatalogReplicaMode;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.HConstants;
Expand Down Expand Up @@ -65,6 +67,7 @@ public class TestAsyncTableUseMetaReplicas {
private static byte[] VALUE = Bytes.toBytes("Value");

private static volatile boolean FAIL_PRIMARY_SCAN = false;
private static volatile boolean USE_META_REPLICA = false;

public static final class FailPrimaryMetaScanCp implements RegionObserver, RegionCoprocessor {

Expand All @@ -77,6 +80,10 @@ public Optional<RegionObserver> getRegionObserver() {
public void preScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c, Scan scan)
throws IOException {
RegionInfo region = c.getEnvironment().getRegionInfo();
if (!USE_META_REPLICA && TableName.isMetaTableName(region.getTable())) {
assert region.getReplicaId()
== RegionReplicaUtil.DEFAULT_REPLICA_ID : "should read default meta region!";
}
if (
FAIL_PRIMARY_SCAN && TableName.isMetaTableName(region.getTable())
&& region.getReplicaId() == RegionReplicaUtil.DEFAULT_REPLICA_ID
Expand Down Expand Up @@ -117,11 +124,12 @@ public void tearDownAfterTest() {
FAIL_PRIMARY_SCAN = false;
}

private void testRead(boolean useMetaReplicas)
private void testRead()
throws IOException, InterruptedException, ExecutionException {
FAIL_PRIMARY_SCAN = true;
Configuration conf = new Configuration(UTIL.getConfiguration());
conf.setBoolean(HConstants.USE_META_REPLICAS, useMetaReplicas);
conf.setBoolean(HConstants.USE_META_REPLICAS, USE_META_REPLICA);
conf.set(LOCATOR_META_REPLICAS_MODE, CatalogReplicaMode.LOAD_BALANCE.toString());
conf.setLong(HConstants.HBASE_CLIENT_META_REPLICA_SCAN_TIMEOUT, TimeUnit.SECONDS.toMicros(1));
try (AsyncConnection conn = ConnectionFactory.createAsyncConnection(conf).get()) {
Result result = FutureUtils.get(conn.getTableBuilder(TABLE_NAME)
Expand All @@ -133,11 +141,13 @@ private void testRead(boolean useMetaReplicas)
@Test(expected = RetriesExhaustedException.class)
public void testNotUseMetaReplicas()
throws IOException, InterruptedException, ExecutionException {
testRead(false);
USE_META_REPLICA = false;
testRead();
}

@Test
public void testUseMetaReplicas() throws IOException, InterruptedException, ExecutionException {
testRead(true);
USE_META_REPLICA = true;
testRead();
}
}