Dubbo-Cluster

2016-08-11

cluster 简介

invoker Directory

Router
loadbalance

  • Failover
  • Failfast
  • Failsafe
  • Failback
  • Forking

负载均衡算法:轮询(roundrobin),最少活跃(leastActive)

FsofProtocol 两个方法:

  • export 暴露 幂等
  • refer 获取proxy

invoker

Cluster
directory
join

Directory

/**
 * Directory. (SPI, Prototype, ThreadSafe)
 * 
 * <a href="http://en.wikipedia.org/wiki/Directory_service">Directory Service</a>
 * 
 * @see com.alibaba.dubbo.rpc.cluster.Cluster#join(Directory)
 * @author william.liangf
 */
public interface Directory<T> extends Node {
    
    /**
     * get service type.
     * 
     * @return service type.
     */
    Class<T> getInterface();

    /**
     * list invokers.
     * 
     * @return invokers
     */
    List<Invoker<T>> list(Invocation invocation) throws RpcException;

Cluster

/**
 * Cluster. (SPI, Singleton, ThreadSafe)
 * 
 * <a href="http://en.wikipedia.org/wiki/Computer_cluster">Cluster</a>
 * <a href="http://en.wikipedia.org/wiki/Fault-tolerant_system">Fault-Tolerant</a>
 * 
 * @author william.liangf
 */
@SPI(FailoverCluster.NAME)
public interface Cluster {

    /**
     * Merge the directory invokers to a virtual invoker.
     * 
     * @param <T>
     * @param directory
     * @return cluster invoker
     * @throws RpcException
     */
    @Adaptive
    <T> Invoker<T> join(Directory<T> directory) throws RpcException;

Default:Failover 重试2次

三种失败策略对比:

Method 策略解释 执行次数
Failover 重试 3次
Failfast 快速失败 1次
Failsafe 快速失败 1次

Directory

List<Invoker> list(Invocation invocation)

Router.route()
```java

public List> route(List> invokers , URL url
, Invocation invocation) throws RpcException {
if (invokers == null || invokers.size() == 0) {
return invokers;
}
try {
if (! matchWhen(url)) {
return invokers;
}
List> result = new ArrayList>();
if (thenCondition == null) {
logger.warn("The current consumer in the service blacklist. consumer: "
+ NetUtils.getLocalHost() + ", service: " + url.getServiceKey());
return result;
}
for (Invoker invoker : invokers) {
if (matchThen(invoker.getUrl(), url)) {
result.add(invoker);
}
}
if (result.size() > 0) {
return result;
} else if (force) {
logger.warn("The route result is empty and force execute. consumer: "
+ NetUtils.getLocalHost() + ", service: " + url.getServiceKey()
+ ", router: " + url.getParameterAndDecoded(Constants.RULE_KEY));
return result;
}
} catch (Throwable t) {
logger.error("Failed to execute condition router rule: " + getUrl()
+ ", invokers: " + invokers + ", cause: " + t.getMessage(), t);
}
return invokers;
}

## ConditionRouter
路由规则

## LoadBalance
roundrobin 轮询
Comments
Write a Comment