HBASE-22108 Avoid passing null in Admin methods

Signed-off-by: Guanghao Zhang <zghao@apache.org>
This commit is contained in:
zhangduo 2019-04-01 20:48:03 +08:00
parent 507af5fe6c
commit b04b1ecc74
41 changed files with 139 additions and 126 deletions

View File

@ -1073,19 +1073,49 @@ public interface Admin extends Abortable, Closeable {
void majorCompactRegionServer(ServerName serverName) throws IOException;
/**
* Move the region <code>r</code> to <code>dest</code>.
*
* Move the region <code>encodedRegionName</code> to a random server.
* @param encodedRegionName The encoded region name; i.e. the hash that makes up the region name
* suffix: e.g. if regionname is
* <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>,
* then the encoded region name is: <code>527db22f95c8a9e0116f0cc13c680396</code>.
* @param destServerName The servername of the destination regionserver. If passed the empty byte
* array we'll assign to a random server. A server name is made of host, port and startcode.
* Here is an example: <code> host187.example.com,60020,1289493121758</code>
* @throws IOException if we can't find a region named
* <code>encodedRegionName</code>
* suffix: e.g. if regionname is
* <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>,
* then the encoded region name is: <code>527db22f95c8a9e0116f0cc13c680396</code>.
* @throws IOException if we can't find a region named <code>encodedRegionName</code>
*/
void move(byte[] encodedRegionName, byte[] destServerName) throws IOException;
void move(byte[] encodedRegionName) throws IOException;
/**
* Move the region <code>rencodedRegionName</code> to <code>destServerName</code>.
* @param encodedRegionName The encoded region name; i.e. the hash that makes up the region name
* suffix: e.g. if regionname is
* <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>,
* then the encoded region name is: <code>527db22f95c8a9e0116f0cc13c680396</code>.
* @param destServerName The servername of the destination regionserver. If passed the empty byte
* array we'll assign to a random server. A server name is made of host, port and
* startcode. Here is an example: <code> host187.example.com,60020,1289493121758</code>
* @throws IOException if we can't find a region named <code>encodedRegionName</code>
* @deprecated Use {@link #move(byte[], ServerName)} instead. And if you want to move the region
* to a random server, please use {@link #move(byte[])}.
*/
@Deprecated
default void move(byte[] encodedRegionName, byte[] destServerName) throws IOException {
if (destServerName == null || destServerName.length == 0) {
move(encodedRegionName);
} else {
move(encodedRegionName, ServerName.valueOf(Bytes.toString(destServerName)));
}
}
/**
* Move the region <code>rencodedRegionName</code> to <code>destServerName</code>.
* @param encodedRegionName The encoded region name; i.e. the hash that makes up the region name
* suffix: e.g. if regionname is
* <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>,
* then the encoded region name is: <code>527db22f95c8a9e0116f0cc13c680396</code>.
* @param destServerName The servername of the destination regionserver. A server name is made of
* host, port and startcode. Here is an example:
* <code> host187.example.com,60020,1289493121758</code>
* @throws IOException if we can't find a region named <code>encodedRegionName</code>
*/
void move(byte[] encodedRegionName, ServerName destServerName) throws IOException;
/**
* Assign a Region.
@ -1096,7 +1126,7 @@ public interface Admin extends Abortable, Closeable {
/**
* Unassign a region from current hosting regionserver. Region will then be assigned to a
* regionserver chosen at random. Region could be reassigned back to the same server. Use {@link
* #move(byte[], byte[])} if you want to control the region movement.
* #move(byte[], ServerName)} if you want to control the region movement.
*
* @param regionName Region to unassign. Will clear any existing RegionPlan if one found.
* @param force If <code>true</code>, force unassign (Will remove region from regions-in-transition too if
@ -1408,6 +1438,13 @@ public interface Admin extends Abortable, Closeable {
void splitRegion(byte[] regionName, byte[] splitPoint)
throws IOException;
/**
* Split an individual region. Asynchronous operation.
* @param regionName region to split
* @throws IOException if a remote or network exception occurs
*/
Future<Void> splitRegionAsync(byte[] regionName) throws IOException;
/**
* Split an individual region. Asynchronous operation.
* @param regionName region to split

View File

@ -1387,14 +1387,17 @@ public class HBaseAdmin implements Admin {
}
@Override
public void move(final byte[] encodedRegionName, final byte[] destServerName) throws IOException {
public void move(byte[] encodedRegionName) throws IOException {
move(encodedRegionName, (ServerName) null);
}
public void move(final byte[] encodedRegionName, ServerName destServerName) throws IOException {
executeCallable(new MasterCallable<Void>(getConnection(), getRpcControllerFactory()) {
@Override
protected Void rpcCall() throws Exception {
setPriority(encodedRegionName);
MoveRegionRequest request =
RequestConverter.buildMoveRegionRequest(encodedRegionName,
destServerName != null ? ServerName.valueOf(Bytes.toString(destServerName)) : null);
RequestConverter.buildMoveRegionRequest(encodedRegionName, destServerName);
master.moveRegion(getRpcController(), request);
return null;
}
@ -1780,12 +1783,9 @@ public class HBaseAdmin implements Admin {
* @param units time units
* @throws IOException
*/
public void splitRegionSync(byte[] regionName, byte[] splitPoint,
final long timeout, final TimeUnit units) throws IOException {
get(
splitRegionAsync(regionName, splitPoint),
timeout,
units);
public void splitRegionSync(byte[] regionName, byte[] splitPoint, final long timeout,
final TimeUnit units) throws IOException {
get(splitRegionAsync(regionName, splitPoint), timeout, units);
}
@Override
@ -4276,4 +4276,9 @@ public class HBaseAdmin implements Admin {
}
});
}
@Override
public Future<Void> splitRegionAsync(byte[] regionName) throws IOException {
return splitRegionAsync(regionName, null);
}
}

