summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLianhao Lu <lianhao.lu@intel.com>2012-01-16 12:07:44 +0800
committerJoshua Lock <josh@linux.intel.com>2012-05-31 13:16:41 -0700
commitaca161f8a05085370a360930793d58a46982ac2f (patch)
tree9c222d541627c9237db9dfbafdc9c881fc612824
parent94c8d01eba5f8fe5a56c7682fd8d534c837e7e57 (diff)
downloadpoky-aca161f8a05085370a360930793d58a46982ac2f.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> Signed-off-by: Joshua Lock <josh@linux.intel.com>
-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 551b58a2a9..4a4505c89b 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)