Oracle LiveLabs实验:Application Continuity Fundamentals

Posted dingdingfish

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle LiveLabs实验:Application Continuity Fundamentals相关的知识,希望对你有一定的参考价值。

概述

此实验申请地址在这里,时间为2小时。实验的保留期为3天。第一次扩展增加了18小时,第二次扩展真假了42小时。

实验帮助在这里。

本实验需要的脚本为:

此实验将在OCI上创建2节点RAC 集群作为展示应用程序连续性功能的基础。所以实验的准备时间需要1个半小时左右。在 RAC 集群上,将定义支持AC和不支持AC的两个数据库服务。 然后,您将配置示例应用程序以使用 AC 服务并查看 AC 为应用程序提供的好处。 通过针对没有 AC 特性的服务运行相同的应用程序,这些优势将得到加强。

当然,其中最常应用的环境还是RAC,RAC相关的解决方案包括:

  • AHF(Automatic Health Framework)
  • AC(Application Continuity)
  • QoSM(Quality of Service Management)
  • Oracle Clusterware
  • ASM(Automatic Storage Management)
  • ACFS(ASM Cluster File System)
  • RAC One Node

或者,您可以检查 FAN 事件,这些事件构成了在发生故障或何时开始维护时通知应用程序的基础。 FAN 事件在中断检测和维护排空(draining)中发挥作用。

介绍

应用程序连续性 (AC) 是 Oracle Real Application Clusters (RAC)、Oracle RAC One Node 和 Oracle Active Data Guard 选项提供的一项功能,通过在可恢复的中断后恢复正在进行的数据库会话来屏蔽最终用户和应用程序的中断。 应用程序连续性在应用程序下执行此恢复,以便应用程序将中断视为稍微延迟的执行。
应用程序连续性改善了计划内维护和计划外中断的用户体验。 应用程序连续性增强了使用 Oracle 数据库的系统和应用程序的容错能力。

实验1和2

实验OCI创建2节点RAC 数据库服务。DB Edition为Enterprise Edition Extreme Performance。Shape为VMStandard2.2。数据库版本19.11。最初有1个PDB PDB1:

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           READ WRITE NO

数据库SYS和SYSTEM用户口令被设置为W3lc0m3#W3lc0m3#@

实验3:服务(Services)

简介

服务代表具有共同属性、服务级别阈值和优先级的应用程序组。 应用程序功能可以划分为由服务标识的工作负载。 您还可以在服务下按类型对工作进行分组。 例如,在线用户、批处理和报表可以分别使用不同的服务来连接到数据库。

响应时间和 CPU 消耗指标、性能和资源统计、等待事件、基于阈值的警报和性能索引由自动为所有服务维护。 服务、模块和操作标签用于识别服务器上服务内的操作。 (MODULE 和 ACTION 由应用程序设置)端到端监控支持在 Service、Module 和 Action 级别进行聚合和跟踪,以识别高负载操作。 Oracle Enterprise Manager 管理响应时间和 CPU 消耗的服务质量阈值,监控顶级服务,并提供深入了解顶级模块和每个服务的顶级操作。

连接时间路由和运行时路由算法平衡提供服务的实例之间的负载均衡。 RAC 使用服务来启用不间断的数据库操作。 通过允许重新定位或禁用/启用服务的接口支持计划的操作。

应用程序连续性被设置为服务的属性。

Oracle 建议共享服务的所有用户具有相同的服务级别要求。 您可以为服务定义特定的特征,每个服务都可以代表一个单独的工作单元。 使用服务时,您可以利用许多选项。 尽管您不必实现这些选项,但使用它们有助于优化应用程序操作和性能。

任务1:登录并识别数据库和实例名称

获取数据库名,为racMJMWZ_icn189

$ sudo su - grid
$ srvctl config database
racMJMWZ_icn189
$ crsctl stat res -t|grep '\\.db'
ora.racmjmwz_icn189.db

获取实例名,分别为racMJMWZ1racMJMWZ2

-- 节点1
$ ps -ef|grep ora_pmon|grep -v grep
oracle   15226     1  0 13:49 ?        00:00:00 ora_pmon_racMJMWZ1
-- 节点2
$ ps -ef|grep ora_pmon|grep -v grep
oracle   83117     1  0 13:49 ?        00:00:00 ora_pmon_racMJMWZ2

