restart: Use health check instead of service info API (#4190)

`mc admin service restart` currently uses ServerInfo() API which is costly.
This commit is contained in:
Anis Elleuch
2022-08-08 09:32:27 -07:00
committed by GitHub
parent de706ef096
commit d43c25ffa3
+17 -9
View File
@@ -106,6 +106,9 @@ func mainAdminServiceRestart(ctx *cli.Context) error {
// Validate serivce restart syntax.
checkAdminServiceRestartSyntax(ctx)
ctxt, cancel := context.WithCancel(globalContext)
defer cancel()
// Set color.
console.SetColor("ServiceOffline", color.New(color.FgRed, color.Bold))
console.SetColor("ServiceInitializing", color.New(color.FgYellow, color.Bold))
@@ -120,11 +123,16 @@ func mainAdminServiceRestart(ctx *cli.Context) error {
fatalIf(err, "Unable to initialize admin connection.")
// Restart the specified MinIO server
fatalIf(probe.NewError(client.ServiceRestart(globalContext)), "Unable to restart the server.")
fatalIf(probe.NewError(client.ServiceRestart(ctxt)), "Unable to restart the server.")
// Success..
printMsg(serviceRestartCommand{Status: "success", ServerURL: aliasedURL})
// Start pinging the service until it is ready
anonClient, err := newAnonymousClient(aliasedURL)
fatalIf(err.Trace(aliasedURL), "Could not ping `"+aliasedURL+"`.")
coloring := color.New(color.FgRed)
mark := "..."
@@ -144,22 +152,22 @@ func mainAdminServiceRestart(ctx *cli.Context) error {
t := time.Now()
for {
select {
case <-globalContext.Done():
return globalContext.Err()
case <-ctxt.Done():
return ctxt.Err()
case <-timer.C:
ctx, cancel := context.WithTimeout(globalContext, 3*time.Second)
// Fetch the service status of the specified MinIO server
info, e := client.ServerInfo(ctx)
cancel()
healthCtx, healthCancel := context.WithTimeout(ctxt, 3*time.Second)
// Fetch the health status of the specified MinIO server
healthResult, healthErr := anonClient.Healthy(healthCtx, madmin.HealthOpts{})
healthCancel()
switch {
case e == nil && info.Mode == string(madmin.ItemOnline):
case healthErr == nil && healthResult.Healthy:
printMsg(serviceRestartMessage{
Status: "success",
ServerURL: aliasedURL,
TimeTaken: time.Since(t),
})
return nil
case err == nil && info.Mode == string(madmin.ItemInitializing):
case healthErr == nil && !healthResult.Healthy:
coloring = color.New(color.FgYellow)
mark = "!"
fallthrough