临时备份表,如果进程失败还原

发布于 2025-01-22 03:28:04 字数 273 浏览 2 评论 0原文

我有一个应用程序,该应用程序会定期下载大XML并将其保存到数据库中。在插入过程中处理故障的正确方法是什么?当前过程:

  1. 下载XML
  2. 解析XML
  3. 清除当前数据
  4. 插入数据到数据库< =跨越8个不同表上的数千行,

我希望能够在步骤4之前进行备份,并且如果步骤4失败,则从备份中恢复数据。目前使用Ebean进行持久性。我试图使用临时表并在此处复制所有数据,如果失败的情况复制了数据,但是我不确定如何在等待4次完成时保持单个会话。

I have an application that periodically downloads a large XML and saves it into a database. What is the proper way to deal with failure during the insertion process. Current process:

  1. download XML
  2. parse XML
  3. clear current data
  4. insert data into database <= spans thousands of rows over 8 different tables

I would like to be able to do a backup before step 4 and if step 4 fails restore the data from backup. Currently using ebean to do persistence. I was trying to use temporary tables and copy all data there and if case of failure copy data back, but I am not sure how to hold on to a single session while waiting for 4 to finish.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠北森屋 2025-01-29 03:28:04

您可以使用 savepoint 参见 ebean 中的保存点:

交易.setnestedusesavepoint()

可以使用TransAction.setNesteduessavepoint()使其能够使用嵌套交易的保存点。这意味着可以将这些嵌套交易滚回去,使外部交易继续进行并可能提交

// start 'outer' transaction
try (Transaction outerTxn = database.beginTransaction()) {

  outerTxn.setNestedUseSavepoint();

  // save backup here...
  

  try (Transaction nestedTransaction = database.beginTransaction()) {
    // nested transaction is a savepoint ...

        // do some piece of work which we might want to either commit or   rollback ...
    otherBean.save();

    if (...) {
      nestedTransaction.rollback();

    } else {
      nestedTransaction.commit();
    }
  }

  // continue using 'outer' transaction ...

  outerTxn.commit();
}

you can use Savepoint see savepoints in ebean:

transaction.setNestedUseSavepoint() :

can use transaction.setNestedUseSavepoint() to enable it to use Savepoint for nested transactions. This means that these nested transactions can be rolled back leaving the outer transaction to continue and potentially commit

// start 'outer' transaction
try (Transaction outerTxn = database.beginTransaction()) {

  outerTxn.setNestedUseSavepoint();

  // save backup here...
  

  try (Transaction nestedTransaction = database.beginTransaction()) {
    // nested transaction is a savepoint ...

        // do some piece of work which we might want to either commit or   rollback ...
    otherBean.save();

    if (...) {
      nestedTransaction.rollback();

    } else {
      nestedTransaction.commit();
    }
  }

  // continue using 'outer' transaction ...

  outerTxn.commit();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文