cassandra3.5

quick start

1
2
bin/cassandra
bin/cqlsh

configuration

1
2
3
4
5
6
7
vi conf/logback.xml
vi conf/cassandra.yaml
#data_file_directories視資料量通當指定到比較大的磁碟上
data_file_directories: g:/var/lib/cassandra/data
saved_caches_directory: g:/var/lib/cassandra/saved_caches
#commitlog_directory可以放到比較快的SSD上
commitlog_directory: g:/var/lib/cassandra/commitlog

test drop/create keyspace/table, import data, count table, find data

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#####create keyspace/table
# use system; drop keyspace test;
#CREATE KEYSPACE test WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 2 };
CREATE KEYSPACE test WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
#describe keyspaces; describe keyspace test;
use test;
create table test(id varchar primary key, value text)
with bloom_filter_fp_chance=1;
alter table test
with bloom_filter_fp_chance=1;
desc test.test;
insert into test(id,value)values('testid','testvalue');
select * from test.test;
delete from test where id='testid';
select * from test.test;
#default 0.01, use 1 to disable bloomfilter and save memory
create table content (id varchar primary key, content text)
with bloom_filter_fp_chance=1;
#default 0.01, use 1 to disable bloomfilter and save memory
alter table content
with bloom_filter_fp_chance=1;
#disable compression
alter table content WITH compression = { 'sstable_compression' : '' };
alter table content WITH compression = { 'sstable_compression' : 'LZ4Compressor' };
alter table content WITH compression = { 'sstable_compression' : 'DeflateCompressor'};
alter table content WITH compression = { 'sstable_compression' : 'DeflateCompressor', 'chunk_length_kb' : 64 };
select * from content;
~~select * from system.schema_keyspaces;~~
desc keyspaces;
desc keyspace test;
describe tables;
describe table content;

#####import from file
copy content(id,content ) from 'g:\t\test.content.data.csv';

#####
use test; select count(*) from content limit 2147483647;
select * from content where id='01435a9f57718a8080e44358b3ff060b';

#

insert into content (id,content) values(‘test’,’test中文許功蓋’);

#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#bin/nodetool flush [keyspace] [cfnames]
bin/nodetool flush test
bin/nodetool -h localhost -p 7199 flush
bin/nodetool -h localhost -p 7199 cfstats
bin/nodetool -h localhost -p 7199 status
bin/nodetool -h localhost -p 7199 gcstatus
bin/nodetool -h localhost -p 7199 cleanup
bin/nodetool -h localhost -p 7199 cleanupsnapshot
bin/nodetool -h localhost -p 7199 compact
bin/nodetool -h localhost -p 7199 compactionhistory
bin/nodetool -h localhost -p 7199 compactionstatus
bin/nodetool -h localhost -p 7199 describecluster
bin/nodetool -h localhost -p 7199 describering
bin/nodetool -h localhost -p 7199 info
bin/nodetool -h localhost -p 7199 join
bin/nodetool -h localhost -p 7199 netstats
bin/nodetool -h localhost -p 7199 repair
bin/nodetool -h localhost -p 7199 rebuild
bin/nodetool -h localhost -p 7199 ring
bin/nodetool -h localhost -p 7199 tpstats
bin/nodetool -h localhost -p 7199 version

bin\nodetool flush &bin\nodetool repair&bin\nodetool compact
bin\nodetool info&bin\nodetool cfstats drifty
bin\nodetool info&bin\nodetool tpstats
bin\nodetool status
bin\nodetool info
bin\nodetool flush
bin\nodetool cleanup
bin\nodetool repair
bin\nodetool compactstatus
bin\nodetool ompactionhistory
bin\nodetool info&bin\nodetool cfstats drifty
bin\nodetool drain

當要使用bin\cqlsh操作copy from/to csv檔時,必須調整cassandra.yaml和cqlsh.py

cassandra.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
< batch_size_warn_threshold_in_kb: 5
---
> batch_size_warn_threshold_in_kb: 5000
681c683
< batch_size_fail_threshold_in_kb: 50
---
> batch_size_fail_threshold_in_kb: 50000
731c733
< read_request_timeout_in_ms: 5000
---
> read_request_timeout_in_ms: 50000
733c735
< range_request_timeout_in_ms: 10000
---
> range_request_timeout_in_ms: 100000
735c737
< write_request_timeout_in_ms: 2000
---
> write_request_timeout_in_ms: 20000
737c739
< counter_write_request_timeout_in_ms: 5000
---
> counter_write_request_timeout_in_ms: 50000
746c748
< request_timeout_in_ms: 10000
---
> request_timeout_in_ms: 100000

cqlsh.py

1
2
3
4
5
import csv
import getpass

#avoid "field larger than field limit (131072)"
csv.field_size_limit(sys.maxsize)

log timezone

比較新版的cassandra使用logback。透過conf/logback.xml修改設定。
預設是沒有指定timezone,所以顯示的時間跟本地時間不致。
修改方式很簡單,只要在conf/logback.xml裡的加上時區資料即可。

1
2
<pattern>%-5level [%thread] %date{ISO8601,Asia/Taipei} %F:%L - %msg%n</pattern>
<pattern>%-5level %date{HH:mm:ss.SSS,Asia/Taipei} %msg%n</pattern>