]> git.hungrycats.org Git - bees/commitdiff
checkpoint: trace deferred checkpoint queue lifecycle
authorZygo Blaxell <bees@furryterror.org>
Sat, 25 Jul 2026 01:19:28 +0000 (21:19 -0400)
committerZygo Blaxell <bees@furryterror.org>
Tue, 6 Oct 2026 05:51:40 +0000 (01:51 -0400)
When state.point.defer=yes, the existing "Saving beespoint.ini" /
"Nothing to save" / "Saved beespoint.ini in Xs" lines say nothing about
whether the deferred checkpoint queue is actually draining as the hash
table writeback catches up.

Give each PendingCheckpoint a monotonic sequence number and a Timer
stamped at enqueue, then log every queue transition with a "checkpoint"
prefix so the lines are greppable regardless of which thread runs the
flush (writeback thread or the shutdown flush):

  checkpoint queued #57 age 0s writeback 12345      enqueued in snapshot_point()
  checkpoint discarded #14 age 500s writeback 12290 superseded by a later entry
  checkpoint wrote #19 age 480s writeback 12301     durable on disk (peek-then-pop)
  checkpoint dequeued #12 age 512s writeback 12280  obligation removed from the queue

The age is the beespoint data's age since it was captured, so "wrote"
directly reports how stale the checkpoint was when it reached disk. The
seq lets a discarded entry be matched to the queued line it superseded.
The writeback count is the hash table's writeback_extent_count() at
capture time; it gates eligibility (a checkpoint writes once writeback
laps a full extent_count() past it) and correlates each line with the
hash table's own writeback progress.

Assisted-by: Claude-Code:claude-opus-4-8
Signed-off-by: Zygo Blaxell <bees@furryterror.org>
src/bees-roots.cc
src/bees.h

index 3325af47fd3aa6d89d8fb3320e8e8e8df04a4bd1..93125bfed8eac130cd80305631fb134de03bf407 100644 (file)
@@ -1854,8 +1854,10 @@ BeesRoots::snapshot_point()
        } else {
                // Deferred write: enqueue with current writeback counter.
                const auto wc = m_ctx->hash_table()->writeback_extent_count();
-               m_pending_checkpoints.push_back({ wc, ini_string });
+               const auto seq = m_next_checkpoint_seq++;
+               m_pending_checkpoints.push_back({ wc, seq, Timer(), ini_string });
                m_crawl_clean = crawl_saved;
+               BEESLOGINFO("checkpoint queued #" << seq << " age " << static_cast<uint64_t>(m_pending_checkpoints.back().queued.age()) << "s writeback " << wc);
        }
 }
 
@@ -1864,6 +1866,9 @@ BeesRoots::flush_pending_checkpoints(bool force)
 {
        while (true) {
                string write_ini;
+               uint64_t write_seq = 0;
+               uint64_t write_wbcount = 0;
+               Timer    write_queued;
                {
                        unique_lock<mutex> lock(m_mutex);
                        if (m_pending_checkpoints.empty()) return;
@@ -1880,6 +1885,8 @@ BeesRoots::flush_pending_checkpoints(bool force)
                                if (!force && writeback_now - second.writeback_count < extent_count) {
                                        break;
                                }
+                               const auto &dropped = m_pending_checkpoints.front();
+                               BEESLOGINFO("checkpoint discarded #" << dropped.seq << " age " << static_cast<uint64_t>(dropped.queued.age()) << "s writeback " << dropped.writeback_count);
                                m_pending_checkpoints.pop_front();
                        }
 
@@ -1895,19 +1902,24 @@ BeesRoots::flush_pending_checkpoints(bool force)
                        // been enqueued meanwhile, the next coalesce iteration discards
                        // this one in favour of the newer one.  Either way the queue
                        // holds the obligation until a write succeeds.
-                       write_ini = front.ini_string;
+                       write_ini     = front.ini_string;
+                       write_seq     = front.seq;
+                       write_wbcount = front.writeback_count;
+                       write_queued  = front.queued;
                }
 
                m_point_file.write(write_ini);  // slow I/O outside the lock; may throw
+               BEESLOGINFO("checkpoint wrote #" << write_seq << " age " << static_cast<uint64_t>(write_queued.age()) << "s writeback " << write_wbcount);
 
                // Write succeeded.  Pop the entry we just wrote.  The front is still
                // that entry because flush_pending_checkpoints is single-consumer
-               // (the writeback thread, REPL save-state, and the shutdown flush do
-               // not overlap), and snapshot_point() only ever appends to the tail.
+               // (the writeback thread and the shutdown flush do not
+               // overlap), and snapshot_point() only ever appends to the tail.
                {
                        unique_lock<mutex> lock(m_mutex);
                        m_pending_checkpoints.pop_front();
                }
+               BEESLOGINFO("checkpoint dequeued #" << write_seq << " age " << static_cast<uint64_t>(write_queued.age()) << "s writeback " << write_wbcount);
                // loop: more entries may now be eligible, or newer ones have arrived
        }
 }
index c91847f43d73c21b5f949a2330cf0cc7573b34fd..fc37bf632995cc491f24af45f36c021461726ca7 100644 (file)
@@ -1010,9 +1010,12 @@ class BeesRoots : public enable_shared_from_this<BeesRoots> {
        /// A checkpoint snapshot waiting to be written to disk.
        struct PendingCheckpoint {
                uint64_t writeback_count;  ///< m_hash_table->writeback_extent_count() at snapshot time.
+               uint64_t seq;              ///< Sequence number for correlating state-writeback log lines.
+               Timer    queued;           ///< Started at enqueue; age() is the data's age when written or discarded.
                string   ini_string;       ///< Serialised beespoint.ini content.
        };
-       deque<PendingCheckpoint>        m_pending_checkpoints;   ///< Queue of deferred checkpoints.
+       deque<PendingCheckpoint>        m_pending_checkpoints;      ///< Queue of deferred checkpoints.
+       uint64_t                        m_next_checkpoint_seq = 0;  ///< Next sequence number to assign to a deferred checkpoint.
 
        vector<shared_ptr<BeesScanMode>>        m_scanners;  ///< Active scan-mode strategy objects.