为简化,在节点1和2的.bash_profile中设置如下环境变量:

export DBNAME=$(srvctl config database)
export INST1=$(srvctl status database -d $DBNAME|awk 'NR==1 print $2')
export INST2=$(srvctl status database -d $DBNAME|awk 'NR==2 print $2')
export SYSPWD='W3lc0m3#W3lc0m3#'

任务2:创建服务

为简化,我们平时会使用EZConnect 连接串,格式为:
user/password@//hostname:port/servicename

但是,EZConnect 并不支持所有服务特性。 应用程序连续性和其他服务特性需要完全指定的 URL 或 TNS 连接字符串。

为pdb1创建服务svctest,然后启动服务,按照定义,服务只在实例1上启动:

sudo su - oracle
srvctl add service -d $DBNAME -s svctest -preferred $INST1 -available $INST2 -pdb pdb1
srvctl start service -d $DBNAME -s svctest
srvctl status service -d $DBNAME -s svctest

Service svctest is running on instance(s) racMJMWZ1

从监听也可以证明服务只在一个实例上运行:

-- 节点1
$ lsnrctl status|grep svctest
Service "svctest.pub.racdblab.oraclevcn.com" has 1 instance(s).

-- 节点2
$ lsnrctl status|grep svctest

任何 SCAN 侦听器都将显示提供服务的位置。 请注意,SCAN 侦听器从 GI HOME 运行,因此您必须更改 ORACLE_HOME 环境变量才能查看有关 SCAN 侦听器的信息。

export ORACLE_HOME=/u01/app/19.0.0.0/grid
$ORACLE_HOME/bin/lsnrctl service LISTENER_SCAN2

以上命令也可以指定参数为LISTENER_SCAN1或LISTENER_SCAN3。对于任一SCAN侦听器,只有一个实例上有svctest服务。

节点1上的输出:

...
Service "svctest.pub.racdblab.oraclevcn.com" has 1 instance(s).
  Instance "racMJMWZ1", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:0 refused:0 state:ready
         REMOTE SERVER
         (ADDRESS=(PROTOCOL=TCP)(HOST=10.0.0.116)(PORT=1521))
The command completed successfully

节点2上的输出:

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 14-JAN-2022 15:25:10

Copyright (c) 1991, 2021, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN3)))
TNS-12541: TNS:no listener
 TNS-12560: TNS:protocol adapter error
  TNS-00511: No listener
   Linux Error: 2: No such file or directory

节点1和节点2上的输出也可能互换。

任务3:服务故障转移

由于服务目前在节点1,因此在节点1执行:

$ ps -ef | grep ora_smon
oracle   15489     1  0 13:49 ?        00:00:00 ora_smon_racMJMWZ1

通过杀掉进程模拟实例故障:

kill -9 15489

以上命令这将导致实例失败,与此实例上的数据库的任何连接都将丢失。 Grid Infrastructure 的 CRS 组件将检测到实例故障,并立即在可用(available)实例上启动服务(基于服务定义)。 然后 CRS 将重新启动数据库实例。

-- 服务迁移到实例2上
$ srvctl status service -d $DBNAME -s svctest
Service svctest is running on instance(s) racMJMWZ2

-- 被kill的实例也启动了
$ srvctl status database -d $DBNAME
Instance racMJMWZ1 is running on node lvracdb-s01-2022-01-14-1230121
Instance racMJMWZ2 is running on node lvracdb-s01-2022-01-14-1230122

$ ps -ef | grep ora_smon
oracle   15507     1  0 15:29 ?        00:00:00 ora_smon_racMJMWZ1

通过SCAN连到服务。

-- 获取SCAN NAME,为lvracdb-s01-2022-01-14-123012-scan.pub.racdblab.oraclevcn.com
$ srvctl config scan
SCAN name: lvracdb-s01-2022-01-14-123012-scan.pub.racdblab.oraclevcn.com, Network: 1
Subnet IPv4: 10.0.0.0/255.255.255.0/ens3, static
Subnet IPv6:
SCAN 1 IPv4 VIP: 10.0.0.213
SCAN VIP is enabled.
SCAN 2 IPv4 VIP: 10.0.0.229
SCAN VIP is enabled.
SCAN 3 IPv4 VIP: 10.0.0.74
SCAN VIP is enabled.

