[cassandra] 블룸필터

cassandra 2017. 4. 28. 07:56



모든 SSTable에는 블룸 필터(Bloom filter)가 있다. 


데이터 요청 시 블룸 필터는 디스크 I/O가 발생하기 전에 요청된 데이터가 SSTable에 있는지 확인한다. 


블룸 필터의 값이 너무 낮으면 각 SSTable에 메모리가 많아질 수 있다. 블룸 필터 값이 높을수록 메모리 사용량이 적다. 


블룸 필터의 값의 범위는 0.000744에서 1.0사이이다. 블룸 필터의 최소값은 0.1 미만으로 유지하는 것이 좋다.

블룸 필터의 컬럼 패밀리의 값은 다음과 같이 CQL 쉘을 통해 조정된다.


ALTER TABLE <컬럼패밀리> WITH bloom_filter_fp_chance = 0.01; 



Posted by '김용환'
,



cassandra를 운영하면서 key cache와 row cache는 성능에 밀접한 연관성이 있다.



좋은 글은 다음과 같다. 


https://www.datastax.com/dev/blog/maximizing-cache-benefit-with-cassandra





http://docs.datastax.com/en/archived/cassandra/3.x/cassandra/dml/dmlAboutReads.html





row key를 잘 설정해 35% 좋아졌다는 내용이



파티셔닝이 점차적으로 커지는 현상





Posted by '김용환'
,



cassandra의 cassandra.yaml 이 버전마다 초기 값이 달라서 링크를 걸어본다.


1.0

http://docs.datastax.com/en/archived/cassandra/1.0/docs/configuration/node_configuration.html



1.2

http://docs.datastax.com/en/archived/cassandra/1.2/cassandra/configuration/configCassandra_yaml_r.html?hl=cassandra.yaml


2.1

https://docs.datastax.com/en/cassandra/2.1/cassandra/configuration/configCassandra_yaml_r.html?hl=commitlog_sync_period_in_ms



3.0

https://docs.datastax.com/en/cassandra/3.0/cassandra/configuration/configCassandra_yaml.html?hl=commitlog_sync

Posted by '김용환'
,

[cassandra] cql

cassandra 2017. 3. 23. 00:01



주요 CQL 커맨드는 대략 다음과 같다.



CAPTURE : 커맨드 결과를 캡쳐해 특정 파일에 추가한다.


https://docs.datastax.com/en/cql/3.1/cql/cql_reference/capture_r.html


CAPTURE '~/mydir/myfile.txt'




CONSISTENCY:  현재 일관성 레벨 또는 주어진 레벨에서 표시하거나 일관성 레벨을 설정한다.


https://docs.datastax.com/en/cql/3.1/cql/cql_reference/consistency_r.html


CONSISTENCY




COPY : 카산드라에서 또는 카산드라로 CSV(컴마로 구분된 값) 데이터를 가져오고 내보낸다.


http://docs.datastax.com/en/cql/3.1/cql/cql_reference/copy_r.html



CREATE KEYSPACE test
  WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'datacenter1' : 1 };

USE test;

CREATE TABLE airplanes (
  name text PRIMARY KEY,
  manufacturer ascii,
  year int,
  mach float
);

INSERT INTO airplanes
  (name, manufacturer, year, mach)
  VALUES ('P38-Lightning', 'Lockheed', 1937, 0.7);
 

COPY airplanes (name, manufacturer, year, mach) TO 'temp.csv';







DESCRIBE : 연결된 카산드라 클러스터에 대한 정보, 클러스터에 저장된 데이터 객체를 제공한다.


https://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlshDescribe.html


DESC keyspaces








EXPAND : 쿼리 결과를 세로로 출력한다.


https://docs.datastax.com/en/cql/3.1/cql/cql_reference/expand.html



cqlsh:my_ks> EXPAND ON
             Now printing expanded output 

cqlsh:my_ks> SELECT * FROM users;








EXIT : cqlsh을 종료한다.


