Skip to content

Commit

Permalink
server: create engines in NewServer
Browse files Browse the repository at this point in the history
We were jumping through a number of hoops to create the engines only in
`(*Server).Start` since that seems to be the "idiomatic" place to start
moving parts. However, it creates a lot of complexity since various
callbacks have to be registered with access to engines. Move engine
creation to `NewServer`.

This unblocks #54936.

Release note: None
  • Loading branch information
tbg authored and jayshrivastava committed Oct 8, 2020
1 parent cd2ce9d commit bbdb9ca
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ type Server struct {
mux http.ServeMux
clock *hlc.Clock
rpcContext *rpc.Context
engines Engines
// The gRPC server on which the different RPC handlers will be registered.
grpc *grpcServer
gossip *gossip.Gossip
Expand Down Expand Up @@ -158,9 +159,7 @@ type Server struct {
externalStorageBuilder *externalStorageBuilder

// The following fields are populated at start time, i.e. in `(*Server).Start`.

startTime time.Time
engines Engines
}

// externalStorageBuilder is a wrapper around the ExternalStorage factory
Expand Down Expand Up @@ -597,12 +596,19 @@ func NewServer(cfg Config, stopper *stop.Stopper) (*Server, error) {
debugServer := debug.NewServer(st, sqlServer.pgServer.HBADebugFn())
node.InitLogger(sqlServer.execCfg)

engines, err := cfg.CreateEngines(ctx)
if err != nil {
return nil, errors.Wrap(err, "failed to create engines")
}
stopper.AddCloser(&engines)

*lateBoundServer = Server{
nodeIDContainer: nodeIDContainer,
cfg: cfg,
st: st,
clock: clock,
rpcContext: rpcContext,
engines: engines,
grpc: grpcServer,
gossip: g,
nodeDialer: nodeDialer,
Expand Down Expand Up @@ -1048,12 +1054,6 @@ func (s *Server) PreStart(ctx context.Context) error {
return err
}

s.engines, err = s.cfg.CreateEngines(ctx)
if err != nil {
return errors.Wrap(err, "failed to create engines")
}
s.stopper.AddCloser(&s.engines)

// Initialize the external storage builders configuration params now that the
// engines have been created. The object can be used to create ExternalStorage
// objects hereafter.
Expand Down

0 comments on commit bbdb9ca

Please sign in to comment.