Sql GCP节点js API中的事务提交正在使用扳手返回{quot;code";:10,“rowCounts";:[]}

Sql GCP节点js API中的事务提交正在使用扳手返回{quot;code";:10,“rowCounts";:[]},sql,node.js,transactions,google-cloud-spanner,Sql,Node.js,Transactions,Google Cloud Spanner,我有一个用nodejs为GCP编写的API。在日志中,有时API会为前两个事务返回{“code”:10,“rowCounts”:[]},但所有其他事务都可以正常工作 除了{“code”:10,“rowCounts”:[]之外,错误中没有其他详细信息 但如果我尝试直接在扳手中运行这个查询。正在执行查询,没有错误 我有以下交易代码: database.runTransaction(async (err, transaction) => { if (queries.length !=

我有一个用nodejs为GCP编写的API。在日志中,有时API会为前两个事务返回{“code”:10,“rowCounts”:[]},但所有其他事务都可以正常工作

除了{“code”:10,“rowCounts”:[]之外,错误中没有其他详细信息

但如果我尝试直接在扳手中运行这个查询。正在执行查询,没有错误

我有以下交易代码:

  database.runTransaction(async (err, transaction) => {
    if (queries.length != 0) {         
      try {
        await transaction.batchUpdate(queries);
        transaction.commit(function(err) {
          if (!err) {
            console.log('transaction commited');
        });
      } catch (error) {
        //I get the error here in transaction commit. 
        console.log(JSON.stringify(error));
        return callback(some code);
      }
    }catch (error) {
        console.log(JSON.stringify(error));
      }
  });
} 

{code:10}引用了中止的[1]。理想情况下,我们的客户机应该处理此错误代码的重试。我在nodejs客户端上提交了一个bug来跟踪这个问题[3]

同时,您可以简单地重试请求,请求应该会成功。此处提供了重试中止事务的指南[2]


  • 看起来您在这里混合了回调和承诺,如果我正确阅读了代码,您的错误实际上来自
    batchUpdate
    。我不确定这是否是在回调运行程序中使用承诺的副作用,但是您可以尝试这样运行您的事务吗

    try {
      await database.runTransactionAsync(async transaction => {
        await transaction.batchUpdate(queries);
        return transaction.commit();
      });
    } catch (e) {
      console.error(error);
    }
    

    如果您决定在
    runTransactionSync
    函数中添加错误处理,则必须重新抛出您看到的任何中止的错误,否则运行程序将不知道这些错误,并且不会触发重试。

    如果您能提供一些代码示例,这将非常有用。Node.js客户端中有两种不同的运行事务的方法,但只有Database#runTransaction方法会重试您看到的错误。我添加了示例代码。callmehipop,你能帮我看看如何在node js中重试失败的事务吗。