You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.6 KiB

  1. package weed_server
  2. import (
  3. "github.com/cenkalti/backoff/v4"
  4. "github.com/seaweedfs/seaweedfs/weed/glog"
  5. "github.com/seaweedfs/seaweedfs/weed/pb"
  6. "github.com/seaweedfs/seaweedfs/weed/storage/needle"
  7. "net/http"
  8. "time"
  9. )
  10. type ClusterStatusResult struct {
  11. IsLeader bool `json:"IsLeader,omitempty"`
  12. Leader pb.ServerAddress `json:"Leader,omitempty"`
  13. Peers []string `json:"Peers,omitempty"`
  14. MaxVolumeId needle.VolumeId `json:"MaxVolumeId,omitempty"`
  15. }
  16. func (s *RaftServer) StatusHandler(w http.ResponseWriter, r *http.Request) {
  17. ret := ClusterStatusResult{
  18. IsLeader: s.topo.IsLeader(),
  19. Peers: s.Peers(),
  20. MaxVolumeId: s.topo.GetMaxVolumeId(),
  21. }
  22. if leader, e := s.topo.Leader(); e == nil {
  23. ret.Leader = leader
  24. }
  25. writeJsonQuiet(w, r, http.StatusOK, ret)
  26. }
  27. func (s *RaftServer) HealthzHandler(w http.ResponseWriter, r *http.Request) {
  28. leader, err := s.topo.Leader()
  29. if err != nil {
  30. w.WriteHeader(http.StatusServiceUnavailable)
  31. return
  32. }
  33. if s.serverAddr == leader {
  34. expBackoff := backoff.NewExponentialBackOff()
  35. expBackoff.InitialInterval = 20 * time.Millisecond
  36. expBackoff.MaxInterval = 1 * time.Second
  37. expBackoff.MaxElapsedTime = 5 * time.Second
  38. isLocked, err := backoff.RetryWithData(s.topo.IsChildLocked, expBackoff)
  39. glog.Errorf("HealthzHandler: %+v", err)
  40. if isLocked {
  41. w.WriteHeader(http.StatusLocked)
  42. return
  43. }
  44. }
  45. w.WriteHeader(http.StatusOK)
  46. }
  47. func (s *RaftServer) StatsRaftHandler(w http.ResponseWriter, r *http.Request) {
  48. if s.RaftHashicorp == nil {
  49. writeJsonQuiet(w, r, http.StatusNotFound, nil)
  50. return
  51. }
  52. writeJsonQuiet(w, r, http.StatusOK, s.RaftHashicorp.Stats())
  53. }