[cassandra] read repair

cassandra 2016. 11. 23. 23:15


카산드라에는 read repair(한국어로 굳이 번역하면 읽기 보수 정도?) 라는 것이 있다.


Eventually consistency를 제공한 것은 성능을 포기할 수 없기 때문인데..


데이터의 동기화를 하지만 완벽하지 않을 수 있다. 언제든지 데이터가 이슈가 될 수 있어서 read repair로 데이터의 이슈를 보정할 수 있다. read할 때 quorum으로 하면 데이터를 안전하게 최신 데이터의 맞춰 가져올 수 있다. 



https://docs.datastax.com/en/cassandra/2.1/cassandra/operations/opsRepairNodesReadRepair.html


https://docs.datastax.com/en/cassandra/2.1/cassandra/dml/dmlClientRequestsRead.html


http://www.datastax.com/dev/blog/common-mistakes-and-misconceptions


하지만, read repair를 한다는 것은 성능의 저하를 발생시킬 수 있는 부분이 있다. 


read_repair_chance의 기본 값이 0.1일 텐데. 0으로 바꾸면 성능 저하가 없을 수 있다. 


만약 write : 1, read: quorum으로 하면 read_repiar_chance의 값을 높일 수도 있을 것이다.







CRDT관점으로 설명된 카산드라


https://aphyr.com/posts/294-jepsen-cassandra


merge하는 부분을 잘 보면 좋을 것 같다.





* 주의할 점

DateTieredCompactionStrategy에는 read repair를 포함하기 때문에 read_repair_chance를 0으로 해야 한다.. 기본 정책은 0.1이기 때문에 cassandra.yml 파일을 수정해서 재시작을 해야 한다. 따라서 테이블에 DateTieredCompactionStrategy의 사용을 주의해서 써야 한다.



The compaction strategy DateTieredCompactionStrategy precludes using read repair, because of the way timestamps are checked for DTCS compaction. In this case, you must set read_repair_chance to zero. For other compaction strategies, read repair should be enabled with a read_repair_chancevalue of 0.2 being typical.



-----


qcon london에서 crdt 내용이 나왔다. 

https://qconlondon.com/london-2016/system/files/presentation-slides/matthiaspeter.pdf

'cassandra' 카테고리의 다른 글

[cassadra] compaction 전략  (0) 2016.12.09
[cassandra] select count(*) 구하기  (0) 2016.12.07
[cassandra] cqlsh 팁  (0) 2016.11.21
[cassandra] counter 테이블 예시 및 유의 사항  (0) 2016.11.17
[cassandra] insert는 update와 같다.  (0) 2016.11.16
Posted by '김용환'
,

[cassandra] cqlsh 팁

cassandra 2016. 11. 21. 13:16



cassandra의 cqlsh이 로컬호스트에 접속을 못할 수 있다면, 간단하게 alias로 작업할 수 있다. 



$ cqlsh

Connection error: ('Unable to connect to any servers', {'127.0.0.1': error(111, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})




$ which cqlsh

/usr/bin/cqlsh



$ vi ~/.bashrc 

// 추가

alias cqlsh='/usr/bin/cqlsh 1.1.1.1'



$ source ~/.bashrc



이제 잘 된다. 


$ cqlsh

Connected to Story Common Cluster at ..

Use HELP for help.

cqlsh>




Posted by '김용환'
,



cassandra에서 counter 테이블로 딱 사용하기 좋다. 


cassandra에서는 default 값으로 null을 사용하지만, counter는 예외다. 0이 디폴트 값이다. 



간단한 컬럼패밀리로 테스트를 진행해보면, null이 저장됨을 볼 수 있다. 



cqlsh> create table test.test(test int, x int, primary key(test));

cqlsh> insert into test.test(test) values(1);

cqlsh> select * from test.test;


 test | x

------+------

    1 | null




그러나, counter 필드는 초기값이 0이 되기 때문에 null + 1로 되어 에러가 발생하지 않는다. 




cqlsh> DROP TABLE IF EXISTS googleplus.user_followee_recent_relation


cqlsh> CREATE TABLE googleplus.user_followee_recent_relation(

   ...   followee_id int,

   ...   profile_id int,

   ...   counter_value counter,

   ...   PRIMARY KEY (followee_id, profile_id)

   ... );



cqlsh> update googleplus.user_followee_recent_relation set counter_value = counter_value + 1 where followee_id = 1 and profile_id = 1;



cqlsh> select * from googleplus.user_followee_recent_relation;


 followee_id | profile_id | counter_value

-------------+------------+---------------

           1 |          1 |             1





하지만, 제약사항이 있다.


1. insert를 사용할 수 없다.


 cqlsh> insert into googleplus.user_followee_recent_relation(followee_id, profile_id, counter_value) values (1,1,0) using ttl 2;

InvalidRequest: code=2200 [Invalid query] message="INSERT statement are not allowed on counter tables, use UPDATE instead"




2. TTL 레코드에서 적용할 수 없다. 



cqlsh> update googleplus.user_followee_recent_relation set counter_value = counter_value + 1 where followee_id = 2 and profile_id = 2 using ttl 3 ;

SyntaxException: <ErrorMessage code=2000 [Syntax error in CQL query] message="line 1:122 missing EOF at 'using' (...2 and profile_id = 2 [using] ttl...)">



cqlsh> update using ttl 10 googleplus.user_followee_recent_relation set counter_value = counter_value + 1 where followee_id = 2 and profile_id = 2;

SyntaxException: <ErrorMessage code=2000 [Syntax error in CQL query] message="line 1:25 no viable alternative at input '.' (update using ttl 10 googleplus[.]...)">




스펙에 따르면, TIMESTAMP와 TTL을 카운터 필드가 포함된 테이블에서는 쓸 수 없도록 명시되어 있다.


https://docs.datastax.com/en/cql/3.1/cql/cql_using/use_counter_t.html


To load data into a counter column, or to increase or decrease the value of the counter, use the UPDATE command. Cassandra rejects USING TIMESTAMP or USING TTL in the command to update a counter column.


 


count 테이블과 TTL을 동시에 사용할 수 없는 속성이다. 따라서 다른 구조체를 고민해봐야 한다.

만약 count가 아주 작은 값으로만 쓴다면, 필드를 여러 개를 만드는 것도 괜찮을 것 같다. 


(key1, key2, counter1, counter2, counter3) 



'cassandra' 카테고리의 다른 글

[cassadra] compaction 전략  (0) 2016.12.09
[cassandra] select count(*) 구하기  (0) 2016.12.07
[cassandra] read repair  (0) 2016.11.23
[cassandra] cqlsh 팁  (0) 2016.11.21
[cassandra] insert는 update와 같다.  (0) 2016.11.16
Posted by '김용환'
,

cassandra는 insert는 update이다.



예시는 다음과 같다. 


cqlsh> insert into google.relation(id, profile_id) values (1, 1) 


 followee_id | profile_id

-------------+------------

           1 |          1


cqlsh> insert into google.relation(id, profile_id) values (1, 1) using ttl 20;






20초 뒤에는..확인하면, 다음과 같다.


cqlsh> select * from story.user_followee_recent_relation;


 followee_id | profile_id

-------------+------------









'cassandra' 카테고리의 다른 글

[cassadra] compaction 전략  (0) 2016.12.09
[cassandra] select count(*) 구하기  (0) 2016.12.07
[cassandra] read repair  (0) 2016.11.23
[cassandra] cqlsh 팁  (0) 2016.11.21
[cassandra] counter 테이블 예시 및 유의 사항  (0) 2016.11.17
Posted by '김용환'
,