注意:咱們分析的sofa-rpc版本是5.4.0。java
圖1 FailFastCluster的類繼承圖框架
Failfast能夠理解爲只發起一次調用,若失敗則當即報錯。ide
核心代碼在FailFastCluster的doInvoke(SofaRequest request)中,源碼以下。spa
@Override public SofaResponse doInvoke(SofaRequest request) throws SofaRpcException { ProviderInfo providerInfo = select(request); try { SofaResponse response = filterChain(providerInfo, request); if (response != null) { return response; } else { throw new SofaRpcException(RpcErrorType.CLIENT_UNDECLARED_ERROR, "Failed to call " + request.getInterfaceName() + "." + request.getMethodName() + " on remote server " + providerInfo + ", return null"); } } catch (Exception e) { throw new SofaRpcException(RpcErrorType.CLIENT_UNDECLARED_ERROR, "Failed to call " + request.getInterfaceName() + "." + request.getMethodName() + " on remote server: " + providerInfo + ", cause by: " + e.getClass().getName() + ", message is: " + e.getMessage(), e); } }
重點在於請求異常以後,當即將異常拋出給調用者。.net
你是否在其它框架中看到過Failfast的實現? Dubbo中有Failfast的實現,能夠去看Dubbo中FailfastClusterInvoker.java的實現,個人博客中分析過。code