ユースケース2: 複数リージョン表の拡張
組織は、2つのオンプレミスKVStoreをフランクフルトとロンドンにそれぞれ1つずつデプロイします。要件に従って、両方のリージョンにいくつかのMR表を作成します。users
表は、この組織が作成および保守する多くのMR表の1つです。組織拡大のため、ダブリンに別のNoSQL Databaseを追加することに決めました。新しいリージョンとしてダブリンを作成した後、既存のMR表を新しいリージョンに拡張します。次のいくつかのトピックでは、前のユースケースですでに作成したusers
表にダブリン・リージョンを追加する方法について学習します。
前にusers
MR表を作成していない場合は、ユースケース1: 複数リージョン環境の設定で説明したステップを実行してください。
前提条件
ステップ:
users
表を新しいリージョンに拡張する前に、次のタスクを実行して新しいリージョンを設定しておく必要があります。
- フランクフルト(
fra
)とロンドン(lnd
)の2つのリージョンで構成される複数リージョンNoSQL Databaseを設定します。ユースケース1: 複数リージョン環境の設定を参照してください。 dubstore
というストア名を持つローカルのKVStoreを新しいリージョンにデプロイします。構成の概要を参照してください。- 新しいリージョンのローカル・リージョン名を
dub
に設定します。ローカル・リージョン名の設定を参照してください。 dub
リージョンでXRegionサービスを構成して起動します。XRegionサービスの構成およびXRegionサービスの起動を参照してください。- 既存のリージョンのフランクフルト(
fra
)およびロンドン(lnd
)のjson.config
ファイルを更新して、dub
(ダブリン)をリモート・リージョンとして追加します。注意:
json.config
ファイルから新しいリージョン(dub
)を選択するには、既存のリージョンのエージェントを再起動する必要があります。 - 新しいリージョン
dub
で、2つのリモート・リージョンfra
およびlnd
を作成します。リモート・リージョンの作成を参照してください。
次に例を示します。
- 新しいリージョン(ダブリン)のローカル・リージョン名を設定します。
# Connect to the KVStore deployed at host7, host8, and host9 from the SQL shell [~]$java -jar $KVHOME/lib/sql.jar \ -helper-hosts host7:5000,host8:5000,host9:5000 \ -store dubstore -- Set the local region name to 'dub' sql-> SET LOCAL REGION dub; Statement completed successfully -- List the regions sql-> SHOW REGIONS; regions dub (local, active)
- 新しいリージョン(ダブリン)の
json.config
ファイルを作成します。# Contents of the configuration file in the 'dub' Region { "path": "<entire path to the home directory for the XRegion Service>", "agentGroupSize": 1, "agentId": 0, "region": "dub", "store": "<storename at the dub region>", "security": "<path to the security file>", "helpers": [ "host7:5000", "host8:5000", "host9:5000" ], "regions": [ { "name": "fra", "store": "<store name at the fra region>", "security": "<path to the security file>", "helpers": [ "host1:5000", "host2:5000", "host3:5000" ] }, { "name": "lnd", "store": "<store name at the lnd region>", "security": "<path to the security file>", "helpers": [ "host4:5000", "host5:5000", "host6:5000" ] } ] }
- 新しいリージョン(ダブリン)でXRegionサービスを起動します。
# Start the XRegion Service in the 'dub' Region [oracle@host7 xrshome]$nohup java -Xms256m -Xmx2048m -jar $KVHOME/lib/kvstore.jar xrstart \ -config <path to the json config file> > \ <path to the home directory of the xregion service>/nohup.out & [1] 24123 [oracle@host7 xrshome]$ nohup: ignoring input and redirecting stderr to stdout # View the status of the xrstart command in the 'dub' Region [oracle@host7 xrshome]$ cat nohup.out Cross-region agent (region=fra,store=mrtstore, helpers=[host7:5000, host8:5000, host9:5000]) starts up from config file=/home/oracle/xrshome/ json.config at 2020-11-07 08:57:34 UTC
- 既存のリージョン(フランクフルトおよびロンドン)の
json.config
ファイルを変更して、ダブリンをリモート・リージョンとして含めます。# Contents of the configuration file in the 'fra' Region { "path": "<path to the json config file>", "agentGroupSize": 1, "agentId": 0, "region": "fra", "store": "<storename at the fra region>", "security": "<path to the security file>", "helpers": [ "host1:5000", "host2:5000", "host3:5000" ], "regions": [ { "name": "lnd", "store": "<storename at the lnd region>", "security": "<path to the security file>", "helpers": [ "host4:5000", "host5:5000", "host6:5000" ] }, { "name": "dub", "store": "<storename at the dub region>", "security": "<path to the security file>", "helpers": [ "host7:5000", "host8:5000", "host9:5000" ] } ] }
# Contents of the configuration file in the 'lnd' Region { "path": "<path to the json config file>", "agentGroupSize": 1, "agentId": 0, "region": "lnd", "store": "<storename at the lnd region>", "security": "<path to the security file>", "helpers": [ "host4:5000", "host5:5000", "host6:5000" ], "regions": [ { "name": "fra", "store": "<storename at the fra region>", "security": "<path to the security file>", "helpers": [ "host1:5000", "host2:5000", "host3:5000" ] }, { "name": "dub", "store": "<storename at the dub region>", "security": "<path to the security file>", "helpers": [ "host7:5000", "host8:5000", "host9:5000" ] } ] }
- 新しいリージョン(ダブリン)で、2つのリモート・リージョン
fra
およびlnd
を作成します。# Connect to the KVStore deployed in the 'dub' region from the SQL shell [~]$java -jar $KVHOME/lib/sql.jar \ -helper-hosts host7:5000,host8:5000,host9:5000 \ -store dubstore –- Create remote regions 'fra' and 'lnd' sql-> CREATE REGION fra; Statement completed successfully sql-> CREATE REGION lnd; Statement completed successfully – List the regions sql-> SHOW REGIONS; regions dub (local, active) fra (remote, active) lnd (remote, active)
新しいリージョンでのMR表の作成
ステップ:
CREATE TABLE
文を使用して新しいリージョンにMR表を作成する必要があります。複数リージョン表の作成を参照してください。
注意:
新しいリージョンのみでMR表を作成しても、既存のリージョンからのデータのレプリケートは実現しません。これは、既存のリージョンからこのMR表に新しいリージョンをまだリンクしていないためです。次に例を示します。
新しいリージョン(ダブリン)でusers
MR表を作成します。
# Connect to the KVStore deployed in the 'dub' region from the SQL shell
[~]$java -jar $KVHOME/lib/sql.jar \
-helper-hosts host7:5000,host8:5000,host9:5000 \
-store dubstore
-- Create the users MR Table
sql-> CREATE TABLE users(
-> id INTEGER,
-> name STRING,
-> team STRING,
-> PRIMARY KEY (id))
-> IN REGIONS dub,fra,lnd;
Statement completed successfully
# Connect to the KVStore deployed in the 'dub' region from the kv prompt
[~]$java -jar $KVHOME/lib/kvstore.jar runadmin \
-helper-hosts host7:5000,host8:5000,host9:5000 \
-store dubstore
# Verify the regions associated with the users MR table
kv-> SHOW TABLE -NAME users
{
"json_version": 1,
"type": "table",
"name": "users",
"regions": {
"1": "dub",
"2": "fra"
"3": "lnd"
},
"fields": [
{
"name": "id",
"type": "INTEGER",
"nullable": false
},
{
"name": "name",
"type": "STRING",
"nullable": true
},
{
"name": "team",
"type": "STRING",
"nullable": true
}
],
"primaryKey": [
"id"
],
"shardKey": [
"id"
]
}
既存のリージョンへの新しいリージョンの追加
ステップ:
既存の各リージョンから次のステップを実行します。
- 新しいリージョンをリモート・リージョンとして追加します。リモート・リージョンの作成を参照してください。
- 次に示すDDLコマンドを使用して、新しいリージョンを既存のMR表に関連付けます。
ALTER TABLE <table name> ADD REGIONS <region name>;
次に例を示します。
- 既存のリージョン(フランクフルトおよびロンドン)から新しいリージョン(ダブリン)をリモート・リージョンとして追加します。
# 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 a remote region 'dub' sql-> CREATE REGION dub; Statement completed successfully – List the regions sql-> SHOW REGIONS; regions fra (local, active) lnd (remote, active) dub (remote, active)
# 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 a remote region 'dub' sql-> CREATE REGION dub; Statement completed successfully – List the regions sql-> SHOW REGIONS; regions lnd (local, active) fra (remote, active) dub (remote, active)
- 既存のリージョンで、
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 –- Add the 'dub' region to the users MR Table sql-> ALTER TABLE users ADD REGIONS dub; 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" "3": "dub" }, "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 –- Add the 'dub' region to the users MR Table sql-> ALTER TABLE users ADD REGIONS dub; 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": { "1": "lnd", "2": "fra" "3": "dub" }, "fields": [ { "name": "id", "type": "INTEGER", "nullable": false }, { "name": "name", "type": "STRING", "nullable": true }, { "name": "team", "type": "STRING", "nullable": true } ], "primaryKey": [ "id" ], "shardKey": [ "id" ] }
新しいリージョンおよび既存のリージョンのMR表へのアクセス
前の各項で説明したタスクを実行すると、新しいリージョンからMR表に対して読取り/書込み操作を中断なしに実行できるようになります。ただし、初期化がバックグラウンドで完了するまで、表は既存のリージョンから完全なデータを返すことができません。特に、MR表に既存のリージョンのデータが大量に含まれている場合は、新しい表にリモート・リージョンのデータが表示されるまでにしばらく時間がかかることがあります。
同様に、既存のリージョンからのMR表に対する読取り/書込み操作も引き続き中断なしに実行できます。新しいリージョンの追加は、既存のリージョンのMR表にアクセスする顧客に対して透過的です。ただし、既存のリージョンのMR表については、新しいリージョンからの書込みを表示するために初期化が必要になる場合もあります。新しいリージョンの表が空か、小さい場合、既存のリージョンはその表とすぐに同期されます。MR表へのアクセス方法の詳細は、複数リージョン表へのアクセスおよび操作を参照してください。