简体   繁体   English

如何处理跨数据库交易

[英]How to handle cross DB transactions

I have a situation where I need to handle cross db transactions. 我遇到需要处理跨数据库事务的情况。 Following are the detailed requirements: 以下是详细要求:

I have 2 DB A and B 我有2个DB A和B

1) Both Db must be in synch eventually. 1)最终两个Db必须同步。 Both Db must be EVENTUAL consistency and not strictly consistency.A record may be present in DB A and may not be present in DB B for some time. 两个Db都必须是EVENTUAL一致性,而不是严格一致性。一条记录可能存在于DB A中,并且可能一段时间不存在于DB B中。 But eventually it must be present in both DB 但最终它必须同时存在于两个数据库中

2) Both DB do not support transactions/rollback 2)两个数据库都不支持事务/回滚

3) Once you commit in Db B, you cannot undo/delete it.But you can delete a record from DB1 3)一旦提交了Db B,就不能撤消/删除它,但是可以从DB1中删除一条记录

4) It's ok to lose some data. 4)可以丢失一些数据。 Maybe 10 records in a day 一天可能有10条记录

One solution is as follows: 一种解决方案如下:

1) Write into DB1 1)写入DB1

2) Then write in DB2 2)然后写在DB2中

If writing to DB2 fails, write into file using log4j. 如果写入DB2失败,请使用log4j写入文件。 This files will then be read and retried to be saved in DB2. 然后将读取并重试此文件以将其保存在DB2中。 Is this approach ok? 这种方法行吗?

That's called two phase commit for ACID databases. 这称为ACID数据库的两阶段提交。

NoSQL doesn't deal with transactions the way that ACID databases do. NoSQL不能像ACID数据库那样处理事务。 It's one of the things you choose to give up when you go NoSQL. 当您使用NoSQL时,这是您选择放弃的事情之一。

I think you have to code this in the service that deals with the databases. 我认为您必须在处理数据库的服务中对此进行编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM