Cassandra Keyspace storage configuration 整理

来源:互联网 发布:php页面静态化技术 编辑:程序博客网 时间:2024/06/07 07:48

整理了一下Cassandra官方文档提供的信息

Cassandra版本:2.0


Synopsis

CREATE ( KEYSPACE | SCHEMA ) IF NOT EXISTS keyspace_name WITH REPLICATION = mapAND DURABLE_WRITES = ( true | false )

map is a map collection, a JSON-style array of literals:

{ literal : literal, literal : literal ... }

Keyspace attributes

A keyspace must have a user-defined name, a replica placement strategy, and options that specify the number of copies per data center or node.

AttributeDefault valuenameNAplacement_strategySimpleStrategystrategy_optionsN/A (container attribute)durable_writesN/A (container attribute)
name
keyspace 的名字,必须填写。
placement_strategy
布局策略有两种
详细http://www.datastax.com/documentation/cassandra/2.0/webhelp/cassandra/architecture/architectureDataDistributeReplication_c.html#concept_ds_yt4_m4f_fk
  • SimpleStrategy or org.apache.cassandra.locator.SimpleStrategy
  • NetworkTopologyStrategy or org.apache.cassandra.locator.NetworkTopologyStrategy
SimpleStrategy :用于单个数据中心,默认
NetworkTopologyStrategy  :用于集群的多个中心

strategy_options

对于复制因子的配置,配置一行记录有多少副本在不同的节点。
如果placement_strategy配置的 SimpleStrategy 就应该配置为 stragegy_options={'replication_factor','1'} 的格式
如果配置的是NetworkTopologyStrategy  应该配置为strategy_options = {'DC1' : 1 , 'DC2' : 1} 的格式,DC1,DC2为 data center name

durable_writers

配置写操作不会绕过commit.log,默认为true,如果设置为false,会有风险


如果不用cql来创建:
CREATE KEYSPACE mykeyspace
with placement_strategy = 'org.apache.cassandra.locator.NetworkTopologyStrategy'
and strategy_options = {'DC1' : 1 , 'DC2' : 1}
and durable_writes = true;


使用cql来创建:
CREATE KEYSPACE mykeyspace           WITH replication = {'class': 'NetworkTopologyStrategy', 'DC1' : 1, 'DC2' : 1}            AND durable_writes = true;
参数详情:
PropertyValueValue Description'class''SimpleStrategy' or 'NetworkTopologyStrategy'Required. The name of the replica placement strategy class for the new keyspace.'replication_factor'An integerRequired if class is SimpleStrategy; otherwise, not used. The number of replicas of data on multiple nodes.'<data center name>'An integerRequired if class is NetworkTopologyStrategy; otherwise, not used. The number of replicas of data on each node in the data center.'<data center name>'An integerOptional if class is NetworkTopologyStrategy. The number of replicas of data on each node in the data center.. . .. . .More optional replication factors for additional named data centers.

原创粉丝点击