Skip to content
Merged
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
42 changes: 21 additions & 21 deletions hbase-hbck2/src/main/java/org/apache/hbase/HBCK2.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.ClusterConnection;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Hbck;
import org.apache.hadoop.hbase.client.Put;
Expand Down Expand Up @@ -151,7 +151,7 @@ public class HBCK2 extends Configured implements org.apache.hadoop.util.Tool {
* Check for HBCK support. Expects created connection.
* @param supportedVersions list of zero or more supported versions.
*/
void checkHBCKSupport(ClusterConnection connection, String cmd, String... supportedVersions)
void checkHBCKSupport(Connection connection, String cmd, String... supportedVersions)
throws IOException {
if (skipCheck) {
LOG.info("Skipped {} command version check; 'skip' set", cmd);
Expand All @@ -172,7 +172,7 @@ void checkHBCKSupport(ClusterConnection connection, String cmd, String... suppor
}
}

void checkFunctionSupported(ClusterConnection connection, String cmd) throws IOException {
void checkFunctionSupported(Connection connection, String cmd) throws IOException {
if (skipCheck) {
LOG.info("Skipped {} command version check; 'skip' set", cmd);
return;
Expand Down Expand Up @@ -234,12 +234,12 @@ TableState setTableState(Hbck hbck, TableName tableName, TableState.State state)
return hbck.setTableStateInMeta(new TableState(tableName, state));
}

int setRegionState(ClusterConnection connection, String region, RegionState.State newState)
int setRegionState(Connection connection, String region, RegionState.State newState)
throws IOException {
return setRegionState(connection, region, 0, newState);
}

int setRegionState(ClusterConnection connection, String[] args) throws IOException {
int setRegionState(Connection connection, String[] args) throws IOException {
Options options = new Options();
Option inputFile = Option.builder("i").longOpt("inputFiles").build();
options.addOption(inputFile);
Expand Down Expand Up @@ -267,7 +267,7 @@ int setRegionState(ClusterConnection connection, String[] args) throws IOExcepti
}
}

int setRegionStateByArgs(ClusterConnection connection, String[] args) throws IOException {
int setRegionStateByArgs(Connection connection, String[] args) throws IOException {
if (args == null || args.length < 3) {
return EXIT_FAILURE;
}
Expand All @@ -276,7 +276,7 @@ int setRegionStateByArgs(ClusterConnection connection, String[] args) throws IOE
return setRegionState(connection, args[0], replicaId, state);
}

int setRegionState(ClusterConnection connection, String region, int replicaId,
int setRegionState(Connection connection, String region, int replicaId,
RegionState.State newState) throws IOException {
if (newState == null) {
throw new IllegalArgumentException("State can't be null.");
Expand Down Expand Up @@ -571,7 +571,7 @@ List<Boolean> bypass(String[] args) throws IOException {
List<Long> pids = Arrays.stream(pidStrs).map(Long::valueOf).collect(Collectors.toList());

// Process here
try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) {
try (Connection connection = connect(); Hbck hbck = connection.getHbck()) {
checkFunctionSupported(connection, BYPASS);
if (batchSize == NO_BATCH_SIZE) {
return hbck.bypassProcedure(pids, lockWait, overrideFlag, recursiveFlag);
Expand Down Expand Up @@ -615,7 +615,7 @@ void regionInfoMismatch(String[] args) throws Exception {
CommandLineParser parser = new DefaultParser();
CommandLine commandLine = parser.parse(options, args, false);
final boolean fix = commandLine.hasOption(dryRunOption.getOpt());
try (ClusterConnection connection = connect()) {
try (Connection connection = connect()) {
new RegionInfoMismatchTool(connection).run(fix);
}
}
Expand Down Expand Up @@ -1140,8 +1140,8 @@ public int run(String[] args) throws IOException {
* Create connection. Needs to be called before we go against remote server. Be sure to close when
* done.
*/
ClusterConnection connect() throws IOException {
return (ClusterConnection) ConnectionFactory.createConnection(getConf());
Connection connect() throws IOException {
return ConnectionFactory.createConnection(getConf());
}

/**
Expand All @@ -1166,7 +1166,7 @@ private int doCommandLine(CommandLine commandLine, Options options) throws IOExc
+ " takes tablename and state arguments: e.g. user ENABLED, or a list of input files");
return EXIT_FAILURE;
}
try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) {
try (Connection connection = connect(); Hbck hbck = connection.getHbck()) {
checkFunctionSupported(connection, command);
setTableState(hbck, purgeFirst(commands));
}
Expand All @@ -1177,7 +1177,7 @@ private int doCommandLine(CommandLine commandLine, Options options) throws IOExc
showErrorMessage(command + " takes one or more encoded region names");
return EXIT_FAILURE;
}
try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) {
try (Connection connection = connect(); Hbck hbck = connection.getHbck()) {
checkFunctionSupported(connection, command);
System.out.println(assigns(hbck, purgeFirst(commands)));
}
Expand Down Expand Up @@ -1206,7 +1206,7 @@ private int doCommandLine(CommandLine commandLine, Options options) throws IOExc
showErrorMessage(command + " takes one or more encoded region names");
return EXIT_FAILURE;
}
try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) {
try (Connection connection = connect(); Hbck hbck = connection.getHbck()) {
checkFunctionSupported(connection, command);
System.out.println(toString(unassigns(hbck, purgeFirst(commands))));
}
Expand All @@ -1219,13 +1219,13 @@ private int doCommandLine(CommandLine commandLine, Options options) throws IOExc
return EXIT_FAILURE;
}

try (ClusterConnection connection = connect()) {
try (Connection connection = connect()) {
checkHBCKSupport(connection, command);
return setRegionState(connection, purgeFirst(commands));
}

case FILESYSTEM:
try (ClusterConnection connection = connect()) {
try (Connection connection = connect()) {
checkHBCKSupport(connection, command);
try (FileSystemFsck fsfsck = new FileSystemFsck(getConf())) {
Pair<CommandLine, List<String>> pair =
Expand All @@ -1237,7 +1237,7 @@ private int doCommandLine(CommandLine commandLine, Options options) throws IOExc
}

case REPLICATION:
try (ClusterConnection connection = connect()) {
try (Connection connection = connect()) {
checkHBCKSupport(connection, command, "2.1.1", "2.2.0", "3.0.0");
try (ReplicationFsck replicationFsck = new ReplicationFsck(getConf())) {
Pair<CommandLine, List<String>> pair =
Expand All @@ -1253,7 +1253,7 @@ private int doCommandLine(CommandLine commandLine, Options options) throws IOExc
showErrorMessage(command + " takes one or more serverNames");
return EXIT_FAILURE;
}
try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) {
try (Connection connection = connect(); Hbck hbck = connection.getHbck()) {
checkFunctionSupported(connection, command);
System.out.println(toString(scheduleRecoveries(hbck, purgeFirst(commands))));
}
Expand All @@ -1264,7 +1264,7 @@ private int doCommandLine(CommandLine commandLine, Options options) throws IOExc
showErrorMessage(command + " doesn't take any arguments");
return EXIT_FAILURE;
}
try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) {
try (Connection connection = connect(); Hbck hbck = connection.getHbck()) {
checkFunctionSupported(connection, command);
System.out.println(toString(recoverUnknown(hbck)));
}
Expand All @@ -1275,7 +1275,7 @@ private int doCommandLine(CommandLine commandLine, Options options) throws IOExc
showErrorMessage(command + " doesn't take any arguments");
return EXIT_FAILURE;
}
try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) {
try (Connection connection = connect(); Hbck hbck = connection.getHbck()) {
checkFunctionSupported(connection, command);
hbck.fixMeta();
System.out.println("Server-side processing of fixMeta triggered.");
Expand Down Expand Up @@ -1320,7 +1320,7 @@ private int doCommandLine(CommandLine commandLine, Options options) throws IOExc
List<String> tableNames = Arrays.asList(purgeFirst(commands));
MissingTableDescriptorGenerator tableInfoGenerator =
new MissingTableDescriptorGenerator(getConf());
try (ClusterConnection connection = connect()) {
try (Connection connection = connect()) {
tableInfoGenerator.generateTableDescriptorFileIfMissing(connection.getAdmin(),
tableNames);
} catch (IOException e) {
Expand Down
27 changes: 13 additions & 14 deletions hbase-hbck2/src/test/java/org/apache/hbase/TestHBCK2.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.ClusterConnection;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Hbck;
Expand Down Expand Up @@ -116,14 +115,14 @@ public void after() throws Exception {

@Test(expected = UnsupportedOperationException.class)
public void testVersions() throws IOException {
try (ClusterConnection connection = this.hbck2.connect()) {
try (Connection connection = this.hbck2.connect()) {
this.hbck2.checkHBCKSupport(connection, "test", "10.0.0");
}
}

@Test
public void testSetTableStateInMeta() throws IOException {
try (ClusterConnection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
try (Connection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
TableState state = this.hbck2.setTableState(hbck, TABLE_NAME, TableState.State.DISABLED);
assertTrue("Found=" + state.getState(), state.isEnabled());
// Restore the state.
Expand All @@ -145,7 +144,7 @@ public void testSetTableStateWithInputFiles() throws IOException {
assertTrue(result.contains("tableName=TestHBCK2, state=ENABLED"));

// Restore the state.
try (ClusterConnection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
try (Connection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
TableState state = this.hbck2.setTableState(hbck, TABLE_NAME, TableState.State.ENABLED);
assertTrue("Found=" + state.getState(), state.isDisabled());
}
Expand Down Expand Up @@ -181,7 +180,7 @@ public void testAssigns() throws IOException {
String[] regionStrsArray =
regions.stream().map(RegionInfo::getEncodedName).toArray(String[]::new);

try (ClusterConnection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
try (Connection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
unassigns(regions, regionStrsArray);
List<Long> pids = this.hbck2.assigns(hbck, regionStrsArray);
validateRegionEndState(pids, regions, true);
Expand Down Expand Up @@ -224,7 +223,7 @@ public void testSetRegionState() throws IOException {
RegionInfo info = regions.get(0);
assertEquals(RegionState.State.OPEN, getCurrentRegionState(info));
String region = info.getEncodedName();
try (ClusterConnection connection = this.hbck2.connect()) {
try (Connection connection = this.hbck2.connect()) {
this.hbck2.setRegionState(connection, region, RegionState.State.CLOSING);
}
assertEquals(RegionState.State.CLOSING, getCurrentRegionState(info));
Expand All @@ -242,7 +241,7 @@ public void testSetRegionStateWithArgsList() throws IOException {
assertEquals(RegionState.State.OPEN, getCurrentRegionState(info));
String region = info.getEncodedName();
String[] args = new String[] { region, "0", "CLOSING" };
try (ClusterConnection connection = this.hbck2.connect()) {
try (Connection connection = this.hbck2.connect()) {
this.hbck2.setRegionStateByArgs(connection, args);
}
assertEquals(RegionState.State.CLOSING, getCurrentRegionState(info));
Expand Down Expand Up @@ -290,7 +289,7 @@ public void testSetReplicaRegionState() throws IOException, InterruptedException
int replicaId = regions.get(1).getReplicaId();
assertEquals(RegionState.State.OPEN, getCurrentRegionState(regions.get(0), replicaId));
String primaryRegion = primaryRegionInfo.getEncodedName();
try (ClusterConnection connection = this.hbck2.connect()) {
try (Connection connection = this.hbck2.connect()) {
this.hbck2.setRegionState(connection, primaryRegion, regions.get(1).getReplicaId(),
RegionState.State.CLOSING);
}
Expand All @@ -302,7 +301,7 @@ public void testSetReplicaRegionState() throws IOException, InterruptedException

@Test
public void testSetRegionStateInvalidRegion() throws IOException {
try (ClusterConnection connection = this.hbck2.connect()) {
try (Connection connection = this.hbck2.connect()) {
assertEquals(HBCK2.EXIT_FAILURE,
this.hbck2.setRegionState(connection, "NO_REGION", RegionState.State.CLOSING));
}
Expand All @@ -316,7 +315,7 @@ public void testSetRegionStateInvalidState() throws IOException {
RegionInfo info = regions.get(0);
assertEquals(RegionState.State.OPEN, getCurrentRegionState(info));
String region = info.getEncodedName();
try (ClusterConnection connection = this.hbck2.connect()) {
try (Connection connection = this.hbck2.connect()) {
this.hbck2.setRegionState(connection, region, null);
}
} finally {
Expand Down Expand Up @@ -409,7 +408,7 @@ private List<Long> getPidsFromResult(String result) {
}

private void unassigns(List<RegionInfo> regions, String[] regionStrsArray) throws IOException {
try (ClusterConnection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
try (Connection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
List<Long> pids = this.hbck2.unassigns(hbck, regionStrsArray);
waitOnPids(pids);
}
Expand Down Expand Up @@ -503,7 +502,7 @@ private void testReportMissingRegionsInMeta(int missingRegionsInTestTbl,

@Test(expected = IllegalArgumentException.class)
public void testSetRegionStateInvalidRegionAndInvalidState() throws IOException {
try (ClusterConnection connection = this.hbck2.connect()) {
try (Connection connection = this.hbck2.connect()) {
this.hbck2.setRegionState(connection, "NO_REGION", null);
}
}
Expand Down Expand Up @@ -682,14 +681,14 @@ public void testFormatFixExtraInMetaOneExtraSpecificTable() throws IOException {

@Test
public void testFunctionSupported() throws IOException {
try (ClusterConnection connection = this.hbck2.connect()) {
try (Connection connection = this.hbck2.connect()) {
this.hbck2.checkFunctionSupported(connection, "scheduleRecoveries");
}
}

@Test(expected = UnsupportedOperationException.class)
public void testFunctionNotSupported() throws IOException {
try (ClusterConnection connection = this.hbck2.connect()) {
try (Connection connection = this.hbck2.connect()) {
this.hbck2.checkFunctionSupported(connection, "test");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.io.IOException;
import java.util.List;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.client.ClusterConnection;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Hbck;
import org.junit.AfterClass;
import org.junit.Before;
Expand Down Expand Up @@ -55,7 +55,7 @@ public void before() {

@Test
public void testKnownServersNotRecovered() throws IOException {
try (ClusterConnection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
try (Connection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
List<Long> pids = this.hbck2.recoverUnknown(hbck);
assertEquals(0, pids.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.io.IOException;
import java.util.List;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.client.ClusterConnection;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Hbck;
import org.junit.AfterClass;
import org.junit.Before;
Expand Down Expand Up @@ -53,7 +53,7 @@ public void before() {
public void testSchedulingSCPWithTwoGoodHosts() throws IOException {
String sn1 = TEST_UTIL.getHBaseCluster().getRegionServer(0).toString();
String sn2 = TEST_UTIL.getHBaseCluster().getRegionServer(1).toString();
try (ClusterConnection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
try (Connection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
List<Long> pids = this.hbck2.scheduleRecoveries(hbck, new String[] { sn1, sn2 });
assertEquals(2, pids.size());
assertTrue(pids.get(0) > 0);
Expand Down