void
BeesRoots::writeback_thread()
{
+ // Sleep before the first save. At startup the crawlers are not
+ // created yet, so an immediate save has nothing to write.
while (true) {
- catch_all([&]() {
- BEESNOTE("saving crawler state");
- save_point();
- });
-
// Report the deferred-checkpoint backlog for the duration of the
// sleep below. A deep backlog is normal, not a fault: entries are
// released one full hash table sweep after they are queued, and the
}
BEESNOTE("idle, " << pending_count << " checkpoints pending");
- unique_lock<mutex> lock(m_stop_mutex);
- if (m_stop_requested) {
- BEESLOGDEBUG("Stop requested in writeback thread");
- catch_all([&]() {
- BEESNOTE("flushing crawler state");
- save_point();
- });
- return;
+ {
+ unique_lock<mutex> lock(m_stop_mutex);
+ if (!m_stop_requested) {
+ m_stop_condvar.wait_for(lock, chrono::duration<double>(m_checkpoint_interval));
+ }
+ if (m_stop_requested) {
+ BEESLOGDEBUG("Stop requested in writeback thread");
+ catch_all([&]() {
+ BEESNOTE("flushing crawler state");
+ save_point();
+ });
+ return;
+ }
}
- m_stop_condvar.wait_for(lock, chrono::duration<double>(m_checkpoint_interval));
+
+ catch_all([&]() {
+ BEESNOTE("saving crawler state");
+ save_point();
+ });
}
}