简体   繁体   中英

ArangoDB Transaction doesn't rollback on error

UPDATE: SOLUTION FOUND. ARANGODB CLUSTER DOES NOT SUPPORT TRANSACTIONS. IT IS ONLY SUPPORTED ON SINGLE INSTANCES.

I am trying to use the transactions function using arangoJS library. 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. However, it did not work on a cluster. Is there no support for transactions on ArangoDB clusters?

Single document operations are atomic in arangodb clusters. Multi-document are not as of now. We are currently working on ACID for multi-document operations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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