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

Code before:
	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")
		}
		s.logger.Debug("raft logstore verifier: WAL store verification",
			"first_index", first,
			"last_index", last,
			"is_monotonic", isMonotonic)

	default:
		s.logger.Debug("raft logstore verifier: store is accessible",
			"first_index", first,
			"last_index", last,
			"type", fmt.Sprintf("%T", s.raftStore))
	}
}

// checkRaftVersionFile reads the Raft version file and returns an error if
// the Raft version is incompatible with the current version configured.
// Provide best-effort check if the file cannot be read.
func (s *Server) checkRaftVersionFile(path string) error {
	raftVersion := s.config.RaftConfig.ProtocolVersion
	baseWarning := "use the 'nomad operator raft list-peers' command to make sure the Raft protocol versions are consistent"

	_, err := os.Stat(path)
	if err != nil {
		if os.IsNotExist(err) {
			return nil
		}

		s.logger.Warn(fmt.Sprintf("unable to read Raft version file, %s", baseWarning), "error", err)

Review comment (suggestion):
This should be unreachable, right? If it were hit that seems like an error condition.

Code after:
	// 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")
		}
		s.logger.Debug("raft logstore verifier: WAL store verification",
			"first_index", first,
			"last_index", last,
			"is_monotonic", isMonotonic)

	default:
		s.logger.Error("raft logstore verifier: unknown store type")
	}
}

// checkRaftVersionFile reads the Raft version file and returns an error if
// the Raft version is incompatible with the current version configured.
// Provide best-effort check if the file cannot be read.
func (s *Server) checkRaftVersionFile(path string) error {
	raftVersion := s.config.RaftConfig.ProtocolVersion
	baseWarning := "use the 'nomad operator raft list-peers' command to make sure the Raft protocol versions are consistent"

	_, err := os.Stat(path)
	if err != nil {
		if os.IsNotExist(err) {
			return nil
		}

		s.logger.Warn(fmt.Sprintf("unable to read Raft version file, %s", baseWarning), "error", err)
		return nil
	}

	v, err := os.ReadFile(path)
	if err != nil {
		s.logger.Warn(fmt.Sprintf("unable to read Raft version file, %s", baseWarning), "error", err)
		return nil
	}