-- 获取服务名
$ srvctl config service -db $DBNAME
Service name: svctest
Server pool:
Cardinality: 1
Service role: PRIMARY
Management policy: AUTOMATIC
DTP transaction: false
AQ HA notifications: false
Global: false
Commit Outcome: false
Failover type:
Failover method:
Failover retries:
Failover delay:
Failover restore: NONE
Connection Load Balancing Goal: LONG
Runtime Load Balancing Goal: NONE
TAF policy specification: NONE
Edition:
Pluggable database name: pdb1
Hub service:
Maximum lag time: ANY
SQL Translation Profile:
Retention: 86400 seconds
Replay Initiation Time: 300 seconds
Drain timeout:
Stop option:
Session State Consistency: DYNAMIC
GSM Flags: 0
Service is enabled
Preferred instances: racMJMWZ1
Available instances: racMJMWZ2
CSS critical: no
Service uses Java: false

SQL> show parameter db_domain

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_domain                            string      pub.racdblab.oraclevcn.com

设置环境变量,实际使用的服务名要加上service_domain,即DB_DOMAIN:

-- 为方便,SCAN_NAME
export SCAN_NAME=lvracdb-s01-2022-01-14-123012-scan.pub.racdblab.oraclevcn.com
export SVC_NAME=svctest.pub.racdblab.oraclevcn.com

在会话1中,使用SYSTEM用户连接PDB,连接串为EZConnect 形式:

$ sqlplus system/$SYSPWD//$SCAN_NAME/$SVC_NAME
SQL> show con_name

CON_NAME
------------------------------
PDB1

在会话2中,使用SYS用户连接PDB,使用PDB默认的服务名连接:

sqlplus sys/$SYSPWD//$SCAN_NAME/pdb1.pub.racdblab.oraclevcn.com as sysdba
SQL>
-- With WRAP OFF, lines are truncated to match the LINESIZE setting
set wrap off
col service_name format  a20
select inst_id, service_name, count(*) from gv$session where service_name = 'svctest' group by inst_id, service_name;

   INST_ID SERVICE_NAME           COUNT(*)
---------- -------------------- ----------
         2 svctest                       1

输出显示实例2上有1个连接使用了服务svctest。

手工将服务从实例2迁移到实例1:

$ srvctl relocate service -d $DBNAME -s svctest -oldinst $INST2 -newinst $INST1

$ srvctl status service -d $DBNAME -s svctest
Service svctest is running on instance(s) racMJMWZ1

在会话2上再次查看,输出并没有变化:

set wrap off
set lines 120
col service_name format  a20
select inst_id, service_name, count(*) from gv$session where service_name = 'svctest' group by inst_id, service_name;

   INST_ID SERVICE_NAME           COUNT(*)
---------- -------------------- ----------
         2 svctest                       1

这是由于除非指定了强制选项 (-force),否则 relocate service 命令不会断开活动会话。 停止服务命令将允许指定排空超时,以允许应用程序在排空间隔内完成其工作。

测试-force选项的结果为,会话1被断开,会话2查询没有输出。这应该是没有配置应用连续性的行为。

在本节最后,可以删除服务svctest:

srvctl remove service -d $DBNAME -s svctest -force

任务 4:配置支持应用程序连续性的服务

FAN、连接标识符、TAC、AC、切换、消费者组以及许多其他功能和操作都基于服务的使用。 不要使用默认数据库服务(自动创建的与数据库或 PDB 同名的服务),因为该服务无法禁用、重定位或限制,因此没有高可用性支持。您使用的服务与 Data Guard 环境中的特定主角色或备用角色相关联。 不要将初始化参数 service_names 用于应用程序使用。

这段话非常重要,现录原文如下:

Do not use the default database service (the service created automatically with the same name as the database or PDB) as this service cannot be disabled, relocated, or restricted and so has no high availability support. The services you use are associated with a specific primary or standby role in a Data Guard environment. Do not use the initialization parameter service_names for application usage.

在这个问题上是有个教训的,那么原文出处可以从Real Application Clusters Administration and Deployment Guide中找到:

All of these services are used for internal management. You cannot stop or disable any of these internal services to do planned outages or to failover to Oracle Data Guard. Do not use these services for client connections.

service_names初始化参数在19c后已经不支持。

