Cluster fault tolerance
When the cluster call fails, Dubbo provides a variety of fault tolerance schemes, the default is failover retry.
The relationship of each node:
- Here
Invoker
isProvider
aService
callable abstraction of , whichInvoker
encapsulatesProvider
address andService
interface information Directory
Represents multipleInvoker
, you can think of it asList<Invoker>
, butList
different from , its value may change dynamically, such as registry push changesCluster
Directory
Disguise multiple inInvoker
as oneInvoker
, which is transparent to the upper layer. The disguise process includes fault-tolerant logic. After the call fails, retry anotherRouter
Responsible for selecting subsets from multipleInvoker
s according to routing rules, such as read-write separation, application isolation, etc.LoadBalance
ResponsibleInvoker
for s for this call. The selection process includes the load balancing algorithm. After the call fails, it needs to be re-selected.
Cluster fault tolerance mode
You can expand the cluster fault tolerance strategy by yourself, see: Cluster expansion
Failover Cluster
Automatically switch on failure, when a failure occurs, retry other servers 1 . Typically used for read operations , but retries incur longer delays. retries="2"
You can set the number of retries (excluding the first time).
The number of retries is configured as follows:
<dubbo:service retries="2" />
or
<dubbo:reference retries="2" />
or
<dubbo:reference>
<dubbo:method name="findFoo" retries="2" />
</dubbo:reference>
Failfast Cluster
Fast failure, only one call is made, and an error is reported immediately upon failure. Usually used for non-idempotent write operations , such as adding new records.
Failsafe Cluster: ignore failures
Fail safe, when an exception occurs, ignore it directly. Typically used for operations such as writing to the audit log.
Failback Cluster
The failure is automatically recovered, and the failed request is recorded in the background and retransmitted regularly. Typically used for message notification operations.
Forking Cluster
Call multiple servers in parallel and return as long as one succeeds. It is usually used for read operations with high real-time requirements , but it needs to waste more service resources. The maximum number of parallels can forks="2"
be set by .
Broadcast Cluster
Broadcast to call all providers, call them one by one, and report error 2 if any one reports an error . Typically used to notify all providers to update local resource information such as caches or logs.
Cluster mode configuration
Follow the example below to configure cluster mode on the service provider and consumer
The setting method supports the following two ways to set, the priority is from low to high
<!--
Failover failed automatic switching retries = "1" switching times
Failfast fail fast
Failsafe do not ignore failure
Failback retry on failure, retry only once after 5 seconds
Forking calls in parallel forks="2" maximum number of parallels
Broadcast broadcast call
-->
<dubbo:service interface="..."cluster="broadcast" />
<dubbo:reference interface="..."cluster="broadcast"/