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

Code before:
	return walStore, nil
}

// startRaftLogVerifier launches a goroutine that periodically verifies the raft
// log store (when the configured store supports verification). It will run
// until the server shutdown context is done. Verification is best-effort: any
// error is logged; the verifier keeps running on the next interval.
func (s *Server) startRaftLogVerifier() {
	// Guard against calling before s.shutdownCtx is initialized
	if s.shutdownCtx == nil {
		return
	}

	interval := 5 * time.Minute
	if s.config.RaftLogStoreConfig != nil && s.config.RaftLogStoreConfig.VerificationInterval > 0 {
		interval = s.config.RaftLogStoreConfig.VerificationInterval
	}
	// Run as a background goroutine
	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
	}

Review comment (suggestion):
We probably don't need to emit this log every time the agent shuts down. It doesn't really tell the user anything useful.

Code after:
	return walStore, nil
}

// startRaftLogVerifier launches a goroutine that periodically verifies the raft
// log store (when the configured store supports verification). It will run
// until the server shutdown context is done. Verification is best-effort: any
// error is logged; the verifier keeps running on the next interval.
func (s *Server) startRaftLogVerifier() {
	// Guard against calling before s.shutdownCtx is initialized
	if s.shutdownCtx == nil {
		return
	}

	interval := 5 * time.Minute
	if s.config.RaftLogStoreConfig != nil && s.config.RaftLogStoreConfig.VerificationInterval > 0 {
		interval = s.config.RaftLogStoreConfig.VerificationInterval
	}
	// Run as a background goroutine
	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
	}