TimesTen 应用层数据库缓存学习:15. TimesTen 缓存组autorefresh的原理

autorefresh操作的数据同步流方向是从Oracle到TimesTen,因此只有read-only缓存组和user managed缓存组才能定义autorefresh。
AWT和SWT缓存的数据同步流方向是从TimesTen到Oracle,由于TimesTen有事务日志,则可以利用日志来做数据同步。
而从Oracle到TimesTen的autorefresh则是依赖于触发器和change log table。这些对于AWT和SWT都是不存在的。

TimesTen为每一个Oracle中需要缓存的表建立一个触发器和change log table,数据更改时,会将相应的主键存入change log table,在auto refresh时,则根据主键关联,刷新(refresh)TimesTen中的数据。成功后,即删除change log table中的行。

Oracle的Jeremy Palmer在 Change Log Tables | Oracle Community中做的解释比较简明:

Each Oracle base table which is autorefreshed into a TimesTen cache
group has an Oracle trigger and an additional Oracle table (called the
“change log table”) associated with it. These objects are created
using the following conventions, where number is the object ID of the
original Oracle table and version is an internal TimesTen version
number:

TT_version_number_L - change log table for recording the changes to
the Oracle table TT_version_number_T - trigger to record changes in
the change log table.

The trigger is fired every time there is DML on the Oracle base table.
The trigger takes the key fields that the DML operation happened on
and inserts the key field values into the change log table. New change
log table records are assigned a number to provide an ordering. The
number is stored in the LOGSEQ field in the change log table. A
bookmark is used to keep track of where the cache agent should start
autorefreshing from.

The Autorefresh operation then does the following:

  1. Finds the max logseq in the change log table associated with the base table
  2. Look for all change log table rows with logseq > the bookmark
  3. Performs an outer join of these change log table records with the base table records
  4. Performs delete/insert/update operations against TimesTen so that the cache table contains the same data as the Oracle base table.

而更详细的内容可以在TimesTen文档:Cache User’s Guide| 7. Managing a Caching Environment | Managing a caching environment with Oracle Database objects中找到:

For an autorefresh cache group, TimesTen creates a change log table and trigger in the Oracle database for each cache table in the cache group. The trigger is fired for each committed insert, update, or delete operation on the cached Oracle Database table. The trigger records the primary key of the updated rows in the change log table. The cache agent periodically scans the change log table for updated keys and then joins this table with the cached Oracle Database table to get a snapshot of the latest updates.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值