TimesTen 应用层数据库缓存学习:19. 理解AWT缓存组的三种模式

2024-02-04 13:38

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

概述

本文很好的讲述了AWT三种缓存组的概念和区别,并给出了3种缓存组从建立到摧毁的完整过程。

AWT缓存组有3中类型:
1. AWT 缺省 (Manually load)
2. AWT Dynamic
3. AWT Dynamic Globle (Cache Grid)

各种AWT类型的区别

AWT 缺省 (Manually load)

  • TimesTen中inserted/updated/deleted的数据传递到Oracle
  • Oracle中新增的数据通过”LOAD CACHE GROUP”同步到TimesTen
  • 如果一个表缓存到两个AWT 缺省Cache Group,缓存组之间并不相互知情,因此一个cache instance可以同时存在于两个缓存组中

语法:
create asynchronous writethrough cache group t1_awt_reg
from t1 (c1 number(22) not null primary key, c2 date, c3 varchar(40));

AWT Dynamic

  • TimesTen中inserted/updated/deleted的数据传递到Oracle
  • Oracle中新增的数据通过”LOAD CACHE GROUP”同步到TimesTen
  • Oracle中新增的数据也可以通过SELECT, UPDATE 和 DELETE语句动态加载
  • 如果一个表缓存到两个AWT 缺省Cache Group,缓存组之间并不相互知情,因此一个cache instance可以同时存在于两个缓存组中

语法:
create dynamic asynchronous writethrough cache group t2_awt_dyn
from t1 (c1 number(22) not null primary key, c2 date, c3 varchar(40));

AWT Dynamic Globle (Cache Grid)

  • TimesTen中inserted/updated/deleted的数据传递到Oracle
  • Oracle中新增的数据通过”LOAD CACHE GROUP”同步到TimesTen
  • Oracle中新增的数据也可以通过SELECT, UPDATE 和 DELETE语句动态加载
  • 如果一个表缓存到两个AWT Dynamic Globle Cache Group,由于缓存组之间相互保持沟通,因此一个cache instance只能存在于一个缓存组中

语法:
create dynamic asynchronous writethrough global cache group t3_awt_dyn_gbl
from t1 (c1 number(22) not null primary key, c2 date, c3 varchar(40));

实验部分

在Oracle中创建表

$ sqlplus tthr/oracle@ttorcl
create table t1 (c1 number(22) not null primary key, c2 date, c3 varchar(40));
create table t2 (c1 number(22) not null primary key, c2 date, c3 varchar(40));
create table t3 (c1 number(22) not null primary key, c2 date, c3 varchar(40));

创建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

