简体   繁体   English

ArangoDB事务不会因错误而回滚

[英]ArangoDB Transaction doesn't rollback on error

UPDATE: SOLUTION FOUND. 更新:解决方案。 ARANGODB CLUSTER DOES NOT SUPPORT TRANSACTIONS. ARANGODB集群不支持交易。 IT IS ONLY SUPPORTED ON SINGLE INSTANCES. 它仅在单个实例上受支持。

I am trying to use the transactions function using arangoJS library. 我正在尝试通过arangoJS库使用事务处理功能。 The function that I will present is just a dummy function that inserts two records, and then tries to get a document that doesn't exist. 我将介绍的函数只是一个虚拟函数,该函数插入两个记录,然后尝试获取不存在的文档。 Getting the nonexistent document generates an error, and the transaction must rollback. 获取不存在的文档会产生错误,并且事务必须回滚。 Indeed, the error gets generated after trying to get the document that doesn't exist. 确实,尝试获取不存在的文档后会生成错误。 However, the database does not rollback, and the two inserted documents remain inserted in the database. 但是,数据库不会回滚,并且两个插入的文档仍然插入数据库中。 Does anyone know how to solve it? 有人知道如何解决吗?

"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);
}

UPDATE: I tried this transaction on a single instance ArangoDB and it worked. 更新:我在单个实例ArangoDB上尝试了此事务,并且它起作用了。 However, it did not work on a cluster. 但是,它在群集上不起作用。 Is there no support for transactions on ArangoDB clusters? ArangoDB群集上不支持事务处理吗?

Single document operations are atomic in arangodb clusters. 单个文档操作在arangodb群集中是原子的。 Multi-document are not as of now. 到目前为止还没有多文档。 We are currently working on ACID for multi-document operations. 我们目前正在为多文档操作开发ACID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM