summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/persist_data.py
diff options
context:
space:
mode:
authorLianhao Lu <lianhao.lu@intel.com>2012-01-16 12:07:44 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-01-19 00:15:38 +0000
commit1fedd166b71a4000116fcc9bd993cb23a7899adb (patch)
tree0ad21e5f57a02ad5921398089a252d607712a278 /bitbake/lib/bb/persist_data.py
parent5724ee9c3a99519fea96446638910b727b89898d (diff)
downloadpoky-1fedd166b71a4000116fcc9bd993cb23a7899adb.tar.gz
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>
Diffstat (limited to 'bitbake/lib/bb/persist_data.py')
-rw-r--r--bitbake/lib/bb/persist_data.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/bitbake/lib/bb/persist_data.py b/bitbake/lib/bb/persist_data.py
index 17620ef331..c4ea23bfda 100644
--- a/bitbake/lib/bb/persist_data.py
+++ b/bitbake/lib/bb/persist_data.py
@@ -47,9 +47,10 @@ if hasattr(sqlite3, 'enable_shared_cache'):
47@total_ordering 47@total_ordering
48class SQLTable(collections.MutableMapping): 48class SQLTable(collections.MutableMapping):
49 """Object representing a table/domain in the database""" 49 """Object representing a table/domain in the database"""
50 def __init__(self, cursor, table): 50 def __init__(self, cachefile, table):
51 self.cursor = cursor 51 self.cachefile = cachefile
52 self.table = table 52 self.table = table
53 self.cursor = connect(self.cachefile)
53 54
54 self._execute("CREATE TABLE IF NOT EXISTS %s(key TEXT, value TEXT);" 55 self._execute("CREATE TABLE IF NOT EXISTS %s(key TEXT, value TEXT);"
55 % table) 56 % table)
@@ -63,6 +64,8 @@ class SQLTable(collections.MutableMapping):
63 except sqlite3.OperationalError as exc: 64 except sqlite3.OperationalError as exc:
64 if 'database is locked' in str(exc) and count < 500: 65 if 'database is locked' in str(exc) and count < 500:
65 count = count + 1 66 count = count + 1
67 self.cursor.close()
68 self.cursor = connect(self.cachefile)
66 continue 69 continue
67 raise 70 raise
68 71
@@ -188,7 +191,7 @@ class PersistData(object):
188 del self.data[domain][key] 191 del self.data[domain][key]
189 192
190def connect(database): 193def connect(database):
191 return sqlite3.connect(database, timeout=30, isolation_level=None) 194 return sqlite3.connect(database, timeout=5, isolation_level=None)
192 195
193def persist(domain, d): 196def persist(domain, d):
194 """Convenience factory for SQLTable objects based upon metadata""" 197 """Convenience factory for SQLTable objects based upon metadata"""
@@ -201,5 +204,4 @@ def persist(domain, d):
201 204
202 bb.utils.mkdirhier(cachedir) 205 bb.utils.mkdirhier(cachedir)
203 cachefile = os.path.join(cachedir, "bb_persist_data.sqlite3") 206 cachefile = os.path.join(cachedir, "bb_persist_data.sqlite3")
204 connection = connect(cachefile) 207 return SQLTable(cachefile, domain)
205 return SQLTable(connection, domain)