python-rocksdb icon indicating copy to clipboard operation
python-rocksdb copied to clipboard

Support for transactions

Open amirouche opened this issue 5 years ago • 15 comments

It seems the bindings are missing transaction support.

amirouche avatar Nov 11 '18 18:11 amirouche

Thank you for using python-rocksdb. these features are coming soon since I am re-making whole project to make it more easily to maintain.

twmht avatar Apr 06 '19 02:04 twmht

tx!

amirouche avatar Apr 07 '19 19:04 amirouche

It has been 2 years since this issue was opened. Any news on this? I was considering using rocksdb for a project written in python, but not having transactions is a showstopper!

NightTsarina avatar Jan 11 '21 03:01 NightTsarina

You can use WriteBatch for that, or even a custom writebatch which stores the key data and statuses for from that.

iFA88 avatar Jan 11 '21 06:01 iFA88

Not really, because I need read-write conflict detection by using GetForUpdate.

NightTsarina avatar Jan 12 '21 12:01 NightTsarina

Not really, because I need read-write conflict detection by using GetForUpdate.

Yeah, you can do that in python. You can use bisect for automatic ordering when you need iter too.

iFA88 avatar Jan 12 '21 20:01 iFA88

Not really, because I need read-write conflict detection by using GetForUpdate.

Yeah, you can do that in python. You can use bisect for automatic ordering when you need iter too.

I am not sure I understand what you mean.. How does bisect help me with this?

NightTsarina avatar Jan 13 '21 13:01 NightTsarina

I am not sure I understand what you mean.. How does bisect help me with this?

So simple:

class OwnWriteBatch:
  def __init__(self, db):
    self.db = db
    self.keys = {}
  def get(self, key, *args, **kwargs):
    if key not in self.keys:
      return self.db.get(key, *args, **kwargs)
    return self.keys[key][1] if self.keys[key][0] else None
  def put(self, key, value):
     self.keys[key] = [True, value]
  def delete(self, key):
     self.keys[key] = [False, None]
  def write(self):
     wb = rocksdb.WriteBatch()
     for k, (s, v) in self.keys.items():
       if s:
         wb.put(k, v)
       else:
         wb.delete(k)
    self.db.write(wb)

iFA88 avatar Jan 13 '21 17:01 iFA88

Right. But this still does not provide read-write or write-write conflict detection. I do need transactions for that.

NightTsarina avatar Jan 16 '21 07:01 NightTsarina

Right. But this still does not provide read-write or write-write conflict detection. I do need transactions for that.

Can you explain that a little more?

iFA88 avatar Jan 16 '21 08:01 iFA88

Transactions can give you guarantees that no other thread has updated an entry your transaction is modifying or depending upon. See https://github.com/facebook/rocksdb/wiki/Transactions

NightTsarina avatar Jan 17 '21 15:01 NightTsarina

I'm using threading.RLock for that. I think what you want there is a "simple" workaround for that, but the Transactions is currently not supported.

iFA88 avatar Jan 17 '21 15:01 iFA88

I appreciate you trying to help, but you are not understanding the problem and I am not looking for workarounds. This bug is about the missing support for transactions as provided by rocksdb.

NightTsarina avatar Jan 18 '21 16:01 NightTsarina

for what it is worth sqlite lsm extension support transactions and you build it standalone as shared lib.

HTH.

amirouche avatar Jan 18 '21 19:01 amirouche

https://github.com/coleifer/python-lsm-db

amirouche avatar Jan 18 '21 20:01 amirouche