TimesTen 데이터베이스 복제 학습: 16.캐시 그룹, 복제, 클라이언트 자동 전환의 직렬 실험

간단한 소개
AWT 캐시 그룹, Active Standby 복제, client auto failover 를 하나로 묶은 통합 실험입니다.전체 과정에서 Doc ID 1359840.1에 대해 본고는 이 문서를 바탕으로 자신의 환경에 따라 다시 한 번 했고 그 중의 작은 오류를 수정하여 자신의 이해를 높였다.본고는 Oracle 측에서 캐시 그룹을 설정하는 과정을 생략하였으며, 앞의 글을 참고하십시오.
구축된 환경은 가상 기기 timesten-hol에 두 개의 Times Ten 실례를 설치했다. 실례명은 각각tt1122와ttnew이고 각각 포트 53392(절약)와 55555tt1122에 데이터베이스는cachedb1이고 ttnew에 데이터베이스는cachedb2 가상 기기에 있고 Oracle 데이터베이스도 있다.
연결 인스턴스 tt1122의 문은 다음과 같습니다.
$ ttisql -v1 -e "set prompt 'cachedb1> '" "dsn=cachedb1;uid=tthr;pwd=timesten;oraclepwd=oracle"

인스턴스 ttnew를 연결하는 문은 다음과 같습니다.
$  . /u01/TimesTen/ttnew/bin/ttenv.sh
$ ttisql -v1 -e "set prompt 'cachedb2> '" "dsn=cachedb2;uid=tthr;pwd=timesten;oraclepwd=oracle"

Oracle을 연결하는 문은 다음과 같습니다.
$ sqlplus tthr/oracle@ttorcl

인스턴스 및 데이터베이스 DSN
두 인스턴스의 정의는 다음과 같습니다.
$ cat /etc/TimesTen/instance_info 
#SUM 55602 1
[ tt1122 ]
Product=TimesTen11.2.2.6.2
InstallDir=/home/oracle/TimesTen/tt1122
InstanceAdministrator=oracle
DaemonHome=/home/oracle/TimesTen/tt1122/info
BitLevel=64
Component=Client/Server and DataManager
TT_PORT=53392

[ ttnew ]
Product=TimesTen11.2.2.8.11
InstallDir=/u01/TimesTen/ttnew
InstanceAdministrator=oracle
DaemonHome=/u01/TimesTen/ttnew/info
BitLevel=64
Component=Client/Server and DataManager
TT_PORT=55555