View File

@ -28,7 +28,6 @@ import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import org.apache.commons.lang3.RandomUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.ClusterMetrics;
@ -253,7 +252,7 @@ public class Action {
break;
}
int targetIx = RandomUtils.nextInt(0, toServers.size());
admin.move(victimRegion, Bytes.toBytes(toServers.get(targetIx).getServerName()));
admin.move(victimRegion, toServers.get(targetIx));
}
}

View File

@ -31,7 +31,6 @@ import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.chaos.factories.MonkeyConstants;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.util.Bytes;
/**
* Action that tries to move every region of a table.
@ -98,9 +97,9 @@ public class MoveRegionsOfTableAction extends Action {
static void moveRegion(Admin admin, ServerName [] servers, RegionInfo regionInfo) {
try {
String destServerName = servers[RandomUtils.nextInt(0, servers.length)].getServerName();
ServerName destServerName = servers[RandomUtils.nextInt(0, servers.length)];
LOG.debug("Moving {} to {}", regionInfo.getRegionNameAsString(), destServerName);
admin.move(regionInfo.getEncodedNameAsBytes(), Bytes.toBytes(destServerName));
admin.move(regionInfo.getEncodedNameAsBytes(), destServerName);
} catch (Exception ex) {
LOG.warn("Move failed, might be caused by other chaos: {}", ex.getMessage());
}

View File

@ -19,7 +19,6 @@
package org.apache.hadoop.hbase.chaos.actions;
import java.util.List;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.TableName;
@ -62,7 +61,7 @@ public class SplitRandomRegionOfTableAction extends Action {
regions.toArray(new HRegionInfo[regions.size()]));
LOG.debug("Splitting region " + region.getRegionNameAsString());
try {
admin.splitRegion(region.getRegionName());
admin.splitRegionAsync(region.getRegionName()).get();
} catch (Exception ex) {
LOG.warn("Split failed, might be caused by other chaos: " + ex.getMessage());
}

View File

@ -128,9 +128,8 @@ public class TestRSGroupsAdmin2 extends TestRSGroupsBase {
});
// Lets move this region to the new group.
TEST_UTIL.getAdmin().move(
Bytes.toBytes(RegionInfo.encodeRegionName(Bytes.toBytes(targetRegion))),
Bytes.toBytes(targetServer.getServerName()));
TEST_UTIL.getAdmin()
.move(Bytes.toBytes(RegionInfo.encodeRegionName(Bytes.toBytes(targetRegion))), targetServer);
TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
@ -362,7 +361,7 @@ public class TestRSGroupsAdmin2 extends TestRSGroupsBase {
for (String region : regionList) {
// Lets move this region to the targetServer
TEST_UTIL.getAdmin().move(Bytes.toBytes(RegionInfo.encodeRegionName(Bytes.toBytes(region))),
Bytes.toBytes(targetServer.getServerName()));
targetServer);
}
TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {

View File

@ -106,7 +106,7 @@ public class TestRSGroupsBalance extends TestRSGroupsBase {
final ServerName first = assignMap.entrySet().iterator().next().getKey();
for (RegionInfo region : admin.getRegions(tableName)) {
if (!assignMap.get(first).contains(region.getRegionNameAsString())) {
admin.move(region.getEncodedNameAsBytes(), Bytes.toBytes(first.getServerName()));
admin.move(region.getEncodedNameAsBytes(), first);
}
}
TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {

View File

@ -118,8 +118,7 @@ public class TestRSGroupsOfflineMode {
if (master.getAssignmentManager().getRegionStates().getRegionAssignments()
.containsValue(failoverRS.getServerName())) {
for (RegionInfo regionInfo : hbaseAdmin.getRegions(failoverRS.getServerName())) {
hbaseAdmin.move(regionInfo.getEncodedNameAsBytes(),
Bytes.toBytes(failoverRS.getServerName().getServerName()));
hbaseAdmin.move(regionInfo.getEncodedNameAsBytes(), failoverRS.getServerName());
}
LOG.info("Waiting for region unassignments on failover RS...");
TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {

View File

@ -18,9 +18,7 @@
*/
package org.apache.hadoop.hbase.master.normalizer;
import java.io.IOException;
import java.util.Arrays;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.yetus.audience.InterfaceAudience;
@ -78,8 +76,8 @@ public class SplitNormalizationPlan implements NormalizationPlan {
public void execute(Admin admin) {
LOG.info("Executing splitting normalization plan: " + this);
try {
admin.splitRegion(regionInfo.getRegionName());
} catch (IOException ex) {
admin.splitRegionAsync(regionInfo.getRegionName()).get();
} catch (Exception ex) {
LOG.error("Error during region split: ", ex);
}
}

View File

@ -271,7 +271,7 @@ public class RegionMover extends AbstractHBaseTool implements Closeable {
LOG.info("Retry " + Integer.toString(count) + " of maximum " + Integer.toString(retries));
}
count = count + 1;
admin.move(region.getEncodedNameAsBytes(), Bytes.toBytes(targetServer.getServerName()));
admin.move(region.getEncodedNameAsBytes(), targetServer);
long maxWait = startTime + (maxWaitInSeconds * 1000);
while (EnvironmentEdgeManager.currentTime() < maxWait) {
sameServer = isSameServer(region, sourceServer);
@ -321,7 +321,7 @@ public class RegionMover extends AbstractHBaseTool implements Closeable {
try {
LOG.info("Moving region:" + region.getEncodedName() + " from " + sourceServer + " to "
+ targetServer);
admin.move(region.getEncodedNameAsBytes(), Bytes.toBytes(targetServer.getServerName()));
admin.move(region.getEncodedNameAsBytes(), targetServer);
LOG.info("Moved " + region.getEncodedName() + " from " + sourceServer + " to "
+ targetServer);
} catch (Exception e) {

View File

@ -3498,8 +3498,7 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility {
throws InterruptedException, IOException {
HMaster master = getMiniHBaseCluster().getMaster();
// TODO: Here we start the move. The move can take a while.
getAdmin().move(destRegion.getEncodedNameAsBytes(),
Bytes.toBytes(destServer.getServerName()));
getAdmin().move(destRegion.getEncodedNameAsBytes(), destServer);
while (true) {
ServerName serverName = master.getAssignmentManager().getRegionStates()
.getRegionServerOfRegion(destRegion);

View File

@ -828,8 +828,7 @@ public class TestPartialResultsFromClientSide {
assertEquals(1, regions.size());
RegionInfo regionInfo = regions.get(0).getFirst();
ServerName name = TEST_UTIL.getHBaseCluster().getRegionServer(index).getServerName();
TEST_UTIL.getAdmin().move(regionInfo.getEncodedNameAsBytes(),
Bytes.toBytes(name.getServerName()));
TEST_UTIL.getAdmin().move(regionInfo.getEncodedNameAsBytes(), name);
}
private void assertCell(Cell cell, byte[] row, byte[] cf, byte[] cq) {

View File

@ -29,7 +29,6 @@ import org.apache.hadoop.hbase.RegionLocations;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.Waiter.ExplainingPredicate;
import org.apache.hadoop.hbase.util.Bytes;
final class RegionReplicaTestHelper {
@ -89,8 +88,7 @@ final class RegionReplicaTestHelper {
ServerName newServerName = util.getHBaseCluster().getRegionServerThreads().stream()
.map(t -> t.getRegionServer().getServerName()).filter(sn -> !sn.equals(serverName)).findAny()
.get();
util.getAdmin().move(regionInfo.getEncodedNameAsBytes(),
Bytes.toBytes(newServerName.getServerName()));
util.getAdmin().move(regionInfo.getEncodedNameAsBytes(), newServerName);
util.waitFor(30000, new ExplainingPredicate<Exception>() {
@Override

View File

@ -1216,7 +1216,7 @@ public class TestAdmin1 {
// the element at index 1 would be a replica (since the metareader gives us ordered
// regions). Try splitting that region via the split API . Should fail
try {
TEST_UTIL.getAdmin().splitRegion(regions.get(1).getFirst().getRegionName());
TEST_UTIL.getAdmin().splitRegionAsync(regions.get(1).getFirst().getRegionName()).get();
} catch (IllegalArgumentException ex) {
gotException = true;
}

View File

@ -457,7 +457,7 @@ public class TestAdmin2 {
RegionInfo hri = tableRegions.get(0);
AssignmentManager am = master.getAssignmentManager();
ServerName server = am.getRegionStates().getRegionServerOfRegion(hri);
localAdmin.move(hri.getEncodedNameAsBytes(), Bytes.toBytes(server.getServerName()));
localAdmin.move(hri.getEncodedNameAsBytes(), server);
assertEquals("Current region server and region server before move should be same.", server,
am.getRegionStates().getRegionServerOfRegion(hri));
}

View File

@ -249,8 +249,7 @@ public class TestAsyncNonMetaRegionLocator {
.map(t -> t.getRegionServer().getServerName()).filter(sn -> !sn.equals(serverName)).findAny()
.get();
TEST_UTIL.getAdmin().move(Bytes.toBytes(loc.getRegion().getEncodedName()),
Bytes.toBytes(newServerName.getServerName()));
TEST_UTIL.getAdmin().move(Bytes.toBytes(loc.getRegion().getEncodedName()), newServerName);
while (!TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName()
.equals(newServerName)) {
Thread.sleep(100);
@ -326,7 +325,7 @@ public class TestAsyncNonMetaRegionLocator {
.get();
Admin admin = TEST_UTIL.getAdmin();
RegionInfo region = admin.getRegions(TABLE_NAME).stream().findAny().get();
admin.move(region.getEncodedNameAsBytes(), Bytes.toBytes(newServerName.getServerName()));
admin.move(region.getEncodedNameAsBytes(), newServerName);
TEST_UTIL.waitFor(30000, new ExplainingPredicate<Exception>() {
@Override

View File

@ -87,15 +87,14 @@ public class TestAsyncSingleRequestRpcRetryingCaller {
// This will leave a cached entry in location cache
HRegionLocation loc = CONN.getRegionLocator(TABLE_NAME).getRegionLocation(ROW).get();
int index = TEST_UTIL.getHBaseCluster().getServerWith(loc.getRegion().getRegionName());
TEST_UTIL.getAdmin().move(loc.getRegion().getEncodedNameAsBytes(), Bytes.toBytes(
TEST_UTIL.getHBaseCluster().getRegionServer(1 - index).getServerName().getServerName()));
TEST_UTIL.getAdmin().move(loc.getRegion().getEncodedNameAsBytes(),
TEST_UTIL.getHBaseCluster().getRegionServer(1 - index).getServerName());
AsyncTable<?> table = CONN.getTableBuilder(TABLE_NAME).setRetryPause(100, TimeUnit.MILLISECONDS)
.setMaxRetries(30).build();
table.put(new Put(ROW).addColumn(FAMILY, QUALIFIER, VALUE)).get();
// move back
TEST_UTIL.getAdmin().move(loc.getRegion().getEncodedNameAsBytes(),
Bytes.toBytes(loc.getServerName().getServerName()));
TEST_UTIL.getAdmin().move(loc.getRegion().getEncodedNameAsBytes(), loc.getServerName());
Result result = table.get(new Get(ROW).addColumn(FAMILY, QUALIFIER)).get();
assertArrayEquals(VALUE, result.getValue(FAMILY, QUALIFIER));
}

View File

@ -172,8 +172,7 @@ public class TestAsyncTableGetMultiThreaded {
ServerName newMetaServer = TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream()
.map(t -> t.getRegionServer().getServerName()).filter(s -> !s.equals(metaServer))
.findAny().get();
admin.move(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes(),
Bytes.toBytes(newMetaServer.getServerName()));
admin.move(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes(), newMetaServer);
Thread.sleep(5000);
}
stop.set(true);

View File

@ -40,7 +40,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.HBaseClassTestRule;
@ -232,8 +231,8 @@ public class TestConnectionImplementation {
final ConnectionImplementation hci = (ConnectionImplementation)TEST_UTIL.getConnection();
try (RegionLocator l = TEST_UTIL.getConnection().getRegionLocator(tableName)) {
while (l.getRegionLocation(rk).getPort() != sn.getPort()) {
TEST_UTIL.getAdmin().move(l.getRegionLocation(rk).getRegionInfo().
getEncodedNameAsBytes(), Bytes.toBytes(sn.toString()));
TEST_UTIL.getAdmin().move(l.getRegionLocation(rk).getRegionInfo().getEncodedNameAsBytes(),
sn);
TEST_UTIL.waitUntilNoRegionsInTransition();
hci.clearRegionCache(tableName);
}
@ -604,10 +603,7 @@ public class TestConnectionImplementation {
// Moving. It's possible that we don't have all the regions online at this point, so
// the test must depend only on the region we're looking at.
LOG.info("Move starting region="+toMove.getRegionInfo().getRegionNameAsString());
TEST_UTIL.getAdmin().move(
toMove.getRegionInfo().getEncodedNameAsBytes(),
destServerName.getServerName().getBytes()
);
TEST_UTIL.getAdmin().move(toMove.getRegionInfo().getEncodedNameAsBytes(), destServerName);
while (destServer.getOnlineRegion(regionName) == null ||
destServer.getRegionsInTransitionInRS().containsKey(encodedRegionNameBytes) ||
@ -670,10 +666,8 @@ public class TestConnectionImplementation {
// We move it back to do another test with a scan
LOG.info("Move starting region=" + toMove.getRegionInfo().getRegionNameAsString());
TEST_UTIL.getAdmin().move(
toMove.getRegionInfo().getEncodedNameAsBytes(),
curServer.getServerName().getServerName().getBytes()
);
TEST_UTIL.getAdmin().move(toMove.getRegionInfo().getEncodedNameAsBytes(),
curServer.getServerName());
while (curServer.getOnlineRegion(regionName) == null ||
destServer.getRegionsInTransitionInRS().containsKey(encodedRegionNameBytes) ||
@ -928,10 +922,7 @@ public class TestConnectionImplementation {
// Moving. It's possible that we don't have all the regions online at this point, so
// the test depends only on the region we're looking at.
LOG.info("Move starting region=" + toMove.getRegionInfo().getRegionNameAsString());
TEST_UTIL.getAdmin().move(
toMove.getRegionInfo().getEncodedNameAsBytes(),
destServerName.getServerName().getBytes()
);
TEST_UTIL.getAdmin().move(toMove.getRegionInfo().getEncodedNameAsBytes(), destServerName);
while (destServer.getOnlineRegion(regionName) == null ||
destServer.getRegionsInTransitionInRS().containsKey(encodedRegionNameBytes) ||

View File

@ -5362,8 +5362,7 @@ public class TestFromClientSide {
HRegionServer regionServer = TEST_UTIL.getHBaseCluster().getRegionServer(i);
ServerName addr = regionServer.getServerName();
if (addr.getPort() != addrBefore.getPort()) {
admin.move(regionInfo.getEncodedNameAsBytes(),
Bytes.toBytes(addr.toString()));
admin.move(regionInfo.getEncodedNameAsBytes(), addr);
// Wait for the region to move.
Thread.sleep(5000);
addrAfter = addr;

View File

@ -185,7 +185,7 @@ public class TestHBaseAdminNoCluster {
testMasterOperationIsRetried(new MethodCaller() {
@Override
public void call(Admin admin) throws Exception {
admin.move(new byte[0], null);
admin.move(new byte[0]);
}
@Override
public void verify(MasterKeepAliveConnection masterAdmin, int count) throws Exception {

View File

@ -131,7 +131,7 @@ public class TestMetaWithReplicas {
TEST_UTIL.getHBaseCluster().getRegionServer(metaServerIndex).getServerName();
assertNotEquals(destinationServerName, metaServerName);
TEST_UTIL.getAdmin().move(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes(),
Bytes.toBytes(destinationServerName.toString()));
destinationServerName);
}
// Disable the balancer
LoadBalancerTracker l = new LoadBalancerTracker(TEST_UTIL.getZooKeeperWatcher(),
@ -230,7 +230,7 @@ public class TestMetaWithReplicas {
// If the servers are the same, then move the test table's region out of the server
// to another random server
if (hrl.getServerName().equals(primary)) {
util.getAdmin().move(hrl.getRegionInfo().getEncodedNameAsBytes(), null);
util.getAdmin().move(hrl.getRegionInfo().getEncodedNameAsBytes());
// wait for the move to complete
do {
Thread.sleep(10);
@ -462,7 +462,7 @@ public class TestMetaWithReplicas {
TEST_UTIL.createTable(tableName, "f");
assertTrue(TEST_UTIL.getAdmin().tableExists(tableName));
TEST_UTIL.getAdmin().move(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes(),
Bytes.toBytes(moveToServer.getServerName()));
moveToServer);
int i = 0;
assert !moveToServer.equals(currentServer);
LOG.info("CurrentServer=" + currentServer + ", moveToServer=" + moveToServer);

View File

@ -92,8 +92,7 @@ public class TestMvccConsistentScanner {
HRegionServer rs =
UTIL.getHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer())
.filter(r -> !r.getOnlineTables().contains(tableName)).findAny().get();
UTIL.getAdmin().move(region.getEncodedNameAsBytes(),
Bytes.toBytes(rs.getServerName().getServerName()));
UTIL.getAdmin().move(region.getEncodedNameAsBytes(), rs.getServerName());
while (UTIL.getRSForFirstRegionInTable(tableName) != rs) {
Thread.sleep(100);
}

View File

@ -165,11 +165,11 @@ public class TestSeparateClientZKCluster {
Get get = new Get(row);
Result result = table.get(get);
// move meta region and confirm client could detect
byte[] destServerName = null;
ServerName destServerName = null;
for (RegionServerThread rst : cluster.getLiveRegionServerThreads()) {
ServerName name = rst.getRegionServer().getServerName();
if (!name.equals(cluster.getServerHoldingMeta())) {
destServerName = Bytes.toBytes(name.getServerName());
destServerName = name;
break;
}
}
@ -182,7 +182,7 @@ public class TestSeparateClientZKCluster {
for (RegionServerThread rst : cluster.getLiveRegionServerThreads()) {
ServerName name = rst.getRegionServer().getServerName();
if (!name.equals(currentServer)) {
destServerName = Bytes.toBytes(name.getServerName());
destServerName = name;
break;
}
}

View File

@ -307,7 +307,7 @@ public class TestSnapshotCloneIndependence {
originalRegionCount, cloneTableRegionCount);
// Split a region on the parent table
admin.splitRegion(originalTableHRegions.get(0).getRegionName());
admin.splitRegionAsync(originalTableHRegions.get(0).getRegionName()).get();
waitOnSplit(UTIL.getConnection(), originalTable, originalRegionCount);
// Verify that the cloned table region is not split

View File

@ -589,7 +589,7 @@ public class TestRegionObserverInterface {
ServerName sn2 = rs1.getRegionServer().getServerName();
String regEN = locator.getAllRegionLocations().get(0).getRegionInfo().getEncodedName();
util.getAdmin().move(regEN.getBytes(), sn2.getServerName().getBytes());
util.getAdmin().move(Bytes.toBytes(regEN), sn2);
while (!sn2.equals(locator.getAllRegionLocations().get(0).getServerName())) {
Thread.sleep(100);
}
@ -639,7 +639,7 @@ public class TestRegionObserverInterface {
ServerName sn2 = rs1.getRegionServer().getServerName();
String regEN = locator.getAllRegionLocations().get(0).getRegionInfo().getEncodedName();
util.getAdmin().move(regEN.getBytes(), sn2.getServerName().getBytes());
util.getAdmin().move(Bytes.toBytes(regEN), sn2);
while (!sn2.equals(locator.getAllRegionLocations().get(0).getServerName())) {
Thread.sleep(100);
}

View File

@ -731,8 +731,7 @@ public abstract class AbstractTestDLS {
// the RS doesn't have regions of the specified table so we need move one to this RS
List<RegionInfo> tableRegions = TEST_UTIL.getAdmin().getRegions(tableName);
RegionInfo hri = tableRegions.get(0);
TEST_UTIL.getAdmin().move(hri.getEncodedNameAsBytes(),
Bytes.toBytes(destRS.getServerName().getServerName()));
TEST_UTIL.getAdmin().move(hri.getEncodedNameAsBytes(), destRS.getServerName());
// wait for region move completes
RegionStates regionStates =
TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager().getRegionStates();

View File

@ -91,7 +91,7 @@ public class TestCatalogJanitorInMemoryStates {
* Test clearing a split parent from memory.
*/
@Test
public void testInMemoryParentCleanup() throws IOException, InterruptedException {
public void testInMemoryParentCleanup() throws Exception {
final AssignmentManager am = TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager();
final ServerManager sm = TEST_UTIL.getHBaseCluster().getMaster().getServerManager();
final CatalogJanitor janitor = TEST_UTIL.getHBaseCluster().getMaster().getCatalogJanitor();
@ -136,12 +136,12 @@ public class TestCatalogJanitorInMemoryStates {
* @throws IOException, InterruptedException
*/
private List<HRegionLocation> splitRegion(final RegionInfo r)
throws IOException, InterruptedException {
throws Exception {
List<HRegionLocation> locations = new ArrayList<>();
// Split this table in two.
Admin admin = TEST_UTIL.getAdmin();
Connection connection = TEST_UTIL.getConnection();
admin.splitRegion(r.getEncodedNameAsBytes());
admin.splitRegionAsync(r.getEncodedNameAsBytes()).get();
admin.close();
PairOfSameType<RegionInfo> regions = waitOnDaughters(r);
if (regions != null) {

View File

@ -115,8 +115,7 @@ public class TestCloseAnOpeningRegion {
HRegionServer dst = UTIL.getOtherRegionServer(src);
Thread move0 = new Thread(() -> {
try {
UTIL.getAdmin().move(region.getEncodedNameAsBytes(),
Bytes.toBytes(dst.getServerName().getServerName()));
UTIL.getAdmin().move(region.getEncodedNameAsBytes(), dst.getServerName());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
@ -125,8 +124,7 @@ public class TestCloseAnOpeningRegion {
ARRIVE.await();
Thread move1 = new Thread(() -> {
try {
UTIL.getAdmin().move(region.getEncodedNameAsBytes(),
Bytes.toBytes(src.getServerName().getServerName()));
UTIL.getAdmin().move(region.getEncodedNameAsBytes(), src.getServerName());
} catch (IOException e) {
throw new UncheckedIOException(e);
}

View File

@ -195,7 +195,7 @@ public class TestMaster {
.setStartKey(Bytes.toBytes("A"))
.setEndKey(Bytes.toBytes("Z"))
.build();
admin.move(hri.getEncodedNameAsBytes(), null);
admin.move(hri.getEncodedNameAsBytes());
fail("Region should not be moved since it is fake");
} catch (IOException ioe) {
assertTrue(ioe instanceof UnknownRegionException);
@ -217,7 +217,7 @@ public class TestMaster {
List<RegionInfo> tableRegions = admin.getRegions(tableName);
master.setInitialized(false); // fake it, set back later
admin.move(tableRegions.get(0).getEncodedNameAsBytes(), null);
admin.move(tableRegions.get(0).getEncodedNameAsBytes());
fail("Region should not be moved since master is not initialized");
} catch (IOException ioe) {
assertTrue(StringUtils.stringifyException(ioe).contains("PleaseHoldException"));

View File

@ -69,7 +69,7 @@ public class TestMasterHandlerFullWhenTransitRegion {
//See HBASE-21754
//There is Only one handler, if ReportRegionStateTransitionRequest executes in the same kind
// of thread with moveRegion, it will lock each other. Making the move operation can not finish.
UTIL.getAdmin().move(regionInfo.getEncodedNameAsBytes(), null);
UTIL.getAdmin().move(regionInfo.getEncodedNameAsBytes());
LOG.info("Region move complete");
}

View File

@ -150,8 +150,7 @@ public class TestCloseRegionWhileRSCrash {
if (!srcRs.getRegions(TableName.META_TABLE_NAME).isEmpty()) {
RegionInfo metaRegion = srcRs.getRegions(TableName.META_TABLE_NAME).get(0).getRegionInfo();
HRegionServer dstRs = UTIL.getOtherRegionServer(srcRs);
UTIL.getAdmin().move(metaRegion.getEncodedNameAsBytes(),
Bytes.toBytes(dstRs.getServerName().getServerName()));
UTIL.getAdmin().move(metaRegion.getEncodedNameAsBytes(), dstRs.getServerName());
UTIL.waitFor(30000, () -> !dstRs.getRegions(TableName.META_TABLE_NAME).isEmpty());
}
}
@ -175,8 +174,7 @@ public class TestCloseRegionWhileRSCrash {
() -> procExec.getProcedures().stream().anyMatch(p -> p instanceof ServerCrashProcedure));
Thread t = new Thread(() -> {
try {
UTIL.getAdmin().move(region.getEncodedNameAsBytes(),
Bytes.toBytes(dstRs.getServerName().getServerName()));
UTIL.getAdmin().move(region.getEncodedNameAsBytes(), dstRs.getServerName());
} catch (IOException e) {
}
});

View File

@ -152,8 +152,7 @@ public class TestFavoredStochasticBalancerPickers extends BalancerTestBase {
RegionStates rst = master.getAssignmentManager().getRegionStates();
for (int i = 0; i < regionsToMove; i++) {
final RegionInfo regionInfo = hris.get(i);
admin.move(regionInfo.getEncodedNameAsBytes(),
Bytes.toBytes(mostLoadedServer.getServerName()));
admin.move(regionInfo.getEncodedNameAsBytes(), mostLoadedServer);
LOG.info("Moving region: " + hris.get(i).getRegionNameAsString() + " to " + mostLoadedServer);
TEST_UTIL.waitFor(60000, new Waiter.Predicate<Exception>() {
@Override

View File

@ -65,7 +65,7 @@ public class TestCleanupMetaWAL {
HRegionServer serverWithMeta = TEST_UTIL.getMiniHBaseCluster()
.getRegionServer(TEST_UTIL.getMiniHBaseCluster().getServerWithMeta());
TEST_UTIL.getAdmin()
.move(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes(), null);
.move(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes());
LOG.info("KILL");
TEST_UTIL.getMiniHBaseCluster().killRegionServer(serverWithMeta.getServerName());
LOG.info("WAIT");

View File

@ -109,8 +109,7 @@ public class TestHRegionOnCluster {
TEST_UTIL.waitUntilAllRegionsAssigned(table.getName());
LOG.info("Moving " + regionInfo.getEncodedName() + " to " + targetServer.getServerName());
hbaseAdmin.move(regionInfo.getEncodedNameAsBytes(),
Bytes.toBytes(targetServer.getServerName().getServerName()));
hbaseAdmin.move(regionInfo.getEncodedNameAsBytes(), targetServer.getServerName());
do {
Thread.sleep(1);
} while (cluster.getServerWith(regionInfo.getRegionName()) == originServerNum);
@ -122,8 +121,7 @@ public class TestHRegionOnCluster {
TEST_UTIL.waitUntilAllRegionsAssigned(table.getName());
// Move region to origin server
LOG.info("Moving " + regionInfo.getEncodedName() + " to " + originServer.getServerName());
hbaseAdmin.move(regionInfo.getEncodedNameAsBytes(),
Bytes.toBytes(originServer.getServerName().getServerName()));
hbaseAdmin.move(regionInfo.getEncodedNameAsBytes(), originServer.getServerName());
do {
Thread.sleep(1);
} while (cluster.getServerWith(regionInfo.getRegionName()) == targetServerNum);

View File

@ -99,8 +99,7 @@ public class TestOpenSeqNumUnexpectedIncrease {
// will fail two times, and then verify that the open sequence number is still openSeqNum + 2
FAILED_OPEN.set(2);
UTIL.getAdmin().move(region.getRegionInfo().getEncodedNameAsBytes(),
Bytes.toBytes(dst.getServerName().getServerName()));
UTIL.getAdmin().move(region.getRegionInfo().getEncodedNameAsBytes(), dst.getServerName());
UTIL.waitTableAvailable(TABLE_NAME);
HRegion region1 = UTIL.getMiniHBaseCluster().getRegions(TABLE_NAME).get(0);

View File

@ -119,8 +119,7 @@ public class TestRegionMove {
// Offline the region and then try to move it. Should fail.
admin.unassign(regionToMove.getRegionName(), true);
try {
admin.move(regionToMove.getEncodedNameAsBytes(),
Bytes.toBytes(rs2.getServerName().toString()));
admin.move(regionToMove.getEncodedNameAsBytes(), rs2.getServerName());
fail();
} catch (DoNotRetryRegionException e) {
// We got expected exception
@ -133,8 +132,7 @@ public class TestRegionMove {
try {
// Move the region to the other RS -- should fail
admin.move(regionToMove.getEncodedNameAsBytes(),
Bytes.toBytes(rs2.getServerName().toString()));
admin.move(regionToMove.getEncodedNameAsBytes(), rs2.getServerName());
fail();
} catch (DoNotRetryIOException e) {
// We got expected exception

View File

@ -328,7 +328,7 @@ public class TestSplitTransactionOnCluster {
// We don't roll back here anymore. Instead we fail-fast on construction of the
// split transaction. Catch the exception instead.
try {
this.admin.splitRegionAsync(hri.getRegionName(), null);
this.admin.splitRegionAsync(hri.getRegionName());
fail();
} catch (DoNotRetryRegionException e) {
// Expected
@ -541,7 +541,7 @@ public class TestSplitTransactionOnCluster {
HRegionServer server = cluster.getRegionServer(tableRegionIndex);
printOutRegions(server, "Initial regions: ");
// Call split.
this.admin.splitRegionAsync(hri.getRegionName(), null);
this.admin.splitRegionAsync(hri.getRegionName());
List<HRegion> daughters = checkAndGetDaughters(tableName);
// Before cleanup, get a new master.
@ -837,7 +837,7 @@ public class TestSplitTransactionOnCluster {
private void split(final RegionInfo hri, final HRegionServer server, final int regionCount)
throws IOException, InterruptedException {
admin.splitRegionAsync(hri.getRegionName(), null);
admin.splitRegionAsync(hri.getRegionName());
for (int i = 0; cluster.getRegions(hri.getTable()).size() <= regionCount && i < 60; i++) {
LOG.debug("Waiting on region " + hri.getRegionNameAsString() + " to split");
Thread.sleep(2000);
@ -885,7 +885,7 @@ public class TestSplitTransactionOnCluster {
LOG.info("Moving " + hri.getRegionNameAsString() + " from " +
metaRegionServer.getServerName() + " to " +
hrs.getServerName() + "; metaServerIndex=" + metaServerIndex);
admin.move(hri.getEncodedNameAsBytes(), Bytes.toBytes(hrs.getServerName().toString()));
admin.move(hri.getEncodedNameAsBytes(), hrs.getServerName());
}
// Wait till table region is up on the server that is NOT carrying hbase:meta.
for (int i = 0; i < 100; i++) {

View File

@ -147,8 +147,7 @@ public class SerialReplicationTestBase {
}
protected static void moveRegion(RegionInfo region, HRegionServer rs) throws Exception {
UTIL.getAdmin().move(region.getEncodedNameAsBytes(),
Bytes.toBytes(rs.getServerName().getServerName()));
UTIL.getAdmin().move(region.getEncodedNameAsBytes(), rs.getServerName());
UTIL.waitFor(30000, new ExplainingPredicate<Exception>() {
@Override

View File

@ -2140,8 +2140,7 @@ public class TestAccessController extends SecureTestUtil {
AccessTestAction moveAction = new AccessTestAction() {
@Override
public Object run() throws Exception {
admin.move(hri.getEncodedNameAsBytes(),
Bytes.toBytes(newRs.getServerName().getServerName()));
admin.move(hri.getEncodedNameAsBytes(), newRs.getServerName());
return null;
}
};

View File

@ -717,9 +717,13 @@ public class ThriftAdmin implements Admin {
}
@Override
public void move(byte[] encodedRegionName, byte[] destServerName) {
public void move(byte[] encodedRegionName) {
throw new NotImplementedException("move not supported in ThriftAdmin");
}
@Override
public void move(byte[] encodedRegionName, ServerName destServerName) {
throw new NotImplementedException("move not supported in ThriftAdmin");
}
@Override
@ -1356,4 +1360,9 @@ public class ThriftAdmin implements Admin {
getUserPermissions(GetUserPermissionsRequest getUserPermissionsRequest) {
throw new NotImplementedException("getUserPermissions not supported in ThriftAdmin");
}
@Override
public Future<Void> splitRegionAsync(byte[] regionName) throws IOException {
return splitRegionAsync(regionName, null);
}
}