1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-01-17 14:07:03 +01:00
Neal H. Walfield 7a634e48b1 g10: Avoid gratuitious SQLite aborts and starving writers.
* g10/tofu.c: Include <time.h>, <utime.h>, <fcntl.h> and <unistd.h>.
(tofu_dbs_s): Add fields want_lock_file and want_lock_file_ctime.
(begin_transaction): Only yield if DBS->WANT_LOCK_FILE_CTIME has
changed since we took the lock.  Don't use gpgrt_yield to yield, but
sleep for 100ms.  After taking the batch lock, update
DBS->WANT_LOCK_FILE_CTIME.  Also take the batch lock the first time we
take the real lock.  When taking the real lock, use immediate not
deferred mode to avoid gratuitious aborts.
(end_transaction): When dropping the outermost real lock, drop the
batch lock.
(busy_handler): New function.
(opendbs): Set the busy handler to it when opening the DB.  Initialize
CTRL->TOFU.DBS->WANT_LOCK_FILE.
(tofu_closedbs): Free DBS->WANT_LOCK_FILE.

--
Signed-off-by: Neal H. Walfield <neal@g10code.com>

By default, SQLite defers transactions until they are actually needed.
A consequence of this is that if we have two readers and both decide
to do a write, then one has to abort.  To avoid this problem, we can
make the outermost transaction an immediate transaction.  This has the
disadvantage that we only allow a single reader at a time, but at
least we don't have gratuitous aborts anymore.

A second problem is that SQLite apparently doesn't actually create a
queue of waiters.  The result is that doing a sched_yield between
dropping and retaking the batch transaction is not enough to allow the
other process to make progress.  Instead, we need to wait a
while (emperically: 100ms seems reasonable).  To avoid waiting when
there is no contention, we use a new file's timestamp to signal that
there is a waiter.
2016-10-30 19:10:42 -07:00
..
2016-09-17 16:00:37 +09:00
2016-10-20 13:30:47 +09:00
2016-06-30 18:50:16 +02:00
2016-10-21 12:04:46 +09:00
2016-02-14 14:46:30 +01:00
2014-10-31 14:21:34 +01:00
2016-10-27 13:04:45 +09:00
2007-07-04 19:49:40 +00:00
2016-09-05 09:52:04 +02:00
2014-11-13 12:01:42 +01:00
2015-02-04 09:15:34 +01:00
2016-10-07 07:54:38 +02:00
2015-02-04 09:15:34 +01:00
2016-09-10 13:42:09 -04:00
2016-10-27 14:59:56 +02:00
2016-10-24 13:12:05 +02:00
2016-10-21 12:04:46 +09:00
2016-01-22 10:54:10 +01:00
2016-10-21 12:04:46 +09:00
2016-10-27 14:59:56 +02:00
2016-07-13 13:31:12 +02:00
2016-08-11 21:32:55 +02:00
2016-06-30 11:45:13 +02:00
2008-12-12 08:54:50 +00:00
2016-08-18 10:08:34 +02:00
2016-06-28 18:21:50 +02:00
2016-06-28 18:21:50 +02:00
2016-03-08 14:08:49 +01:00
2016-07-01 09:47:48 +02:00
2016-08-10 16:50:29 +02:00
2016-05-03 11:26:06 +02:00
2016-06-30 18:50:16 +02:00
2016-09-15 14:46:06 +02:00
2014-01-29 17:45:05 +01:00