Skip to content

Commit

Permalink
Delay the monitorStorageVersion goroutine until the server is fully r…
Browse files Browse the repository at this point in the history
…eady

Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Dec 11, 2024
1 parent 3cf550d commit 06e7fba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion server/embed/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package embed

import (
"context"
"errors"
"fmt"
"io"
defaultLog "log"
Expand Down Expand Up @@ -100,7 +101,12 @@ func (sctx *serveCtx) serve(
gopts ...grpc.ServerOption,
) (err error) {
logger := defaultLog.New(io.Discard, "etcdhttp", 0)
<-s.ReadyNotify()

select {
case <-s.StoppingNotify():
return errors.New("server is stopping")

Check warning on line 107 in server/embed/serve.go

View check run for this annotation

Codecov / codecov/patch

server/embed/serve.go#L106-L107

Added lines #L106 - L107 were not covered by tests
case <-s.ReadyNotify():
}

sctx.lg.Info("ready to serve client requests")

Expand Down
15 changes: 15 additions & 0 deletions server/etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,21 @@ func (s *EtcdServer) monitorClusterVersions() {
func (s *EtcdServer) monitorStorageVersion() {
lg := s.Logger()
monitor := serverversion.NewMonitor(lg, NewServerVersionAdapter(s))

// The field "storageVersion" in Meta bucket was introduced in 3.6.
// It doesn't exist in 3.5 and older versions. We depend on fields
// "confState" and "term" to identify 3.5, as the two fields were
// introduced in 3.5.
// But the field "confState" is only guaranteed to be populated
// after the member fully bootstraps itself. So we need to wait
// for the etcdserver ready for serve client requests here.
select {
case <-s.StoppingNotify():
return
case <-s.ReadyNotify():
}
lg.Info("monitorStorageVersion: start running")

for {
select {
case <-time.After(monitorVersionInterval):
Expand Down

0 comments on commit 06e7fba

Please sign in to comment.