Skip to content

Commit

Permalink
* Do a short sleep after SQLITE_BUSY.
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Dec 17, 2010
1 parent b1eb252 commit c931a7a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 1 addition & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <time.h>

#include <sqlite3.h>

Expand All @@ -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
Expand Down

0 comments on commit c931a7a

Please sign in to comment.