Skip to content

Commit 70f35da

Browse files
authored
HBASE-22712 [HBCK2] Remove ClusterConnection dependency in hbck2 (#149)
Signed-off-by: Nihal Jain <nihaljain@apache.org>
1 parent fd5a5fb commit 70f35da

4 files changed

Lines changed: 38 additions & 39 deletions

File tree

hbase-hbck2/src/main/java/org/apache/hbase/HBCK2.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
import org.apache.hadoop.hbase.ServerName;
5252
import org.apache.hadoop.hbase.TableName;
5353
import org.apache.hadoop.hbase.client.Admin;
54-
import org.apache.hadoop.hbase.client.ClusterConnection;
54+
import org.apache.hadoop.hbase.client.Connection;
5555
import org.apache.hadoop.hbase.client.ConnectionFactory;
5656
import org.apache.hadoop.hbase.client.Hbck;
5757
import org.apache.hadoop.hbase.client.Put;
@@ -151,7 +151,7 @@ public class HBCK2 extends Configured implements org.apache.hadoop.util.Tool {
151151
* Check for HBCK support. Expects created connection.
152152
* @param supportedVersions list of zero or more supported versions.
153153
*/
154-
void checkHBCKSupport(ClusterConnection connection, String cmd, String... supportedVersions)
154+
void checkHBCKSupport(Connection connection, String cmd, String... supportedVersions)
155155
throws IOException {
156156
if (skipCheck) {
157157
LOG.info("Skipped {} command version check; 'skip' set", cmd);
@@ -172,7 +172,7 @@ void checkHBCKSupport(ClusterConnection connection, String cmd, String... suppor
172172
}
173173
}
174174

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

237-
int setRegionState(ClusterConnection connection, String region, RegionState.State newState)
237+
int setRegionState(Connection connection, String region, RegionState.State newState)
238238
throws IOException {
239239
return setRegionState(connection, region, 0, newState);
240240
}
241241

242-
int setRegionState(ClusterConnection connection, String[] args) throws IOException {
242+
int setRegionState(Connection connection, String[] args) throws IOException {
243243
Options options = new Options();
244244
Option inputFile = Option.builder("i").longOpt("inputFiles").build();
245245
options.addOption(inputFile);
@@ -267,7 +267,7 @@ int setRegionState(ClusterConnection connection, String[] args) throws IOExcepti
267267
}
268268
}
269269

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

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

573573
// Process here
574-
try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) {
574+
try (Connection connection = connect(); Hbck hbck = connection.getHbck()) {
575575
checkFunctionSupported(connection, BYPASS);
576576
if (batchSize == NO_BATCH_SIZE) {
577577
return hbck.bypassProcedure(pids, lockWait, overrideFlag, recursiveFlag);
@@ -615,7 +615,7 @@ void regionInfoMismatch(String[] args) throws Exception {
615615
CommandLineParser parser = new DefaultParser();
616616
CommandLine commandLine = parser.parse(options, args, false);
617617
final boolean fix = commandLine.hasOption(dryRunOption.getOpt());
618-
try (ClusterConnection connection = connect()) {
618+
try (Connection connection = connect()) {
619619
new RegionInfoMismatchTool(connection).run(fix);
620620
}
621621
}
@@ -1140,8 +1140,8 @@ public int run(String[] args) throws IOException {
11401140
* Create connection. Needs to be called before we go against remote server. Be sure to close when
11411141
* done.
11421142
*/
1143-
ClusterConnection connect() throws IOException {
1144-
return (ClusterConnection) ConnectionFactory.createConnection(getConf());
1143+
Connection connect() throws IOException {
1144+
return ConnectionFactory.createConnection(getConf());
11451145
}
11461146

11471147
/**
@@ -1166,7 +1166,7 @@ private int doCommandLine(CommandLine commandLine, Options options) throws IOExc
11661166
+ " takes tablename and state arguments: e.g. user ENABLED, or a list of input files");
11671167
return EXIT_FAILURE;
11681168
}
1169-
try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) {
1169+
try (Connection connection = connect(); Hbck hbck = connection.getHbck()) {
11701170
checkFunctionSupported(connection, command);
11711171
setTableState(hbck, purgeFirst(commands));
11721172
}
@@ -1177,7 +1177,7 @@ private int doCommandLine(CommandLine commandLine, Options options) throws IOExc
11771177
showErrorMessage(command + " takes one or more encoded region names");
11781178
return EXIT_FAILURE;
11791179
}
1180-
try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) {
1180+
try (Connection connection = connect(); Hbck hbck = connection.getHbck()) {
11811181
checkFunctionSupported(connection, command);
11821182
System.out.println(assigns(hbck, purgeFirst(commands)));
11831183
}
@@ -1206,7 +1206,7 @@ private int doCommandLine(CommandLine commandLine, Options options) throws IOExc
12061206
showErrorMessage(command + " takes one or more encoded region names");
12071207
return EXIT_FAILURE;
12081208
}
1209-
try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) {
1209+
try (Connection connection = connect(); Hbck hbck = connection.getHbck()) {
12101210
checkFunctionSupported(connection, command);
12111211
System.out.println(toString(unassigns(hbck, purgeFirst(commands))));
12121212
}
@@ -1219,13 +1219,13 @@ private int doCommandLine(CommandLine commandLine, Options options) throws IOExc
12191219
return EXIT_FAILURE;
12201220
}
12211221

1222-
try (ClusterConnection connection = connect()) {
1222+
try (Connection connection = connect()) {
12231223
checkHBCKSupport(connection, command);
12241224
return setRegionState(connection, purgeFirst(commands));
12251225
}
12261226

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

12391239
case REPLICATION:
1240-
try (ClusterConnection connection = connect()) {
1240+
try (Connection connection = connect()) {
12411241
checkHBCKSupport(connection, command, "2.1.1", "2.2.0", "3.0.0");
12421242
try (ReplicationFsck replicationFsck = new ReplicationFsck(getConf())) {
12431243
Pair<CommandLine, List<String>> pair =
@@ -1253,7 +1253,7 @@ private int doCommandLine(CommandLine commandLine, Options options) throws IOExc
12531253
showErrorMessage(command + " takes one or more serverNames");
12541254
return EXIT_FAILURE;
12551255
}
1256-
try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) {
1256+
try (Connection connection = connect(); Hbck hbck = connection.getHbck()) {
12571257
checkFunctionSupported(connection, command);
12581258
System.out.println(toString(scheduleRecoveries(hbck, purgeFirst(commands))));
12591259
}
@@ -1264,7 +1264,7 @@ private int doCommandLine(CommandLine commandLine, Options options) throws IOExc
12641264
showErrorMessage(command + " doesn't take any arguments");
12651265
return EXIT_FAILURE;
12661266
}
1267-
try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) {
1267+
try (Connection connection = connect(); Hbck hbck = connection.getHbck()) {
12681268
checkFunctionSupported(connection, command);
12691269
System.out.println(toString(recoverUnknown(hbck)));
12701270
}
@@ -1275,7 +1275,7 @@ private int doCommandLine(CommandLine commandLine, Options options) throws IOExc
12751275
showErrorMessage(command + " doesn't take any arguments");
12761276
return EXIT_FAILURE;
12771277
}
1278-
try (ClusterConnection connection = connect(); Hbck hbck = connection.getHbck()) {
1278+
try (Connection connection = connect(); Hbck hbck = connection.getHbck()) {
12791279
checkFunctionSupported(connection, command);
12801280
hbck.fixMeta();
12811281
System.out.println("Server-side processing of fixMeta triggered.");
@@ -1320,7 +1320,7 @@ private int doCommandLine(CommandLine commandLine, Options options) throws IOExc
13201320
List<String> tableNames = Arrays.asList(purgeFirst(commands));
13211321
MissingTableDescriptorGenerator tableInfoGenerator =
13221322
new MissingTableDescriptorGenerator(getConf());
1323-
try (ClusterConnection connection = connect()) {
1323+
try (Connection connection = connect()) {
13241324
tableInfoGenerator.generateTableDescriptorFileIfMissing(connection.getAdmin(),
13251325
tableNames);
13261326
} catch (IOException e) {

hbase-hbck2/src/test/java/org/apache/hbase/TestHBCK2.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.apache.hadoop.hbase.HConstants;
4242
import org.apache.hadoop.hbase.TableName;
4343
import org.apache.hadoop.hbase.client.Admin;
44-
import org.apache.hadoop.hbase.client.ClusterConnection;
4544
import org.apache.hadoop.hbase.client.Connection;
4645
import org.apache.hadoop.hbase.client.Get;
4746
import org.apache.hadoop.hbase.client.Hbck;
@@ -116,14 +115,14 @@ public void after() throws Exception {
116115

117116
@Test(expected = UnsupportedOperationException.class)
118117
public void testVersions() throws IOException {
119-
try (ClusterConnection connection = this.hbck2.connect()) {
118+
try (Connection connection = this.hbck2.connect()) {
120119
this.hbck2.checkHBCKSupport(connection, "test", "10.0.0");
121120
}
122121
}
123122

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

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

184-
try (ClusterConnection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
183+
try (Connection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
185184
unassigns(regions, regionStrsArray);
186185
List<Long> pids = this.hbck2.assigns(hbck, regionStrsArray);
187186
validateRegionEndState(pids, regions, true);
@@ -224,7 +223,7 @@ public void testSetRegionState() throws IOException {
224223
RegionInfo info = regions.get(0);
225224
assertEquals(RegionState.State.OPEN, getCurrentRegionState(info));
226225
String region = info.getEncodedName();
227-
try (ClusterConnection connection = this.hbck2.connect()) {
226+
try (Connection connection = this.hbck2.connect()) {
228227
this.hbck2.setRegionState(connection, region, RegionState.State.CLOSING);
229228
}
230229
assertEquals(RegionState.State.CLOSING, getCurrentRegionState(info));
@@ -242,7 +241,7 @@ public void testSetRegionStateWithArgsList() throws IOException {
242241
assertEquals(RegionState.State.OPEN, getCurrentRegionState(info));
243242
String region = info.getEncodedName();
244243
String[] args = new String[] { region, "0", "CLOSING" };
245-
try (ClusterConnection connection = this.hbck2.connect()) {
244+
try (Connection connection = this.hbck2.connect()) {
246245
this.hbck2.setRegionStateByArgs(connection, args);
247246
}
248247
assertEquals(RegionState.State.CLOSING, getCurrentRegionState(info));
@@ -290,7 +289,7 @@ public void testSetReplicaRegionState() throws IOException, InterruptedException
290289
int replicaId = regions.get(1).getReplicaId();
291290
assertEquals(RegionState.State.OPEN, getCurrentRegionState(regions.get(0), replicaId));
292291
String primaryRegion = primaryRegionInfo.getEncodedName();
293-
try (ClusterConnection connection = this.hbck2.connect()) {
292+
try (Connection connection = this.hbck2.connect()) {
294293
this.hbck2.setRegionState(connection, primaryRegion, regions.get(1).getReplicaId(),
295294
RegionState.State.CLOSING);
296295
}
@@ -302,7 +301,7 @@ public void testSetReplicaRegionState() throws IOException, InterruptedException
302301

303302
@Test
304303
public void testSetRegionStateInvalidRegion() throws IOException {
305-
try (ClusterConnection connection = this.hbck2.connect()) {
304+
try (Connection connection = this.hbck2.connect()) {
306305
assertEquals(HBCK2.EXIT_FAILURE,
307306
this.hbck2.setRegionState(connection, "NO_REGION", RegionState.State.CLOSING));
308307
}
@@ -316,7 +315,7 @@ public void testSetRegionStateInvalidState() throws IOException {
316315
RegionInfo info = regions.get(0);
317316
assertEquals(RegionState.State.OPEN, getCurrentRegionState(info));
318317
String region = info.getEncodedName();
319-
try (ClusterConnection connection = this.hbck2.connect()) {
318+
try (Connection connection = this.hbck2.connect()) {
320319
this.hbck2.setRegionState(connection, region, null);
321320
}
322321
} finally {
@@ -409,7 +408,7 @@ private List<Long> getPidsFromResult(String result) {
409408
}
410409

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

504503
@Test(expected = IllegalArgumentException.class)
505504
public void testSetRegionStateInvalidRegionAndInvalidState() throws IOException {
506-
try (ClusterConnection connection = this.hbck2.connect()) {
505+
try (Connection connection = this.hbck2.connect()) {
507506
this.hbck2.setRegionState(connection, "NO_REGION", null);
508507
}
509508
}
@@ -682,14 +681,14 @@ public void testFormatFixExtraInMetaOneExtraSpecificTable() throws IOException {
682681

683682
@Test
684683
public void testFunctionSupported() throws IOException {
685-
try (ClusterConnection connection = this.hbck2.connect()) {
684+
try (Connection connection = this.hbck2.connect()) {
686685
this.hbck2.checkFunctionSupported(connection, "scheduleRecoveries");
687686
}
688687
}
689688

690689
@Test(expected = UnsupportedOperationException.class)
691690
public void testFunctionNotSupported() throws IOException {
692-
try (ClusterConnection connection = this.hbck2.connect()) {
691+
try (Connection connection = this.hbck2.connect()) {
693692
this.hbck2.checkFunctionSupported(connection, "test");
694693
}
695694
}

hbase-hbck2/src/test/java/org/apache/hbase/TestRecoverUnknown.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.io.IOException;
2323
import java.util.List;
2424
import org.apache.hadoop.hbase.HBaseTestingUtility;
25-
import org.apache.hadoop.hbase.client.ClusterConnection;
25+
import org.apache.hadoop.hbase.client.Connection;
2626
import org.apache.hadoop.hbase.client.Hbck;
2727
import org.junit.AfterClass;
2828
import org.junit.Before;
@@ -55,7 +55,7 @@ public void before() {
5555

5656
@Test
5757
public void testKnownServersNotRecovered() throws IOException {
58-
try (ClusterConnection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
58+
try (Connection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
5959
List<Long> pids = this.hbck2.recoverUnknown(hbck);
6060
assertEquals(0, pids.size());
6161
}

hbase-hbck2/src/test/java/org/apache/hbase/TestSchedulingRecoveries.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.io.IOException;
2424
import java.util.List;
2525
import org.apache.hadoop.hbase.HBaseTestingUtility;
26-
import org.apache.hadoop.hbase.client.ClusterConnection;
26+
import org.apache.hadoop.hbase.client.Connection;
2727
import org.apache.hadoop.hbase.client.Hbck;
2828
import org.junit.AfterClass;
2929
import org.junit.Before;
@@ -53,7 +53,7 @@ public void before() {
5353
public void testSchedulingSCPWithTwoGoodHosts() throws IOException {
5454
String sn1 = TEST_UTIL.getHBaseCluster().getRegionServer(0).toString();
5555
String sn2 = TEST_UTIL.getHBaseCluster().getRegionServer(1).toString();
56-
try (ClusterConnection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
56+
try (Connection connection = this.hbck2.connect(); Hbck hbck = connection.getHbck()) {
5757
List<Long> pids = this.hbck2.scheduleRecoveries(hbck, new String[] { sn1, sn2 });
5858
assertEquals(2, pids.size());
5959
assertTrue(pids.get(0) > 0);

0 commit comments

Comments
 (0)