TimesTen 数据库复制学习:12. Classic带缓存组复制的几种固定架构模式

来源:互联网 发布:微商发图软件 编辑:程序博客网 时间:2023/02/04 17:37

先说明一点,对于classic复制,是不区分普通表和缓存表的,所以普通表和缓存表都可以混搭作为复制的源或目标。置于缓存表后端与Oracle的同步,对于classic复制是透明的。

从只读缓存表到非缓存表的复制

拓扑如下:

示例如下:

SQL> select * from a;        ID NAME---------- --------------------------------         3 guangzhou         1 beijing         2 shanghaicachedb1> call ttcachestart;cachedb1>CREATE READONLY CACHE GROUP "RO"  AUTOREFRESH MODE INCREMENTAL INTERVAL 5 SECONDS STATE PAUSED FROM  "TTHR"."A" (    "ID"   NUMBER(38)        NOT NULL,    "NAME" VARCHAR2(32 BYTE),    PRIMARY KEY("ID")  )Classic复制不能建立Dynamic Cache Group,否则报错如下:17056: Dynamic Cache Group Table TTHR.A can only be replicated in an ACTIVE STANDBY PAIR replication schemecachedb1> select * from a;cachedb2> create table a(id int, name varchar2(32), primary key(id));在cachedb1和cachedb2中同时创建classic复制:CREATE REPLICATION repscheme    ELEMENT e TABLE a    MASTER cachedb1 ON "timesten-hol"    SUBSCRIBER cachedb2 ON "timesten-hol"    RETURN RECEIPT;在cachedb1和cachedb2中同时启动复制代理:call ttrepstart;cachedb1> load cache group ro commit every 256 rows;cachedb1> select * from a;< 1, beijing >< 2, shanghai >< 3, guangzhou >cachedb2> select * from a;< 1, beijing >< 2, shanghai >< 3, guangzhou >注意,在这种模式中,是从一个cache table复制到一个普通的非缓存table。

从只读缓存表到只读缓存表的复制

特点是,在复制目标端,autorefresh状态设置为Paused,除非其需要接管称为主库,好处是:

The autorefresh bookmark is replicated from the master to the subscriber. Therefore when the subscriber is changed to being the new master, autorefresh can be resumed from the same point.

拓扑如下:

示例如下:

SQL> select * from a;        ID NAME---------- --------------------------------         3 guangzhou         1 beijing         2 shanghai首先在两个数据库中确保没有非缓存表存在:cachedb1> select * from a; 2206: Table TTHR.A not foundcachedb2> select * from a; 2206: Table TTHR.A not found

在cachedb1和cachedb2中同时创建只读缓存组

call ttcachestart;CREATE READONLY CACHE GROUP "RO"  AUTOREFRESH MODE INCREMENTAL INTERVAL 5 SECONDS STATE PAUSED FROM  "TTHR"."A" (    "ID"   NUMBER(38)        NOT NULL,    "NAME" VARCHAR2(32 BYTE),    PRIMARY KEY("ID")  )cachedb1> select * from a;在cachedb1和cachedb2中同时创建classic复制:CREATE REPLICATION repscheme    ELEMENT e TABLE a    MASTER cachedb1 ON "timesten-hol"    SUBSCRIBER cachedb2 ON "timesten-hol"    RETURN RECEIPT;在cachedb1和cachedb2中同时启动复制代理:call ttrepstart;cachedb1> load cache group ro commit every 256 rows;cachedb1> select * from a;< 1, beijing >< 2, shanghai >< 3, guangzhou >cachedb2> select * from a;< 1, beijing >< 2, shanghai >< 3, guangzhou >cachedb1> cachegroups;Cache Group TTHR.RO:  Cache Group Type: Read Only  Autorefresh: Yes  Autorefresh Mode: Incremental  Autorefresh State: On  Autorefresh Interval: 5 Seconds  Autorefresh Status: ok  Aging: No aging defined  Root Table: TTHR.A  Table Type: Read Onlycachedb2> cachegroups;Cache Group TTHR.RO:  Cache Group Type: Read Only  Autorefresh: Yes  Autorefresh Mode: Incremental  Autorefresh State: Paused <- 一致保持Paused状态  Autorefresh Interval: 5 Seconds  Autorefresh Status: ok  Aging: No aging defined  Root Table: TTHR.A  Table Type: Read Onlycachedb1> call ttcachestop;cachedb1> call ttrepstop;SQL> insert into a values(4, 'changsha');1 row created.SQL> commit;Commit complete.cachedb2> alter cache group ro set autorefresh state on; 5165: Autorefresh state ON for TTHR.RO is incompatible with replication scheme.  Autorefresh state should be OFF or PAUSED.cachedb2> call ttrepstop;cachedb2> drop replication repscheme;cachedb2> CREATE REPLICATION repscheme    ELEMENT e TABLE a    MASTER cachedb2 ON "timesten-hol"    SUBSCRIBER cachedb1 ON "timesten-hol"    RETURN RECEIPT;cachedb2> call ttrepstart;cachedb2> alter cache group ro set autorefresh state on;cachedb2> select * from a;< 1, beijing >< 2, shanghai >< 3, guangzhou >< 4, changsha >cachedb1> call ttrepstart;cacachedb1> select * from a;< 1, beijing >< 2, shanghai >< 3, guangzhou >cachedb1> cachegroups;Cache Group TTHR.RO:  Cache Group Type: Read Only  Autorefresh: Yes  Autorefresh Mode: Incremental  Autorefresh State: Paused  Autorefresh Interval: 5 Seconds  Autorefresh Status: ok  Aging: No aging defined  Root Table: TTHR.A  Table Type: Read OnlySQL> insert into a values(5, 'nanjing');1 row created.SQL> commit;Commit complete.cachedb2> select * from a;< 1, beijing >< 2, shanghai >< 3, guangzhou >< 4, changsha >< 5, nanjing >cachedb1> call ttrepstop;cachedb1> drop replication repscheme;cachedb1> select * from a;< 1, beijing >< 2, shanghai >< 3, guangzhou >cachedb1> delete from a; 8225: Table A is read onlycachedb1> CREATE REPLICATION repscheme        >     ELEMENT e TABLE a        >     MASTER cachedb2 ON "timesten-hol"        >     SUBSCRIBER cachedb1 ON "timesten-hol"        >     RETURN RECEIPT;cachedb1> call ttrepstart;cachedb1> call ttcachestart;12026: The agent is already running for the data store.cachedb1> select * from a;< 1, beijing >< 2, shanghai >< 3, guangzhou >< 4, changsha >< 5, nanjing >

