2011-05-22

Cassandra0.7のスキーマを構築する(スキーマサンプル)

■目的

Cassandra0.7のスキーマを操作する。
Cassandra0.7に付属のサンプルのスキーマを構築する。

■環境

OS Windows XP
Cassandra 0.7.6-2

CASSANDRA_HOME D:\cassandra\apache-cassandra-0.7.6-2

※特に説明がないかぎり、コマンドは%CASSNDEA_HOME%で実行しています。

■サンプルのスキーマの構築

Cassaandra0.7では、「Cassandra CLI」にスキーマを操作するコマンドが用意されました。
また、「Cassandra CLI」では、コマンドを記載したファイルを読み込み実行することができるので、Cassandra0.7に付属しているサンプルスキーマのファイルを読み込んでスキーマを作成してみます。
(スキーマサンプルのコメントにも記載されています。)

スキーマサンプルファイル conf/schema-sample.txt

【Cassandra CLIのusage抜粋】
>bin\cassandra-cli.bat -help
Starting Cassandra Client
usage: cassandra-cli
:
 -f,--file         load statements from the specific file
:

Cassandra CLIで、スキーマサンプルのファイルをロードします。
bin\cassandra-cli.bat -h localhost -f conf\schema-sample.txt

【実行例】
>bin\cassandra-cli.bat -h localhost -f conf\schema-sample.txt
Starting Cassandra Client
Connected to: "Test Cluster" on localhost/9160
a874f6d2-845c-11e0-ab0d-e700f669bcfc
Waiting for schema agreement...
... schemas agree across the cluster
Authenticated to keyspace: Keyspace1
a8abe553-845c-11e0-ab0d-e700f669bcfc
Waiting for schema agreement...
... schemas agree across the cluster
a8b7cc34-845c-11e0-ab0d-e700f669bcfc
Waiting for schema agreement...
... schemas agree across the cluster
a8c14215-845c-11e0-ab0d-e700f669bcfc
Waiting for schema agreement...
... schemas agree across the cluster
a8cf99f6-845c-11e0-ab0d-e700f669bcfc
Waiting for schema agreement...
... schemas agree across the cluster
a8f5bf97-845c-11e0-ab0d-e700f669bcfc
Waiting for schema agreement...
... schemas agree across the cluster
a8ff5c88-845c-11e0-ab0d-e700f669bcfc
Waiting for schema agreement...
... schemas agree across the cluster
a914b949-845c-11e0-ab0d-e700f669bcfc
Waiting for schema agreement...
... schemas agree across the cluster

■スキーマの確認

「Cassandra CLI」を使用して構築されたスキーマを確認します。
「Cassandra CLI」で、Cassandraに接続します。
>bin\cassandra-cli.bat -h localhost
Starting Cassandra Client
Connected to: "Test Cluster" on localhost/9160
Welcome to cassandra CLI.

Type 'help;' or '?' for help. Type 'quit;' or 'exit;' to quit.
[default@unknown]

「show keyspaces」で、キースペースを確認します。
show keyspaces;

【実行例】
[default@unknown] show keyspaces;
Keyspace: Keyspace1:
  Replication Strategy: org.apache.cassandra.locator.SimpleStrategy
    Replication Factor: 1
  Column Families:
    ColumnFamily: Indexed1
:
    ColumnFamily: Standard1
:
    ColumnFamily: Standard2
:
    ColumnFamily: StandardByUUID1
:
    ColumnFamily: Super1 (Super)
:
    ColumnFamily: Super2 (Super)
:
    ColumnFamily: Super3 (Super)
:
Keyspace: system:
:
キースペース「Keyapace1」が作成され、「Keyapace1」の中に、「Indexed1」~「Super3」のカラムファミリーが作成されました。

■作成したキースペースへのアクセス

作成したキースペースとカラムファミリに簡単にアクセスしてみます。
作成したキースペース(Keyspace1)にスイッチし、カラムファミリ(Standard1)を表示してみます。
カラムファミリのデータの表示は「list [カラムファミリー]」コマンドを使用します。
[default@unknown] use Keyspace1;
Authenticated to keyspace: Keyspace1
[default@Keyspace1] list Standard1;
Using default limit of 100

0 Row Returned.

Keyspace1にスイッチしました。
listコマンドでStandard1を表示すると、0件であることが表示されます。
プロンプトも「Keyspace1」に変更されます。

■カラムファミリの削除

カラムファミリを削除して、削除されたことを確認します。
カラムファミリ(Standard1)を削除し、カララムファミリ(Standard1)の件数を表示してみます。
カラムファミリの削除は「drop column family [カラムファミリー]」を使用します。
[default@Keyspace1] drop column family Standard1;
e92bdc4a-845f-11e0-ab0d-e700f669bcfc
Waiting for schema agreement...
... schemas agree across the cluster
[default@Keyspace1] list Standard1;
Using default limit of 100
unconfigured columnfamily Standard1

Standard1が削除されます。
listコマンドででStandard1を表示すると、Standard1が定義されていないことが表示さます。

■キースペースの削除

キースペースも削除してみます。
キースペースの削除は、「drop keyspace [キースペース]」を使用します。
[default@Keyspace1] drop keyspace Keyspace1;
5a5aed7b-8460-11e0-ab0d-e700f669bcfc
Waiting for schema agreement...
... schemas agree across the cluster
[default@Keyspace1] use Keyspace1;
Keyspace 'Keyspace1' not found.
[default@Keyspace1]

Keyspace1が削除されました。
Keyspace1へスイッチしようとすると、Keyspace1が見つからない事が表示されます。
(プロンプトには、Keyspace1が表示されていますが...)
「show Keyspaces;」コマンドで確認してもKeyspace1は表示されません。

0 件のコメント: