首页  

cassandra架构要点     所属分类 cassandra 浏览量 1053
分布式结构基于Amazon的Dynamo,数据模型基于Google的bigtable
分布式 去中心化  强调AP 最终一致性  多数据中心复制
LSM结构 写入性能高 
读性能优化点  
row cache 
key cache
Bloom Filters
LeveledCompactionStrategy
读时碎片化结果重新写入机制

Gossip and Failure Detection
Gossip是一种p2p协议,用于failure detection,跟踪其他节点的状态,每秒运行一次。
运用Phi Accrual Failure Detection实现failure detection
计算出一个结果level of suspicion,表示节点失败的可能性。

Snitches
snitch定义了集群中每个节点相对其他节点的邻近度, 以此来确定从哪个节点读取和写入。
一般采用手动定义的模式,在cassandra.yaml配置为endpoint_snitch: GossipingPropertyFileSnitch
同时在cassandra-rackdc.properties配置当前节点的dc和rack,比如
dc=dc1
rack=rack1

Rings and Tokens
partition key的hash值


Virtual Nodes   vnode
默认每个节点 256个vnode     num_tokens


Partitioners
partitioners决定数据存放在哪个vnode上
partition key的hash值
org.apache.cassandra.dht   Murmur3Partitioner
DHT distributed hash table


Replication Strategies
副本策略  副本存放位置
replica strategy( replica placement strategy)

两种策略

SimpleStrategy
将副本放置在环上的连续节点处,从分区器指示的节点开始。

NetworkTopologyStrategy
允许为每个数据中心指定不同的复制因子。在数据中心内,它将副本分配给不同的rack,以最大限度地提高可用性


Consistency Levels
根据CAP理论,一致性,可用性和分区容忍性不可兼得
通过设置读写时最少响应节点的数量,实现了可调的一致性。
可选的一致性级别:ANY, ONE, TWO,THREE, QUORUM, ALL
其中QUORUM,ALL是强一致性。

强一致性公式 R+W>N 
R:读复本数, W:写复本数,N:复本因子

Queries and Coordinator Nodes

可以连接任一节点来执行读写操作
被连接的节点叫做Coordinator Nodes,需要处理读写一致性。比如:写到多个节点,从多个节点读取


Memtables, SSTables, and Commit Log

2.1开始 memtable 使用 native memory


Caching

三种cache

key cache
缓存partiton keys到row index entries的映射, heap

row cache
缓存常用的row,off heap

counter cache
提升counter性能


Hinted Hando
一种写入高可用特性
写入请求发给coordinator,replica节点可能因为某种原因不可用(网络、硬件等),coordinator会临时保存写请求,等到replica节点重新上线时再写入。
默认保留两个小时

Lightweight Transactions and Paxos
check-and-set(insertIfNotExist)操作被称作linearizable consistency
通过Paxos来实现LWT,每个分区维持一个paxos状态

Tombstones
SStables文件不可修改
删除数据被当做一个update,更新为tombstone
compact 清理tombstones
GCGraceSeconds 默认864000,10天

Bloom Filters
判断确定不存在的key ,避免耗时的读取过程

Compaction

SSTables 不可变,通过compaction 重新生成新的SSTable文件( 清理被删除的数据)

三种策略

SizeTieredCompactionStrategy (STCS)
LeveledCompactionStrategy (LCS)
DateTieredCompactionStrategy (DTCS)
2.1开始 anticompaction ,可禁用compaction


Anti-Entropy, Repair, and Merkle Trees


Anti-Entropy协议  用于修复复本数据的gossip协议

read repair
读取时发现有不是最新的数据 开始修复

Anti-Entropy repair
通过nodetool手动运行修复


Merkle Trees来源于Ralph Merkle,也叫做hash tree,是一种二叉树。
每个父节点是它直接子节点的hash值用于减少网络I/O




Staged Event-Driven Architecture (SEDA)

分阶段事件驱动架构
一个stage由事件队列、事件处理器和线程池组成

org.apache.cassandra.concurrent.StageManager

Read (local reads)
Mutation (local writes)
Gossip
Request/response (interactions with other nodes)
Anti-entropy (nodetool repair)
Read repair
Migration (making schema changes)
Hinted handoff


System Keyspaces
system_traces


system_schema
keyspaces
tables
columns  
materialized_views  
functions 用户定义函数
types 用户自定义类型
triggers 每个表的触发配置
aggregates 聚合定义


system_auth 


system

local
peers 存储节点信息
available_ranges
range_xfers 存储token范围
materialized_ views_builds_in_progres
built_materialized_views 跟踪view的构建
paxos 存储paxos状态
batchlog 存储 atomic batch操作的状态
size_estimates 存储每个表的分区的估计数量,用于hadoop集成


集群配置
cassandra.yaml

auto_bootstrap: true
cluster_name: 'MyCluster'
authenticator: PasswordAuthenticator
authorizer: CassandraAuthorizer
seed_provider:
    - class_name: org.apache.cassandra.locator.SimpleSeedProvider
      parameters:
          - seeds: "ip1,ip2"  #至少两个,但不要全部节点都写上
listen_address: ip # 不要设置为0.0.0.0
rpc_address: 192.168.1.10  
endpoint_snitch: GossipingPropertyFileSnitch

上一篇     下一篇
LongAdder和LongAccumulator

mysql面试题

redis面试题

Elasticsearch知识点

kafka面试题

tcpdump使用简介