Context findFailoverNode ( final VirtualHost . HostEntry entry , final String domain , final String session , final String jvmRoute , final boolean forceStickySession ) { // If configured, deterministically choose the failover target by calculating hash of the session ID modulo number of electable nodes if ( modCluster . isDeterministicFailover ( ) ) { List < String > candidates = new ArrayList <> ( entry . getNodes ( ) . size ( ) ) ; for ( String route : entry . getNodes ( ) ) { Node node = nodes . get ( route ) ; if ( node != null && ! node . isInErrorState ( ) && ! node . isHotStandby ( ) ) { candidates . add ( route ) ; } } // If there are no available regular nodes, all hot standby nodes become candidates if ( candidates . isEmpty ( ) ) { for ( String route : entry . getNodes ( ) ) { Node node = nodes . get ( route ) ; if ( node != null && ! node . isInErrorState ( ) && node . isHotStandby ( ) ) { candidates . add ( route ) ; } } } if ( candidates . isEmpty ( ) ) { return null ; } String sessionId = session . substring ( 0 , session . indexOf ( ' ' ) ) ; int index = ( int ) ( Math . abs ( ( long ) sessionId . hashCode ( ) ) % candidates . size ( ) ) ; Collections . sort ( candidates ) ; String electedRoute = candidates . get ( index ) ; UndertowLogger . ROOT_LOGGER . debugf ( "Using deterministic failover target: %s" , electedRoute ) ; return entry . getContextForNode ( electedRoute ) ; } String failOverDomain = null ; if ( domain == null ) { final Node node = nodes . get ( jvmRoute ) ; if ( node != null ) { failOverDomain = node . getNodeConfig ( ) . getDomain ( ) ; } if ( failOverDomain == null ) { failOverDomain = failoverDomains . get ( jvmRoute ) ; } } else { failOverDomain = domain ; } final Collection < Context > contexts = entry . getContexts ( ) ; if ( failOverDomain != null ) { final Context context = electNode ( contexts , true , failOverDomain ) ; if ( context != null ) { return context ; } } if ( forceStickySession ) { return null ; } else { return electNode ( contexts , false , null ) ; } }
Try to find a failover node within the same load balancing group .