You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Philip Martin <ph...@wandisco.com> on 2011/06/17 12:06:11 UTC

SQLite locking and FSFS rep-sharing

The FSFS rep-sharing database is an SQLite database updated
post-commit.  I thought that the SQLite busy timeout would handle
concurrent updates from multiple commits but it doesn't work the way I
expected.

Start with a new repository and use gdb to interrupt the post-commit:

  $ gdb -arg svn import -mm Makefile file://`pwd`/repo/f1
  (gdb) b write_reps_to_cache
  (gdb) r
  Breakpoint 1
  (gdb) fin

That runs to the end of write_reps_to_cache so the process has written
to the database but not released the lock. Then in another terminal run:

  $ svn import -mm Makefile file://`pwd`/repo/f2
  Adding         Makefile

  Committed revision 2.

  Warning: post commit FS processing had error:
  database is locked

The second commit doesn't wait for the 10 second SQLite busy timeout, it
gives the 'database is locked' error immediately.

Should we be doing more to support concurrent writes here?  An explicit
loop in the post-commit?  A different SQLite configuration?

-- 
Philip

Re: SQLite locking and FSFS rep-sharing

Posted by Mark Phippard <ma...@gmail.com>.
On Mon, Jun 20, 2011 at 7:01 AM, Philip Martin
<ph...@wandisco.com> wrote:
> Philip Martin <ph...@wandisco.com> writes:
>
>> The second commit doesn't wait for the 10 second SQLite busy timeout, it
>> gives the 'database is locked' error immediately.
>>
>> Should we be doing more to support concurrent writes here?  An explicit
>> loop in the post-commit?  A different SQLite configuration?
>
> A change from 1.6 is that 1.7 uses sqlite for packed revprops.  It turns
> out that the packed revprop database doesn't have this problem because
> access to it is protected by the FSFS repository lock.
>
> We could change the rep-sharing database access to take the FSFS
> repository lock.  Read access to the database already occurs at a point
> when the lock is held.

Would that open us back up to this problem?

http://subversion.tigris.org/issues/show_bug.cgi?id=3506


-- 
Thanks

Mark Phippard
http://markphip.blogspot.com/

Re: SQLite locking and FSFS rep-sharing

Posted by Daniel Shahaf <da...@elego.de>.
Philip Martin wrote on Mon, Jun 20, 2011 at 15:51:11 +0100:
> Daniel Shahaf <da...@elego.de> writes:
> 
> > Philip Martin wrote on Mon, Jun 20, 2011 at 12:01:44 +0100:
> >
> >> We could change the rep-sharing database access to take the FSFS
> >> repository lock.
> 
> It probably makes more sense to use a separate rep-sharing lock.
> 
> > Hmm.  Intuitively I wouldn't want sqlite writes to have to take the FSFS
> > write lock, since I don't want to block commits on them.
> >
> > But.  SQLite writers block readers, so as long as we write to
> > rep-cache.db outside the FSFS write lock (with or without retries) we
> > should ensure we don't start readers that hold the FSFS write lock.
> 
> Writers blocking readers doesn't seem to be a hard rule with current
> SQLite.  With one process stopped in gdb holding a rep-cache write lock
> (after write_reps_to_cache has finished) another process can read the
> rep-cache and get representations.
> 

I'm not surprised.  By the time write_reps_to_cache() has finished,
the INSERT stmt had been run and reset already, so as far as sqlite is
concerned there are no writers around.

> -- 
> Philip

Re: SQLite locking and FSFS rep-sharing

Posted by Philip Martin <ph...@wandisco.com>.
Daniel Shahaf <da...@elego.de> writes:

> Philip Martin wrote on Mon, Jun 20, 2011 at 12:01:44 +0100:
>
>> We could change the rep-sharing database access to take the FSFS
>> repository lock.

It probably makes more sense to use a separate rep-sharing lock.