https://docs.datastax.com/en/cql/3.1/cql/cql_reference/exit_r.html





PAGING : 쿼리 페이징을 활성화 또는 비활성화한다.


https://docs.datastax.com/en/cql/3.1/cql/cql_reference/paging.html


PAGING  ON | OFF 






SHOW : 카산드라 버전, 장비, 현재 cqlsh 클라이언트 세션에 대한 추적 정보 보여준다.


http://docs.datastax.com/en/cql/3.1/cql/cql_reference/show_r.html



SHOW VERSION
| HOST 

| SESSION tracing_session_id









SOURCE : CQL 문을 포함하는 파일을 실행한다.


https://docs.datastax.com/en/cql/3.1/cql/cql_reference/source_r.html



SOURCE 'file'








TRACING :  추적 요청을 활성화 또는 비활성화한다.


https://docs.datastax.com/en/cql/3.1/cql/cql_reference/tracing_r.html



TRACING ON | OFF



Posted by '김용환'
,



cqlsh에서 위,아래,좌,우 키를 못 움직일 수 있다.


cqlsh> ^[[D^[[A^[[C^[[B

Invalid syntax at line 1, char 1




이럴 때는 다음을 설치한다. 



  sudo -E yum install -y ncurses-devel

  

  sudo -E pip install readline



Posted by '김용환'
,


2017년 3월 현재


cassandra 3.x 이상의 버전에 대해서는 opscenter는 무료로 제공되지 않는다. 


오직 상용 버전만 지원한다. 



opscenter는 cassandra 3.0 이상을 지원하지 않는다.


http://docs.datastax.com/en/landing_page/doc/landing_page/compatibility.html#compatibilityDocument__opsc-compatibility


Enterpise만 지원한다....



opscenter에 cassandra 3.0에 접근하려면 다음에러가 발생한다.


2017-01-01 01:23:11+0900 []  WARN: [control connection] Error connecting to 11.11.11.11: <ErrorMessage code=000a [Protocol error] message="Invalid or unsupported protocol version (2); the lowest supported version is 3 and the greatest is 4">

2017-01-01 01:23:11+0900 [] ERROR: Control connection failed to connect, shutting down Cluster: ('Unable to connect to any servers', {u'172.17.56.90': <ErrorMessage code=000a [Protocol error] message="Invalid or unsupported protocol version (2); the lowest supported version is 3 and the greatest is 4">})

2017-01-01 01:23:11+0900 []  WARN: ProcessingError while calling CreateClusterConfController: Unable to connect to cluster. Error is: Unable to connect to any servers






https://medium.com/@mlowicki/alternatives-to-datastax-opscenter-8ad893efe063#.z8hdmauma


grafana graphite만 답인듯...



Posted by '김용환'
,


python 2.7.11이상에서 cql을 실행할 수 없었던 버그가 있었다. 이는 2.1.16, 2.2.8, 3.0.9, 3.8 이상에서 패치되었다. 

(거의 최근에 발견된 내용이다..)

https://issues.apache.org/jira/browse/CASSANDRA-11850


안전하게 2.7.9를 사용한다.


python 2.7.9 설치

http://knight76.tistory.com/entry/python-26-%EC%97%90%EC%84%9C-python-279-%EC%97%85%EA%B7%B8%EB%A0%88%EC%9D%B4%EB%93%9C-%ED%95%98%EA%B8%B0


pip 설치

http://knight76.tistory.com/entry/python-python-279%EC%97%90-%ED%95%B4%EB%8B%B9%EB%90%98%EB%8A%94-pip-%EC%84%A4%EC%B9%98%ED%95%98%EA%B8%B0



cqlsh를 설치한다.


$ sudo -E pip install cqlsh



버전을 확인한다. 

$ cqlsh --version
cqlsh 5.0.1
$ nodetool version
ReleaseVersion: 3.0.9



cqlsh를 실행하면 아래와 같은 에러가 발생할 수 있다.

$ cqlsh 
Connection error: ('Unable to connect to any servers', {'::1': error(113, "Tried connecting to [('::1', 9042, 0, 0)]. Last error: No route to host"), '127.0.0.1': ProtocolError("cql_version '3.3.1' is not supported by remote (w/ native protocol). Supported versions: [u'3.4.0']",)})

$ 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")})


파이썬 드라이버 소스가 안맞거나 ip가 없어서이니.. 단순히 아래와 같이 처리한다.
참고로 cassandra 3.0.9는 cql 버전을 3.4.0을 사용한다.


~/.bashrc 파일에 다음과 같이 설정한다. 

alias cqlsh="/usr/local/bin/cqlsh --cqlversion=3.4.0 11.11.11.17"


다시 cqlsh를 실행하면 잘 동작한다.

$ cqlsh
Connected to StoryCluster at 172.17.56.91:9042.
[cqlsh 5.0.1 | Cassandra 3.0.9 | CQL spec 3.4.0 | Native protocol v4]
Use HELP for help.
cqlsh>



Posted by '김용환'
,

cassandra 3.0에서 IllegalArgumentException : Failed to add contact point 예외가 발생했다.



Caused by: java.lang.IllegalArgumentException: Failed to add contact point:  1.1.1.2

at com.datastax.driver.core.Cluster$Builder.addContactPoint(Cluster.java:851)

at com.datastax.driver.core.Cluster$Builder.addContactPoints(Cluster.java:874)

Caused by: java.net.UnknownHostException:  172.17.56.91: unknown error

at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)

at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:907)

at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1302)

at java.net.InetAddress.getAllByName0(InetAddress.java:1255)



코드는 매우 간단했다..


String[] contactPoints = StringUtils.split(urls, ",")

cluster = Cluster.builder().addContactPoints(contactPoints).

withQueryOptions(queryOptions).

...




확인해보니,ip 목록을 받을 때 공백문자가 있으면 java에서는 unknown error가 발생한다. 


재현 코드는 다음과 같다. 


import java.net.*;

public class Test {

public static void main(String args[]) throws Exception{

InetAddress ipAddress=null;


ipAddress = InetAddress.getByName(" 1.1.1.2");

System.out.println("getHostName:"+ipAddress.getHostName());

System.out.println("getHostAddr:"+ipAddress.getHostAddress());

}

}




$ java Test

Exception in thread "main" java.net.UnknownHostException:  172.17.56.91: unknown error

at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)

at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:907)

at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1302)

at java.net.InetAddress.getAllByName0(InetAddress.java:1255)





이 문제 해결을 위해 단순하게 split만 하지 않고 공백 문자가 들어와도 공백을 없애도록 코드를 수정했다.


String[] contactPoints = Arrays.stream(StringUtils.split(urls, ",")).map(String::trim).toArray(String[]::new);



Posted by '김용환'
,


 개발용으로 사용할 cassandra 3.0 설치 방법이다.  


참고 자료는 아래 링크이다. 하지만 완벽하지 않다.. 

http://docs.datastax.com/en/cassandra/3.0/cassandra/install/installRHEL.html



python 2.7 이상이어야 한다. python 2.6이면 아래를 참고한다.(cassandra 2점 대에서는 python 2.6에도 잘 동작했지만, cassandra 3점대부터는 python 2.7이 필수이다)

http://knight76.tistory.com/entry/python-26-%EC%97%90%EC%84%9C-python-279-%EC%97%85%EA%B7%B8%EB%A0%88%EC%9D%B4%EB%93%9C-%ED%95%98%EA%B8%B0


python 2.7을 확인한 후, java 8을 설치한다.



다음 cassandra를 설치한다.



$ su

/etc/yum.repos.d/datastax.repo 파일에 다음을 추가한다.


[datastax] 

name = DataStax Repo for Apache Cassandra

baseurl = http://rpm.datastax.com/community

enabled = 1

gpgcheck = 0



cassandra 바이너리와 운영 툴을 설치한다.

$ yum install dsc30

$ yum install cassandra30-tools



혹시 cqlsh를 실행할 수 없다면 pip로 cqlsh를 설치한다. 

$ cqlsh
Traceback (most recent call last):
  File "/usr/bin/cqlsh.py", line 163, in <module>
    from cqlshlib import cql3handling, cqlhandling, pylexotron, sslhandling
ImportError: No module named cqlshlib

$ python get-pip.py
$ pip install cqlsh



cassandra3의 테스트 장비 설치를 했지만 외부에서 포트 연결이 안될 수 있다. 

아래와 같이 설정을 바꾼다.  1.1.1.1에 실제 ip를 등록한다. 


$ vi /etc/cassandra/conf/cassandra.yaml

listen_address: 1.1.1.1

broadcast_address: 1.1.1.1

rpc_address: 0.0.0.0  

broadcast_rpc_address: 1.1.1.1



cassandra 서비스를 실행한다.


$ service cassandra start



cqlsh과 nodetool로 정상적으로 문제 없는지 확인한다. 


$ cqlsh

Connected to Test Cluster at 127.0.0.1:9042.

[cqlsh 5.0.1 | Cassandra 3.0.9 | CQL spec 3.4.0 | Native protocol v4]

Use HELP for help.


$ nodetool status

...


문제가 있으면 아래 로그를 확인한다.


$ tail -f /var/log/cassandra/




============


만약 2.1에서 3.0으로 업그레이드하려면 다음 내용을 참조한다.





sudo -s


rm -rf /var/lib/cassandra

rm -rf /var/log/cassandra

rm -rf /etc/cassandra


yum remove -y cassandra21-2.1.12-1.noarch


yum remove python


export https_proxy=..

export http_proxy=..


wget http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz

xz -d Python-2.7.8.tar.xz 

tar xvf Python-2.7.8.tar


cd Python-2.7.8

./configure --prefix=/usr/local


make

make install



cat > /etc/yum.repos.d/datastax.repo  << EOF

[datastax] 

name = DataStax Repo for Apache Cassandra

baseurl = http://rpm.datastax.com/community

enabled = 1

gpgcheck = 0

EOF


yum install -y dsc30

yum install -y cassandra30-tools




Posted by '김용환'
,

아래 카산드라 설정은 문제 없어보이지만, error를 유발하고 데몬이 뜨지 않는다.




rpc_address:0.0.0.0



에러 내용은 다음과 같다. 



INFO  23:31:56 Configuration location: file:/etc/cassandra/default.conf/cassandra.yaml

Exception (org.apache.cassandra.exceptions.ConfigurationException) encountered during startup: Invalid yaml: file:/etc/cassandra/default.conf/cassandra.yaml

org.apache.cassandra.exceptions.ConfigurationException: Invalid yaml: file:/etc/cassandra/default.conf/cassandra.yaml

at org.apache.cassandra.config.YamlConfigurationLoader.loadConfig(YamlConfigurationLoader.java:124)

at org.apache.cassandra.config.YamlConfigurationLoader.loadConfig(YamlConfigurationLoader.java:95)

at org.apache.cassandra.config.DatabaseDescriptor.loadConfig(DatabaseDescriptor.java:135)

at org.apache.cassandra.config.DatabaseDescriptor.<clinit>(DatabaseDescriptor.java:119)

at org.apache.cassandra.service.CassandraDaemon.activate(CassandraDaemon.java:543)

at org.apache.cassandra.service.CassandraDaemon.main(CassandraDaemon.java:696)

Caused by: while scanning a simple key

 in 'reader', line 962, column 1:

    rpc_address:0.0.0.0

    ^

could not found expected ':'

 in 'reader', line 964, column 1:






: 다음에 공백이 한 칸 있어야 한다. 더 이상 에러는 발생하지 않는다.


rpc_address: 0.0.0.0



Posted by '김용환'
,