diff options
author | Ed Bartosh <ed.bartosh@linux.intel.com> | 2015-12-09 19:56:40 -0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-12-14 23:13:07 +0000 |
commit | 507aafbd7ac90b4dfbe0f070e8180368012dc1f5 (patch) | |
tree | 81282cdc990ab16beb08f89ed9e4e8fbe3051c84 | |
parent | 322b4709d84dadb6d34612781f1fdf0ebad7faa8 (diff) | |
download | poky-507aafbd7ac90b4dfbe0f070e8180368012dc1f5.tar.gz |
bitbake: toaster: work around 'database is locked' error
When sqlite can not cope with a stream of 'insert' queries it throws
'database is locked' exception.
Wrapping model.save in transaction.atomic context and repeating the call
should solve this issue.
(Bitbake rev: eb305308ca8f6228c6f52dac1bd941f29c7e5eb6)
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: brian avery <avery.brian@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | bitbake/lib/toaster/orm/models.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py index 3c51c6f798..0d598aca19 100644 --- a/bitbake/lib/toaster/orm/models.py +++ b/bitbake/lib/toaster/orm/models.py | |||
@@ -29,10 +29,28 @@ from django.core import validators | |||
29 | from django.conf import settings | 29 | from django.conf import settings |
30 | import django.db.models.signals | 30 | import django.db.models.signals |
31 | 31 | ||
32 | |||
33 | import logging | 32 | import logging |
34 | logger = logging.getLogger("toaster") | 33 | logger = logging.getLogger("toaster") |
35 | 34 | ||
35 | if 'sqlite' in settings.DATABASES['default']['ENGINE']: | ||
36 | from django.db import transaction, OperationalError | ||
37 | from time import sleep | ||
38 | |||
39 | _base_save = models.Model.save | ||
40 | def save(self, *args, **kwargs): | ||
41 | while True: | ||
42 | try: | ||
43 | with transaction.atomic(): | ||
44 | return _base_save(self, *args, **kwargs) | ||
45 | except OperationalError as err: | ||
46 | if 'database is locked' in str(err): | ||
47 | logger.warning("%s, model: %s, args: %s, kwargs: %s", | ||
48 | err, self.__class__, args, kwargs) | ||
49 | sleep(0.5) | ||
50 | continue | ||
51 | raise | ||
52 | |||
53 | models.Model.save = save | ||
36 | 54 | ||
37 | class GitURLValidator(validators.URLValidator): | 55 | class GitURLValidator(validators.URLValidator): |
38 | import re | 56 | import re |