인스턴스 tt1122의 데이터베이스 cachedb1의 DSN, 복제 소스
more /home/oracle/TimesTen/tt1122/info/sys.odbc.ini
[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은 복제 목표를 위해 강조해야 할 것이 하나 있다. 즉, 드라이브는 자신의 경로 아래의 드라이브, 즉 /u01/TimesTen/ttnew/lib/libtten.so를 써야 한다. 최초의cachedb2의DSN은cachedb1에서 복사된 것이기 때문에 최초의 드라이브는 드라이브=/home/oracle/TimesTen/tt1122/lib/libtten으로 썼다.so, 설령 이것이라도.so 파일은 이전과 같습니다. 이런 문법은 다음에 client auto failover 실험을 할 때 오류가 발생할 수 있습니다.
more /u01/TimesTen/ttnew/info/sys.odbc.ini
[cachedb2]
Driver=/u01/TimesTen/ttnew/lib/libtten.so
#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

Oracle 데이터베이스에 테이블 작성
여기서 t1은 읽기 전용 캐시 그룹, t2는 AWT 캐시 그룹에 사용됩니다.
$ sqlplus tthr/oracle@ttorcl
drop table t1;
drop table t2;
create table t1 (c1 number(22) not null primary key, c2 date, c3 varchar(40));
insert into t1 values (1, sysdate, 't1 data inserted in oracle');
insert into t1 values (2, sysdate, 't1 data inserted in oracle');
commit;
create table t2 (c1 number(22) not null primary key, c2 date, c3 varchar(40));
insert into t2 values (1, sysdate, 't2 data inserted in oracle');
insert into t2 values (2, sysdate, 't2 data inserted in oracle');
commit;

Readonly Autorefresh 캐시 그룹 설정
tthr에서 관리자 권한을 부여했습니다. active 데이터베이스 복제에 사용되며,cache관리자 권한은cache admin을 하기 위한 것이지만, 우리의 예에서cacheadm 사용자를 사용합니다.
$ ttisql cachedb1

drop user tthr;
create user tthr identified by timesten;
grant admin, create session, cache_manager, create any table to tthr; ???
exit;

읽기 전용 캐시 그룹 t1 설정roa
$ ttisql -v1 -e "set prompt 'cachedb1> '" "dsn=cachedb1;uid=tthr;pwd=timesten;oraclepwd=oracle"

call ttcacheuidpwdset('cacheadm','oracle');
call ttcachestart;
create readonly cache group t1_roa autorefresh interval 10 seconds
from t1 (c1 number(22) not null primary key, c2 date, c3 varchar(40));
load cache group t1_roa commit every 100 rows;

select * from t1;
< 1, 2016-07-01 20:04:51, t1 data inserted in oracle >
< 2, 2016-07-01 20:04:51, t1 data inserted in oracle >
exit;

AWT 캐시 그룹 t2 설정awt
$ ttisql -v1 -e "set prompt 'cachedb1> '" "dsn=cachedb1;uid=tthr;pwd=timesten;oraclepwd=oracle"

create asynchronous writethrough cache group t2_awt
from t2 (c1 number(22) not null primary key, c2 date, c3 varchar(40));
load cache group t2_awt commit every 100 rows;
call ttrepstart;

select * from t2;
< 1, 2016-07-01 20:04:51, t2 data inserted in oracle >
< 2, 2016-07-01 20:04:51, t2 data inserted in oracle >

exit;

Active Standby Pair 복제 작성
자동 협상 포트가 아닌 고정 복제 포트가 지정되어 있음을 주의하십시오.ttnew daemon이 부족한 포트에서 시작하지 않기 때문에
alter cache group t1_roa set autorefresh state paused;
call ttrepstop;
create active standby pair cachedb1 on "timesten-hol", cachedb2 on "timesten-hol" return receipt store cachedb1 on "timesten-hol" port 11102 store cachedb2 on "timesten-hol" port 11202;
call ttrepstart;
call ttrepstateget;
call ttrepstateset('ACTIVE');
alter cache group t1_roa set autorefresh state on;
call ttrepstateget; 
exit;

Standby 데이터베이스 복제, 주의 -verbosity 2, 유용한 정보 제공
$ ttRepAdmin -verbosity 2 -duplicate -from cachedb1 -host timesten-hol -remotedaemonport 53392 -dsn cachedb2 -uid tthr -pwd timesten -keepcg -cacheuid cacheadm -cachepwd oracle
20:32:38 Contacting remote main daemon at 127.0.0.1 port 53392
20:32:38 Contacting the replication agent for CACHEDB1 ON TIMESTEN-HOL (127.0.0.1) port 11102
20:32:38 Beginning transfer from CACHEDB1 ON TIMESTEN-HOL to CACHEDB2 ON TIMESTEN-HOL
20:33:06 Checkpoint transfer 10 percent complete
20:33:06 Checkpoint transfer 20 percent complete
20:33:06 Checkpoint transfer 30 percent complete
20:33:06 Checkpoint transfer 100 percent complete
20:33:06 Checkpoint transfer phase complete
20:33:09 Log transfer 100 percent complete
20:33:09 Log transfer phase complete
20:33:10 Transfer complete

Subscriber                                                       State
CACHEDB1 ON TIMESTEN-H                                           START
_ORACLE ON TIMESTEN-H                                            START

20:33:16 Duplicate Operation Ends

$ ttisql -v1 -e "set prompt 'cachedb2> '" "dsn=cachedb2;uid=tthr;pwd=timesten;oraclepwd=oracle"
call ttrepstart;
call ttcachestart;
call ttrepstateget;
< STANDBY, NO GRID >
exit;

읽기 전용 캐시 그룹이 올바르게 작동하는지 확인(Oracle 측에 삽입)
$ sqlplus tthr/oracle@ttorcl
insert into t1 values (3, sysdate, 't1 data inserted in oracle');
commit;
$ ttisql -v1 -e "set prompt 'cachedb1> '" "dsn=cachedb1;uid=tthr;pwd=timesten;oraclepwd=oracle"
sleep 70; <- refresh interval    60s
select * from t1;
Command> select * from t1;
< 1, 2016-07-01 20:04:51, t1 data inserted in oracle >
< 2, 2016-07-01 20:04:51, t1 data inserted in oracle >
< 3, 2016-07-02 01:26:34, t1 data inserted in oracle >

AWT 캐시 그룹이 올바르게 작동하는지 확인(TimesTen에 삽입)
$ ttisql -v1 -e "set prompt 'cachedb1> '" "dsn=cachedb1;uid=tthr;pwd=timesten;oraclepwd=oracle"
insert into t2 values (3, sysdate, 't2 data inserted in timesten');
commit;
$ sqlplus tthr/oracle@ttorcl
select * from t2;
SQL> select * from t2;

        C1 C2        C3
---------- --------- ----------------------------------------
         1 01-JUL-16 t2 data inserted in oracle
         2 01-JUL-16 t2 data inserted in oracle
         3 02-JUL-16 t2 data inserted in timesten

active 노드에서 C/S 연결 생성
클라이언트 자동 전환 관련 속성 ttcserver2, ttc_server_ns2와 tcpport2
TCP_Port는 daemon이 아닌 timesten 서버의 포트입니다.
The TCP/IP port number where the TimesTen Server is running. Default for TimesTen release 11.2.2 is 53393 for 32-bit platforms and 53397 for 64-bit platforms.
자동 전환 없이 active에 연결하도록 지정:
ttIsqlCS -connstr "ttc_server=timesten-hol;tcp_port=53393;ttc_server_dsn=cachedb1;uid=tthr;pwd=timesten;connectionname=cs_without_failover1" -e "set prompt 'cs_without_failover1> '"
cs_without_failover1> call ttrepstateget;
< ACTIVE, NO GRID >

자동 전환 연결이 있고 client auto failover는 C/S 연결만 지원하므로 ttIsqlcS를 사용해야 하며 항상 active 노드에 연결해야 합니다.
ttIsqlCS -connstr "ttc_server=timesten-hol;tcp_port=53393;ttc_server_dsn=cachedb1;ttc_server2=timesten-hol;tcp_port2=55556;ttc_server_dsn2=cachedb2;uid=tthr;pwd=timesten;connectionname=cs_with_failover1" -e "set prompt 'cs_with_failover1> '"
cs_with_failover1> call ttrepstateget;
< ACTIVE, NO GRID >

active와standby 노드에서 어떤 연결이 있는지 확인하기
이로써 active 데이터베이스cachedb1에 두 개의 연결이 있고standby 데이터베이스cachedb2에 연결이 없습니다
ACTIVE: tt1122 환경 변수에서 수행해야 합니다.
ttisql -connstr "dsn=cachedb1;uid=tthr;pwd=timesten;oraclepwd=oracle" -e "call ttrepstateget;call ttdatastorestatus;exit" | egrep -i "failover1|active|standby"
< ACTIVE, NO GRID >
< /home/oracle/TimesTen/tt1122/info/DemoDataStore/cachedb1, 15427, 000000000138DB90, application     , 5900C901, cs_without_failover1          , 1 >
< /home/oracle/TimesTen/tt1122/info/DemoDataStore/cachedb1, 15438, 0000000001CB4B90, application     , 5900C901, cs_with_failover1             , 2 >

STANDBY: ttnew 환경 변수에서 실행해야 합니다.
ttisql -connstr "dsn=cachedb2;uid=tthr;pwd=timesten;oraclepwd=oracle" -e "call ttrepstateget;call ttdatastorestatus;exit" | egrep -i "failover1|active|standby"
< STANDBY, NO GRID >

active와standby 역할 바꾸기
ACTIVE 노드에서 다음을 수행합니다.
$ ttisql -v1 -e "set prompt 'cachedb1> '" "dsn=cachedb1;uid=tthr;pwd=timesten;oraclepwd=oracle"
call ttrepsubscriberwait(,,,,-1); <-      < 00 >
call ttrepstop;
alter cache group t1_roa set autorefresh state paused;
call ttrepdeactivate;
call ttrepstateget;

   :
< 00 >
< IDLE, NO GRID >

STANDBY 노드에서 STANDBY를 새 ACTIVE로 만듭니다.
$ ttisql -v1 -e "set prompt 'cachedb2> '" "dsn=cachedb2;uid=tthr;pwd=timesten;oraclepwd=oracle"
call ttrepstateset('ACTIVE');
exit;

오래된 ACTIVE 노드에서 다음을 수행합니다.
$ ttisql -v1 -e "set prompt 'cachedb1> '" "dsn=cachedb1;uid=tthr;pwd=timesten;oraclepwd=oracle"
call ttrepstart;
sleep 10;
call ttrepstateget; <-     < STANDBY, NO GRID >
exit;

이로써,cachedb2는 새로운 active가 되었고,cachedb1은standby가 되었다
active와standby 노드에서 어떤 연결이 있는지 확인하기
새 STANDBY: tt1122 환경 변수에서 실행해야 합니다.
$ ttisql -connstr "dsn=cachedb1;uid=tthr;pwd=timesten;oraclepwd=oracle" -e "call ttrepstateget;call ttdatastorestatus;exit" | egrep -i "failover1|active|standby"
< STANDBY, NO GRID >
< /home/oracle/TimesTen/tt1122/info/DemoDataStore/cachedb1, 15427, 000000000138DB90, application     , 5900C901, cs_without_failover1          , 1 >


cachedb1은standby가 되어failover 기능을 갖추지 못한 c/s연결은 여전히 그 위에 보존되어 있습니다
새 ACTIVE:ttnew 환경 변수에서 수행해야 합니다.
이 때 연결이 하나 생겼는데, 이전의cachedb2에는 연결이 없습니다. 이 연결은 이전의cachedb1에서 autoclient failover를 통해 전환된 것입니다
$ ttisql -connstr "dsn=cachedb2;uid=tthr;pwd=timesten;oraclepwd=oracle" -e "call ttrepstateget;call ttdatastorestatus;exit" | egrep -i "failover1|active|standby"
< ACTIVE, NO GRID >
< /home/oracle/TimesTen/tt1122/info/DemoDataStore/cachedb2, 15518, 00000000021F8C60, application     , 0A020081, cs_with_failover1             , 9 >

주 노드 실효 시뮬레이션
캐치 에이전트와rep 에이전트가 자동으로 리셋되지 않도록 하십시오. 즉, 리셋 정책이 'manual' 이나 'norestart' 입니다.
The daemon restart while there are active connections to the database will cause a database invalidation.
현재 active 데이터베이스가cachedb2이기 때문에ttnew 실례를 다시 시작해야 합니다. 다시 시작하면 ACTIVE 상태가 IDLE로 바뀝니다
$ . /u01/TimesTen/ttnew/bin/ttenv.sh
$ daemonadmin -restart
$ ttisql -v1 -e "set prompt 'cachedb2> '" "dsn=cachedb2;uid=tthr;pwd=timesten;oraclepwd=oracle"
cachedb2> call ttrepstateget;
< IDLE, NO GRID >

standby 노드를 active로 승급하고 이전의 active를 실효로 표시합니다
$ ttisql -v1 -e "set prompt 'cachedb1> '" "dsn=cachedb1;uid=tthr;pwd=timesten;oraclepwd=oracle"
call ttrepstateset('ACTIVE');
call ttRepStateSave('FAILED', 'cachedb2', 'timesten-hol');
call ttrepstateget;
< ACTIVE, NO GRID >

오래된 active를 standby로 복구
$ ttdestroy -force cachedb2
$ ttRepAdmin -verbosity 2 -duplicate -from cachedb1 -host timesten-hol -remotedaemonport 53392 -dsn cachedb2 -uid tthr -pwd timesten -keepcg -cacheuid cacheadm -cachepwd oracle

$ ttisql -v1 -e "set prompt 'cachedb2> '" "dsn=cachedb2;uid=tthr;pwd=timesten;oraclepwd=oracle"cachedb2> call ttrepstart;
cachedb2> call ttcachestart;
cachedb2> call ttrepstateget;
< STANDBY, NO GRID >

클라이언트 연결 데이터베이스 확인
$ ttisql -connstr "dsn=cachedb1;uid=tthr;pwd=timesten;oraclepwd=oracle" -e "call ttrepstateget;call ttdatastorestatus;exit" | egrep -i "failover1|active|standby"
< ACTIVE, NO GRID >
< /home/oracle/TimesTen/tt1122/info/DemoDataStore/cachedb1, 15427, 000000000138DB90, application     , 5900C901, cs_without_failover1          , 1 >
< /home/oracle/TimesTen/tt1122/info/DemoDataStore/cachedb1, 16209, 00000000013D4B90, application     , 5900C901, cs_with_failover1             , 9 >


$ ttisql -connstr "dsn=cachedb2;uid=tthr;pwd=timesten;oraclepwd=oracle" -e "call ttrepstateget;call ttdatastorestatus;exit" | egrep -i "failover1|active|standby"
< STANDBY, NO GRID >

auto client failover라면 연결이 항상 active 노드를 가리키는 것을 볼 수 있습니다.
참고 자료
  • HOWTO : Add Active Standby Pair and Automatic Client Failover To Database With Oracle Cache Connect (Doc ID 1359840.1)
  • 좋은 웹페이지 즐겨찾기