リージョンの作成
Oracle NoSQL Databaseでは、表を複数のKVStore内に作成できるマルチリージョン・アーキテクチャがサポートされています。Oracle NoSQL Databaseにより、挿入、更新および削除が、その表がまたがるすべてのリージョンにわたり多方向に自動的にレプリケートされます。マルチリージョンのNoSQL Database設定においては、各KVStoreクラスタがリージョンと呼ばれます。
my_region1
という名前のリモート・リージョンを作成します。
CREATE REGION my_region1
マルチリージョンのOracle NoSQL Database設定では、各ローカル・リージョンに対してすべてのリモート・リージョンを定義する必要があります。たとえば、マルチリージョン設定に3つのリージョンがある場合、それぞれの参加リージョンで他の2つのリージョンを定義する必要があります。CREATE REGION文を使用して、マルチリージョンのOracle NoSQL Databaseでリモート・リージョンを定義します。
例2: リージョンに表を作成します。
CREATE TABLE stream_acct_region(acct_id INTEGER,
acct_data JSON,
PRIMARY KEY(acct_id)) IN REGIONS my_region1
ノート:
表を作成する前に、リージョンmy_region1
をローカル・リージョンとして設定する必要があります。
APIの使用によるリージョンの作成:
SystemRequest
クラスを使用してリージョンを作成できます。SystemRequest
クラスは、表に依存しない管理操作を実行するために使用します。リージョンの作成後、表を作成しTableRequest
クラスを使用してそのリージョンに追加できます。
/* Create a remote region and a local region*/
private static void crtRegion(NoSQLHandle handle) throws Exception {
// Create a remote region
String createRemRegDDL = "CREATE REGION "+ remRegName;
SystemRequest sysreq1 = new SystemRequest();
sysreq1.setStatement(createRemRegDDL.toCharArray());
SystemResult sysres1 = handle.systemRequest(sysreq1);
sysres1.waitForCompletion(handle, 60000,1000);
System.out.println(" Remote Region " + remRegName + " is created");
// Create a local region
String createLocRegDDL = "SET LOCAL REGION "+ localRegName;
SystemRequest sysreq2 = new SystemRequest();
sysreq2.setStatement(createLocRegDDL.toCharArray());
SystemResult sysres2 = handle.systemRequest(sysreq2);
sysres2.waitForCompletion(handle, 60000,1000);
System.out.println(" Local Region " + localRegName + " is created");
}
/**
* Create a table and add the table in a region
*/
private static void crtTabInRegion(NoSQLHandle handle) throws Exception {
String createTableDDL = "CREATE TABLE IF NOT EXISTS " + tableName +
"(acct_Id INTEGER," +
"profile_name STRING," +
"account_expiry TIMESTAMP(1) ," +
"acct_data JSON, " +
"PRIMARY KEY(acct_Id)) IN REGIONS FRA";
TableRequest treq = new TableRequest().setStatement(createTableDDL);
TableResult tres = handle.tableRequest(treq);
/* The request is async,
* so wait for the table to become active.
*/
System.out.println("Table " + tableName + " is active");
}
SystemRequest
クラスを使用してリージョンを作成できます。SystemRequest
クラスは、表に依存しない管理操作を実行するために使用します。リージョンの作成後、表を作成しborneo.TableRequest
クラスを使用してそのリージョンに追加できます。
# create a remote and local region
def create_region(handle):
#Create a remote region
statement = '''CREATE REGION LON'''
sysreq = SystemRequest().set_statement(statement)
sys_result = handle.system_request(sysreq)
sys_result.wait_for_completion(handle, 40000, 3000)
print('Remote region LON is created')
#Create a local region
statement1 = '''SET LOCAL REGION FRA'''
sysreq1 = SystemRequest().set_statement(statement1)
sys_result1 = handle.system_request(sysreq1)
sys_result1.wait_for_completion(handle, 40000, 3000)
print('Local region FRA is created')
#Create a table in the local region
def create_tab_region(handle):
statement = '''create table if not exists stream_acct (acct_Id INTEGER,
profile_name STRING,
account_expiry TIMESTAMP(1),
acct_data JSON,
primary key(acct_Id)) IN REGIONS FRA'''
request = TableRequest().set_statement(statement)
# Ask the cloud service to create the table, waiting for a total of 40000 milliseconds
# and polling the service every 3000 milliseconds to see if the table is active
table_result = handle.do_table_request(request, 40000, 3000)
table_result.wait_for_completion(handle, 40000, 3000)
if (table_result.get_state() == State.ACTIVE):
print('Created table: stream_acct')
else:
raise NameError('Table stream_acct is in an unexpected state ' + str(table_result.get_state()))
SystemRequest
クラスを使用してリージョンを作成できます。SystemRequest
クラスは、表に依存しない管理操作を実行するために使用します。リージョンの作成後、表を作成しTableRequest
クラスを使用してそのリージョンに追加できます。
//Creates a remote and a local region
func crtRegion(client *nosqldb.Client, err error)(){
// Create a remote region
stmt := fmt.Sprintf("CREATE REGION LON")
sysReq := &nosqldb.SystemRequest{
Statement: stmt,
}
sysRes, err := client.DoSystemRequest(sysReq)
_, err = sysRes.WaitForCompletion(client, 60*time.Second, time.Second)
if err != nil {
fmt.Printf("Error finishing CREATE REGION request: %v\n", err)
return
}
fmt.Println("Created REGION LON ")
// Create a local region
stmt1 := fmt.Sprintf("SET LOCAL REGION FRA")
sysReq1 := &nosqldb.SystemRequest{
Statement: stmt1,
}
sysRes1, err1 := client.DoSystemRequest(sysReq1)
_, err1 = sysRes1.WaitForCompletion(client, 60*time.Second, time.Second)
if err1 != nil {
fmt.Printf("Error finishing CREATE REGION request: %v\n", err)
return
}
fmt.Println("Created REGION FRA ")
return
}
//creates a table in a specific region
func crtTabInRegion(client *nosqldb.Client, err error, tableName string)(){
stmt := fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s ("+
"acct_Id INTEGER," +
"profile_name STRING," +
"account_expiry TIMESTAMP(1) ," +
"acct_data JSON, " +
"PRIMARY KEY(acct_Id)) IN REGIONS FRA",tableName)
tableReq := &nosqldb.TableRequest{
Statement: stmt
}
tableRes, err := client.DoTableRequest(tableReq)
if err != nil {
fmt.Printf("cannot initiate CREATE TABLE request: %v\n", err)
return
}
// The create table request is asynchronous, wait for table creation to complete.
_, err = tableRes.WaitForCompletion(client, 60*time.Second, time.Second)
if err != nil {
fmt.Printf("Error finishing CREATE TABLE request: %v\n", err)
return
}
fmt.Println("Created table ", tableName)
return
}
adminDDL
メソッドを使用してリージョンを作成できます。adminDDL
メソッドは、表に依存しない管理操作を実行するために使用します。リージョンの作成後、表を作成しtableDDL
メソッドを使用してそのリージョンに追加できます。
//creates a remote and a local region
async function createRegion(handle) {
// Create a remote region
const crtRemReg = `CREATE REGION LON`;
let res = await handle.adminDDL(crtRemReg);
console.log('Remote region created: LON' );
// Create a local region
const crtLocalReg = `SET LOCAL REGION FRA`;
let res1 = await handle.adminDDL(crtLocalReg);
console.log('Local region created: FRA' );
}
//creates a table in a given region
async function crtTabInRegion(handle) {
const createDDL = `CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (acct_Id INTEGER,
profile_name STRING,
account_expiry TIMESTAMP(1),
acct_data JSON,
primary key(acct_Id)) IN REGIONS FRA`;
let res = await handle.tableDDL(createDDL, {
complete: true
});
console.log('Table created: ' + TABLE_NAME);
}
ExecuteAdminSync
モジュールを使用してリージョンを作成できます。ExecuteAdminSync
メソッドは、表に依存しない管理操作を実行するために使用します。リージョンの作成後、表を作成しExecuteTableDDLAsync
メソッドまたはExecuteTableDDLWithCompletionAsync
メソッドを使用してそのリージョンに追加できます。
private static async Task createRegion(NoSQLClient client){
// Create a remote region
var sql = $@"CREATE REGION LON";
var adminResult = await client.ExecuteAdminAsync(sql);
// Wait for the operation completion
await adminResult.WaitForCompletionAsync();
Console.WriteLine(" Created remote REGION LON");
// Create a local region
var sql1 = $@"SET LOCAL REGION FRA";
var adminResult1 = await client.ExecuteAdminAsync(sql1);
// Wait for the operation completion
await adminResult1.WaitForCompletionAsync();
Console.WriteLine(" Created local REGION FRA");
}
private static async Task createTabInRegion(NoSQLClient client){
// Create a table
var sql =
$@"CREATE TABLE IF NOT EXISTS {TableName}(acct_Id INTEGER,
profile_name STRING,
account_expiry TIMESTAMP(1),
acct_data JSON,
primary key(acct_Id)) IN REGIONS FRA";
Console.WriteLine("\nCreate table {0}", TableName);
var tableResult = await client.ExecuteTableDDLAsync(sql);
// Wait for the operation completion
await tableResult.WaitForCompletionAsync();
Console.WriteLine(" Table {0} is created",tableResult.TableName);
Console.WriteLine(" Table state: {0}", tableResult.TableState);
}