查看文档,分析了一下 hbase replication的原理,简单记录一下:
http://hbase.apache.org/book.html#cluster_replication
/hbase/replication/peers /1 [Value: zk1.host.com,zk2.host.com,zk3.host.com:2181:/hbase] /2 [Value: zk5.host.com,zk6.host.com,zk7.host.com:2181:/hbase]
/hbase/replication/peers /1/peer-state [Value: ENABLED] /2/peer-state [Value: DISABLED]
RS znode:
rs node包含了哪些WAL 是需要复制的,包括:rs hostname,client port,start code
/hbase/replication/rs /hostname.example.org,6020,1234 /hostname2.example.org,6020,2856
每一个rs znode包括一个WAL replication 队列,
/hbase/replication/rs /hostname.example.org,6020,1234 /1 /2
说明 hostname.example.org 的start code 为 1234 的wal 需要复制到 peer 1 和 peer 2
每一个队列都有一个znode 标示 每一个WAL 上次复制的位置,每次复制的时候都会更新这个值
/hbase/replication/rs /hostname.example.org,6020,1234 /1 23522342.23422 [VALUE: 254] 12340993.22342 [VALUE: 0]
Given a master cluster with 3 region servers replicating to a single slave with id 2
, the following hierarchy represents what the znodes layout could be at some point in time. The region servers' znodes all contain a peers
znode which contains a single queue. The znode names in the queues represent the actual file names on HDFS in the form
.address
,port
.timestamp
/hbase/replication/rs/ 1.1.1.1,60020,123456780/ 2/ 1.1.1.1,60020.1234 (Contains a position) 1.1.1.1,60020.1265 1.1.1.2,60020,123456790/ 2/ 1.1.1.2,60020.1214 (Contains a position) 1.1.1.2,60020.1248 1.1.1.2,60020.1312 1.1.1.3,60020, 123456630/ 2/ 1.1.1.3,60020.1280 (Contains a position)
Assume that 1.1.1.2 loses its ZooKeeper session. The survivors will race to create a lock, and, arbitrarily, 1.1.1.3 wins. It will then start transferring all the queues to its local peers znode by appending the name of the dead server. Right before 1.1.1.3 is able to clean up the old znodes, the layout will look like the following:
/hbase/replication/rs/ 1.1.1.1,60020,123456780/ 2/ 1.1.1.1,60020.1234 (Contains a position) 1.1.1.1,60020.1265 1.1.1.2,60020,123456790/ lock 2/ 1.1.1.2,60020.1214 (Contains a position) 1.1.1.2,60020.1248 1.1.1.2,60020.1312 1.1.1.3,60020,123456630/ 2/ 1.1.1.3,60020.1280 (Contains a position) 2-1.1.1.2,60020,123456790/ 1.1.1.2,60020.1214 (Contains a position) 1.1.1.2,60020.1248 1.1.1.2,60020.1312
Some time later, but before 1.1.1.3 is able to finish replicating the last WAL from 1.1.1.2, it dies too. Some new logs were also created in the normal queues. The last region server will then try to lock 1.1.1.3's znode and will begin transferring all the queues. The new layout will be:
/hbase/replication/rs/ 1.1.1.1,60020,123456780/ 2/ 1.1.1.1,60020.1378 (Contains a position) 2-1.1.1.3,60020,123456630/ 1.1.1.3,60020.1325 (Contains a position) 1.1.1.3,60020.1401 2-1.1.1.2,60020,123456790-1.1.1.3,60020,123456630/ 1.1.1.2,60020.1312 (Contains a position) 1.1.1.3,60020,123456630/ lock 2/ 1.1.1.3,60020.1325 (Contains a position) 1.1.1.3,60020.1401 2-1.1.1.2,60020,123456790/ 1.1.1.2,60020.1312 (Contains a position)
Replication Metrics. The following metrics are exposed at the global region server level and (since HBase 0.95) at the peer level:
-
number of WALs to process (excludes the one which is being processed) at the Replication source
-
number of mutations shipped
-
number of mutations read from HLogs at the replication source
-
age of last batch that was shipped by the replication source
source.sizeOfLogQueue
source.shippedOps
source.logEditsRead
source.ageOfLastShippedOp