0

I'm using TokuMx in order to organize a transaction. It has specific commands to do so.

I tried to run db.runCommand("beginTransaction") in Mongo shell. It worked well.

However, when I did the same thing in Jongo:

PlayJongo.jongo().runCommand("beginTransaction");

It gave me [error] play - Cannot invoke the action, eventually got an error: java.lang.IllegalArgumentException: Cannot parse query: beginTransaction

What did I do wrong?

EDIT

public static boolean buyProduct(User buyer, User seller, int accountIndex, float productPrice){
    boolean isSuccess = false;
    PlayJongo.jongo().runCommand("{beginTransaction : 1}");
    try{
        // Deposit money to seller
        seller.getAccounts().get(0).deposit(productPrice);
        UserRepository.update(seller);
        // Withdraw money from buyer
        buyer.getAccounts().get(accountIndex).withdraw(productPrice);
        UserRepository.update(buyer);
        throw new Exception();
        //isSuccess = true;
    }
    catch (Exception e){
        PlayJongo.jongo().runCommand("{rollbackTransaction : 1 }");
        isSuccess = false;
    }

    return isSuccess;
}
Stennie
  • 63,885
  • 14
  • 149
  • 175
lvarayut
  • 13,963
  • 17
  • 63
  • 87

1 Answers1

2

I'm not a jongo expert but I do work on tokumx and I just checked the jongo docs. I think you want

PlayJongo.jongo().runCommand("{beginTransaction:1}");
leif
  • 1,987
  • 4
  • 19
  • 22
  • There is no error. But ACID doesn't work at all. Please see my updated question. – lvarayut Jun 26 '14 at 09:47
  • Can you describe what the problem is now? I only see code at this point, not a problem description. Maybe that would be better as a new question. One thing I do see is that you never commit the transaction. You should do that before the end of the try block probably. You also unconditionally throw an exception, so I really don't know what this is supposed to do. Depending what you're doing you may also want a serializable transaction so you take locks on read (avoids lost updates you can get with repeatable read, which is the default). HTH – leif Jun 27 '14 at 11:08
  • Thanks for your response. The code in my question is just the simulation of transaction that there are some errors happen during the updating process, `throw new Exception()`. However, it didn't give me some errors, so that is very hard to tell what was wrong :( All I could monitor is that the document in my DB was updated and has never been rolled back. – lvarayut Jun 28 '14 at 09:01
  • Please split that into a separate question then, or post to the tokumx-user google group. Make sure you post the code, what you expect it to do, and all server logs and the client-side results of each command. However, my best guess is that your driver is doing something weird with connection pools. See http://docs.tokutek.com/tokumx/tokumx-transactions.html#tokumx-transactions-multi-statement-drivers for details about connection pooling. – leif Jun 28 '14 at 19:48
  • I think so. The problem maybe my java driver. BTW, +1 thanks for your help. – lvarayut Jun 28 '14 at 20:06