1
0
Fork 0

Hook in commit flag to /readyz

master
Philip O'Toole 7 months ago
parent 0c2ac1ca3c
commit 45f0ca7414

@ -76,6 +76,10 @@ type Store interface {
// Ready returns whether the Store is ready to service requests.
Ready() bool
// Committed blocks until the local commit index is greater than or
// equal to the Leader index, as checked when the function is called.
Committed(timeout time.Duration) (uint64, error)
// Stats returns stats on the Store.
Stats() (map[string]interface{}, error)
@ -1003,8 +1007,17 @@ func (s *Service) handleReadyz(w http.ResponseWriter, r *http.Request, qp QueryP
return
}
okMsg := "[+]node ok\n[+]leader ok\n[+]store ok"
if qp.Commit() {
if _, err := s.store.Committed(qp.Timeout(defaultTimeout)); err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
w.Write([]byte(fmt.Sprintf("[+]node ok\n[+]leader ok\n[+]store ok\n[+]commit %s", err.Error())))
return
}
okMsg += "\n[+]commit ok"
}
w.WriteHeader(http.StatusOK)
w.Write([]byte("[+]node ok\n[+]leader ok\n[+]store ok"))
w.Write([]byte(okMsg))
}
func (s *Service) handleExecute(w http.ResponseWriter, r *http.Request, qp QueryParams) {

@ -1419,6 +1419,10 @@ func (m *MockStore) Ready() bool {
return !m.notReady
}
func (m *MockStore) Committed(timeout time.Duration) (uint64, error) {
return 0, nil
}
func (m *MockStore) Stats() (map[string]interface{}, error) {
return nil, nil
}

@ -633,6 +633,17 @@ func (s *Store) Ready() bool {
}()
}
// Committed blocks until the local commit index is greater than or
// equal to the Leader index, as checked when the function is called.
// It returns the committed index.
func (s *Store) Committed(timeout time.Duration) (uint64, error) {
lci, err := s.LeaderCommitIndex()
if err != nil {
return lci, err
}
return lci, s.WaitForCommitIndex(lci, timeout)
}
// Close closes the store. If wait is true, waits for a graceful shutdown.
func (s *Store) Close(wait bool) (retErr error) {
defer func() {

Loading…
Cancel
Save