Share
Embed
Cassandra入門 #TechLunch
2012/03/21(水) @ Livesense TechLunch
発表者:春日 太志
Livesense Inc. PRO
April 23, 2014
Transcript
25 slides
-
⽬目次 Livesense Inc. 2 1. cassandraとは 2. ⽣生い⽴立立ち 3. 導⼊入実績
4. データモデル 5. Windowsに⼊入れる 6. 次回予告 -
⽬目次 Livesense Inc. 4 1. cassandraとは 2. ⽣生い⽴立立ち 3. 導⼊入実績
4. データモデル 5. Windowsに⼊入れる 6. 次回予告 -
2. ⽣生い⽴立立ち Livesense Inc. 5 Facebook(Jul.) 2008 2009 2010 2011
2012 Apache Incubator(Mar.) Apache Top Level (Feb.) Ver.1.0.8(Mar.) Facebook社で開発され、後にApacheプロジェクトとなる。 -
⽬目次 Livesense Inc. 6 1. cassandraとは 2. ⽣生い⽴立立ち 3. 導⼊入実績
4. データモデル 5. Windowsに⼊入れる 6. 次回予告 -
⽬目次 Livesense Inc. 8 1. cassandraとは 2. ⽣生い⽴立立ち 3. 導⼊入実績
4. データモデル 5. Windowsに⼊入れる 6. 次回予告 -
Key Space Column Family Column Family 4-‐‑‒1. データモデル Livesense Inc.
9 単純なKey-‐‑‒Valueではなく、4次元 or 5次元のHash。 Key Column Super Column Column Key Column Column Key Column Column Super Column Key Column Column Super Column Column Column Column Column -
4-‐‑‒2. データモデル(Column) Livesense Inc. 10 最⼩小単位のデータ構造、Column Column name value timestamp
・名前、値、タイムスタンプを保持 ・タイムスタンプもクライアント側からセット ・タイムスタンプの書式はクライアント側で決める -
4-‐‑‒2. データモデル(Super Column) Livesense Inc. 11 複数のColumnをまとめるSuper Column Super Column
{column, column, column, ...} ・複数のカラムに1つのキーでアクセスできる ・値はソート済みColumn連想配列列 ・Super Columnを使うと5次元になる -
4-‐‑‒3. データモデル(Column Family) Livesense Inc. 12 アトミックに処理理する関連カラムの集合Column Family Column Family
{column, column, ...} or {super column, ...} ・RDBMSのTableのような粒粒度度 ・0.6以前は設定ファイルに定義、0.7以降降は動的追加 ・値はColumnかSuper Columnで混合は不不可 -
4-‐‑‒4. データモデル(Key Space) Livesense Inc. 13 最上位のデータ構造であるKey Space Key Space
{column family, column family, column family, ...} ・RDBMSのdatabaseのような粒粒度度 ・Column Familyの集合を保持 ・0.6以前は設定ファイルに定義、0.7以降降は動的追加 ・Key Spaceの集まりはCluster(cassandra instance) -
4-‐‑‒4. データモデル(例例) Livesense Inc. 14 Key Space jsen Column Family
entry Super Column 1312 Column 1313 client_̲id 40376 12714192523 name ⼭山⽥田太郎郎 12714192523 mail [email protected] 12714192523 tel 090-‐‑‒1111-‐‑‒2222 12714192523 client_̲id 51204 12714193165 name 斎藤五郎郎 12714193165 mail [email protected] 12714193165 tel 080-‐‑‒3333-‐‑‒4444 12714193165 iwaikin 1 12714197451 -
⽬目次 Livesense Inc. 15 1. cassandraとは 2. ⽣生い⽴立立ち 3. 導⼊入実績
4. データモデル 5. Windowsに⼊入れる 6. 次回予告 -
5-‐‑‒1. Windowsに⼊入れる(インストール〜~起動) Livesense Inc. 16 1. Javaを⼊入れてJAVA_̲HOMEを設定 2. 本家サイトから〜~bin.tar.gzを落落として解凍 3.
CASSANDRA_̲HOMEを環境設定 4. cassandra.ymlを編集して出⼒力力系パスを変更更 5. cassandra.batを実⾏行行(ポート番号変更更可) 6. cassandra-‐‑‒cli.batを実⾏行行 -
5-‐‑‒2. Windowsに⼊入れる(コマンドライン操作) Livesense Inc. 17 C:\dev\cassandra\bin>cassandra-cli Starting Cassandra Client Welcome
to Cassandra CLI version 1.0.8 Type 'help;' or '?' for help. Type 'quit;' or 'exit;' to quit. [default@unknown] cassandra-‐‑‒cliで対話形式で操作できる。 -
5-‐‑‒3. Windowsに⼊入れる(コマンドライン操作) Livesense Inc. 18 ? Display this help. help;
Display this help. help <command>; Display command-specific help. exit; Exit this utility. quit; Exit this utility. コマンドは毎回セミコロンが必要。 -
5-‐‑‒4. Windowsに⼊入れる(コマンドライン操作) Livesense Inc. 19 [default@unknown] connect localhost/9160; Connected to:
"Test Cluster" on localhost/9160 [default@unknown] Clusterに接続。 -
5-‐‑‒5. Windowsに⼊入れる(コマンドライン操作) Livesense Inc. 20 [default@unknown] create keyspace Keyspace1 with
placement_strategy = 'org.apache.cassandra.locator.Si‘ and strategy_options = {replication_factor:1}; 55f7f320-7262-11e1-0000-242d50cf1fff Waiting for schema agreement... ... schemas agree across the cluster Key Spaceを作成。 -
5-‐‑‒6. Windowsに⼊入れる(コマンドライン操作) Livesense Inc. 21 [default@unknown] create column family Super1
with column_type = 'Super‘ and comparator = 'AsciiType‘ and rows_cached = 10000; b8f617d0-7263-11e1-0000-242d50cf1fff Waiting for schema agreement... ... schemas agree across the cluster カラムファミリーを作成。 -
5-‐‑‒7. Windowsに⼊入れる(コマンドライン操作) Livesense Inc. 22 [default@unknown] set Super1 [ascii('testkey')] [ascii('testsuper')]
[ascii('testcol')]=ascii('hogehoge'); Value inserted. Elapsed time: 5 msec(s). Columnを追加。 -
5-‐‑‒8. Windowsに⼊入れる(コマンドライン操作) Livesense Inc. 23 [default@Keyspace1] get Super1[ascii('testkey')]; => (super_column=testsuper,
(column=74657374636f6c, value=hogehoge, timestamp=1332232166579000) (column=74657374636f6c32, value=fugafuga, timestamp=1332232318105000)) Returned 1 results. Elapsed time: 74 msec(s). Columnを取得。 -
⽬目次 Livesense Inc. 24 1. cassandraとは 2. ⽣生い⽴立立ち 3. 導⼊入実績
4. データモデル 5. インストール 6. 次回予告