@@ -226,20 +226,32 @@ private Flow confirmOpened(MasterProcedureEnv env, RegionStateNode regionNode)
226226 return Flow .HAS_MORE_STATE ;
227227 }
228228
229- if (incrementAndCheckMaxAttempts (env , regionNode )) {
229+ int retries = env .getAssignmentManager ().getRegionStates ().addToFailedOpen (regionNode )
230+ .incrementAndGetRetries ();
231+ int maxAttempts = env .getAssignmentManager ().getAssignMaxAttempts ();
232+ LOG .info ("Retry={} of max={}; {}; {}" , retries , maxAttempts , this , regionNode .toShortString ());
233+
234+ if (retries >= maxAttempts ) {
230235 env .getAssignmentManager ().regionFailedOpen (regionNode , true );
231236 setFailure (getClass ().getSimpleName (), new RetriesExhaustedException (
232237 "Max attempts " + env .getAssignmentManager ().getAssignMaxAttempts () + " exceeded" ));
233238 regionNode .unsetProcedure (this );
234239 return Flow .NO_MORE_STATE ;
235240 }
241+
236242 env .getAssignmentManager ().regionFailedOpen (regionNode , false );
237243 // we failed to assign the region, force a new plan
238244 forceNewPlan = true ;
239245 regionNode .setRegionLocation (null );
240246 setNextState (RegionStateTransitionState .REGION_STATE_TRANSITION_GET_ASSIGN_CANDIDATE );
241- // Here we do not throw exception because we want to the region to be online ASAP
242- return Flow .HAS_MORE_STATE ;
247+
248+ if (retries > env .getAssignmentManager ().getAssignRetryImmediatelyMaxAttempts ()) {
249+ // Throw exception to backoff and retry when failed open too many times
250+ throw new HBaseIOException ("Failed to open region" );
251+ } else {
252+ // Here we do not throw exception because we want to the region to be online ASAP
253+ return Flow .HAS_MORE_STATE ;
254+ }
243255 }
244256
245257 private void closeRegion (MasterProcedureEnv env , RegionStateNode regionNode ) throws IOException {
@@ -400,14 +412,6 @@ void unattachRemoteProc(RegionRemoteProcedureBase proc) {
400412 this .remoteProc = null ;
401413 }
402414
403- private boolean incrementAndCheckMaxAttempts (MasterProcedureEnv env , RegionStateNode regionNode ) {
404- int retries = env .getAssignmentManager ().getRegionStates ().addToFailedOpen (regionNode )
405- .incrementAndGetRetries ();
406- int max = env .getAssignmentManager ().getAssignMaxAttempts ();
407- LOG .info ("Retry={} of max={}; {}; {}" , retries , max , this , regionNode .toShortString ());
408- return retries >= max ;
409- }
410-
411415 @ Override
412416 protected void rollbackState (MasterProcedureEnv env , RegionStateTransitionState state )
413417 throws IOException , InterruptedException {
0 commit comments