mirror of
https://git.yoctoproject.org/poky
synced 2026-05-31 12:49:46 +00:00
bitbake/persist_data: Reconnect when DB is locked
[YOCTO #1761] Reconnect to the backend Sqlite DB in 'database is locked' exception so the timeout can be leveraged in each time retry. (Bitbake rev: b310382764367b573c84f33d847c6eb821266f9e) Signed-off-by: Lianhao Lu <lianhao.lu@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
5724ee9c3a
commit
1fedd166b7
@@ -47,9 +47,10 @@ if hasattr(sqlite3, 'enable_shared_cache'):
|
|||||||
@total_ordering
|
@total_ordering
|
||||||
class SQLTable(collections.MutableMapping):
|
class SQLTable(collections.MutableMapping):
|
||||||
"""Object representing a table/domain in the database"""
|
"""Object representing a table/domain in the database"""
|
||||||
def __init__(self, cursor, table):
|
def __init__(self, cachefile, table):
|
||||||
self.cursor = cursor
|
self.cachefile = cachefile
|
||||||
self.table = table
|
self.table = table
|
||||||
|
self.cursor = connect(self.cachefile)
|
||||||
|
|
||||||
self._execute("CREATE TABLE IF NOT EXISTS %s(key TEXT, value TEXT);"
|
self._execute("CREATE TABLE IF NOT EXISTS %s(key TEXT, value TEXT);"
|
||||||
% table)
|
% table)
|
||||||
@@ -63,6 +64,8 @@ class SQLTable(collections.MutableMapping):
|
|||||||
except sqlite3.OperationalError as exc:
|
except sqlite3.OperationalError as exc:
|
||||||
if 'database is locked' in str(exc) and count < 500:
|
if 'database is locked' in str(exc) and count < 500:
|
||||||
count = count + 1
|
count = count + 1
|
||||||
|
self.cursor.close()
|
||||||
|
self.cursor = connect(self.cachefile)
|
||||||
continue
|
continue
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@@ -188,7 +191,7 @@ class PersistData(object):
|
|||||||
del self.data[domain][key]
|
del self.data[domain][key]
|
||||||
|
|
||||||
def connect(database):
|
def connect(database):
|
||||||
return sqlite3.connect(database, timeout=30, isolation_level=None)
|
return sqlite3.connect(database, timeout=5, isolation_level=None)
|
||||||
|
|
||||||
def persist(domain, d):
|
def persist(domain, d):
|
||||||
"""Convenience factory for SQLTable objects based upon metadata"""
|
"""Convenience factory for SQLTable objects based upon metadata"""
|
||||||
@@ -201,5 +204,4 @@ def persist(domain, d):
|
|||||||
|
|
||||||
bb.utils.mkdirhier(cachedir)
|
bb.utils.mkdirhier(cachedir)
|
||||||
cachefile = os.path.join(cachedir, "bb_persist_data.sqlite3")
|
cachefile = os.path.join(cachedir, "bb_persist_data.sqlite3")
|
||||||
connection = connect(cachefile)
|
return SQLTable(cachefile, domain)
|
||||||
return SQLTable(connection, domain)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user