ArangoDB事务不会在出错时回滚

时间:2017-07-19 07:49:18

标签: node.js transactions arangodb arangojs

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

我正在尝试使用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集群上的事务?

1 个答案:

答案 0 :(得分:0)

单个文档操作在arangodb集群中是原子的。多文档不是现在。我们目前正致力于ACID的多文档操作。

相关问题