服务上设置的属性使应用程序能够使用应用程序连续性。 创建服务,设置应用程序连续性 (AC) 的属性 failover_restore(是否恢复会话状态)、commit_outcome(是否启用Transaction Guard)和 failovertype(AC,TAC,TAF)。 将“-d”、“-s”、“-preferred”和“-available”的值替换为您系统的值。

创建2个服务并启动,一个支持AC,另一个不支持。这2个服务将在下一个实验中使用:

srvctl add service -d $DBNAME -s yesac -commit_outcome TRUE -failovertype TRANSACTION -failover_restore LEVEL1 -preferred $INST1 -available $INST2 -pdb pdb1 -clbgoal LONG -rlbgoal NONE

srvctl add service -d $DBNAME -s noac -commit_outcome FALSE -failovertype NONE -failover_restore NONE -preferred $INST1 -available $INST2 -pdb pdb1 -clbgoal LONG -rlbgoal NONE

srvctl start service -d $DBNAME -s noac
srvctl start service -d $DBNAME -s yesac

srvctl的通用帮助参见这里。和RAC相关的srvctl命令帮助见这里

实验4:应用连续性(Application Continuity)

任务 1:安装示例程序并配置服务

在任一RAC节点下载测试脚本:

sudo su - oracle

wget https://objectstorage.us-ashburn-1.oraclecloud.com/p/O8AOujhwl1dSTqhfH69f3nkV6TNZWU3KaIF4TZ-XuCaZ5w-xHEQ14ViOVhUXQjPB/n/oradbclouducm/b/LiveLabTemp/o/ACDemo_19c.zip

unzip ACDemo_19c.zip

chmod +x SETUP_AC_TEST.sh

运行测试设置脚本:

$ ./SETUP_AC_TEST.sh
Enter a value for ORACLE_HOME [/u01/app/oracle/product/19.0.0.0/dbhome_1]:
Enter the database name [racMJMWZ_icn189]:
Enter the PDB to use [pdb1]:
Enter the SYSTEM user password:W3lc0m3#W3lc0m3#
Enter the SCAN name [lvracdb-s01-2022-01-14-123012-scan.pub.racdblab.oraclevcn.com]:
Enter a new service name [ac_service]:
Enter the tablespace name for the HR user [USERS]:
...
The following services have been created and are running:
Service ac_service is running on instance(s) racMJMWZ1
Service noac is running on instance(s) racMJMWZ1
Service svctest is running on instance(s) racMJMWZ1
Service tac_service is running on instance(s) racMJMWZ1
Service unisrv is running on instance(s) racMJMWZ1,racMJMWZ2
Service yesac is running on instance(s) racMJMWZ1

这个测试脚本可以好好研究一下,其中有很多命令可以模仿,例如获取service domain的命令:

srvctl config scan | $GREP 'SCAN name' | $AWK 'print $3' | cut -d '.' -f2-

赋予测试脚本执行权限:

cd /home/oracle/acdemo
chmod +x run*
chmod +x kill_session.sh

任务 2:检查服务属性和程序设置

通过在数据库服务上设置属性来启用应用程序连续性(无论是 AC 还是 TAC)。 对于 JDBC 应用程序,还必须使用支持重放(Replay)的驱动程序。

查看服务名:

$ srvctl status service -d `srvctl config database`
Service ac_service is running on instance(s) racMJMWZ1
Service noac is running on instance(s) racMJMWZ1
Service svctest is running on instance(s) racMJMWZ1
Service tac_service is running on instance(s) racMJMWZ1
Service unisrv is running on instance(s) racMJMWZ1,racMJMWZ2
Service yesac is running on instance(s) racMJMWZ1
[oracle@lvracdb-s01-2022-01-14-1230121 ~]$

查看服务详情:

-- NO AC
$ srvctl config service -d  `srvctl config database` -s noac
Service name: noac
Server pool:
Cardinality: 1
Service role: PRIMARY
Management policy: AUTOMATIC
DTP transaction: false
AQ HA notifications: false
Global: false
Commit Outcome: false <<<<- 看这里
Failover type: NONE <<<<- 看这里
Failover method:
Failover retries:
Failover delay:
Failover restore: NONE <<<<- 看这里
Connection Load Balancing Goal: LONG
Runtime Load Balancing Goal: NONE
TAF policy specification: NONE
Edition:
Pluggable database name: pdb1
Hub service:
Maximum lag time: ANY
SQL Translation Profile:
Retention: 86400 seconds
Replay Initiation Time: 300 seconds
Drain timeout:
Stop option:
Session State Consistency: DYNAMIC
GSM Flags: 0
Service is enabled
Preferred instances: racMJMWZ1
Available instances: racMJMWZ2
CSS critical: no
Service uses Java: false

