Couchbase集群和Redis集群解析

首先,关于一些数据库或者是缓存的集群有两种结构,一种是Cluster;一种是master-salve.

关于缓存系统一般使用的就是Redis,Redis是开源的,它可以单机使用,也可以做集群使用。

Redis集群是一个分布式、容错、的Redis实现,集群可以使用的功能是普通单机Redis所能使用的功能的一个子集

Redis集群中不存在中心节点或者代理节点,集群的其中一个主要的目标是达到线性可扩展性

集群的容错功能是通过使用主节点和从节点来实现的(master-slave)。

Redis集群中的节点有3大责任:

(1)      持有键值对数据。

(2)      记录集群的状态,包括键到正确节点的映射。

(3)      自动发现其它节点,识别工作不正常的节点,并在有需要时,在从节点中选举出新的主节点。

Redis节点之间使用Gossip协议来进行工作:

(1)      传播关于集群的信息,以此来发现新的节点。

(2)      向其它节点发送PING数据包,确定节点是否正常工作。

(3)      在特定事件发生时,发送集群信息。

键分布模型:Redis集群的键空间被分割为16384个槽,集群的最大节点数量也是16384个。(官方文档推荐的最大节点数量为1000个左右)。

每个主节点都负责处理16384个哈希槽的其中一部分。

当集群没有执行重置操作,每个哈希槽都只由一个节点进行处理。

重置是指将某个/某些槽从一个节点移动到另一个节点。(移动键操作是原子操作,在移动期间,两个节点都会处于阻塞状态,以免出现竞争条件)。

MOVED转向

一个Redis客户端可以向集群中的任意节点(包括从节点)发送命令请求。

请求节点将会查询命令所要处理的键所在的槽。

(1)      如果要查找的哈希槽正好就是本节点负责,就直接处理。

(2)      如果查找的槽不是本节点负责,记录请求的记录,并向客户端回复一个MOVE错误,给出键当前所在的IP和端口。

ASK转向

 

容错(添加节点和节点失效的情况):节点失效检测、集群状态检测、从节点选举

以上说的Redis的功能在2.8才稳定使用。

而Couchbase可以实现Redis的缓存功能同时还可以对数据进行持久化,存入到硬盘中,Couchbase是基于文档或者是JSON格式数据的存储的数据库,

数据存储采用vBuckets处理的。

The diagram below shows how the Key to Server mapping (vBucket map) works. There are three servers in the cluster. A client wants to look up ( get ) the value of KEY. The client first hashes the key to calculate the vBucket which owns KEY. In this example, the hash resolves to vBucket 8 ( vB8 ) By examining the vBucket map, the client determines Server C hosts vB8. The get operation is sent directly to Server C.

 

After some period of time, there is a need to add a server to the cluster. A new node, Server D is added to the cluster and the vBucket Map is updated.

 

The vBucket map is updated during the rebalance operation; the updated map is then sent the cluster to all the cluster participants, including the other nodes, any connected “smart” clients, and the Moxi proxy service.

Within the new four-node cluster model, when a client again wants to get the value of KEY, the hashing algorithm will still resolve to vBucket 8 ( vB8 ). The new vBucket map however now maps that vBucket to Server D. The client now communicates directly with Server D to obtain the information.

Couchbase不但支持Cluster同时,Cluster之间还支持Replication

现在最好的结构有两种:

 

posted on 2013-11-16 15:34  刀锋诚心  阅读(2087)  评论(0编辑  收藏  举报