@@ -424,6 +424,25 @@ public boolean unloadFromRack()
424
424
}
425
425
426
426
private boolean unloadRegions (boolean unloadFromRack )
427
+ throws ExecutionException , InterruptedException , TimeoutException {
428
+ return unloadRegions (unloadFromRack , null );
429
+ }
430
+
431
+ /**
432
+ * Isolated regions specified in {@link #isolateRegionIdArray} on {@link #hostname} in ack Mode
433
+ * and Unload regions from given {@link #hostname} using ack/noAck mode and {@link #maxthreads}.
434
+ * In noAck mode we do not make sure that region is successfully online on the target region
435
+ * server,hence it is the best effort. We do not unload regions to hostnames given in
436
+ * {@link #excludeFile}. If designatedFile is present with some contents, we will unload regions
437
+ * to hostnames provided in {@link #designatedFile}
438
+ * @return true if region isolation succeeded, false otherwise
439
+ */
440
+ public boolean isolateRegions ()
441
+ throws ExecutionException , InterruptedException , TimeoutException {
442
+ return unloadRegions (false , isolateRegionIdArray );
443
+ }
444
+
445
+ private boolean unloadRegions (boolean unloadFromRack , List <String > isolateRegionIdArray )
427
446
throws InterruptedException , ExecutionException , TimeoutException {
428
447
deleteFile (this .filename );
429
448
ExecutorService unloadPool = Executors .newFixedThreadPool (1 );
@@ -481,7 +500,7 @@ private boolean unloadRegions(boolean unloadFromRack)
481
500
} else {
482
501
LOG .info ("Available servers {}" , regionServers );
483
502
}
484
- unloadRegions (server , regionServers , movedRegions );
503
+ unloadRegions (server , regionServers , movedRegions , isolateRegionIdArray );
485
504
} catch (Exception e ) {
486
505
LOG .error ("Error while unloading regions " , e );
487
506
return false ;
@@ -512,7 +531,7 @@ Collection<ServerName> filterRSGroupServers(RSGroupInfo rsgroup,
512
531
}
513
532
514
533
private void unloadRegions (ServerName server , List <ServerName > regionServers ,
515
- List <RegionInfo > movedRegions ) throws Exception {
534
+ List <RegionInfo > movedRegions , List < String > isolateRegionIdArray ) throws Exception {
516
535
while (true ) {
517
536
List <RegionInfo > isolateRegionInfoList = Collections .synchronizedList (new ArrayList <>());
518
537
RegionInfo isolateRegionInfo = null ;
@@ -860,12 +879,13 @@ private ServerName stripServer(List<ServerName> regionServers, String hostname,
860
879
@ Override
861
880
protected void addOptions () {
862
881
this .addRequiredOptWithArg ("r" , "regionserverhost" , "region server <hostname>|<hostname:port>" );
863
- this .addRequiredOptWithArg ("o" , "operation" , "Expected: load/unload/unload_from_rack" );
882
+ this .addRequiredOptWithArg ("o" , "operation" ,
883
+ "Expected: load/unload/unload_from_rack/isolate_regions" );
864
884
this .addOptWithArg ("m" , "maxthreads" ,
865
885
"Define the maximum number of threads to use to unload and reload the regions" );
866
886
this .addOptWithArg ("isolateRegionIds" ,
867
- "Comma separated list of Region IDs to isolate on the RegionServer and put "
868
- + " region server host in draining mode. This option should only be used with '-o unload '"
887
+ "Comma separated list of Region IDs hash to isolate on a RegionServer and put "
888
+ + " region server in draining mode. This option should only be used with '-o isolate_regions '"
869
889
+ " only. By putting region server in decommission/draining mode, master can't assign any"
870
890
+ " new region on this server. If one or more regions are not found OR failed to isolate"
871
891
+ " successfully, utility will exist without putting RS in draining/decommission mode."
@@ -895,7 +915,7 @@ protected void processOptions(CommandLine cmd) {
895
915
if (cmd .hasOption ('m' )) {
896
916
rmbuilder .maxthreads (Integer .parseInt (cmd .getOptionValue ('m' )));
897
917
}
898
- if (cmd . hasOption ( "isolateRegionIds " ) && this . loadUnload . equals ( "unload " )) {
918
+ if (this . loadUnload . equals ( "isolate_regions " ) && cmd . hasOption ( "isolateRegionIds " )) {
899
919
rmbuilder
900
920
.isolateRegionIdArray (Arrays .asList (cmd .getOptionValue ("isolateRegionIds" ).split ("," )));
901
921
}
@@ -926,6 +946,8 @@ protected int doWork() throws Exception {
926
946
success = rm .unload ();
927
947
} else if (loadUnload .equalsIgnoreCase ("unload_from_rack" )) {
928
948
success = rm .unloadFromRack ();
949
+ } else if (loadUnload .equalsIgnoreCase ("isolate_regions" )) {
950
+ success = rm .isolateRegions ();
929
951
} else {
930
952
printUsage ();
931
953
success = false ;
0 commit comments