> Hmm.  Intuitively I wouldn't want sqlite writes to have to take the FSFS
> write lock, since I don't want to block commits on them.
>
> But.  SQLite writers block readers, so as long as we write to
> rep-cache.db outside the FSFS write lock (with or without retries) we
> should ensure we don't start readers that hold the FSFS write lock.

Writers blocking readers doesn't seem to be a hard rule with current
SQLite.  With one process stopped in gdb holding a rep-cache write lock
(after write_reps_to_cache has finished) another process can read the
rep-cache and get representations.

-- 
Philip

Re: SQLite locking and FSFS rep-sharing

Posted by Philip Martin <ph...@wandisco.com>.
Daniel Shahaf <da...@elego.de> writes:

> Philip Martin wrote on Mon, Jun 20, 2011 at 12:01:44 +0100:
>
>> We could change the rep-sharing database access to take the FSFS
>> repository lock.

I was mistaken about this bit:

>> Read access to the database already occurs at a point
>> when the lock is held.

Access happens inside svn_fs_fs__set_contents, this normally happens
when the database lock is not held.

> Hmm.  Intuitively I wouldn't want sqlite writes to have to take the FSFS
> write lock, since I don't want to block commits on them.
>
> But.  SQLite writers block readers, so as long as we write to
> rep-cache.db outside the FSFS write lock (with or without retries) we
> should ensure we don't start readers that hold the FSFS write lock.

-- 
Philip

Re: SQLite locking and FSFS rep-sharing

Posted by Daniel Shahaf <da...@elego.de>.
Philip Martin wrote on Mon, Jun 20, 2011 at 12:01:44 +0100:
> Philip Martin <ph...@wandisco.com> writes:
> 
> > The second commit doesn't wait for the 10 second SQLite busy timeout, it
> > gives the 'database is locked' error immediately.
> >
> > Should we be doing more to support concurrent writes here?  An explicit
> > loop in the post-commit?  A different SQLite configuration?
> 
> A change from 1.6 is that 1.7 uses sqlite for packed revprops.  It turns
> out that the packed revprop database doesn't have this problem because
> access to it is protected by the FSFS repository lock.
> 

Another difference: failed access to revprops.db should be treated as an
error condition, failed access to rep-cache.db should be reported as
"Commit succeeded but post-commit FS processing failed".

> We could change the rep-sharing database access to take the FSFS
> repository lock.  Read access to the database already occurs at a point
> when the lock is held.
> 

Hmm.  Intuitively I wouldn't want sqlite writes to have to take the FSFS
write lock, since I don't want to block commits on them.

But.  SQLite writers block readers, so as long as we write to
rep-cache.db outside the FSFS write lock (with or without retries) we
should ensure we don't start readers that hold the FSFS write lock.

> -- 
> Philip

Re: SQLite locking and FSFS rep-sharing

Posted by Philip Martin <ph...@wandisco.com>.
Philip Martin <ph...@wandisco.com> writes:

> The second commit doesn't wait for the 10 second SQLite busy timeout, it
> gives the 'database is locked' error immediately.
>
> Should we be doing more to support concurrent writes here?  An explicit
> loop in the post-commit?  A different SQLite configuration?

A change from 1.6 is that 1.7 uses sqlite for packed revprops.  It turns
out that the packed revprop database doesn't have this problem because
access to it is protected by the FSFS repository lock.

We could change the rep-sharing database access to take the FSFS
repository lock.  Read access to the database already occurs at a point
when the lock is held.

-- 
Philip

Re: SQLite locking and FSFS rep-sharing

Posted by Philip Martin <ph...@wandisco.com>.
Philip Martin <ph...@wandisco.com> writes:

> The second commit doesn't wait for the 10 second SQLite busy timeout, it
> gives the 'database is locked' error immediately.

r1137660 changed the rep-cache update to optimise for the common case
when the reps are not already present.  It means that most of the time
the update will only use INSERT statements and no SELECT statements.  It
has is an unintended side-effect: it appears to make the SQLITE_BUSY
timeout apply before I see the 'database is locked' error, and if I
release the lock during that timeout the error doesn't get raised.

-- 
Philip