在TimesTen中,如果创建完Replication之后,是否能做一些调整呢?比如系统上线之后,发现要增加新的表到Replication中,或者说要调整某些列(增加,删除,修改缺省值等等),TimesTen是否支持这些要求?如果支持,如何去做呢?而且在做的时候,是否对运行的业务有影响?因为Replication的主要作用就是保证服务的不停止。
 
在TimesTen的标准文档中,Replication.pdf一书中,详细介绍了具体的过程以及功能,现摘录如下。
 
Alter 或者 Drop Replication Scheme
 
其支持的功能如下
  • Adding a table or sequence to an existing replication scheme
  • Adding a cache group to an existing replication scheme
  • Adding a DATASTORE element to an existing replication scheme
  • Dropping a table or sequence from a replication scheme
  • Creating and adding a subscriber data store
  • Dropping a subscriber data store
  • Changing a TABLE or SEQUENCE element name
  • Replacing a master data store
  • Eliminating conflict detection
  • Eliminating the return receipt service
  • Changing the port number
  • Changing the replication route
 
 以active standby pair为例(下面的试验均已它为例,如果不熟悉这一块的,请参考
http://www.ttisql.com/replication/pair-disaster-recovery-1.html),创建好两个DataStore,分别为dsa(active)和dsb(Standby),创建一个表并在此基础之上创建active standby pair:
 
create table TEST.TT (
        A NUMBER(38) NOT NULL,
        B NUMBER(38) DEFAULT 88,
    primary key (A));
 
create active standby pair
    DSA on "WEST-MOUNTAIN", DSB on "WEST-MOUNTAIN" return receipt
    store DSA on "WEST-MOUNTAIN"
        port 20000
        failthreshold 5
    store DSB on "WEST-MOUNTAIN"
        port 22000
        failthreshold 5;
 
验证复制正常工作。然后在创建一个新的表T1:
 
create table TEST.T1 (
        A NUMBER(38) NOT NULL,
        B NUMBER(38),
    primary key (A));
 
那么如何将新加的这个表T1包含到replication中去呢:
 
DSA:
Command> call ttrepstop;
Command> ALTER  active standby pair  INCLUDE table t1;
Command> repschemes;
Command> call ttrepstart;
 
DSB:
ttadmin -repstop dsb
ttdestroy dsb
ttrepadmin -duplicate -from dsa -host "west-mountain" -setMasterRepStart -uid test -pwd test -remoteDaemonPort 17050 -nokeepCG  -localhost "west-mountain" dsb
 
也就是说针对这种修改,active standby pair是通过 duplicate 到 standby端的。
 
Alter  Table 在 Replication中
 
alter table可以是增加或者删除列,这些修改可以直接被复制到对端。但如果是修改一个列的缺省值,则不能被复制,需要把这个修改在每个节点上手工做一遍。从另一个角度说明针对某个列,各个节点可以有不同的缺省值。
 
在双向复制的复制器中,需要确定所有的修改都已经同步到对端(通过ttRepSubscriberWait验证),然后再做列的修改。
 
如果有多次alter table,最好是每次alter table之后,确认一下是否已经成功,然后再进行下一个alter table。
 
以上面的例子为试验对象,
 
DSA:
Command> alter table tt add column c int;
Command> insert into tt values (1,1,1);
Command> insert into tt values (2,2,2);
Command> commit;
 
DSB:
Command> desc tt;
Table TEST.TT:
  Columns:
   *A                               NUMBER (38) NOT NULL
    B                               NUMBER (38) DEFAULT 88
    C                               NUMBER (38)
1 table found.
(primary key columns are indicated with *)
Command> select * from tt;
< 1, 1, 1 >
< 2, 2, 2 >
2 rows found.
Command>
 
可以看出,对列的增加和删除,并不用停止replication agent,而且很方便。但在alter table的过程中肯定是要加表级锁的,所以在那一刹那对应用还是有阻塞的,也是正常的。
 
但如果是修改列的缺省属性,则不会被复制到对端,而需要手工在对端同样修改一次。
 
Truncate Table 在 Replication 中
 
Truncate可以被复制到对端,相当于每个节点上执行truncate操作。类似于delete,但和delete不同的是,delete删除的记录两边是一摸一样的,而truncate则不会判断记录是否一样,一次性全部删除。
 
改变 Subscriber DataStore的状态
 
可以通过命令行工具ttRepAdmin -state 或者调用存储过程 ttRepSubscriberStateSet来设置,可能的状态有Start、Pause、Stop、Failed等。
 
解决 Update 冲突
 
实际中只有在双向复制的时候才会发生这种冲突,但一般不建议使用双向复制,即使迫不得已使用,也最好是数据针对应用切分,即底层不会有交叉应用的数据。否则真的等到冲突的时候,代价太大了,多半需要人工干预,也就失去了Replication的本意。
 
从失败中恢复
 
这个涉及的范围很广,具体分为硬件问题(系统、网络),软件问题(操作系统、应用程序、数据库、误操作)。具体可参考http://www.ttisql.com/replication/pair-disaster-restore-1.html
 
升级DataStore
 
这个也涉及很多东西,包括版本、数据类型、应用程序等等,一般通过ttMigrate 和 ttRepAdmin等工具进行。以后会写一篇专门的帖子来谈升级的问题。
 
在TimesTen中,因为历史的原因,有两种类型的replication,一种是旧的,老版本的replication;另一种是新的,我们称之为active standby pair 类型,那么针对active standby pair,在修改的时候,有些特别的地方的。其支持的修改功能如下:
 
  • Adding or dropping a subscriber data store
  • Altering store attributes - Only the PORT and TIMEOUT attributes can be set for subscribers. The RELEASE clause cannot be set for any data store in an active standby pair.
  • Including tables or cache groups in the active standby pair
  • Excluding tables or cache groups from the active standby pair
     
  1. 针对 Active Standby Pair ,一般Alter步骤如下:
  2. 停止active上的replication agent
  3. 停止active上的cache agent,如果有用到的话
  4. 在active上执行alter active standby pair…
  5. 启动Active上的replication agent
  6. 启动Active上的cache agent,如果需要的话
  7. Destroy 掉standby 以及 subscriber 对应的datastore
  8. 重建Standby 以及 Subscriber (通过dulicate)
 

留言已经关闭