Forum: Building VoltDB Applications

Post: ROLLBACK a transaction in VoltDB from client side

ROLLBACK a transaction in VoltDB from client side
leobon
Feb 27, 2014
Hi all,
I write a Java application, which insert data to a table in VoltDB.

I want to manually control COMMIT, ROLLBACK action.
I tried:
if (!flightid) { throw new VoltAbortException(); }
guide in book "Using VoltDB", but it didn't take effect.

Can anyone help me?

Thanks!!
nshi
Feb 27, 2014
Hi leobon,

When you say that it didn't take effect, do yo mean that the insertion succeed even though the transaction was aborted?

Could you share the procedure code with us? You can email me at nshi AT voltdb.com if you want.
leobon
Feb 28, 2014
Hi nshi,
I tried to put throw new VoltAbortException() in procedure Insert.java; and it take effect now.
Before, I put this in Client.java.

So, this way is only applied when put in procedure??

I have a business: insert a list of data to a table; if any element of this list is error (eg: wrong data format), ROLLBACK all inserted actions (destination table is still empty)
What should I do??
nshi
Feb 28, 2014
Hi leobon,

Throwing the VoltAbortException will only take effect inside the procedure.

Transactions in VoltDB run from start to completion on the server. Your procedure class is run on the server when the transaction runs. So you would throw the VoltAbortException within the procedure in order to abort it. Otherwise it will commit if it ran to completion.


I have a business: insert a list of data to a table; if any element of this list is error (eg: wrong data format), ROLLBACK all inserted actions (destination table is still empty)
What should I do??


I just want to make sure that I understand your question.

1. Are you inserting the list of data in one procedure call, or multiple procedure calls?

2. Are you asking if VoltDB will rollback all inserted rows or are you asking how to prevent it from rolling back all inserted rows?

Thanks,
leobon
Mar 2, 2014
Hi nshi,

1. Are you inserting the list of data in one procedure call, or multiple procedure calls?

2. Are you asking if VoltDB will rollback all inserted rows or are you asking how to prevent it from rolling back all inserted rows?


1. Source code like this:
boolean isRollback = false;
for (int i=0; i<list.size(); i++) {

if (<wrong_data_format>) {
isRollback = true;
break;

}

client.callProcedure(new ProcedureCallback(), 'Insert', list.get(i));

}

if (isRollback) {
// Rollback all inserted rows
}


2. I want Voltdb DO ROLLBACK all inserted rows.
nshi
Mar 3, 2014
Hi leobon,

You are calling the Insert procedure from the client once for each row. Each call to Insert is an individual transaction. You can rollback a single transaction by throwing VoltAbortException inside the transaction. You cannot rollback other inserts that are in different transactions.

To cancel all inserted rows in the table when the wrong data format is detected, you can call DELETE FROM {table-name}.
mangesh
Aug 10, 2016
Hi nshi,

Is client side rollback supported in latest(2016) release of VoltDB?
jpiekos
Aug 10, 2016
Hi Mangesh,

Client-side rollback is not supported, as VoltDB executes transactions lock-free and serially, within each partition. VoltDB's transaction execution architecture is one of the primary reasons we can support such amazing tx/sec throughput. It's based on research done at MIT, Brown, and Yale, leading to the H-Store paper/research (http://hstore.cs.brown.edu/).

Additionally, there's a good description of the VoltDB transaction architecture here: https://voltdb.com/sites/default/files/tn-transactions.pdf

John