-- TAC
$ srvctl config service -d  `srvctl config database` -s tac_service
Service name: tac_service
Server pool:
Cardinality: 1
Service role: PRIMARY
Management policy: AUTOMATIC
DTP transaction: false
AQ HA notifications: false
Global: false
Commit Outcome: true <<<<- 看这里
Failover type: AUTO <<<<- 看这里
Failover method:
Failover retries: 30
Failover delay: 10
Failover restore: AUTO <<<<- 看这里
Connection Load Balancing Goal: LONG
Runtime Load Balancing Goal: NONE
TAF policy specification: NONE
Edition:
Pluggable database name: pdb1
Hub service:
Maximum lag time: ANY
SQL Translation Profile:
Retention: 86400 seconds
Replay Initiation Time: 300 seconds
Drain timeout:
Stop option:
Session State Consistency: AUTO
GSM Flags: 0
Service is enabled
Preferred instances: racMJMWZ1
Available instances: racMJMWZ2
CSS critical: no
Service uses Java: false

-- AC
$ srvctl config service -d  `srvctl config database` -s ac_service
Service name: ac_service
Server pool:
Cardinality: 1
Service role: PRIMARY
Management policy: AUTOMATIC
DTP transaction: false
AQ HA notifications: true
Global: false
Commit Outcome: true <<<<- 看这里
Failover type: TRANSACTION <<<<- 看这里
Failover method:
Failover retries:
Failover delay:
Failover restore: LEVEL1 <<<<- 看这里
Connection Load Balancing Goal: LONG
Runtime Load Balancing Goal: NONE
TAF policy specification: NONE
Edition:
Pluggable database name: pdb1
Hub service:
Maximum lag time: ANY
SQL Translation Profile:
Retention: 86400 seconds
Replay Initiation Time: 300 seconds
Drain timeout:
Stop option:
Session State Consistency: DYNAMIC
GSM Flags: 0
Service is enabled
Preferred instances: racMJMWZ1
Available instances: racMJMWZ2
CSS critical: no
Service uses Java: false

测试程序为acdemo,位于目录acdemo下。你可以运行以下命令来终止Java测试应用程序:

ps -ef|grep acdemo
kill -9 xxxx

任务 3:NO Replay (NO AC)

应用程序连续性的一个关键原则是不需要更改应用程序。 我们使用属性文件管理这个示例应用程序。 我们使用 SHELL 脚本来设置环境并选择将产生特定行为的属性文件。

检查 ac_noreplay.properties 文件,可以看到我们正在使用池数据源 oracle.jdbc.pool.OracleDataSource ,但已禁用 FAN、fastConnectionFailover=FALSE 和连接测试 validateConnectionOnBorrow=FALSE。 URL 使用推荐的格式并连接到没有设置 AC 属性的服务 noac。

$ more ac_noreplay.properties
#Stub file to build ac_noreplay.properties
# Use vanilla datasource
datasource=oracle.jdbc.pool.OracleDataSource

# Set verbose mode
VERBOSE=FALSE

# database JDBC URL
url=jdbc:oracle:thin:@(DESCRIPTION=(CONNECT_TIMEOUT=90)(RETRY_COUNT=50)(RETRY_DELAY=3)(TRANSPORT_CONNECT_TIMEOUT=3)(ADDRESS_LIST=(ADDRESS=(PROTOCO
L=tcp)(HOST=lvracdb-s01-2022-01-14-123012-scan.pub.racdblab.oraclevcn.com)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=noac.pub.racdblab.oraclevcn.com
)))

# database username and password
username=hr
password=W3lc0m3#W3lc0m3#

# Disable FAN
fastConnectionFailover=FALSE

#Disable connection tests
validateConnectionOnBorrow=FALSE

# number of connections in the UCP's pool
ucp_pool_size=20

#Connection Wait Timeout for busy pool
connectionWaitTimeout=5

# number of active threads (this simulates concurrent load)
number_of_threads=10

# think time is how much time the threads will sleep before looping
thread_think_time=50

