[译]Cassandra内部架构
作者:会写代码的猪 发布时间:February 20, 2010 分类:猪在写代码,全说中国话
最近想看看Cassandra的源码,于是去看他们的wiki,先把一个概述翻了,当誓师,hoho
原文链接:http://wiki.apache.org/cassandra/ArchitectureInternals
General
概述
Configuration file is parsed by DatabaseDescriptor (which also has all the default values, if any)
DatabaseDescriptor是专门解析配制文件的,配制的默认值也跟这定义。
Thrift generates an API interface in Cassandra.java; the implementation is CassandraServer, and CassandraDaemon ties it together.
Cassandra.java调用Thrift(一个apache的跨语言框架)产生一个API接口,CassandraServer负责实现,CassandraDaemon把二者联系起来。
CassandraServer turns thrift requests into the internal equivalents, then StorageProxy does the actual work, then CassandraServer turns it back into thrift again
CassandraServer把thrift请求丢到一个内部容器里,然后StorageProxy来完成具体的工作,CassandraServer再把它拿回到thrift。
StorageService is kind of the internal counterpart to CassandraDaemon. It handles turning raw gossip into the right internal state.
StorageService是一个类似内部CassandraDaemon的玩艺儿。它就是为了让那些还没处理过的请求待在他们应该在的位置上。
AbstractReplicationStrategy controls what nodes get secondary, tertiary, etc. replicas of each key range. Primary replica is always determined by the token ring (in TokenMetadata) but you can do a lot of variation with the others. RackUnaware just puts replicas on the next N-1 nodes in the ring. RackAware puts the first non-primary replica in the next node in the ring in ANOTHER data center than the primary; then the remaining replicas in the same as the primary.
AbstractReplicationStrategy控制节点等级。每一个键的副本都有顺序。主副本是由定义在TokenMetadata里的token ring决定的,但是在其他副本上你可以有很大的发挥空间。RackUnaware只负责把副本送到环上另外N-1个节点。RackAware把把第一个非主副本放到不同于主副本的另外一个数据中心的后续节点上;剩下的副本就跟主副本在一起了。
MessagingService handles connection pooling and running internal commands on the appropriate stage (basically, a threaded executorservice). Stages are set up in StageManager; currently there are read, write, and stream stages. (Streaming is for when one node copies large sections of its sstables to another, for bootstrap or relocation on the ring.) The internal commands are defined in StorageService; look for registerVerbHandlers.
MessagingService统筹链接并在合适的阶段运行内部命令(其实就是个线程池)。各个阶段由StageManager发起;目前包括读,写和流阶段。(流,是当一个节点需要拷贝一个大段数据到另外的节点时,提供环上的引导和重定位。)内部命令在StorageService中定义,参考registerVerbHandlers。
