Repository: hashicorp/nomad
File: nomad/server.go (Go)

Code before:
	go func() {
		t := time.NewTicker(interval)
		defer t.Stop()
		s.logger.Info("starting raft logstore verifier", "interval", interval)
		for {
			select {
			case <-s.shutdownCtx.Done():
				s.logger.Info("stopping raft logstore verifier")
				return
			case <-t.C:
				s.verifyRaftStore()
			}
		}
	}()
}

// verifyRaftStore performs health checks on the configured raft store. For
// BoltDB stores, it collects database statistics including transaction counts
// and page information. For WAL stores, it verifies that log indices are
// monotonically increasing. This is called periodically by
// startRaftLogVerifier.
func (s *Server) verifyRaftStore() {
	if s.raftStore == nil {
		s.logger.Debug("raft logstore verifier: no raft store available yet")
		return
	}

	// Perform basic health check by verifying we can read index information
	first, err := s.raftStore.FirstIndex()
	if err != nil {
		s.logger.Error("raft logstore verifier: failed to get first index", "error", err)
		return
	}

	last, err := s.raftStore.LastIndex()
	if err != nil {
		s.logger.Error("raft logstore verifier: failed to get last index", "error", err)
		return
	}

	// Perform store-specific verification
	switch store := s.raftStore.(type) {
	case *raftboltdb.BoltStore:
		// Get BoltDB statistics for health monitoring
		stats := store.Stats()
		s.logger.Debug("raft logstore verifier: BoltDB store verification",
			"first_index", first,
			"last_index", last,
			"open_tx", stats.OpenTxN,
			"free_pages", stats.FreePageN,
			"pending_pages", stats.PendingPageN)

Review comment (bug):
This block seems "off": the log line suggests that maybe the calling goroutine might set `s.raftStore` concurrently and that we just haven't done it yet. Which would be a data race. But as far as I can tell from the caller, this will _always_ be non-nil because we set it before we ever start the verifier loop. If we're doing a belt-and-suspenders nil-check here that's fine, but if we were to hit it that seems like a error-level log.

Code after:
	go func() {
		t := time.NewTicker(interval)
		defer t.Stop()
		s.logger.Info("starting raft logstore verifier", "interval", interval)
		for {
			select {
			case <-s.shutdownCtx.Done():
				return
			case <-t.C:
				s.verifyRaftStore()
			}
		}
	}()
}

// verifyRaftStore performs health checks on the configured raft store. For
// BoltDB stores, it collects database statistics including transaction counts
// and page information. For WAL stores, it verifies that log indices are
// monotonically increasing. This is called periodically by
// startRaftLogVerifier.
func (s *Server) verifyRaftStore() {
	// Perform basic health check by verifying we can read index information
	first, err := s.raftStore.FirstIndex()
	if err != nil {
		s.logger.Error("raft logstore verifier: failed to get first index", "error", err)
		return
	}

	last, err := s.raftStore.LastIndex()
	if err != nil {
		s.logger.Error("raft logstore verifier: failed to get last index", "error", err)
		return
	}

	// Perform store-specific verification
	switch store := s.raftStore.(type) {
	case *raftboltdb.BoltStore:
		// Get BoltDB statistics for health monitoring
		stats := store.Stats()
		s.logger.Debug("raft logstore verifier: BoltDB store verification",
			"first_index", first,
			"last_index", last,
			"open_tx", stats.OpenTxN,
			"free_pages", stats.FreePageN,
			"pending_pages", stats.PendingPageN)

	case *raftwal.WAL:
		// Check if WAL indices are monotonic
		isMonotonic := store.IsMonotonic()
		if !isMonotonic {
			s.logger.Warn("raft logstore verifier: WAL indices are not monotonic")