运行测试程序:

cd /home/oracle/acdemo
./runnoreplay

应用程序将启动,创建一个连接池,并开始对数据库发出事务。

$ ./runnoreplay
######################################################
Connecting to jdbc:oracle:thin:@(DESCRIPTION=(CONNECT_TIMEOUT=90)(RETRY_COUNT=50)(RETRY_DELAY=3)(TRANSPORT_CONNECT_TIMEOUT=3)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=lvracdb-s01-2022-01-14-123012-scan.pub.racdblab.oraclevcn.com)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=noac.pub.racdblab.oraclevcn.com)))
 # of Threads             : 10
 UCP pool size            : 20
FCF Enabled:  false
VCoB Enabled: false
ONS Configuration:  null
Enable Intensive Wload:  false
Thread think time        : 50 ms
######################################################

Starting the pool now... (please wait)
Pool is started in 4190ms
1 borrowed, 0 pending, 0ms getConnection wait, TotalBorrowed 725, avg response time from db 7ms
0 borrowed, 0 pending, 0ms getConnection wait, TotalBorrowed 1562, avg response time from db 7ms
1 borrowed, 0 pending, 0ms getConnection wait, TotalBorrowed 2420, avg response time from db 5ms
1 borrowed, 0 pending, 0ms getConnection wait, TotalBorrowed 3262, avg response time from db 6ms
...

确认服务noac运行所在的实例,然后在实例上杀掉smon进程模拟实例失效:

$ srvctl status service -d `srvctl config database` -s noac
Service noac is running on instance(s) racMJMWZ1

$ ps -ef | grep ora_smon
oracle   15507     1  0 Jan14 ?        00:00:01 ora_smon_racMJMWZ1

$ kill -9 15507

应用程序将看到来自数据库的错误,并将进入其自己的错误处理例程。系统可能需要一些时间来纠正和恢复,但如果应用程序没有超时,或者没有达到某些错误阈值(应用程序为自己设置),则可以重新建立连接并重新开始活动。

...
Application error handling: attempting to get a new connection No more data to read from socket.java.sql.SQLRecoverableException: No more data to read from socket
...
FCF information:
0 borrowed, 10 pending, 0ms getConnection wait, TotalBorrowed 42149, avg response time from db 9ms
 Application driven connection retry succeeded
 Application driven connection retry succeeded
 Application driven connection retry succeeded
 Application driven connection retry succeeded
 Application driven connection retry succeeded
 Application driven connection retry succeeded
 Application driven connection retry succeeded
 Application driven connection retry succeeded
 Application driven connection retry succeeded
 Application driven connection retry succeeded
10 borrowed, 0 pending, 1ms getConnection wait, TotalBorrowed 42159
10 borrowed, 0 pending, 1ms getConnection wait, TotalBorrowed 42159
4 borrowed, 0 pending, 1ms getConnection wait, TotalBorrowed 42631, avg response time from db 174ms
2 borrowed, 0 pending, 1ms getConnection wait, TotalBorrowed 43291, avg response time from db 22ms
2 borrowed, 0 pending, 1ms getConnection wait, TotalBorrowed 44147, avg response time from db 5ms
...

总的来说,连接虽然重建了,但过程中应用仍然发生了中断。

任务 4:应用连续性 (AC)

这一次我们使用的配置文件为ac_replay.properties,服务为ac_service:

$ cat ac_replay.properties
# Stub file to create ac_replay.properties
# Use replay datasource
datasource=oracle.jdbc.replay.OracleDataSourceImpl

# Set verbose mode
VERBOSE=FALSE

# database JDBC URL
url=jdbc:oracle:thin:@(DESCRIPTION=(CONNECT_TIMEOUT=90)(RETRY_COUNT=50)(RETRY_DELAY=3)(TRANSPORT_CONNECT_TIMEOUT=3)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=lvracdb-s01-2022-01-14-123012-scan.pub.racdblab.oraclevcn.com)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ac_service.pub.racdblab.oraclevcn.com)))

# database username and password:
username=hr
password=W3lc0m3#W3lc0m3#

# Enable FAN
fastConnectionFailover=TRUE

#Disable connection tests
validateConnectionOnBorrow=TRUE

# number of connections in the UCP's pool:
ucp_pool_size=20

#Connection Wait Timeout for busy pool
connectionWaitTimeout=5

