Timesten cache group aging 功能的實現

Ellison發表於2014-06-13

Timesten 資料過期策略有兩種,一種是 基於LRU策略,一種是基於日期時間。以下記錄兩個例子,time_based 經過本人測試,LRU 還木有測試過,摘錄官網原文,方便查閱。

LRU aging

CREATE ASYNCHRONOUS WRITETHROUGH CACHE GROUP new_customers
FROM oratt.customer
 (cust_num NUMBER(6) NOT NULL,
  region   VARCHAR2(10),
  name     VARCHAR2(50),
  address  VARCHAR2(100),
  PRIMARY KEY(cust_num))
AGING LRU ON;

呼叫內建函式 ttAgingLRUConfig 開啟 LRU 屬性。
The following built-in procedure call specifies that the aging process checks every 5 minutes to see if the TimesTen database's permanent partition space
 usage is above 95 percent. If it is, the least recently used data is automatically aged out or deleted until the space usage is at or below 75 percent.

CALL ttAgingLRUConfig(.75, .95, 5);

Time-based aging

---建基表
CREATE TABLE orders
(ord_num      NUMBER(10) NOT NULL PRIMARY KEY,
 cust_num     NUMBER(6) NOT NULL,
 when_placed  DATE NOT NULL,
 when_shipped DATE NOT NULL
);


---插入測試資料
insert into orders values(1,10,to_date('2014-06-13 20:10:00','yyyy-mm-dd hh24:mi:ss'),sysdate);
insert into orders values(2,20,to_date('2014-06-13 20:20:00','yyyy-mm-dd hh24:mi:ss'),sysdate);
insert into orders values(3,30,to_date('2014-06-13 21:10:00','yyyy-mm-dd hh24:mi:ss'),sysdate);
commit ;

-----建立一個AWT 型別或 read cache group 型別的cache group 資料自動aging 

CREATE ASYNCHRONOUS WRITETHROUGH CACHE GROUP cache_ordered_1
FROM ytord.orders
 (ord_num      NUMBER(10) NOT NULL,
  cust_num     NUMBER(6) NOT NULL,
  when_placed  DATE NOT NULL,
  when_shipped DATE NOT NULL,
  PRIMARY KEY(ord_num))
AGING USE when_placed LIFETIME 5 MINUTES CYCLE 1 MINUTES ON ;

---建立一個 read cache group
CREATE READONLY CACHE GROUP cache_ordered_3
AUTOREFRESH MODE INCREMENTAL INTERVAL 1 MINUTES
FROM ytord.orders3
 (ord_num      NUMBER(10) NOT NULL,
  cust_num     NUMBER(6) NOT NULL,
  when_placed  DATE NOT NULL,
  when_shipped DATE NOT NULL,
  PRIMARY KEY(ord_num))
AGING USE when_placed LIFETIME 5 MINUTES CYCLE 1 MINUTES ON;



關於aging 還有一些用法上的細節,後面進行補充。

相關文章