Merge "libstore: make SQLite busy back-off logic portable" into main

This commit is contained in:
Lily Ballard
2025-02-06 04:45:30 +00:00
committed by Gerrit Code Review
+5 -6
View File
@@ -5,9 +5,10 @@
#include "lix/libutil/signals.hh"
#include "lix/libutil/url.hh"
#include <random>
#include <sqlite3.h>
#include <random>
#include <thread>
namespace nix {
@@ -284,12 +285,10 @@ void handleSQLiteBusy(const SQLiteBusy & e, time_t & nextWarning)
/* Sleep for a while since retrying the transaction right away
is likely to fail again. */
checkInterrupt();
static thread_local std::default_random_engine generator(clock());
static thread_local std::default_random_engine generator(std::random_device{}());
std::uniform_int_distribution<long> uniform_dist(0, 100);
struct timespec t;
t.tv_sec = 0;
t.tv_nsec = uniform_dist(generator) * 1000 * 1000; /* <= 0.1s */
nanosleep(&t, 0);
/* <= 0.1s */
std::this_thread::sleep_for(std::chrono::milliseconds { uniform_dist(generator) });
}
}