TimesTen 应用层数据库缓存学习:7. 同步读写缓存

2024-02-04 13:48

本文主要是介绍TimesTen 应用层数据库缓存学习:7. 同步读写缓存,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

同步读写缓存(SWT)比较少用到,它性能肯定是不如AWT,但数据一致性强于AWT。
数据先在Oracle提交,然后才在TimesTen中提交,因此TimesTen的约束可以比Oracle弱。

和AWT一样,SWT的定义不能出现where条件
和AWT一样,虽然Oracle端可以修改,但是不建议。

定义dynamic SWT缓存

CREATE DYNAMIC SYNCHRONOUS WRITETHROUGH CACHE GROUP "D_SWT" FROM"TTHR"."DEPARTMENTS" ("DEPARTMENT_ID"   NUMBER(4)         NOT NULL,"DEPARTMENT_NAME" VARCHAR2(30 BYTE) NOT NULL,"MANAGER_ID"      NUMBER(6)        ,"LOCATION_ID"     NUMBER(4)        ,PRIMARY KEY("DEPARTMENT_ID"))AGING LRU ONcachaadm> cachegroups;Cache Group CACHEADM.D_SWT:Cache Group Type: Synchronous Writethrough (Dynamic)Autorefresh: NoAging: LRU onRoot Table: TTHR.DEPARTMENTSTable Type: Propagate1 cache group found.cacheadm> call ttrepstart;8191: This store (CACHEDB1_1122 on TIMESTEN-HOL) is not involved in a replication scheme
The command failed.

SWT缓存无需cache agent,因为其是在Oracle中先提交,所以AWT是复制,而SWT是两阶段提交。
上例中ttrepstart失败也说明了这一点。

tthr> select * from departments;
0 rows found.
tthr> select * from departments where department_id = 80;
< 80, Sales, 145, 2500 > <-dynamic load
1 row found.
Command> load cache group d_swt where department_id < 100 commit every 256 rows;
8 cache instances affected.
tthr>select * from departments;
< 10, Administration, 200, 1700 >
< 20, Marketing, 201, 1800 >
< 30, Purchasing, 114, 1700 >
< 40, Human Resources, 203, 2400 >
< 50, Shipping, 121, 1500 >
< 60, IT, 103, 1400 >
< 70, Public Relations, 204, 2700 >
< 80, Sales, 145, 2500 >
< 90, Executive, 100, 1700 >
9 rows found.
tthr>update departments set department_name = 'SALES' where department_id = 80;
1 row updated.
SQL> select * from departments where department_id = 80;DEPARTMENT_ID DEPARTMENT_NAME                MANAGER_ID LOCATION_ID
------------- ------------------------------ ---------- -----------80 SALES                                 145        2500

由于不建议在Oracle端修改数据,因此refresh操作通常意义不大,不过我们还是做了一个测试,来说明refresh的行为特征:

SQL> update departments set department_name = 'Sales' where department_id = 80;1 row updated.SQL> commit;Commit complete.
cacheadm>refresh cache group d_swt where department_id = 80 commit every 256 rows;3022: Refresh cache group with a where clause is only allowed only if the cache group is not dynamic
The command failed.
tthr>select * from departments where department_id = 80;
< 80, SALES, 145, 2500 >
1 row found.cacheadm>refresh cache group d_swt commit every 256 rows;
9 cache instances affected.
tthr>select * from departments where department_id = 80;
< 80, Sales, 145, 2500 >
1 row found.

错误处理

在Oralce中失败,在TimesTen中成功,这时需要在TimesTen端rollback交易

If the transaction fails to commit in the Oracle database, the application must roll back the transaction in TimesTen.

