@@ -38,6 +38,7 @@ import (
3838 "github.com/cockroachdb/cockroach/pkg/security/clientsecopts"
3939 "github.com/cockroachdb/cockroach/pkg/security/username"
4040 "github.com/cockroachdb/cockroach/pkg/server"
41+ "github.com/cockroachdb/cockroach/pkg/server/serverctl"
4142 "github.com/cockroachdb/cockroach/pkg/server/status"
4243 "github.com/cockroachdb/cockroach/pkg/settings"
4344 "github.com/cockroachdb/cockroach/pkg/settings/cluster"
@@ -312,45 +313,7 @@ func initTempStorageConfig(
312313 return tempStorageConfig , nil
313314}
314315
315- type newServerFn func (ctx context.Context , serverCfg server.Config , stopper * stop.Stopper ) (serverStartupInterface , error )
316-
317- type serverStartupInterface interface {
318- serverShutdownInterface
319-
320- // ClusterSettings retrieves this server's settings.
321- ClusterSettings () * cluster.Settings
322-
323- // LogicalClusterID retrieves this server's logical cluster ID.
324- LogicalClusterID () uuid.UUID
325-
326- // PreStart starts the server on the specified port(s) and
327- // initializes subsystems.
328- // It does not activate the pgwire listener over the network / unix
329- // socket, which is done by the AcceptClients() method. The separation
330- // between the two exists so that SQL initialization can take place
331- // before the first client is accepted.
332- PreStart (ctx context.Context ) error
333-
334- // AcceptClients starts listening for incoming SQL clients over the network.
335- AcceptClients (ctx context.Context ) error
336- // AcceptInternalClients starts listening for incoming internal SQL clients over the
337- // loopback interface.
338- AcceptInternalClients (ctx context.Context ) error
339-
340- // InitialStart returns whether this node is starting for the first time.
341- // This is (currently) used when displaying the server status report
342- // on the terminal & in logs. We know that some folk have automation
343- // that depend on certain strings displayed from this when orchestrating
344- // KV-only nodes.
345- InitialStart () bool
346-
347- // RunInitialSQL runs the SQL initialization for brand new clusters,
348- // if the cluster is being started for the first time.
349- // The arguments are:
350- // - startSingleNode is used by 'demo' and 'start-single-node'.
351- // - adminUser/adminPassword is used for 'demo'.
352- RunInitialSQL (ctx context.Context , startSingleNode bool , adminUser , adminPassword string ) error
353- }
316+ type newServerFn func (ctx context.Context , serverCfg server.Config , stopper * stop.Stopper ) (serverctl.ServerStartupInterface , error )
354317
355318var errCannotUseJoin = errors .New ("cannot use --join with 'cockroach start-single-node' -- use 'cockroach start' instead" )
356319
@@ -398,9 +361,9 @@ func runStartJoin(cmd *cobra.Command, args []string) error {
398361func runStart (cmd * cobra.Command , args []string , startSingleNode bool ) error {
399362 const serverType redact.SafeString = "node"
400363
401- newServerFn := func (_ context.Context , serverCfg server.Config , stopper * stop.Stopper ) (serverStartupInterface , error ) {
364+ newServerFn := func (_ context.Context , serverCfg server.Config , stopper * stop.Stopper ) (serverctl. ServerStartupInterface , error ) {
402365 // Beware of not writing simply 'return server.NewServer()'. This is
403- // because it would cause the serverStartupInterface reference to
366+ // because it would cause the serverctl.ServerStartupInterface reference to
404367 // always be non-nil, even if NewServer returns a nil pointer (and
405368 // an error). The code below is dependent on the interface
406369 // reference remaining nil in case of error.
@@ -757,10 +720,10 @@ func createAndStartServerAsync(
757720 newServerFn newServerFn ,
758721 startSingleNode bool ,
759722 serverType redact.SafeString ,
760- ) (srvStatus * serverStatus , serverShutdownReqC <- chan server .ShutdownRequest ) {
723+ ) (srvStatus * serverStatus , serverShutdownReqC <- chan serverctl .ShutdownRequest ) {
761724 var serverStatusMu serverStatus
762- var s serverStartupInterface
763- shutdownReqC := make (chan server .ShutdownRequest , 1 )
725+ var s serverctl. ServerStartupInterface
726+ shutdownReqC := make (chan serverctl .ShutdownRequest , 1 )
764727
765728 log .Ops .Infof (ctx , "starting cockroach %s" , serverType )
766729
@@ -851,8 +814,8 @@ func createAndStartServerAsync(
851814 return reportServerInfo (ctx , tBegin , serverCfg , s .ClusterSettings (),
852815 serverType , s .InitialStart (), s .LogicalClusterID ())
853816 }(); err != nil {
854- shutdownReqC <- server .MakeShutdownRequest (
855- server .ShutdownReasonServerStartupError , errors .Wrapf (err , "server startup failed" ))
817+ shutdownReqC <- serverctl .MakeShutdownRequest (
818+ serverctl .ShutdownReasonServerStartupError , errors .Wrapf (err , "server startup failed" ))
856819 } else {
857820 // Start a goroutine that watches for shutdown requests and notifies
858821 // errChan.
@@ -885,7 +848,7 @@ type serverStatus struct {
885848 // s is a reference to the server, to be used by the shutdown process. This
886849 // starts as nil, and is set by setStarted(). Once set, a graceful shutdown
887850 // should use a soft drain.
888- s serverShutdownInterface
851+ s serverctl. ServerShutdownInterface
889852 // stopper is the server's stopper. This is set in setStarted(), together with
890853 // `s`. The stopper is handed out to callers of startShutdown(), who will
891854 // Stop() it.
@@ -904,7 +867,9 @@ type serverStatus struct {
904867// setStarted returns whether shutdown has been requested already. If it has,
905868// then the serverStatus does not take ownership of the stopper; the caller is
906869// responsible for calling stopper.Stop().
907- func (s * serverStatus ) setStarted (server serverShutdownInterface , stopper * stop.Stopper ) bool {
870+ func (s * serverStatus ) setStarted (
871+ server serverctl.ServerShutdownInterface , stopper * stop.Stopper ,
872+ ) bool {
908873 s .Lock ()
909874 defer s .Unlock ()
910875 if s .shutdownRequested {
@@ -927,21 +892,13 @@ func (s *serverStatus) shutdownInProgress() bool {
927892// was started already. If the server started, a reference to the server is also
928893// returned, and a reference to the stopper that the caller needs to eventually
929894// Stop().
930- func (s * serverStatus ) startShutdown () (bool , serverShutdownInterface , * stop.Stopper ) {
895+ func (s * serverStatus ) startShutdown () (bool , serverctl. ServerShutdownInterface , * stop.Stopper ) {
931896 s .Lock ()
932897 defer s .Unlock ()
933898 s .shutdownRequested = true
934899 return s .s != nil , s .s , s .stopper
935900}
936901
937- // serverShutdownInterface is the subset of the APIs on a server
938- // object that's sufficient to run a server shutdown.
939- type serverShutdownInterface interface {
940- AnnotateCtx (context.Context ) context.Context
941- Drain (ctx context.Context , verbose bool ) (uint64 , redact.RedactableString , error )
942- ShutdownRequested () <- chan server.ShutdownRequest
943- }
944-
945902// waitForShutdown blocks until interrupted by a shutdown signal, which can come
946903// in several forms:
947904// - a shutdown request coming from an internal module being signaled on
@@ -953,7 +910,7 @@ type serverShutdownInterface interface {
953910// before shutting down.
954911func waitForShutdown (
955912 stopper * stop.Stopper ,
956- shutdownC <- chan server .ShutdownRequest ,
913+ shutdownC <- chan serverctl .ShutdownRequest ,
957914 signalCh <- chan os.Signal ,
958915 serverStatusMu * serverStatus ,
959916) (returnErr error ) {
@@ -966,7 +923,7 @@ func waitForShutdown(
966923 case shutdownRequest := <- shutdownC :
967924 returnErr = shutdownRequest .ShutdownCause ()
968925 // There's no point in draining if the server didn't even fully start.
969- drain := shutdownRequest .Reason != server .ShutdownReasonServerStartupError
926+ drain := shutdownRequest .Reason != serverctl .ShutdownReasonServerStartupError
970927 startShutdownAsync (serverStatusMu , stopWithoutDrain , drain )
971928
972929 case sig := <- signalCh :
0 commit comments