From c931a7aec5ccb2209d3c4bcf4452c807fe894d94 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 17 Dec 2010 17:23:15 +0000 Subject: * Do a short sleep after SQLITE_BUSY. --- configure.ac | 3 +-- src/libstore/local-store.cc | 11 +++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 2a8bedb0d1f6..46e825899c79 100644 --- a/configure.ac +++ b/configure.ac @@ -286,8 +286,7 @@ AC_CHECK_FUNCS([setresuid setreuid lchown]) # Nice to have, but not essential. -AC_CHECK_FUNCS([strsignal]) -AC_CHECK_FUNCS([posix_fallocate]) +AC_CHECK_FUNCS([strsignal posix_fallocate nanosleep]) # This is needed if ATerm or bzip2 are static libraries, diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 56d05c7bb55c..6af34cc77814 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -35,6 +36,16 @@ static void throwSQLiteError(sqlite3 * db, const format & f) int err = sqlite3_errcode(db); if (err == SQLITE_BUSY) { printMsg(lvlError, "warning: SQLite database is busy"); + /* Sleep for a while since retrying the transaction right away + is likely to fail again. */ +#if HAVE_NANOSLEEP + struct timespec t; + t.tv_sec = 0; + t.tv_nsec = 100 * 1000 * 1000; /* 0.1s */ + nanosleep(&t, 0); +#else + sleep(1); +#endif throw SQLiteBusy(format("%1%: %2%") % f.str() % sqlite3_errmsg(db)); } else -- cgit 1.4.1