Replication的类结构:
replication的类结构包括了ReplicationSource、ReplicationSourceManager和ReplicationSink、ReplicationSinkManger以及ReplicationEndpoint五部分组成。
ReplicationSource是源端负责读取wal entry的对象,每个RegionServer对应每个peerid分配一个ReplicationSource,这里每个peerid对应唯一的一个slave集群。ReplicationSource中将待replicate的wal log按照prefix name的不同组织成不同的queue,每个queue由一个work thread负责处理该queue中的log entry,work thread会依次读取log file的内容并解析成对象WALEntry(过滤在这里发生),最终经由HBaseInterClusterReplicationEndpoint发送到目标集群。
发送经由HBaseInterClusterReplicationEndpoint实现,实际的处理代码在shipEdits中,发送交由线程池执行的,池中线程的个数由hbase.replication.source.maxthreads定义,默认是10个,这些线程接收实现了Callable接口的Replicator对象,在call方法中将WALEntry序列化后经protobuf同步到目标端集群。每一个ReplicationSource配备一个endpoint执行ship逻辑。
ReplicationSource和HBaseInterClusterReplicationEndpoint的设计,使得源端HLog的读取与发送解耦,并且发送可以由多线程来完成,如此提升了源端的发送吞吐和能力。
目标端集群的每个RegionServer都有一个ReplicationSink对象,该对象同步接收源端传送过来的entries,并将之转化为hbase内部的mutation,调用HTabe的batch API应用到本地集群。
ReplicationSourceManager负责管理所有的ReplicationSource,处理RegionS