tthr>set autocommit off
tthr>call ttCachePropagateFlagSet(0); <- 设置timesten中的更改不传递到Oracle
tthr>delete from departments where department_id = 80;
1 row deleted.
tthr>commit;
tthr>select * from departments;
< 10, Administration, 200, 1700 >
< 20, Marketing, 201, 1800 >
< 30, Purchasing, 114, 1700 >
< 40, Human Resources, 203, 2400 >
< 50, Shipping, 121, 1500 >
< 60, IT, 103, 1400 >
< 70, Public Relations, 204, 2700 >
< 90, Executive, 100, 1700 >
8 rows found.
tthr>call ttCachePropagateFlagSet(1);
# TimesTen中数据已删,而Oracle数据仍在
SQL> select * from departments where department_id = 80;DEPARTMENT_ID DEPARTMENT_NAME                MANAGER_ID LOCATION_ID
------------- ------------------------------ ---------- -----------80 Sales                                 145        2500# TimesTen插入数据成功,但Oracle端重复索引故障
tthr>insert into departments values(80, 'Sales', 145, 2500);
1 row inserted.
tthr>commit;5210: Oracle unique constraint violation error in OCIStmtExecute(): ORA-00001: unique constraint (TTHR.SYS_C0014410) violated rc = -15055: Cannot synchronize Oracle with TimesTen.  The TimesTen transaction must be rolled back.5025: Commit failure in Oracle. Transaction must be rolled back in TimesTen.
The command failed.
tthr>select * from departments;5025: Commit failure in Oracle. Transaction must be rolled back in TimesTen.
The command failed.
tthr>rollback; <-TimesTen端(应用端)必须执行回退操作
tthr>select * from departments;
< 10, Administration, 200, 1700 >
< 20, Marketing, 201, 1800 >
< 30, Purchasing, 114, 1700 >
< 40, Human Resources, 203, 2400 >
< 50, Shipping, 121, 1500 >
< 60, IT, 103, 1400 >
< 70, Public Relations, 204, 2700 >
< 90, Executive, 100, 1700 >
8 rows found.
这时数据已经不一致了,我们仍可以用ttCachePropagateFlagSet来将数据补齐
tthr>autocommit 0
tthr>show autocommit
autocommit = 0 (OFF)
tthr>call ttCachePropagateFlagSet(0);
tthr>insert into departments values(80, 'Sales', 145, 2500);
1 row inserted.
tthr>commit;
tthr>call ttCachePropagateFlagSet(1);
tthr>select count(*) from departments;
< 9 >
1 row found.
tthr>passthrough 3
tthr>select count(*) from departments;
< 27 >
1 row found.
tthr>select count(*) from departments where department_id < 100;
< 9 >
1 row found.
tthr>passthrough 0

如果Oracle端成功,而TimesTen端失败,那么两边的数据就不一致了,需要人工同步

If the Oracle Database transaction commits successfully but the TimesTen transaction fails to commit, the cache tables in the SWT cache group are no longer synchronized with the cached Oracle Database tables.

cacheadm>unload cache group d_swt;
9 cache instances affected.
cacheadm>load cache group d_swt where department_id < 100 commit every 256 rows;
9 cache instances affected.
# 在TimesTen端插入一条数据,并且不同步到Oracle
tthr>autocommit;
autocommit = 1 (ON)
tthr>call ttCachePropagateFlagSet(0);
tthr>select * from departments;
< 10, Administration, 200, 1700 >
< 20, Marketing, 201, 1800 >
< 30, Purchasing, 114, 1700 >
< 40, Human Resources, 203, 2400 >
< 50, Shipping, 121, 1500 >
< 60, IT, 103, 1400 >
< 70, Public Relations, 204, 2700 >
< 80, Sales, 145, 2500 >
< 90, Executive, 100, 1700 >
9 rows found.
tthr>insert into departments values(99, 'Consultant', 145, 2500);
1 row inserted.
tthr>commit;
tthr>call ttCachePropagateFlagSet(1);
tthr>autocommit 1;
tthr>insert into departments values(99, 'Consultant', 145, 2500);907: Unique constraint (DEPARTMENTS on TTHR.DEPARTMENTS) violated at Rowid <BMUFVUAAABWAgAAFBd>
The command failed.
# Oracle端数据插入成功
SQL> select * from departments where department_id = 99;DEPARTMENT_ID DEPARTMENT_NAME                MANAGER_ID LOCATION_ID
------------- ------------------------------ ---------- -----------99 Consultant                            145        2500
# 由于TimesTen无法控制Oracle端,因此成功的交易也就无法回退了,这时数据不一致,需要人工补数据

Explicitly SWT的load和refresh

tthr>cachegroups;Cache Group CACHEADM.SWT:Cache Group Type: Synchronous WritethroughAutorefresh: NoAging: LRU onRoot Table: TTHR.DEPARTMENTSTable Type: Propagate1 cache group found.
tthr>select * from departments;
0 rows found.# 简单的说,对于explicitly缓存组,refresh就等于unload+load,开销很大。load等于insert。
cacheadm>load cache group swt where department_id < 100 commit every 256 rows;
10 cache instances affected.
cacheadm>load cache group swt where department_id < 100 commit every 256 rows;
0 cache instances affected.
cacheadm>refresh cache group swt where department_id < 100 commit every 256 rows;
10 cache instances affected.
cacheadm>refresh cache group swt where department_id < 100 commit every 256 rows;
10 cache instances affected.
cacheadm>refresh cache group swt where department_id < 100 commit every 256 rows;
10 cache instances affected.
cacheadm>refresh cache group swt  commit every 256 rows;
28 cache instances affected.
cacheadm>load cache group swt where department_id < 100 commit every 256 rows;
0 cache instances affected.