至此,角色整个翻转过来了。

从非缓存表到可写缓存组的复制

拓扑如下:

从上图可以看出,目标端的master必须支持手工flush操作,因此其建立的缓存组为user managed类型。不过我们下面的实验中使用AWT测试了一下。

在本例中,主点的非缓存表可以理解为发起更新的应用。

示例如下:

SQL> select * from a;no rows selectedcachedb2> select * from a; 2206: Table TTHR.A not foundcachedb2> CREATE ASYNCHRONOUS WRITETHROUGH CACHE GROUP "AWT"         >  FROM        >   "TTHR"."A" (        >     "ID"   NUMBER(38)        NOT NULL,        >     "NAME" VARCHAR2(32 BYTE),        >     PRIMARY KEY("ID")        >   );cachedb2> call ttcachestart;cachedb2> select * from a;cachedb1> select * from a; 2206: Table TTHR.A not foundcachedb1> create table a(id int, name varchar2(32), primary key(id));cachedb1> select * from a;在cachedb1和cachedb2中同时创建classic复制:CREATE REPLICATION repscheme    ELEMENT e TABLE a    MASTER cachedb1 ON "timesten-hol"    SUBSCRIBER cachedb2 ON "timesten-hol"    RETURN RECEIPT;然后在cachedb1和cachedb2中同时启动复制代理:call ttrepstart;cachedb1> insert into a values(1, 'beijing');cachedb2> select * from a;< 1, beijing >SQL> select * from a;no rows selectedcachedb2> insert into a values(2, 'shanghai');SQL> select * from a;        ID NAME---------- --------------------------------         2 shanghaicachedb2> flush cache group awt; 8271: Manual FLUSH operations are not allowed on cache group TTHR.AWT because it is system managed

决定还是换User Managed Group做一次, 这次成功了,缓存组为user managed(no propagate + no autorefresh):

SQL> select * from a;no rows selectedcachedb2> select * from a; 2206: Table TTHR.A not foundcachedb2> CREATE USERMANAGED CACHE GROUP "UM_FLUSH"  FROM  "TTHR"."A" (    "ID"   NUMBER(38)        NOT NULL,    "NAME" VARCHAR2(32 BYTE),    PRIMARY KEY("ID")  );cachedb2> call ttcachestart;cachedb2> select * from a;cachedb1> select * from a; 2206: Table TTHR.A not foundcachedb1> create table a(id int, name varchar2(32), primary key(id));cachedb1> select * from a;在cachedb1和cachedb2中同时创建classic复制:CREATE REPLICATION repscheme    ELEMENT e TABLE a    MASTER cachedb1 ON "timesten-hol"    SUBSCRIBER cachedb2 ON "timesten-hol"    RETURN RECEIPT;然后在cachedb1和cachedb2中同时启动复制代理:call ttrepstart;cachedb1> insert into a values(1, 'beijing');cachedb2> select * from a;< 1, beijing >SQL> select * from a;no rows selectedcachedb2> flush cache group UM_FLUSH;SQL> select * from a;        ID NAME---------- --------------------------------         1 beijing

参考

HOWTO : Understand Combining TimesTen Replication and TimesTen Cache Connect to Oracle (Doc ID 789404.1)

0 0
原创粉丝点击