using System;
using System.Data;
using DBMotoPublic;
using DBMotoScript;
namespace DBRS
{
public class ReplicationScript : IReplicationScript
{
public override void Record_onAfterMapping(DBMotoPublic.IRecord recSource,
DBMotoPublic.IRecord recTarget, ref bool AbortRecord)
{
switch(recTarget.OperationType)
{
case enmOperationType.Insert:
if (recTarget.GetValueAfter("SID") == null)
{
recTarget.SetValueAfter("NAME", null);
}
else
{
//UpdateSTUDENTFields
(recTarget);
}
break;
case enmOperationType.Update:
if (recTarget.GetValueAfter("SID") == null)
{
recTarget.SetValueAfter("NAME", null);
}
else if(recTarget.GetValueBefore("SID") == null)
{
//Field SID was null and now it has a value
//UpdateSTUDENTFields
(recTarget);
}
else if(recTarget.GetValueBefore("SID") != recTarget.GetValueAfter("SID"))
{
//Field SID has changed
//UpdateSTUDENTFields
(recTarget);
}
break;
}
}
}
}
参照、編集権限 grant select any table to DBMOTO; grant insert any table, update any table, delete any table to DBMOTO;
テーブルを作成する権限 grant unlimited tablespace to DBMOTO; grant create any table to DBMOTO;
テーブルを削除する権限 grant alter any table to DBMOTO; grant drop any table to DBMOTO;
●ミラーリング実施時に必要な権限
ログテーブルのサイズを制御するための表領域を設定する場合(任意) create tablespace DBMOTO_TBLSPACE datafile ‘dbmoto_tblspace.dat’ size 100M online;
ログテーブル作成先の表領域を操作する権限 alter user DBMOTO quota unlimited on DBMOTO_TBLSPACE;
DBへ接続する権限 grant create session to DBMOTO;
ログテーブルを作成する権限 grant create any table to DBMOTO; grant create any index to DBMOTO;
参照、編集権限 grant select any table to DBMOTO; grant insert any table, update any table, delete any table to DBMOTO;
テーブルを削除する権限 grant alter any table to DBMOTO; grant drop any table to DBMOTO;
トリガーを作成、削除する権限 grant create any trigger to DBMOTO; grant drop any trigger to DBMOTO;
シーケンスを作成、削除、参照する権限 grant create any sequence to DBMOTO; grant drop any sequence to DBMOTO; grant select any sequence to DBMOTO;
トランザクションログへアクセスする権限 grant select on SCOTT.”_DBM__TRG_OBJS” to DBMOTO; ※SCOTTはログテーブル作成先のスキーマ
■権限一覧まとめ
create user dbmoto identified by DBMOTO; grant create session to DBMOTO; grant select any table to DBMOTO; grant insert any table, update any table, delete any table to DBMOTO; grant unlimited tablespace to DBMOTO; grant create any table to DBMOTO; grant create any index to DBMOTO; grant alter any table to DBMOTO; grant drop any table to DBMOTO; create tablespace DBMOTO_TBLSPACE datafile ‘dbmoto_tblspace.dat’ size 100M online; alter user DBMOTO quota unlimited on DBMOTO_TBLSPACE; grant create any trigger to DBMOTO; grant drop any trigger to DBMOTO; grant create any sequence to DBMOTO; grant drop any sequence to DBMOTO; grant select any sequence to DBMOTO; grant select on SCOTT.”_DBM__TRG_OBJS” to DBMOTO; ※SCOTTはログテーブル作成先のスキーマ
パフォーマンスや可用性が今ほど重要でなかった時代は、データがどんどん増えて容量が足りなくなれば、「縦方向に拡張する」のみでした(Scale UP vs. Scale Outの記事参照)。クーラーの利いたサーバー室にデータベース専用ホストがあって、バックアップのスクリプトを夜中に自動実行されるように設定して、「週7日24時間稼働!」なんてプレッシャーもなく、古き良きのんびりした時代でした…(遠い目でつぶやく)。
少し話が逸れましたが、つまりACIDがデータベース設計の基本原理です。ACIDとは、「Scale UP vs. Scale Out」の記事でも触れたとおり、A(atomicity=原子性/不可分性)C(consistency=一貫性/整合性)I(isolation=独立性/隔離性)D(durability=耐久性/永続性)のことです。
このようなAmazon S3に対しても、Syniti Data Replicationであればコーディングすることなく、
すべてGUIベースでオンプレ/仮想/クラウドに展開されているデータベースからレコードを連携することができます。
それでは早速Syniti Data ReplicationでAmazon S3を登録する方法をご紹介します。
事前準備
Syniti Data Replication(旧DBMoto)をインストールしたWindowsマシンに、AWS Toolkit for .NETが必要となります。 こちらのAWS公式サイトより、インストーラを取得してインストールします。
デフォルトのインストールでは、以下のフォルダパスへ展開されます。 C:\Program Files (x86)\AWS SDK for .NET\bin
Syniti Data Replicationへの登録
まず、ターゲット接続追加ウィザードにて、 Amazon S3を選択します。 次に、各種パラメータを追加していきます。
Imports System
Imports System.Data
Imports Microsoft.VisualBasic
Imports DBMotoPublic
Imports DBMotoScript
Imports DBRS.GlobalScript
Namespace DBRS
Public Class ReplicationScript : Inherits IReplicationScript
Public Overrides Sub Record_onAfterMapping( recSource As DBMotoPublic.IRecord, recTarget As DBMotoPublic.IRecord, ByRef AbortRecord As Boolean, ByRef DisableReplication As Boolean)
' ソーステーブルカラム名の変数
Dim strField As String
' ソース側へUpdateクエリが実行された時
If (recSource.OperationType = enmOperationType.Update) Then
' "DFLUG"というカラム名を指定し、値を取得
strField = CType(recSource.GetValueAfter("DFLUG").ToString(), Integer)
End If
' "DFLUG"の値が"1"だった場合、ターゲットのレコードにDeleteクエリを発行
If (strField = "1") Then
recTarget.OperationType = enmOperationType.Delete
End If
End Sub
End Class
End Namespace