管理从一个数据库到另一个数据库的数据的方法

时间:2022-09-15 22:19:32

There are two databases, MAIN and TEMP, used in a website. TEMP database is used to manage data fetched from MAIN for insert/update and on publishing the data moved back to MAIN database. What can be the approaches for error handling while publishing ?

在网站中使用了两个数据库,MAIN和TEMP。 TEMP数据库用于管理从MAIN获取的数据以进行插入/更新,以及发布移回MAIN数据库的数据。发布时错误处理的方法是什么?

I think of below two approaches :

我想到以下两种方法:

  1. Rollback script - if error occurred while insert/update then the rollback can help.

    回滚脚本 - 如果插入/更新时发生错误,则回滚可以提供帮助。

  2. Third DB Concept - Introduce a third database same as MAIN and first use this database for insert/update and if it result success then execute the same commands to MAIN database otherwise no need to update MAIN database.

    第三个DB概念 - 引入与MAIN相同的第三个数据库,并首先使用此数据库进行插入/更新,如果结果成功,则执行相同的命令到MAIN数据库,否则无需更新MAIN数据库。

I am not sure which approach is better among the two. Can there be any other approach?

我不确定哪种方法在两者中更好。可以有任何其他方法吗?

Suggestions are really helpful.

建议真有帮助。

1 个解决方案

#1


0  

Use a transaction to move/update the data from TEMP to MAIN. You either want it to work, or not, right? Presumably leaving the state in TEMP if it doesn't?

使用事务将数据从TEMP移动/更新到MAIN。你要么想要它工作,要么不工作,对吧?如果没有,可能会将该州留在TEMP中?

The only case I can see where you might want to do anything different is if you deliberately want to NOT leave the data in TEMP if a publish fails (if for example there's no sensible way to follow such a case up), in which case you could consider having 2 transactions, one that removes it from TEMP followed by a second one that adds it back to MAIN only if the first succeeds, and if either of those transactions fails an error is reported and the whole thing has to be restarted again.

我可以看到你可能想要做任何不同的事情的唯一情况是,如果你故意不想在发布失败的情况下将数据保留在TEMP中(例如,如果没有明智的方法来遵循这样的情况),在这种情况下你可以考虑有2个事务,一个从TEMP中删除它,然后是第二个事务,只有在第一个成功时才将其添加回MAIN,如果这些事务中的任何一个失败,则报告错误并且必须重新启动整个事务。

Using a third DB doens't help. You could still succeed with the attempt to the third DB and fail with MAIN, and keeping the third DB up to date with MAIN means you immediately double all your work.

使用第三个数据库没有帮助。您仍然可以尝试使用第三个数据库并使用MAIN失败,并使第三个数据库与MAIN保持同步意味着您立即将所有工作加倍。

#1


0  

Use a transaction to move/update the data from TEMP to MAIN. You either want it to work, or not, right? Presumably leaving the state in TEMP if it doesn't?

使用事务将数据从TEMP移动/更新到MAIN。你要么想要它工作,要么不工作,对吧?如果没有,可能会将该州留在TEMP中?

The only case I can see where you might want to do anything different is if you deliberately want to NOT leave the data in TEMP if a publish fails (if for example there's no sensible way to follow such a case up), in which case you could consider having 2 transactions, one that removes it from TEMP followed by a second one that adds it back to MAIN only if the first succeeds, and if either of those transactions fails an error is reported and the whole thing has to be restarted again.

我可以看到你可能想要做任何不同的事情的唯一情况是,如果你故意不想在发布失败的情况下将数据保留在TEMP中(例如,如果没有明智的方法来遵循这样的情况),在这种情况下你可以考虑有2个事务,一个从TEMP中删除它,然后是第二个事务,只有在第一个成功时才将其添加回MAIN,如果这些事务中的任何一个失败,则报告错误并且必须重新启动整个事务。

Using a third DB doens't help. You could still succeed with the attempt to the third DB and fail with MAIN, and keeping the third DB up to date with MAIN means you immediately double all your work.

使用第三个数据库没有帮助。您仍然可以尝试使用第三个数据库并使用MAIN失败,并使第三个数据库与MAIN保持同步意味着您立即将所有工作加倍。