@@ -156,7 +156,6 @@ public enum Counters {
156
156
private int sleepMsBeforeReCompare ;
157
157
private String delimiter = "" ;
158
158
private boolean verbose = false ;
159
- private int batch = -1 ;
160
159
161
160
/**
162
161
* Map method that compares every scanned row with the equivalent from a distant cluster.
@@ -178,7 +177,7 @@ public void map(ImmutableBytesWritable row, final Result value, Context context)
178
177
}
179
178
delimiter = conf .get (NAME + ".delimiter" , "" );
180
179
verbose = conf .getBoolean (NAME + ".verbose" , false );
181
- batch = conf .getInt (NAME + ".batch" , -1 );
180
+ int batch = conf .getInt (NAME + ".batch" , -1 );
182
181
final Scan scan = new Scan ();
183
182
if (batch > 0 ) {
184
183
scan .setBatch (batch );
@@ -200,7 +199,7 @@ public void map(ImmutableBytesWritable row, final Result value, Context context)
200
199
setRowPrefixFilter (scan , rowPrefixes );
201
200
scan .setTimeRange (startTime , endTime );
202
201
int versions = conf .getInt (NAME + ".versions" , -1 );
203
- LOG .info ("Setting number of version inside map as: " + versions );
202
+ LOG .info ("Setting number of version inside map as: {}" , versions );
204
203
if (versions >= 0 ) {
205
204
scan .readVersions (versions );
206
205
}
@@ -245,9 +244,9 @@ public void map(ImmutableBytesWritable row, final Result value, Context context)
245
244
String peerHBaseRootAddress = conf .get (NAME + ".peerHBaseRootAddress" , null );
246
245
FileSystem .setDefaultUri (peerConf , peerFSAddress );
247
246
CommonFSUtils .setRootDir (peerConf , new Path (peerHBaseRootAddress ));
248
- LOG .info ("Using peer snapshot:" + peerSnapshotName + " with temp dir:"
249
- + peerSnapshotTmpDir + " peer root uri:" + CommonFSUtils .getRootDir (peerConf )
250
- + " peerFSAddress:" + peerFSAddress );
247
+ LOG .info ("Using peer snapshot:{} with temp dir:{} peer root uri:{} peerFSAddress:{}" ,
248
+ peerSnapshotName , peerSnapshotTmpDir , CommonFSUtils .getRootDir (peerConf ),
249
+ peerFSAddress );
251
250
252
251
replicatedScanner = new TableSnapshotScanner (peerConf , CommonFSUtils .getRootDir (peerConf ),
253
252
new Path (peerFSAddress , peerSnapshotTmpDir ), peerSnapshotName , scan , true );
@@ -269,8 +268,8 @@ public void map(ImmutableBytesWritable row, final Result value, Context context)
269
268
Result .compareResults (value , currentCompareRowInPeerTable , false );
270
269
context .getCounter (Counters .GOODROWS ).increment (1 );
271
270
if (verbose ) {
272
- LOG .info (
273
- "Good row key: " + delimiter + Bytes .toStringBinary (value .getRow ()) + delimiter );
271
+ LOG .info ("Good row key: {}" ,
272
+ delimiter + Bytes .toStringBinary (value .getRow ()) + delimiter );
274
273
}
275
274
} catch (Exception e ) {
276
275
logFailRowAndIncreaseCounter (context , Counters .CONTENT_DIFFERENT_ROWS , value ,
@@ -291,7 +290,6 @@ public void map(ImmutableBytesWritable row, final Result value, Context context)
291
290
}
292
291
}
293
292
294
- @ SuppressWarnings ("FutureReturnValueIgnored" )
295
293
private void logFailRowAndIncreaseCounter (Context context , Counters counter , Result row ,
296
294
Result replicatedRow ) {
297
295
byte [] rowKey = getRow (row , replicatedRow );
@@ -311,7 +309,11 @@ private void logFailRowAndIncreaseCounter(Context context, Counters counter, Res
311
309
return ;
312
310
}
313
311
314
- reCompareExecutor .submit (runnable );
312
+ try {
313
+ reCompareExecutor .submit (runnable ).get ();
314
+ } catch (Exception e ) {
315
+ throw new RuntimeException (e );
316
+ }
315
317
}
316
318
317
319
@ Override
@@ -389,18 +391,16 @@ protected void cleanup(Context context) {
389
391
390
392
private static Pair <ReplicationPeerConfig , Configuration >
391
393
getPeerQuorumConfig (final Configuration conf , String peerId ) throws IOException {
392
- ZKWatcher localZKW = null ;
393
- try {
394
- localZKW = new ZKWatcher (conf , "VerifyReplication" , new Abortable () {
395
- @ Override
396
- public void abort (String why , Throwable e ) {
397
- }
394
+ try (ZKWatcher localZKW = new ZKWatcher (conf , "VerifyReplication" , new Abortable () {
395
+ @ Override
396
+ public void abort (String why , Throwable e ) {
397
+ }
398
398
399
- @ Override
400
- public boolean isAborted () {
401
- return false ;
402
- }
403
- });
399
+ @ Override
400
+ public boolean isAborted () {
401
+ return false ;
402
+ }
403
+ })) {
404
404
ReplicationPeerStorage storage =
405
405
ReplicationStorageFactory .getReplicationPeerStorage (FileSystem .get (conf ), localZKW , conf );
406
406
ReplicationPeerConfig peerConfig = storage .getPeerConfig (peerId );
@@ -409,10 +409,6 @@ public boolean isAborted() {
409
409
} catch (ReplicationException e ) {
410
410
throw new IOException ("An error occurred while trying to connect to the remote peer cluster" ,
411
411
e );
412
- } finally {
413
- if (localZKW != null ) {
414
- localZKW .close ();
415
- }
416
412
}
417
413
}
418
414
@@ -471,25 +467,25 @@ public Job createSubmittableJob(Configuration conf, String[] args) throws IOExce
471
467
peerConfigPair = getPeerQuorumConfig (conf , peerId );
472
468
ReplicationPeerConfig peerConfig = peerConfigPair .getFirst ();
473
469
peerQuorumAddress = peerConfig .getClusterKey ();
474
- LOG .info ("Peer Quorum Address: " + peerQuorumAddress + " , Peer Configuration: "
475
- + peerConfig .getConfiguration ());
470
+ LOG .info ("Peer Quorum Address: {} , Peer Configuration: {}" , peerQuorumAddress ,
471
+ peerConfig .getConfiguration ());
476
472
conf .set (NAME + ".peerQuorumAddress" , peerQuorumAddress );
477
473
HBaseConfiguration .setWithPrefix (conf , PEER_CONFIG_PREFIX ,
478
474
peerConfig .getConfiguration ().entrySet ());
479
475
} else {
480
476
assert this .peerQuorumAddress != null ;
481
477
peerQuorumAddress = this .peerQuorumAddress ;
482
- LOG .info ("Peer Quorum Address: " + peerQuorumAddress );
478
+ LOG .info ("Peer Quorum Address: {}" , peerQuorumAddress );
483
479
conf .set (NAME + ".peerQuorumAddress" , peerQuorumAddress );
484
480
}
485
481
486
482
if (peerTableName != null ) {
487
- LOG .info ("Peer Table Name: " + peerTableName );
483
+ LOG .info ("Peer Table Name: {}" , peerTableName );
488
484
conf .set (NAME + ".peerTableName" , peerTableName );
489
485
}
490
486
491
487
conf .setInt (NAME + ".versions" , versions );
492
- LOG .info ("Number of version: " + versions );
488
+ LOG .info ("Number of version: {}" , versions );
493
489
494
490
conf .setInt (NAME + ".recompareTries" , reCompareTries );
495
491
conf .setInt (NAME + ".recompareBackoffExponent" , reCompareBackoffExponent );
@@ -524,7 +520,7 @@ public Job createSubmittableJob(Configuration conf, String[] args) throws IOExce
524
520
}
525
521
if (versions >= 0 ) {
526
522
scan .readVersions (versions );
527
- LOG .info ("Number of versions set to " + versions );
523
+ LOG .info ("Number of versions set to {}" , versions );
528
524
}
529
525
if (families != null ) {
530
526
String [] fams = families .split ("," );
@@ -537,8 +533,8 @@ public Job createSubmittableJob(Configuration conf, String[] args) throws IOExce
537
533
538
534
if (sourceSnapshotName != null ) {
539
535
Path snapshotTempPath = new Path (sourceSnapshotTmpDir );
540
- LOG .info (
541
- "Using source snapshot-" + sourceSnapshotName + " with temp dir:" + sourceSnapshotTmpDir );
536
+ LOG .info ("Using source snapshot-{} with temp dir:{}" , sourceSnapshotName ,
537
+ sourceSnapshotTmpDir );
542
538
TableMapReduceUtil .initTableSnapshotMapperJob (sourceSnapshotName , scan , Verifier .class , null ,
543
539
null , job , true , snapshotTempPath );
544
540
restoreSnapshotForPeerCluster (conf , peerQuorumAddress );
@@ -819,7 +815,7 @@ private boolean isPeerQuorumAddress(String cmd) {
819
815
* @param errorMsg Error message. Can be null.
820
816
*/
821
817
private static void printUsage (final String errorMsg ) {
822
- if (errorMsg != null && errorMsg .length () > 0 ) {
818
+ if (errorMsg != null && ! errorMsg .isEmpty () ) {
823
819
System .err .println ("ERROR: " + errorMsg );
824
820
}
825
821
System .err .println ("Usage: verifyrep [--starttime=X]"
@@ -914,7 +910,8 @@ private static void printUsage(final String errorMsg) {
914
910
+ "2181:/cluster-b \\ \n " + " TestTable" );
915
911
}
916
912
917
- private static ThreadPoolExecutor buildReCompareExecutor (int maxThreads , Mapper .Context context ) {
913
+ private static ThreadPoolExecutor buildReCompareExecutor (int maxThreads ,
914
+ Mapper <?, ?, ?, ?>.Context context ) {
918
915
if (maxThreads == 0 ) {
919
916
return null ;
920
917
}
@@ -923,7 +920,7 @@ private static ThreadPoolExecutor buildReCompareExecutor(int maxThreads, Mapper.
923
920
buildRejectedReComparePolicy (context ));
924
921
}
925
922
926
- private static CallerRunsPolicy buildRejectedReComparePolicy (Mapper .Context context ) {
923
+ private static CallerRunsPolicy buildRejectedReComparePolicy (Mapper <?, ?, ?, ?> .Context context ) {
927
924
return new CallerRunsPolicy () {
928
925
@ Override
929
926
public void rejectedExecution (Runnable runnable , ThreadPoolExecutor e ) {
@@ -938,9 +935,10 @@ public void rejectedExecution(Runnable runnable, ThreadPoolExecutor e) {
938
935
@ Override
939
936
public int run (String [] args ) throws Exception {
940
937
Configuration conf = this .getConf ();
941
- Job job = createSubmittableJob (conf , args );
942
- if (job != null ) {
943
- return job .waitForCompletion (true ) ? 0 : 1 ;
938
+ try (Job job = createSubmittableJob (conf , args )) {
939
+ if (job != null ) {
940
+ return job .waitForCompletion (true ) ? 0 : 1 ;
941
+ }
944
942
}
945
943
return 1 ;
946
944
}
0 commit comments