mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
storage: take the DB lock when writing to disk.
This commit is contained in:
parent
73e656522e
commit
63963323be
2 changed files with 1 additions and 6 deletions
|
@ -61,9 +61,6 @@ class JsonDB(Logger):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def commit(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@locked
|
@locked
|
||||||
def dump(self):
|
def dump(self):
|
||||||
return json.dumps(self.data, indent=4, sort_keys=True, cls=JsonDBJsonEncoder)
|
return json.dumps(self.data, indent=4, sort_keys=True, cls=JsonDBJsonEncoder)
|
||||||
|
|
|
@ -57,7 +57,6 @@ class WalletStorage(Logger):
|
||||||
|
|
||||||
def __init__(self, path, *, manual_upgrades: bool = False):
|
def __init__(self, path, *, manual_upgrades: bool = False):
|
||||||
Logger.__init__(self)
|
Logger.__init__(self)
|
||||||
self.lock = threading.RLock()
|
|
||||||
self.path = standardize_path(path)
|
self.path = standardize_path(path)
|
||||||
self._file_exists = bool(self.path and os.path.exists(self.path))
|
self._file_exists = bool(self.path and os.path.exists(self.path))
|
||||||
self._manual_upgrades = manual_upgrades
|
self._manual_upgrades = manual_upgrades
|
||||||
|
@ -112,7 +111,7 @@ class WalletStorage(Logger):
|
||||||
|
|
||||||
@profiler
|
@profiler
|
||||||
def write(self):
|
def write(self):
|
||||||
with self.lock:
|
with self.db.lock:
|
||||||
self._write()
|
self._write()
|
||||||
|
|
||||||
def _write(self):
|
def _write(self):
|
||||||
|
@ -121,7 +120,6 @@ class WalletStorage(Logger):
|
||||||
return
|
return
|
||||||
if not self.db.modified():
|
if not self.db.modified():
|
||||||
return
|
return
|
||||||
self.db.commit()
|
|
||||||
s = self.encrypt_before_writing(self.db.dump())
|
s = self.encrypt_before_writing(self.db.dump())
|
||||||
temp_path = "%s.tmp.%s" % (self.path, os.getpid())
|
temp_path = "%s.tmp.%s" % (self.path, os.getpid())
|
||||||
with open(temp_path, "w", encoding='utf-8') as f:
|
with open(temp_path, "w", encoding='utf-8') as f:
|
||||||
|
|
Loading…
Add table
Reference in a new issue