# number of active threads (this simulates concurrent load):
number_of_threads=10

# think time is how much time the threads will sleep before looping:
thread_think_time=50

运行测试程序,这一次是runreplay:

cd /home/oracle/acdemo
./runreplay

和上一个测试一样,应用程序将启动,创建一个连接池,并开始对数据库发出事务。

$ ./runreplay
######################################################
Connecting to jdbc:oracle:thin:@(DESCRIPTION=(CONNECT_TIMEOUT=90)(RETRY_COUNT=50)(RETRY_DELAY=3)(TRANSPORT_CONNECT_TIMEOUT=3)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=lvracdb-s01-2022-01-14-123012-scan.pub.racdblab.oraclevcn.com)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ac_service.pub.racdblab.oraclevcn.com)))
 # of Threads             : 10
 UCP pool size            : 20
FCF Enabled:  true
VCoB Enabled: true
ONS Configuration:  null
Enable Intensive Wload:  false
Thread think time        : 50 ms
######################################################

Starting the pool now... (please wait)
Pool is started in 4994ms
0 borrowed, 0 pending, 0ms getConnection wait, TotalBorrowed 715, avg response time from db 9ms
2 borrowed, 0 pending, 0ms getConnection wait, TotalBorrowed 1557, avg response time from db 6ms
2 borrowed, 0 pending, 0ms getConnection wait, TotalBorrowed 2406, avg response time from db 5ms
1 borrowed, 0 pending, 0ms getConnection wait, TotalBorrowed 3262, avg response time from db 5ms
...

实验中提供了一个脚本kill_session.sh,也可以模拟应用中断。它的原理是从数据库内部杀掉会话进程:

-- 输出为20行,因为连接池大小是20
SQL> select sid, serial# from v$session where username = 'HR';

       SID    SERIAL#
---------- ----------
        28      32873
        30      16861
        31      27187
        33       8272
       188      19131
       189      18030
       191      13257
       192      44977
       193      52800
       338      49331
       341       7887
       343      40597
       348      61856
       349      18738
       353      24020
       355      40564
       506      17666
       509      65326
       510      63791
       511       2568

20 rows selected.

-- 执行20个kill语句
SQL> ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;

不过我们还是使用上一个实验的方法,通过杀掉smon进程来模拟实例失效:

$ srvctl status service -d `srvctl config database` -s ac_service
Service ac_service is running on instance(s) racMJMWZ2

$ ps -ef | grep ora_smon
oracle   34026 23274  0 02:56 pts/1    00:00:00 grep --color=auto ora_smon
oracle   83379     1  0 Jan14 ?        00:00:03 ora_smon_racMJMWZ2

$ kill -9 83379

从应用程序的输出中可以看到没有中断,注意其中有一个响应时间较长:

...
1 borrowed, 0 pending, 0ms getConnection wait, TotalBorrowed 13249, avg response time from db 5ms
0 borrowed, 0 pending, 0ms getConnection wait, TotalBorrowed 14067, avg response time from db 7ms
10 borrowed, 0 pending, 0ms getConnection wait, TotalBorrowed 14809, avg response time from db 6ms
10 borrowed, 0 pending, 0ms getConnection wait, TotalBorrowed 14809
5 borrowed, 0 pending, 0ms getConnection wait, TotalBorrowed 15143, avg response time from db 258ms
2 borrowed, 0 pending, 0ms getConnection wait, TotalBorrowed 15928, avg response time from db 10ms
4 borrowed, 2 pending, 0ms getConnection wait, TotalBorrowed 16738, avg response time from db 8ms
...

任务 5:透明应用连续性 (TAC)

这一次我们使用的配置文件为tac_replay.properties,服务为tac_service:

$ cat tac_replay.properties
# Stub file to create tac_replay.properties
# Use replay datasource
datasource=oracle.jdbc.replay.OracleDataSourceImpl

# Set verbose mode
VERBOSEOracle LiveLabs实验:Oracle RAC Fundamentals

Oracle LiveLabs实验:Install Oracle Database 21c

Oracle LiveLabs实验:DB Security - Oracle Label Security (OLS)

Oracle LiveLabs实验:Oracle Label Security (OLS)

Oracle LiveLabs实验:Introduction to Oracle Spatial

Oracle LiveLabs实验:Introduction to Oracle Spatial