清理cache group

就说一点,无需停rep agent就行了,因为他用不到

这篇关于TimesTen 应用层数据库缓存学习:7. 同步读写缓存的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/677708

相关文章

数据库oracle用户密码过期查询及解决方案

《数据库oracle用户密码过期查询及解决方案》:本文主要介绍如何处理ORACLE数据库用户密码过期和修改密码期限的问题,包括创建用户、赋予权限、修改密码、解锁用户和设置密码期限,文中通过代码介绍... 目录前言一、创建用户、赋予权限、修改密码、解锁用户和设置期限二、查询用户密码期限和过期后的修改1.查询用

mysql数据库分区的使用

《mysql数据库分区的使用》MySQL分区技术通过将大表分割成多个较小片段,提高查询性能、管理效率和数据存储效率,本文就来介绍一下mysql数据库分区的使用,感兴趣的可以了解一下... 目录【一】分区的基本概念【1】物理存储与逻辑分割【2】查询性能提升【3】数据管理与维护【4】扩展性与并行处理【二】分区的

IDEA如何切换数据库版本mysql5或mysql8

《IDEA如何切换数据库版本mysql5或mysql8》本文介绍了如何将IntelliJIDEA从MySQL5切换到MySQL8的详细步骤,包括下载MySQL8、安装、配置、停止旧服务、启动新服务以及... 目录问题描述解决方案第一步第二步第三步第四步第五步总结问题描述最近想开发一个新应用,想使用mysq

Python实现高效地读写大型文件

《Python实现高效地读写大型文件》Python如何读写的是大型文件,有没有什么方法来提高效率呢,这篇文章就来和大家聊聊如何在Python中高效地读写大型文件,需要的可以了解下... 目录一、逐行读取大型文件二、分块读取大型文件三、使用 mmap 模块进行内存映射文件操作(适用于大文件)四、使用 pand

C# 读写ini文件操作实现

《C#读写ini文件操作实现》本文主要介绍了C#读写ini文件操作实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录一、INI文件结构二、读取INI文件中的数据在C#应用程序中,常将INI文件作为配置文件,用于存储应用程序的

Oracle数据库使用 listagg去重删除重复数据的方法汇总

《Oracle数据库使用listagg去重删除重复数据的方法汇总》文章介绍了在Oracle数据库中使用LISTAGG和XMLAGG函数进行字符串聚合并去重的方法,包括去重聚合、使用XML解析和CLO... 目录案例表第一种:使用wm_concat() + distinct去重聚合第二种:使用listagg,

Redis缓存问题与缓存更新机制详解

《Redis缓存问题与缓存更新机制详解》本文主要介绍了缓存问题及其解决方案,包括缓存穿透、缓存击穿、缓存雪崩等问题的成因以及相应的预防和解决方法,同时,还详细探讨了缓存更新机制,包括不同情况下的缓存更... 目录一、缓存问题1.1 缓存穿透1.1.1 问题来源1.1.2 解决方案1.2 缓存击穿1.2.1

Java读取InfluxDB数据库的方法详解

《Java读取InfluxDB数据库的方法详解》本文介绍基于Java语言,读取InfluxDB数据库的方法,包括读取InfluxDB的所有数据库,以及指定数据库中的measurement、field、... 首先,创建一个Java项目,用于撰写代码。接下来,配置所需要的依赖;这里我们就选择可用于与Infl

详谈redis跟数据库的数据同步问题

《详谈redis跟数据库的数据同步问题》文章讨论了在Redis和数据库数据一致性问题上的解决方案,主要比较了先更新Redis缓存再更新数据库和先更新数据库再更新Redis缓存两种方案,文章指出,删除R... 目录一、Redis 数据库数据一致性的解决方案1.1、更新Redis缓存、删除Redis缓存的区别二

oracle数据库索引失效的问题及解决

《oracle数据库索引失效的问题及解决》本文总结了在Oracle数据库中索引失效的一些常见场景,包括使用isnull、isnotnull、!=、、、函数处理、like前置%查询以及范围索引和等值索引... 目录oracle数据库索引失效问题场景环境索引失效情况及验证结论一结论二结论三结论四结论五总结ora