bzr-svn aborts instead of waiting if its sqlite DB is locked

Bug #685251 reported by Samuel Bronson
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Bazaar Subversion Plugin
Fix Released
Low
Jelmer Vernooij
Launchpad itself
Fix Released
High
Jelmer Vernooij

Bug Description

While running "bzr qlog" against a particular SVN repository, I also did an "svn-import"

C:\code\comical>bzr svn-import https://comical.svn.sourceforge.net/svnroot/comical .
Using repository layout: trunk0
bzr: ERROR: sqlite3.OperationalError: database is locked

Traceback (most recent call last):
  File "bzrlib\commands.pyo", line 853, in exception_to_return_code
  File "bzrlib\commands.pyo", line 1055, in run_bzr
  File "bzrlib\commands.pyo", line 661, in run_argv_aliases
  File "bzrlib\commands.pyo", line 665, in run_direct
  File "bzrlib\cleanup.pyo", line 122, in run_simple
  File "bzrlib\cleanup.pyo", line 156, in _do_with_cleanups
  File "C:/Program Files/Bazaar/plugins\svn\commands.py", line 188, in run
  File "C:/Program Files/Bazaar/plugins\svn\convert.py", line 355, in convert_repository
  File "C:/Program Files/Bazaar/plugins\svn\convert.py", line 242, in __init__
  File "C:/Program Files/Bazaar/plugins\svn\convert.py", line 277, in _fetch_to_shared_repo
  File "C:/Program Files/Bazaar/plugins\svn\fetch.py", line 993, in find_iter_revisions
  File "C:/Program Files/Bazaar/plugins\svn\revmeta.py", line 344, in get_appropriate_mappings
  File "C:/Program Files/Bazaar/plugins\svn\revmeta.py", line 845, in get_original_mapping
  File "C:/Program Files/Bazaar/plugins\svn\cache\sqlitecache.py", line 250, inset_original_mapping
OperationalError: database is locked

bzr 2.1.1 on python 2.5.4 (Windows-XP-5.1.2600-SP3)
arguments: ['bzr', 'svn-import', 'https://comical.svn.sourceforge.net/svnroot/comical', '.']
encoding: 'cp1252', fsenc: 'mbcs', lang: None
plugins:
  bzrtools C:\Program Files\Bazaar\plugins\bzrtools [2.1.0]
  explorer C:\Program Files\Bazaar\plugins\explorer [1.0.1]
  launchpad C:\Program Files\Bazaar\plugins\launchpad [2.1.1]
  netrc_credential_store C:\Program Files\Bazaar\plugins\netrc_credential_store [2.1.1]
  news_merge C:\Program Files\Bazaar\plugins\news_merge [2.1.1]
  qbzr C:\Program Files\Bazaar\plugins\qbzr [0.18.4]
  rebase C:\Program Files\Bazaar\plugins\rebase [0.5.5]
  svn C:\Program Files\Bazaar\plugins\svn [1.0.2]
  upload C:\Program Files\Bazaar\plugins\upload [1.0.0dev]
  xmloutput C:\Program Files\Bazaar\plugins\xmloutput [0.8.7.dev]

*** Bazaar has encountered an internal error. This probably indicates a
    bug in Bazaar. You can help us fix it by filing a bug report at
        https://bugs.launchpad.net/bzr/+filebug
    including this traceback and a description of the problem.

This is hardly ideal, though at least each SVN repository has its own cache database...

Tags: qa-ok

Related branches

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

You can work around this by installing python-tdb, but unfortunately that doesn't work on windows.

Jelmer Vernooij (jelmer)
Changed in bzr-svn:
status: New → Triaged
importance: Undecided → Low
Revision history for this message
Yuval Hager (yhager) wrote :

Can you detail or point out how to install python-tdb? I don't have root access.
I downloaded from http://tdb.samba.org and tried:
$ ./configure --prefix=${HOME}
$ make
$ make install

And tried again, still, bzr-svn uses sqlite3. Are there any environment variables to set or config variables to make bzr-svn use tdb?

Revision history for this message
Jelmer Vernooij (jelmer) wrote : Re: [Bug 685251] Re: bzr-svn aborts instead of waiting if its sqlite DB is locked

On Tue, 2010-12-14 at 06:14 +0000, Yuval Hager wrote:
> Can you detail or point out how to install python-tdb? I don't have root access.
> I downloaded from http://tdb.samba.org and tried:
> $ ./configure --prefix=${HOME}
> $ make
> $ make install
>
> And tried again, still, bzr-svn uses sqlite3. Are there any environment
> variables to set or config variables to make bzr-svn use tdb?
The easiest thing to do is probably to install the python-tdb package
from your distribution.

Alternatively you can set LD_LIBRARY_PATH and PYTHONPATH appropriately -
LD_LIBRARY_PATH to the path holding libtdb.so.1 and PYTHONPATH to the
path with tdb.so.

Cheers,

Jelmer

Revision history for this message
Yuval Hager (yhager) wrote :

Thanks, although I am giving up now. I am forced to use RHEL5.5, which has python2.4. I tried compiling tdb, but configure fails to find python-config.
I then tried to use ActiveState's python or python from source and install tdb on top of that (had to tweak the configure script a bit, to find the correct python version). Eventually, I always ended up with:
$ python -c 'import tdb'
Fatal Python error: Interpreter not initialized (version mismatch?)
Aborted

I straced it and verified that it loads the correct tdb library that I just compiled for the same python version, but nothing worked.

