Skip to content

Commit

Permalink
server: fix a race condition during server initialization
Browse files Browse the repository at this point in the history
Fixes cockroachdb#91414.
Fixes cockroachdb#101010.
Fixes cockroachdb#100902.

The call to registerEnginesForDiskStatsMap needs to wait until the store
IDs are known.

Release note: None
  • Loading branch information
irfansharif committed Apr 10, 2023
1 parent 71a94e5 commit bde558a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,13 @@ func (s *Server) PreStart(ctx context.Context) error {
// to bypass admission control.
s.storeGrantCoords.SetPebbleMetricsProvider(ctx, s.node, s.node)

// Connect the engines to the disk stats map constructor. This also needs to
// wait until after `waitForAdditionalStoreInit` returns, as the store IDs
// may not be known until then.
if err := s.node.registerEnginesForDiskStatsMap(s.cfg.Stores.Specs, s.engines); err != nil {
return errors.Wrapf(err, "failed to register engines for the disk stats map")
}

// Once all stores are initialized, check if offline storage recovery
// was done prior to start and record any actions appropriately.
logPendingLossOfQuorumRecoveryEvents(ctx, s.node.stores)
Expand Down Expand Up @@ -1648,10 +1655,6 @@ func (s *Server) PreStart(ctx context.Context) error {
return err
}

if err := s.node.registerEnginesForDiskStatsMap(s.cfg.Stores.Specs, s.engines); err != nil {
return errors.Wrapf(err, "failed to register engines for the disk stats map")
}

if err := s.debug.RegisterEngines(s.cfg.Stores.Specs, s.engines); err != nil {
return errors.Wrapf(err, "failed to register engines with debug server")
}
Expand Down

0 comments on commit bde558a

Please sign in to comment.