【问题标题】:ArangoDB Transaction doesn't rollback on errorArangoDB 事务不会因错误而回滚
【发布时间】:2017-07-19 07:49:17
【问题描述】:

更新:找到解决方案。 ARANGODB 集群不支持交易。它仅支持单个实例。

我正在尝试使用 arangoJS 库来使用交易功能。我将介绍的函数只是一个虚拟函数,它插入两条记录,然后尝试获取一个不存在的文档。获取不存在的文档会产生错误,并且事务必须回滚。实际上,在尝试获取不存在的文档后会生成错误。但是,数据库并没有回滚,两个插入的文档仍然插入到数据库中。有人知道怎么解决吗?

"updateCustomer" : function (options, cb) {
    const action = String(function (params) {
        // This code will be executed inside ArangoDB! 
        const db = require('@arangodb').db;
        const aql = require('@arangodb').aql;
        const customer = db._collection('customer');
        try{
            //insert two documents
            db._query(aql`INSERT ${params.user} INTO ${customer} Return NEW`);
            db._query(aql`INSERT ${params.customer} INTO ${customer} Return NEW`);
            //Get a document that doesn't exist
            customer.document('does-not-exist');
        }catch(e){
            throw new Error("Everything is bad");
        }
    });
    let opts = {
        collections : {
            read : ["customer"],
            write : ["customer"]
        },
        action : action,
        params : {user: options, customer: options},
        lockTimeout : 5
    };
    Arango.transaction(opts,(err, result) => {
        console.log("err: " + err);
        console.log("result: " + JSON.stringify(result));
        return cb(err, result);
    });
}

"transaction" : function (options, cb) {
    utils.dbConnect().transaction(options.collections, options.action, options.params, options.lockTimeout, cb);
}

更新:我在单个实例 ArangoDB 上尝试了此事务并且它有效。但是,它不适用于集群。不支持 ArangoDB 集群上的事务吗?

【问题讨论】:

    标签: node.js transactions arangodb arangojs


    【解决方案1】:

    单个文档操作在 arangodb 集群中是原子操作。目前还没有多文档。我们目前正在研究用于多文档操作的 ACID。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-04
      相关资源
      最近更新 更多