Building a Mutant Monitoring System (MMS) Day 1やってみたメモ

* 環境
・Windows10 + VirtualBox + Vagrant
　→Ubuntu16.04　RAM：1024MB

* Ubuntuはdocker-composeを入れる

```
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ docker-compose --version
##バージョンが確認出来たらインストールに成功している
```

* 環境構築

```
$ git clone https://github.com/scylladb/scylla-code-samples.git
$ cd scylla-code-samples/mms
$ sudo docker-compose up -d
```

* ↑以降、dockerコマンド実行時はsudoを追加している。実行完了まで10分～かかる

```
(完了時のプロンプト)
    Creating mms_scylla-node3_1 ... done
    Creating mms_scylla-node2_1 ... done
    Creating mms_scylla-node1_1 ... done
```

* 状態確認
    * ↓終了しないので、気を付ける
    
 ```
$ sudo docker exec -it mms_scylla-node1_1 nodetool status
Datacenter: DC1
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address     Load       Tokens       Owns (effective)  Host ID                               Rack
    UN  172.18.0.2  134.13 KB  256          66.2%             3fdba230-32d7-4cca-8eb4-2f050bf5a698  Rack1
    UN  172.18.0.3  154.25 KB  256          66.4%             af5d756d-4a6d-4d83-976e-341f88ddab91  Rack1
    UN  172.18.0.4  134.68 KB  256          67.4%             c06b4213-94b4-4d34-80cd-963733512736  Rack1
```

* いよいよscylla起動
 
```
$ sudo docker exec -it mms_scylla-node1_1 cqlsh
Connected to  at scylla-node1:9042.
[cqlsh 5.0.1 | Cassandra 3.0.8 | CQL spec 3.3.1 | Native protocol v4]
Use HELP for help.
cqlsh>
```

* CQLで制御

```
cqlsh> CREATE KEYSPACE catalog WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy','DC1' : 3};
cqlsh> use catalog;
cqlsh:catalog> CREATE TABLE mutant_data (
        ...  first_name text,
        ...  last_name text,
        ...  address text,
        ...  picture_location text,
        ...  PRIMARY KEY((first_name, last_name)));
    
## 3データ挿入
cqlsh:catalog> insert into mutant_data ("first_name","last_name","address","picture_location") VALUES ('Bob','Loblaw','1313 Mockingbird Lane', 'http://www.facebook.com/bobloblaw');
cqlsh:catalog> insert into mutant_data ("first_name","last_name","address","picture_location") VALUES ('Bob','Zemuda','1202 Coffman Lane', 'http://www.facebook.com/bzemuda');
cqlsh:catalog> insert into mutant_data ("first_name","last_name","address","picture_location") VALUES ('Jim','Jeffries','1211 Hollywood Lane', 'http://www.facebook.com/jeffries');

## テーブル取得
cqlsh:catalog> select * from mutant_data;

    first_name | last_name | address               | picture_location
    ------------+-----------+-----------------------+-----------------------------------
            Bob |    Loblaw | 1313 Mockingbird Lane | http://www.facebook.com/bobloblaw
            Jim |  Jeffries |   1211 Hollywood Lane |  http://www.facebook.com/jeffries
            Bob |    Zemuda |     1202 Coffman Lane |   http://www.facebook.com/bzemuda

    (3 rows)

## 指定データの取得
cqlsh:catalog> select * from mutant_data where first_name='Bob' AND last_name='Loblaw';

    first_name | last_name | address               | picture_location
    ------------+-----------+-----------------------+-----------------------------------
            Bob |    Loblaw | 1313 Mockingbird Lane | http://www.facebook.com/bobloblaw

    (1 rows)
```