lix/src/libstore
Eelco Dolstra d05bf04444 Treat SQLITE_PROTOCOL as SQLITE_BUSY
In the Hydra build farm we fairly regularly get SQLITE_PROTOCOL errors
(e.g., "querying path in database: locking protocol").  The docs for
this error code say that it "is returned if some other process is
messing with file locks and has violated the file locking protocol
that SQLite uses on its rollback journal files."  However, the SQLite
source code reveals that this error can also occur under high load:

  if( cnt>5 ){
    int nDelay = 1;                      /* Pause time in microseconds */
    if( cnt>100 ){
      VVA_ONLY( pWal->lockError = 1; )
      return SQLITE_PROTOCOL;
    }
    if( cnt>=10 ) nDelay = (cnt-9)*238;  /* Max delay 21ms. Total delay 996ms */
    sqlite3OsSleep(pWal->pVfs, nDelay);
  }

i.e. if certain locks cannot be not acquired, SQLite will retry a
number of times before giving up and returing SQLITE_PROTOCOL.  The
comments say:

  Circumstances that cause a RETRY should only last for the briefest
  instances of time.  No I/O or other system calls are done while the
  locks are held, so the locks should not be held for very long. But
  if we are unlucky, another process that is holding a lock might get
  paged out or take a page-fault that is time-consuming to resolve,
  during the few nanoseconds that it is holding the lock.  In that case,
  it might take longer than normal for the lock to free.
  ...
  The total delay time before giving up is less than 1 second.

On a heavily loaded machine like lucifer (the main Hydra server),
which often has dozens of processes waiting for I/O, it seems to me
that a page fault could easily take more than a second to resolve.
So, let's treat SQLITE_PROTOCOL as SQLITE_BUSY and retry the
transaction.

Issue NixOS/hydra#14.
2013-10-16 14:19:59 +02:00
..
build.cc Only show trace messages when tracing is enabled 2013-09-02 12:01:04 +02:00
derivations.cc Only substitute wanted outputs of a derivation 2012-11-26 17:15:09 +01:00
derivations.hh Only substitute wanted outputs of a derivation 2012-11-26 17:15:09 +01:00
gc.cc Garbage collector: Don't follow symlinks arbitrarily 2013-07-12 14:03:36 +02:00
globals.cc Don't apply the CPU affinity hack to nix-shell (and other Perl programs) 2013-09-06 16:36:56 +02:00
globals.hh Don't apply the CPU affinity hack to nix-shell (and other Perl programs) 2013-09-06 16:36:56 +02:00
local-store.cc Treat SQLITE_PROTOCOL as SQLITE_BUSY 2013-10-16 14:19:59 +02:00
local-store.hh Fix typos, especially those that end up in the Nix manual 2013-08-26 11:15:22 +02:00
Makefile.am Add builtin constants ‘langVersion’ and ‘nixVersion’ 2012-11-27 13:29:55 +01:00
misc.cc Don't substitute derivations that have preferLocalBuild set 2013-06-20 19:26:31 +02:00
misc.hh Don't set $preferLocalBuild and $requiredSystemFeatures in builders 2013-06-20 18:07:27 +00:00
optimise-store.cc Revert "Prevent config.h from being clobbered" 2013-03-08 01:24:59 +01:00
pathlocks.cc Set the close-on-exec flag on file descriptors 2012-03-05 20:29:00 +01:00
pathlocks.hh Use "#pragma once" to prevent repeated header file inclusion 2012-07-18 14:59:03 -04:00
references.cc Use data() instead of c_str() where appropriate 2012-02-09 18:27:45 +01:00
references.hh Use "#pragma once" to prevent repeated header file inclusion 2012-07-18 14:59:03 -04:00
remote-store.cc Don't apply the CPU affinity hack to nix-shell (and other Perl programs) 2013-09-06 16:36:56 +02:00
remote-store.hh nix-store -q --roots: Respect the gc-keep-outputs/gc-keep-derivations settings 2012-12-20 18:41:44 +01:00
schema.sql * Store the size of a store path in the database (to be precise, the 2010-11-16 17:11:46 +00:00
store-api.cc Garbage collector: Don't follow symlinks arbitrarily 2013-07-12 14:03:36 +02:00
store-api.hh nix-store --export: Export paths in topologically sorted order 2013-05-23 14:55:36 -04:00
worker-protocol.hh Run the daemon worker on the same CPU as the client 2013-08-07 14:02:04 +02:00