TimesTen 应用层数据库缓存学习:21. AWT复制Oracle事务失败时的处理

前一阵有用户问到,如果AWT缓存组复制时,在TimesTen中成功,而在Oracle中失败,会有何影响,需如何处理。本文讨论此问题。
在Oracle中创建基础表,并特意为本实验定义了一个约束。虽然这是不建议的。

SQL> create table t1(k int, v int, primary key(k));
Table created.
SQL> alter table t1 add constraint min_value check (v > 0) ;
Table altered.
SQL> grant select,delete,update,insert on t1 to cacheadm;
Grant succeeded.

在TimesTen中创建AWT缓存组:

CREATE ASYNCHRONOUS WRITETHROUGH CACHE GROUP "AWT" 
 FROM
  "TTUSER"."T1" (
"K" NUMBER(38) NOT NULL,
"V" NUMBER(38),
PRIMARY KEY("K")
  )

然后在TimesTen中依次插入(1,1),(2,2),(3,-1),(4,4),(5,5)
以下是TimesTen中的结果:

Command> select * from t1;
< 1, 1 >
< 2, 2 >
< 3, -1 >
< 4, 4 >
< 5, 5 >
5 rows found.

以下是Oracle中的结果:

SQL> select * from t1;

 K  V

 1  1
 2  2
 4  4
 5  5

我们发现数据(3,-1)因为Oracle约束原因没有插入Oracle,但数据已在TimesTen提交,并且TimesTen捕捉到了此错误。
在文件sampledb_1122.awterrs中的错误信息如下:

Error occurred 16:19:41 on 10-22-2017 Datastore: /home/timesten/TimesTen/tt1122/info/DemoDataStore/sampledb_1122 Oracle Id: ORCL Transmitting agent: PID 7553(140455982597888) for SAMPLEDB_1122 Error message: TT5222: Oracle constraint violation error in INSERT INTO “TTUSER”.”T1” (“K”,”V”) VALUES (3,-1)
ORA-02290: check constraint (TTUSER.MIN_VALUE) violated – file “bdbTblH.c”, lineno 1995, procedure “bdbAWTPlSqlWithMetaExecDirect()”
TT5130: Error executing the following statement on Oracle: AWT PL/SQL BLOCK WITH META DATA – file “bdbTblH.c”, lineno 2033, procedure “bdbAWTPlSqlWithMetaExecDirect()”
TT5059: Cannot apply Awt changes to Oracle. The Oracle transaction will be rolled back. – file “bdbTblH.c”, lineno 4879, procedure “ttBDbStmtForce()”

Operation that caused the error:
INSERT INTO “TTUSER”.”T1” (“K”,”V”) VALUES (3,-1)

Failed transaction:
Insert Into
TTUSER.T1( K, V )
Values ( 3, -1 );

End of failed transaction

查看TimesTen数据库,没有发现outstanding的事务:

Command> host ttxactadmin -connstr "dsn=sampledb_1122"
2017-10-24 17:04:02.249
/home/timesten/TimesTen/tt1122/info/DemoDataStore/sampledb_1122
TimesTen Release 11.2.2.8.20

0 outstanding transactions found

运行多次命令,也未发现异常:

Command> vertical call ttbookmark;

  WRITELFN:   0
  WRITELFO:   19239176
  FORCELFN:   0
  FORCELFO:   19238912
  HOLDLFN:0
  HOLDLFO:19222792

1 row found.

根据以上的实验得出结论,当事务在TimesTen端成功而在Oracle端失败时:
1. 不影响后续的复制事务,例如(4,4),(5,5)依然成功
2. 但你必须处理两端数据不一致的问题
3. 但日志是否会不断累积导致无法删除,目前还不确定,我的结论是不会

后来又在群里深入讨论了一下,得到一些有益的信息。
1.HOWTO : Understand TimesTen Errors Observed With TimesTen AWT Cache Reporting Oracle Error Codes (Doc ID 1300882.1)

Permanent errors should be investigated to determine if there is an issue that needs to be resolved. Insert, update, or delete errors that occur while applying changes to Oracle are saved in an error file located in the database directory with the following name:
DatastoreName.awterr

Errors reported to this file are permanent errors. TimesTen does not retry the transaction. The errors may be reported in the AWT error file long after the commit to TimesTen occurs.

然后在TimesTen Cache User Guide中:

An AWT cache group cannot guarantee that:
■ All transactions committed successfully in the TimesTen database are successfully
propagated to and committed in the Oracle database. Execution errors on the
Oracle database cause the transaction in the Oracle database to be rolled back. For
example, an update on the Oracle database may fail because of a unique constraint
violation. Transactions that contain execution errors are not retried.
Execution errors are considered permanent errors and are reported to the
TimesTenDatabaseFileName.awterrs file that resides in the same directory as the
TimesTen database’s checkpoint files.

因此,结论就是,除了数据一致性的问题需要人工介入处理,事务日志是不会受影响的。

猜你喜欢

转载自blog.csdn.net/stevensxiao/article/details/78331961