This is probably remotely related to bzr-svn, but I am writing this here, since this is what stops me from using it at the moment :-(

Revision history for this message
Yuval Hager (yhager) wrote :

Running with
use-cache = False

in ~/.bazaar/bazaar.conf workarounds this problem.

Revision history for this message
Yonggang Luo (luoyonggang) wrote :

I think that's just because calling sqlite didn't call commit after execute!

=== modified file cache/sqlitecache.py
--- cache/sqlitecache.py 2011-07-30 16:44:57 +0000
+++ cache/sqlitecache.py 2011-08-02 13:04:50 +0000
@@ -240,7 +240,11 @@
             orig_mapping_name = original_mapping.name
         else:
             orig_mapping_name = None
- self.cachedb.execute("insert into original_mapping (path, revnum, original_mapping) values (?, ?, ?)", (foreign_revid[1].decode("utf-8"), foreign_revid[2], orig_mapping_name))
+ try:
+ self.cachedb.execute("insert into original_mapping (path, revnum, original_mapping) values (?, ?, ?)", (foreign_revid[1].decode("utf-8"), foreign_revid[2], orig_mapping_name))
+ self.commit()
+ except:
+ raise Exception("set_original_mapping error with %s : %s!" % (foreign_revid, orig_mapping_name))

     def insert_revision(self, foreign_revid, mapping, (revno, revid, hidden),
             stored_lhs_parent_revid):

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

On Tue, 2011-08-02 at 13:08 +0000, Yonggang Luo wrote:
> I think that's just because calling sqlite didn't call commit after
> execute!

> === modified file cache/sqlitecache.py
> --- cache/sqlitecache.py 2011-07-30 16:44:57 +0000
> +++ cache/sqlitecache.py 2011-08-02 13:04:50 +0000
> @@ -240,7 +240,11 @@
> orig_mapping_name = original_mapping.name
> else:
> orig_mapping_name = None
> - self.cachedb.execute("insert into original_mapping (path, revnum, original_mapping) values (?, ?, ?)", (foreign_revid[1].decode("utf-8"), foreign_revid[2], orig_mapping_name))
> + try:
> + self.cachedb.execute("insert into original_mapping (path, revnum, original_mapping) values (?, ?, ?)", (foreign_revid[1].decode("utf-8"), foreign_revid[2], orig_mapping_name))
> + self.commit()
> + except:
> + raise Exception("set_original_mapping error with %s : %s!" % (foreign_revid, orig_mapping_name))
This doesn't help. It just means writing the data to the database more
often, which hurts performance. That might slightly decrease the window
where there is a lock open on the database, but it doesn't solve the
fundamental problem.

Doing commits at the wrong time can also make it becomes possible to
write incomplete data to the database, which can cause a corrupt cache
if bzr-svn gets killed at the wrong moment.

Cheers,

Jelmer

Revision history for this message
Jelmer Vernooij (jelmer) wrote : Re: [bzr-svn] There is should be some lock problems around sqllite.

(CC'ing the bug. Usually, the bug tracker is the right place for
comments specific to a particular bug. )

On Wed, 2011-08-03 at 00:43 +0800, 罗勇刚(Yonggang Luo) wrote:
> Maybe this is the solution.

> http://stackoverflow.com/questions/5529820/sqlite3-operationalerror-database-is-locked

> We need specify separate sql database for each repo, not for each url.
That would negate a lot of the benefit of actually having a cache. It's
possible to have multiple processes working against the same bzr
repository - which would mean we could still hit locking issues.

We don't need a database that can support multiple writers with high
concurrency. It's fine if we have to wait for another process to release
the database lock - the only thing that it could be working on is
updating the cache, and that's what the process that's waiting would do
too.

The main thing that's missing is actually asking sqlite to wait for the
lock to be released rather than raising an exception immediately if it
finds a lock. IIUC this is possible, but I haven't had the time to look
up the right functions in the API, write some tests and patch bzr-svn to
use it.

Cheers,

Jelmer

>
> 2011/8/2 Jelmer Vernooij <email address hidden>
> On Tue, 2011-08-02 at 20:44 +0800, 罗勇刚(Yonggang Luo) wrote:
> > Delete br llvm/branches/release_21:41946
> > Delete br llvm/branches/release_21:41945
> > Delete br llvm/branches/release_21:41943
> > Delete br llvm/branches/release_21:41920
> > bzr: ERROR: sqlite3.OperationalError: database is locked
>
> Please see the bug tracker:
>
> This is http://pad.lv/685251
>
> Patches welcome.
>
> Cheers,
>
> Jelmer
>
>
>
>
>
> --
> 此致
> 礼
> 罗勇刚
> Yours
> sincerely,
> Yonggang Luo
>
>

Jelmer Vernooij (jelmer)
Changed in launchpad:
status: New → Triaged
importance: Undecided → High
assignee: nobody → Jelmer Vernooij (jelmer)
Changed in bzr-svn:
assignee: nobody → Jelmer Vernooij (jelmer)
status: Triaged → In Progress
Changed in launchpad:
status: Triaged → In Progress
Revision history for this message
Launchpad QA Bot (lpqabot) wrote :
tags: added: qa-needstesting
Changed in launchpad:
status: In Progress → Fix Committed
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

This can't be QA'ed at the moment because tellarium appears to be down, which breaks code imports on qastaging.

Jelmer Vernooij (jelmer)
tags: added: qa-ok
removed: qa-needstesting
William Grant (wgrant)
Changed in launchpad:
status: Fix Committed → Fix Released
Jelmer Vernooij (jelmer)
Changed in bzr-svn:
status: In Progress → Fix Committed
milestone: none → 1.1.0
Jelmer Vernooij (jelmer)
Changed in bzr-svn:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.