Hive: Is Hive surpport transaction?

Created on 3 Oct 2019  路  10Comments  路  Source: hivedb/hive

question

Most helpful comment

The feature of transaction seems useful in such a case.

I agree. It's still on my radar...

All 10 comments

Not currently. What would you need transactions for?

If you want to write multiple entries with a single disk access, you can use putAll().

If putAll() fails, are all the kv pairs not written?

Yes exactly

Thanks @leisim

Hi @leisim ,

Do you plan to implement a "transaction" on multiples boxes ? I would like to save a complete set of data, or nothing.

Here is an example for an invoice and its lines/products :

Hive.transaction((transaction) {
   transaction.add(Hive.box('invoices').add(invoiceId, invoice));
   transaction.add(Hive.box('lines').add(lineId, line));

   // commit
   // rollback in case of error
});

@benoitverstraete

I do but it is not high on the priority list. The next update will improve performance and introduce HiveObjects, ListView and MapView. The update after that will contain queries. Then I plan to look at transactions...

What if you need to do both put() and delete() in a single transaction?

e.g. ToDo app

  • categoryA

    • task1

    • task2

  • categoryB

    • task3

If you want to delete categoryB at the same time as task3 is moved to categoryA which makes categoryB empty, a series of update and removal operations is probably necessary. The feature of transaction seems useful in such a case.

The feature of transaction seems useful in such a case.

I agree. It's still on my radar...

An additional use case example would be a conditional write (reading value A and only writing value B if A satisfies a certain condition).

@ShangyanLi Why are transactions needed for such an operation? Wouldn't it be possible to implement this with the operations currently available?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aminjoharinia picture aminjoharinia  路  3Comments

rupamking1 picture rupamking1  路  3Comments

yannickvg picture yannickvg  路  4Comments

kaboc picture kaboc  路  3Comments

NourEldinShobier picture NourEldinShobier  路  3Comments