[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和cachedb2中执行:
create user tthr identified by timesten;
grant admin, create session, cache_manager, create any table to tthr;

创建cache group, cache grid并关联到grid

同时在cachedb1和cachedb2中执行:
ttisqlv1esetpromptcachedb1>dsn=cachedb1;uid=tthr;pwd=timesten;oraclepwd=oracle ttisql -v1 -e “set prompt ‘cachedb2> ‘” “dsn=cachedb2;uid=tthr;pwd=timesten;oraclepwd=oracle”

call ttcacheuidpwdset(‘cacheadm’, ‘oracle’);
call ttcachestart;
call ttgriddestroy(‘samplegrid’,1); <- 此命令很好用
call ttgridnodestatus(‘samplegrid’);
call ttgridcreate(‘samplegrid’); <- 在任意一个TimesTen数据库中执行一次即可
call ttgridinfo(‘samplegrid’);
call ttgridnameset(‘samplegrid’);
call ttgridinfo(‘samplegrid’);
call ttgridnodestatus(‘samplegrid’);

三个表分布对应regular, dynamic, dynamic global缓存组
create asynchronous writethrough cache group t1_awt
from t1 (c1 number(22) not null primary key, c2 date, c3 varchar(40));
create dynamic asynchronous writethrough cache group t2_awt_dyn
from t2 (c1 number(22) not null primary key, c2 date, c3 varchar(40));
create dynamic asynchronous writethrough global cache group t3_awt_dyn_gbl
from t3 (c1 number(22) not null primary key, c2 date, c3 varchar(40));

cachedb1>
call ttgridattach(1,’member1’,’127.0.0.1’,5001);
call ttgridnodestatus(‘samplegrid’);
call ttrepstart;

cachedb2>
call ttgridattach(1,’member2’,’127.0.0.1’,5002); <- 使用不同的端口是因为两个TimesTen数据库在同一主机上
call ttgridnodestatus(‘samplegrid’);
call ttrepstart;

在两个数据库中,针对每一个缓存组插入数据

cachedb1>
insert into t1 values (1, sysdate, ‘t1 data’);
insert into t2 values (1, sysdate, ‘t2 data’);
insert into t3 values (1, sysdate, ‘t3 data’);
unload cache group t1_awt;
unload cache group t2_awt_dyn;
unload cache group t3_awt_dyn_gbl; <- unload后在TimesTen中看不到缓存数据

cachedb2>
insert into t1 values (2, sysdate, ‘t1 data’);
insert into t2 values (2, sysdate, ‘t2 data’);
insert into t3 values (2, sysdate, ‘t3 data’);
unload cache group t1_awt;
unload cache group t2_awt_dyn;
unload cache group t3_awt_dyn_gbl; <- unload后在TimesTen中看不到缓存数据

人工从Oracle中LOAD数据

cachedb1>
load cache group t1_awt where c1 = 1 commit every 10 rows parallel 10;
load cache group t2_awt_dyn where c1 = 1 commit every 10 rows parallel 10;
load cache group t3_awt_dyn_gbl where c1 = 1 commit every 10 rows parallel 10;
select * from t1;
select * from t2;
select * from t3;
unload cache group t1_awt;
unload cache group t2_awt_dyn;
unload cache group t3_awt_dyn_gbl;

cachedb2>
load cache group t1_awt where c1 = 2 commit every 10 rows parallel 10;
load cache group t2_awt_dyn where c1 = 2 commit every 10 rows parallel 10;
load cache group t3_awt_dyn_gbl where c1 = 2 commit every 10 rows parallel 10;
select * from t1;
select * from t2;
select * from t3;
unload cache group t1_awt;
unload cache group t2_awt_dyn;
unload cache group t3_awt_dyn_gbl;

通过SQL动态从Oracle中LOAD数据

cachedb1>
select * from t1 where c1 = 1;
select * from t2 where c1 = 1;
select * from t3 where c1 = 1;
select * from t1;
select * from t2;
select * from t3;

输出:
cachedb1> select * from t1; <- 没有输出,因为需要手工load
cachedb1> select * from t2; <- 有输出因为满足dynamic load条件
< 1, 2016-06-19 22:41:56, t2 data >
cachedb1> select * from t3; <- 有输出因为满足dynamic load条件
< 1, 2016-06-19 22:41:57, t3 data >

cachedb2>
select * from t1 where c1 = 2;
select * from t2 where c1 = 2;
select * from t3 where c1 = 2;
select * from t1;
select * from t2;
select * from t3;

输出:
cachedb2> select * from t1; <- 没有输出,因为需要手工load
cachedb2> select * from t2; <- 有输出因为满足dynamic load条件
< 2, 2016-06-19 22:45:12, t2 data >
cachedb2> select * from t3; <- 有输出因为满足dynamic load条件
< 2, 2016-06-19 22:46:07, t3 data >

通过SQL动态从Oracle或Cache grid中LOAD数据

cachedb1>
select * from t1 where c1 = 2;
select * from t2 where c1 = 2;
select * from t3 where c1 = 2;
select * from t1;
select * from t2;
select * from t3;

输出:
cachedb1> select * from t1;
cachedb1> select * from t2;
< 1, 2016-06-19 22:41:56, t2 data >
< 2, 2016-06-19 22:45:12, t2 data > <- 这条数据是从Oracle中dynamic load而来
cachedb1> select * from t3;
< 1, 2016-06-19 22:41:57, t3 data >
< 2, 2016-06-19 22:46:07, t3 data > <- 这条数据是从Cache Grid的另一个member: cachedb2中load而来

cachedb2>
select * from t1 where c1 = 1;
select * from t2 where c1 = 1;
select * from t3 where c1 = 1;
select * from t1;
select * from t2;
select * from t3;

输出:
cachedb2> select * from t1;
cachedb2> select * from t2;
< 1, 2016-06-19 22:41:56, t2 data > <- 对于普通的dynamic AWT,由于互不知情,因此这两条数据在两个TimesTen数据库中都存在
< 2, 2016-06-19 22:45:12, t2 data > <- 这条数据是从Oracle中dynamic load而来
cachedb2> select * from t3;
< 1, 2016-06-19 22:41:57, t3 data > <- 这条数据是从Cache Grid的另一个member: cachedb1中load而来
cachedb1> select * from t3;
< 2, 2016-06-19 22:46:07, t3 data > <- 对于global awt, cache instance只会在一个TimesTen中出现

删除缓存组并从Grid脱离关系

cachedb1>
call ttrepstop;
call ttgriddetach;
drop cache group t1_awt;
drop cache group t2_awt_dyn;
drop cache group t3_awt_dyn_gbl;
call ttcachestop;

cachedb2>
call ttrepstop;
call ttgriddetach;
drop cache group t1_awt;
drop cache group t2_awt_dyn;
drop cache group t3_awt_dyn_gbl;
call ttcachestop;
call ttgriddestroy(‘samplegrid’,1);

参考

HOWTO : Understand The Three Fundamental Types Of TimesTen Asynchronous (AWT) Cache Groups (Doc ID 1471954.1)

这篇关于TimesTen 应用层数据库缓存学习:19. 理解AWT缓存组的三种模式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

Linux下MySQL数据库定时备份脚本与Crontab配置教学

《Linux下MySQL数据库定时备份脚本与Crontab配置教学》在生产环境中,数据库是核心资产之一,定期备份数据库可以有效防止意外数据丢失,本文将分享一份MySQL定时备份脚本,并讲解如何通过cr... 目录备份脚本详解脚本功能说明授权与可执行权限使用 Crontab 定时执行编辑 Crontab添加定

JavaScript中比较两个数组是否有相同元素(交集)的三种常用方法

《JavaScript中比较两个数组是否有相同元素(交集)的三种常用方法》:本文主要介绍JavaScript中比较两个数组是否有相同元素(交集)的三种常用方法,每种方法结合实例代码给大家介绍的非常... 目录引言:为什么"相等"判断如此重要?方法1:使用some()+includes()(适合小数组)方法2

如何通过try-catch判断数据库唯一键字段是否重复

《如何通过try-catch判断数据库唯一键字段是否重复》在MyBatis+MySQL中,通过try-catch捕获唯一约束异常可避免重复数据查询,优点是减少数据库交互、提升并发安全,缺点是异常处理开... 目录1、原理2、怎么理解“异常走的是数据库错误路径,开销比普通逻辑分支稍高”?1. 普通逻辑分支 v

Python与MySQL实现数据库实时同步的详细步骤

《Python与MySQL实现数据库实时同步的详细步骤》在日常开发中,数据同步是一项常见的需求,本篇文章将使用Python和MySQL来实现数据库实时同步,我们将围绕数据变更捕获、数据处理和数据写入这... 目录前言摘要概述:数据同步方案1. 基本思路2. mysql Binlog 简介实现步骤与代码示例1

使用shardingsphere实现mysql数据库分片方式

《使用shardingsphere实现mysql数据库分片方式》本文介绍如何使用ShardingSphere-JDBC在SpringBoot中实现MySQL水平分库,涵盖分片策略、路由算法及零侵入配置... 目录一、ShardingSphere 简介1.1 对比1.2 核心概念1.3 Sharding-Sp

使用Spring Cache本地缓存示例代码

《使用SpringCache本地缓存示例代码》缓存是提高应用程序性能的重要手段,通过将频繁访问的数据存储在内存中,可以减少数据库访问次数,从而加速数据读取,:本文主要介绍使用SpringCac... 目录一、Spring Cache简介核心特点:二、基础配置1. 添加依赖2. 启用缓存3. 缓存配置方案方案

Unity新手入门学习殿堂级知识详细讲解(图文)

《Unity新手入门学习殿堂级知识详细讲解(图文)》Unity是一款跨平台游戏引擎,支持2D/3D及VR/AR开发,核心功能模块包括图形、音频、物理等,通过可视化编辑器与脚本扩展实现开发,项目结构含A... 目录入门概述什么是 UnityUnity引擎基础认知编辑器核心操作Unity 编辑器项目模式分类工程

Go语言连接MySQL数据库执行基本的增删改查

《Go语言连接MySQL数据库执行基本的增删改查》在后端开发中,MySQL是最常用的关系型数据库之一,本文主要为大家详细介绍了如何使用Go连接MySQL数据库并执行基本的增删改查吧... 目录Go语言连接mysql数据库准备工作安装 MySQL 驱动代码实现运行结果注意事项Go语言执行基本的增删改查准备工作

Java实现本地缓存的四种方法实现与对比

《Java实现本地缓存的四种方法实现与对比》本地缓存的优点就是速度非常快,没有网络消耗,本地缓存比如caffine,guavacache这些都是比较常用的,下面我们来看看这四种缓存的具体实现吧... 目录1、HashMap2、Guava Cache3、Caffeine4、Encache本地缓存比如 caff

C#和Unity中的中介者模式使用方式

《C#和Unity中的中介者模式使用方式》中介者模式通过中介者封装对象交互,降低耦合度,集中控制逻辑,适用于复杂系统组件交互场景,C#中可用事件、委托或MediatR实现,提升可维护性与灵活性... 目录C#中的中介者模式详解一、中介者模式的基本概念1. 定义2. 组成要素3. 模式结构二、中介者模式的特点