複数リージョン表の作成
接続されたグラフの各KVStoreにMR表を作成し、表がまたがるリージョンのリストを指定する必要があります。ここで説明するユースケースでは、任意の順序で両方のリージョンに
users
表をMR表として作成する必要があります。
ステップ:
MR表を作成するには、次の手順を実行します。
- 表定義を作成するには、
CREATE TABLE
文を使用します。開発者ガイドの表の作成に関する項を参照してください。 - 必要に応じて、
kv
プロンプトから次のコマンドを実行して、MR表に関連付けられたリージョンを検証できます。kv-> SHOW TABLE -NAME <table name>
次に例を示します。
フランクフルトとロンドンの両リージョンでusers
というMR表を作成します。
# Connect to the KVStore deployed in the 'fra' region from the SQL shell
[~]$java -jar $KVHOME/lib/sql.jar \
-helper-hosts host1:5000,host2:5000,host3:5000 \
-store mrtstore
-- Create the users MR Table
sql-> CREATE TABLE users(
-> id INTEGER,
-> name STRING,
-> team STRING,
-> PRIMARY KEY (id))
-> IN REGIONS fra,lnd;
Statement completed successfully
# Connect to the KVStore deployed in the 'fra' region from the kv prompt
[~]$java -jar $KVHOME/lib/kvstore.jar runadmin \
-helper-hosts host1:5000,host2:5000,host3:5000 \
-store mrtstore
# Verify the regions associated with the users MR table
kv-> SHOW TABLE -NAME users
{
"json_version": 1,
"type": "table",
"name": "users",
"regions": {
"1": "fra",
"2": "lnd"
},
"fields": [
{
"name": "id",
"type": "INTEGER",
"nullable": false
},
{
"name": "name",
"type": "STRING",
"nullable": true
},
{
"name": "team",
"type": "STRING",
"nullable": true
}
],
"primaryKey": [
"id"
],
"shardKey": [
"id"
]
}
# Connect to the KVStore deployed in the 'lnd' region from the SQL shell
[~]$java -jar $KVHOME/lib/sql.jar \
-helper-hosts host4:5000,host5:5000,host6:5000 \
-store mrtstore
-- Create the users MR Table
sql-> CREATE TABLE users(
-> id INTEGER,
-> name STRING,
-> team STRING,
-> PRIMARY KEY (id))
-> IN REGIONS lnd,fra;
Statement completed successfully
# Connect to the KVStore deployed in the 'lnd' region from the kv prompt
[~]$java -jar $KVHOME/lib/kvstore.jar runadmin \
-helper-hosts host4:5000,host5:5000,host6:5000 \
-store mrtstore
# Verify the regions associated with the users MR table
kv-> SHOW TABLE -NAME users
{
"json_version": 1,
"type": "table",
"name": "users",
"regions": {
"2": "fra",
"1": "lnd"
},
"fields": [
{
"name": "id",
"type": "INTEGER",
"nullable": false
},
{
"name": "name",
"type": "STRING",
"nullable": true
},
{
"name": "team",
"type": "STRING",
"nullable": true
}
],
"primaryKey": [
"id"
],
"shardKey": [
"id"
]
}