TimesTen 应用层数据库缓存学习:17. 全局数据缓存(cache grid)的高可用性
Posted dingdingfish
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TimesTen 应用层数据库缓存学习:17. 全局数据缓存(cache grid)的高可用性相关的知识,希望对你有一定的参考价值。
概述
本文有两个目的:
1. 介绍TimesTen Global Cache Grid的高可用性
2. 给出了一个简单的建立和清理Global Cache Grid的过程,前面已经有一篇文章: TimesTen 应用层数据库缓存学习:13. 全局数据缓存(cache grid),但那个Cache Group太复杂
建立一个简单的Global Cache Grid
首先建立两个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 >
Cache Grid中某节点异常时的情况
以上即演示,一切正常,下面来看一下异常的情况。
若某一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;
好久都没出来!一直都没出来!!!
结论
- Cache Grid中的每个成员,如果是单节点,此架构是没有弹性(Resilience)的。数据不会重新分布,查询操作会超时或者HANG
- Cache Grid的每个成员的保护,通常是通过Active Standby Pair来保护的,每一个节点都需要配一个standby,不过这样的架构比较重
- Cache Grid(Global Cache Group)适用的场景较少,可扩展性方面是有限制的。
- TimesTen 未来会推出12版,应该可以替代掉现在的Cache Grid功能。
以上是关于TimesTen 应用层数据库缓存学习:17. 全局数据缓存(cache grid)的高可用性的主要内容,如果未能解决你的问题,请参考以下文章
TimesTen 应用层数据库缓存学习:19. 理解AWT缓存组的三种模式
TimesTen 应用层数据库缓存学习:16. Aging策略与AWT缓存组
TimesTen 数据库复制学习:8. 管理Active Standby Pair(带缓存组)
TimesTen 数据库复制学习:16. 一个缓存组,复制,客户端自动切换的串烧实验