@@ -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,7 @@ 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:{}" , peerSnapshotName , peerSnapshotTmpDir , CommonFSUtils .getRootDir (peerConf ), peerFSAddress );
251
248
252
249
replicatedScanner = new TableSnapshotScanner (peerConf , CommonFSUtils .getRootDir (peerConf ),
253
250
new Path (peerFSAddress , peerSnapshotTmpDir ), peerSnapshotName , scan , true );
@@ -270,7 +267,7 @@ public void map(ImmutableBytesWritable row, final Result value, Context context)
270
267
context .getCounter (Counters .GOODROWS ).increment (1 );
271
268
if (verbose ) {
272
269
LOG .info (
273
- "Good row key: " + delimiter + Bytes .toStringBinary (value .getRow ()) + delimiter );
270
+ "Good row key: {}" , delimiter + Bytes .toStringBinary (value .getRow ()) + delimiter );
274
271
}
275
272
} catch (Exception e ) {
276
273
logFailRowAndIncreaseCounter (context , Counters .CONTENT_DIFFERENT_ROWS , value ,
@@ -291,7 +288,6 @@ public void map(ImmutableBytesWritable row, final Result value, Context context)
291
288
}
292
289
}
293
290
294
- @ SuppressWarnings ("FutureReturnValueIgnored" )
295
291
private void logFailRowAndIncreaseCounter (Context context , Counters counter , Result row ,
296
292
Result replicatedRow ) {
297
293
byte [] rowKey = getRow (row , replicatedRow );
@@ -311,7 +307,11 @@ private void logFailRowAndIncreaseCounter(Context context, Counters counter, Res
311
307
return ;
312
308
}
313
309
314
- reCompareExecutor .submit (runnable );
310
+ try {
311
+ reCompareExecutor .submit (runnable ).get ();
312
+ } catch (Exception e ) {
313
+ throw new RuntimeException (e );
314
+ }
315
315
}
316
316
317
317
@ Override
@@ -389,18 +389,14 @@ protected void cleanup(Context context) {
389
389
390
390
private static Pair <ReplicationPeerConfig , Configuration >
391
391
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
- }
392
+ try (ZKWatcher localZKW = new ZKWatcher (conf , "VerifyReplication" , new Abortable () {
393
+ @ Override public void abort (String why , Throwable e ) {
394
+ }
398
395
399
- @ Override
400
- public boolean isAborted () {
401
- return false ;
402
- }
403
- });
396
+ @ Override public boolean isAborted () {
397
+ return false ;
398
+ }
399
+ })) {
404
400
ReplicationPeerStorage storage =
405
401
ReplicationStorageFactory .getReplicationPeerStorage (FileSystem .get (conf ), localZKW , conf );
406
402
ReplicationPeerConfig peerConfig = storage .getPeerConfig (peerId );
@@ -409,10 +405,6 @@ public boolean isAborted() {
409
405
} catch (ReplicationException e ) {
410
406
throw new IOException ("An error occurred while trying to connect to the remote peer cluster" ,
411
407
e );
412
- } finally {
413
- if (localZKW != null ) {
414
- localZKW .close ();
415
- }
416
408
}
417
409
}
418
410
@@ -471,25 +463,25 @@ public Job createSubmittableJob(Configuration conf, String[] args) throws IOExce
471
463
peerConfigPair = getPeerQuorumConfig (conf , peerId );
472
464
ReplicationPeerConfig peerConfig = peerConfigPair .getFirst ();
473
465
peerQuorumAddress = peerConfig .getClusterKey ();
474
- LOG .info ("Peer Quorum Address: " + peerQuorumAddress + " , Peer Configuration: "
475
- + peerConfig .getConfiguration ());
466
+ LOG .info ("Peer Quorum Address: {} , Peer Configuration: {}" , peerQuorumAddress ,
467
+ peerConfig .getConfiguration ());
476
468
conf .set (NAME + ".peerQuorumAddress" , peerQuorumAddress );
477
469
HBaseConfiguration .setWithPrefix (conf , PEER_CONFIG_PREFIX ,
478
470
peerConfig .getConfiguration ().entrySet ());
479
471
} else {
480
472
assert this .peerQuorumAddress != null ;
481
473
peerQuorumAddress = this .peerQuorumAddress ;
482
- LOG .info ("Peer Quorum Address: " + peerQuorumAddress );
474
+ LOG .info ("Peer Quorum Address: {}" , peerQuorumAddress );
483
475
conf .set (NAME + ".peerQuorumAddress" , peerQuorumAddress );
484
476
}
485
477
486
478
if (peerTableName != null ) {
487
- LOG .info ("Peer Table Name: " + peerTableName );
479
+ LOG .info ("Peer Table Name: {}" , peerTableName );
488
480
conf .set (NAME + ".peerTableName" , peerTableName );
489
481
}
490
482
491
483
conf .setInt (NAME + ".versions" , versions );
492
- LOG .info ("Number of version: " + versions );
484
+ LOG .info ("Number of version: {}" , versions );
493
485
494
486
conf .setInt (NAME + ".recompareTries" , reCompareTries );
495
487
conf .setInt (NAME + ".recompareBackoffExponent" , reCompareBackoffExponent );
@@ -524,7 +516,7 @@ public Job createSubmittableJob(Configuration conf, String[] args) throws IOExce
524
516
}
525
517
if (versions >= 0 ) {
526
518
scan .readVersions (versions );
527
- LOG .info ("Number of versions set to " + versions );
519
+ LOG .info ("Number of versions set to {}" , versions );
528
520
}
529
521
if (families != null ) {
530
522
String [] fams = families .split ("," );
@@ -537,8 +529,8 @@ public Job createSubmittableJob(Configuration conf, String[] args) throws IOExce
537
529
538
530
if (sourceSnapshotName != null ) {
539
531
Path snapshotTempPath = new Path (sourceSnapshotTmpDir );
540
- LOG .info (
541
- "Using source snapshot-" + sourceSnapshotName + " with temp dir:" + sourceSnapshotTmpDir );
532
+ LOG .info ("Using source snapshot-{} with temp dir:{}" , sourceSnapshotName ,
533
+ sourceSnapshotTmpDir );
542
534
TableMapReduceUtil .initTableSnapshotMapperJob (sourceSnapshotName , scan , Verifier .class , null ,
543
535
null , job , true , snapshotTempPath );
544
536
restoreSnapshotForPeerCluster (conf , peerQuorumAddress );
@@ -819,7 +811,7 @@ private boolean isPeerQuorumAddress(String cmd) {
819
811
* @param errorMsg Error message. Can be null.
820
812
*/
821
813
private static void printUsage (final String errorMsg ) {
822
- if (errorMsg != null && errorMsg .length () > 0 ) {
814
+ if (errorMsg != null && ! errorMsg .isEmpty () ) {
823
815
System .err .println ("ERROR: " + errorMsg );
824
816
}
825
817
System .err .println ("Usage: verifyrep [--starttime=X]"
@@ -914,7 +906,7 @@ private static void printUsage(final String errorMsg) {
914
906
+ "2181:/cluster-b \\ \n " + " TestTable" );
915
907
}
916
908
917
- private static ThreadPoolExecutor buildReCompareExecutor (int maxThreads , Mapper .Context context ) {
909
+ private static ThreadPoolExecutor buildReCompareExecutor (int maxThreads , Mapper <?, ?, ?, ?> .Context context ) {
918
910
if (maxThreads == 0 ) {
919
911
return null ;
920
912
}
@@ -923,7 +915,7 @@ private static ThreadPoolExecutor buildReCompareExecutor(int maxThreads, Mapper.
923
915
buildRejectedReComparePolicy (context ));
924
916
}
925
917
926
- private static CallerRunsPolicy buildRejectedReComparePolicy (Mapper .Context context ) {
918
+ private static CallerRunsPolicy buildRejectedReComparePolicy (Mapper <?, ?, ?, ?> .Context context ) {
927
919
return new CallerRunsPolicy () {
928
920
@ Override
929
921
public void rejectedExecution (Runnable runnable , ThreadPoolExecutor e ) {
@@ -938,9 +930,10 @@ public void rejectedExecution(Runnable runnable, ThreadPoolExecutor e) {
938
930
@ Override
939
931
public int run (String [] args ) throws Exception {
940
932
Configuration conf = this .getConf ();
941
- Job job = createSubmittableJob (conf , args );
942
- if (job != null ) {
943
- return job .waitForCompletion (true ) ? 0 : 1 ;
933
+ try (Job job = createSubmittableJob (conf , args )) {
934
+ if (job != null ) {
935
+ return job .waitForCompletion (true ) ? 0 : 1 ;
936
+ }
944
937
}
945
938
return 1 ;
946
939
}
0 commit comments