mirror of
https://github.com/borgbase/vorta
synced 2025-03-12 07:09:37 +00:00
Address DB Locking issues (#1109)
This commit is contained in:
parent
5b769b104f
commit
0c77fdde97
3 changed files with 34 additions and 32 deletions
|
@ -2,7 +2,7 @@ import os
|
|||
import signal
|
||||
import sys
|
||||
|
||||
import peewee
|
||||
from peewee import SqliteDatabase
|
||||
from vorta._version import __version__
|
||||
from vorta.i18n import trans_late, translate
|
||||
from vorta.config import SETTINGS_DIR
|
||||
|
@ -50,7 +50,7 @@ def main():
|
|||
init_logger(background=want_background)
|
||||
|
||||
# Init database
|
||||
sqlite_db = peewee.SqliteDatabase(os.path.join(SETTINGS_DIR, 'settings.db'), pragmas={'journal_mode': 'wal', })
|
||||
sqlite_db = SqliteDatabase(os.path.join(SETTINGS_DIR, 'settings.db'), pragmas={'journal_mode': 'wal', })
|
||||
init_db(sqlite_db)
|
||||
|
||||
# Init app after database is available
|
||||
|
|
|
@ -21,7 +21,8 @@ from vorta.utils import borg_compat, pretty_bytes
|
|||
from vorta.keyring.abc import VortaKeyring
|
||||
from vorta.keyring.db import VortaDBKeyring
|
||||
|
||||
temp_mutex = Lock()
|
||||
keyring_lock = Lock()
|
||||
db_lock = Lock()
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
FakeRepo = namedtuple('Repo', ['url', 'id', 'extra_borg_arguments', 'encryption'])
|
||||
|
@ -144,7 +145,7 @@ class BorgJob(JobInterface, BackupProfileMixin):
|
|||
return ret
|
||||
|
||||
# Try to get password from chosen keyring backend.
|
||||
temp_mutex.acquire()
|
||||
with keyring_lock:
|
||||
cls.keyring = VortaKeyring.get_keyring()
|
||||
logger.debug("Using %s keyring to store passwords.", cls.keyring.__class__.__name__)
|
||||
ret['password'] = cls.keyring.get_password('vorta-repo', profile.repo.url)
|
||||
|
@ -164,7 +165,6 @@ class BorgJob(JobInterface, BackupProfileMixin):
|
|||
if ret['password'] is not None:
|
||||
logger.warning('Found password in database, but secure storage was available. '
|
||||
'Consider re-adding the repo to use it.')
|
||||
temp_mutex.release()
|
||||
|
||||
# Password is required for encryption, cannot continue
|
||||
if ret['password'] is None and not isinstance(profile.repo, FakeRepo) and profile.repo.encryption != 'none':
|
||||
|
@ -204,6 +204,7 @@ class BorgJob(JobInterface, BackupProfileMixin):
|
|||
|
||||
def run(self):
|
||||
self.started_event()
|
||||
with db_lock:
|
||||
log_entry = EventLogModel(category=self.params.get('category', 'user'),
|
||||
subcommand=self.cmd[1],
|
||||
profile=self.params.get('profile_id', None)
|
||||
|
@ -285,9 +286,10 @@ class BorgJob(JobInterface, BackupProfileMixin):
|
|||
log_entry.returncode = p.returncode
|
||||
log_entry.repo_url = self.params.get('repo_url', None)
|
||||
log_entry.end_time = dt.now()
|
||||
with db_lock:
|
||||
log_entry.save()
|
||||
|
||||
self.process_result(result)
|
||||
|
||||
self.finished_event(result)
|
||||
|
||||
def process_result(self, result):
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import os
|
||||
import peewee
|
||||
from peewee import SqliteDatabase
|
||||
import pytest
|
||||
import sys
|
||||
from datetime import datetime as dt
|
||||
|
@ -26,7 +26,7 @@ def pytest_configure(config):
|
|||
def qapp(tmpdir_factory):
|
||||
# DB is required to init QApplication. New DB used for every test.
|
||||
tmp_db = tmpdir_factory.mktemp('Vorta').join('settings.sqlite')
|
||||
mock_db = peewee.SqliteDatabase(str(tmp_db))
|
||||
mock_db = SqliteDatabase(str(tmp_db))
|
||||
vorta.models.init_db(mock_db)
|
||||
|
||||
from vorta.application import VortaApp
|
||||
|
@ -43,7 +43,7 @@ def qapp(tmpdir_factory):
|
|||
@pytest.fixture(scope='function', autouse=True)
|
||||
def init_db(qapp, qtbot, tmpdir_factory):
|
||||
tmp_db = tmpdir_factory.mktemp('Vorta').join('settings.sqlite')
|
||||
mock_db = peewee.SqliteDatabase(str(tmp_db), pragmas={'journal_mode': 'wal', })
|
||||
mock_db = SqliteDatabase(str(tmp_db), pragmas={'journal_mode': 'wal', })
|
||||
vorta.models.init_db(mock_db)
|
||||
|
||||
default_profile = BackupProfileModel(name='Default')
|
||||
|
|
Loading…
Add table
Reference in a new issue