标签:
本文有两个目的:
1. 介绍TimesTen Global Cache Grid的高可用性
2. 给出了一个简单的建立和清理Global Cache Grid的过程,前面已经有一篇文章: TimesTen 应用层数据库缓存学习:13. 全局数据缓存(cache grid),但那个Cache Group太复杂
首先建立两个TimesTen instance,一个为tt1122, 一个为ttnew。
之所以建立两个实例,是为了停instance方便。现在还没有找到一个方法来停DB。
详细的过程如下:
在tt1122实例上,建立cachedb1的DSN
[cachedb1]
Driver=/home/oracle/TimesTen/tt1122/lib/libtten.so
DataStore=/home/oracle/TimesTen/tt1122/info/DemoDataStore/cachedb1
PermSize=32
TempSize=64
LogFileSize=32
LogBufMB=32
DatabaseCharacterSet=AL32UTF8
OracleNetServiceName=ttorcl
在ttnew实例上,建立cachedb2的DSN
[cachedb2]
Driver=/home/oracle/TimesTen/tt1122/lib/libtten.so
DataStore=/home/oracle/TimesTen/tt1122/info/DemoDataStore/cachedb2
PermSize=32
TempSize=64
LogFileSize=32
LogBufMB=32
DatabaseCharacterSet=AL32UTF8
OracleNetServiceName=ttorcl
建立cachedb1中的schema用户
$ ttisql -v1 cachedb1
Command> set prompt ‘cachedb1> ‘
cachedb1> create user tthr identified by tthr;
User created.
cachedb1> grant admin to tthr;
在cachedb1和cachedb2中设置cacheadm的用户名和口令
$ ttadmin -connstr "dsn=cachedb1;uid=tthr;pwd=tthr;oraclepwd=tthr" -cacheUidPwdSet -cacheUid cacheadm -cachePwd oracle
cachedb1上创建cache grid
$ ttisql -v1 -e "set prompt ‘cachedb1> ‘" "dsn=cachedb1;uid=tthr;pwd=tthr;oraclepwd=oracle"
cachedb1> call ttGridCreate (‘samplegrid‘);
cachedb1> call ttGridInfo;
< SAMPLEGRID, CACHEADM, Linux x86-64, 64-bit, 11, 2, 2 >
cachedb1> call ttGridNameSet (‘samplegrid‘);
启动cachedb1上的cache agent
ttadmin -cacheStart cachedb1
创建Oracle中的Schema:
$ sqlplus tthr/oracle@ttorcl
create table a(id int, name varchar(32), primary key(id));
SQL> grant select, insert, delete, update on a to cacheadm;
SQL> insert into a values(1, ‘beijing‘);
SQL> insert into a values(2, ‘shanghai‘);
SQL> insert into a values(3, ‘guangzhou‘);
cachedb1上创建Global Dynamic Asynchronous Writethrough Cache Group
CREATE DYNAMIC ASYNCHRONOUS WRITETHROUGH GLOBAL CACHE GROUP "G_AWT"
FROM
"TTHR"."A" (
"ID" NUMBER(38) NOT NULL,
"NAME" VARCHAR2(32 BYTE),
PRIMARY KEY("ID")
)
cachedb1上启动replication agent:
ttadmin -repStart cachedb1
将cachedb1 attach到cache grid
$ ttisql -v1 -e "set prompt ‘cachedb1> ‘" "dsn=cachedb1;uid=tthr;pwd=tthr"
cachedb1> call ttGridNodeStatus;
cachedb1> call ttGridAttach (1,‘cachedb1‘,‘localhost‘,9991);
cachedb1> call ttGridNodeStatus;
< SAMPLEGRID, 1, 1, T, localhost, SAMPLEGRID_cachedb1_1, 127.0.0.1, 9991, <NULL>, <NULL>, <NULL>, <NULL>, <NULL> >
确认cachedb1可以访问数据
$ ttisql -v1 -e "set prompt ‘cachedb1> ‘" "dsn=cachedb1;uid=tthr;pwd=tthr;oraclepwd=oracle"
cachedb1> select * from a;
cachedb1> select * from a where id = 1;
< 1, beijing >
建立cachedb2中的schema用户
$ ttisql -v1 -e "set prompt ‘cachedb2> ‘" cachedb2
cachedb2> create user tthr identified by tthr;
User created.
cachedb2> grant admin to tthr;
cachedb2上设置cache admin账户信息,等等…
ttadmin -connstr "dsn=cachedb2;uid=tthr;pwd=tthr;oraclepwd=tthr" -cacheUidPwdSet -cacheUid cacheadm -cachePwd oracle
[oracle@timesten-hol ~]$ ttisql -v1 -e "set prompt ‘cachedb2> ‘" "dsn=cachedb2;uid=tthr;pwd=tthr;oraclepwd=oracle"
cachedb2> call ttGridInfo;
< SAMPLEGRID, CACHEADM, Linux x86-64, 64-bit, 11, 2, 2 >
cachedb2> call ttGridNameSet (‘samplegrid‘);
cachedb2> call ttCacheStart();
cachedb2> CREATE DYNAMIC ASYNCHRONOUS WRITETHROUGH GLOBAL CACHE GROUP "G_AWT"
> FROM
> "TTHR"."A" (
> "ID" NUMBER(38) NOT NULL,
> "NAME" VARCHAR2(32 BYTE),
> PRIMARY KEY("ID")
> );
cachedb2> call ttrepstart();
cachedb2> call ttGridAttach (1,‘cachedb2‘,‘localhost‘,9992);
cachedb2> call ttGridNodeStatus;
< SAMPLEGRID, 1, 1, T, localhost, SAMPLEGRID_cachedb1_1, 127.0.0.1, 9991, <NULL>, <NULL>, <NULL>, <NULL>, <NULL> >
< SAMPLEGRID, 2, 1, T, localhost, SAMPLEGRID_cachedb2_2, 127.0.0.1, 9992, <NULL>, <NULL>, <NULL>, <NULL>, <NULL> >
cachedb1> autocommit 0
cachedb1> CALL ttOptSetFlag(‘GlobalProcessing‘, 1);
cachedb1> select * from a;
< 2, shanghai >
< 1, beijing >
cachedb1> SELECT id, TTGRIDUSERASSIGNEDNAME(), TTGRIDMEMBERID() FROM a;
< 1, cachedb1, 1 >
< 2, cachedb2, 2 >
以上即演示,一切正常,下面来看一下异常的情况。
若某一grid member宕机
[oracle@timesten-hol ~]$ ttdaemonadmin -stop
TimesTen Daemon stopped.
[oracle@timesten-hol ~]$ ttstatus cachedb1
ttStatus: Could not connect to the TimesTen daemon.
If the TimesTen daemon is not running, please start it
by running "ttDaemonAdmin -start".
[oracle@timesten-hol ~]$
[oracle@timesten-hol ~]$ ttisql -v1 -e "set prompt ‘cachedb2> ‘" "dsn=cachedb2;uid=tthr;pwd=tthr;oraclepwd=oracle"
cachedb2> show autocommit;
autocommit = 1 (ON)
cachedb2> select * from a;
< 2, shanghai >
cachedb2> select * from a where id = 1;
3333: Time out waiting for a response from member SAMPLEGRID_cachedb2_2 <- 大致一分钟
cachedb2>
cachedb2> autocommit 0;
cachedb2> CALL ttOptSetFlag(‘GlobalProcessing‘, 1);
cachedb2> select * from a;
好久都没出来!一直都没出来!!!
TimesTen 应用层数据库缓存学习:17. 全局数据缓存(cache grid)的高可用性
标签:
原文地址:http://blog.csdn.net/stevensxiao/article/details/51678364