- def put(self, key, id):
- while True:
- try:
- with db.txn(self.db.env.env) as tx:
- obid = struct.pack(">Q", id)
- if not self.db.ob.has_key(obid, txn=tx.tx):
- raise ValueError("no such object in database: " + str(id))
- try:
- self.bk.put(self.typ.encode(key), obid, txn=tx.tx, flags=bd.DB_NODUPDATA)
- except bd.DBKeyExistError:
- return False
- tx.commit()
- return True
- except deadlock:
- continue
-
- def remove(self, key, id):
- while True:
+ @txnfun(lambda self: self.db.env.env)
+ def put(self, key, id, *, tx):
+ obid = struct.pack(">Q", id)
+ if not self.db.ob.has_key(obid, txn=tx.tx):
+ raise ValueError("no such object in database: " + str(id))
+ try:
+ self.bk.put(self.typ.encode(key), obid, txn=tx.tx, flags=bd.DB_NODUPDATA)
+ except bd.DBKeyExistError:
+ return False
+ return True
+
+ @txnfun(lambda self: self.db.env.env)
+ def remove(self, key, id, *, tx):
+ obid = struct.pack(">Q", id)
+ if not self.db.ob.has_key(obid, txn=tx.tx):
+ raise ValueError("no such object in database: " + str(id))
+ cur = self.bk.cursor(txn=tx.tx)
+ try: