Unverified Commit 3d1f6e6f authored by Jim Kalafut's avatar Jim Kalafut Committed by GitHub
Browse files

Retry failing migration check instead of exiting (#5427)

parent 0e5c2c39
Showing with 37 additions and 10 deletions
+37 -10
......@@ -463,16 +463,8 @@ func (c *ServerCommand) Run(args []string) int {
return 1
}
migrationStatus, err := CheckMigration(backend)
if err != nil {
c.UI.Error("Error checking migration status")
return 1
}
if migrationStatus != nil {
startTime := migrationStatus.Start.Format(time.RFC3339)
c.UI.Error(wrapAtLength(fmt.Sprintf("Storage migration in progress (started: %s). "+
"Use 'vault operator migrate -reset' to force clear the migration lock.", startTime)))
// Prevent server startup if migration is active
if c.migrationActive(backend) {
return 1
}
......@@ -1789,6 +1781,41 @@ func (c *ServerCommand) removePidFile(pidPath string) error {
return os.Remove(pidPath)
}
// migrationActive checks and warns against in-progress storage migrations.
// This function will block until storage is available.
func (c *ServerCommand) migrationActive(backend physical.Backend) bool {
first := true
for {
migrationStatus, err := CheckMigration(backend)
if err == nil {
if migrationStatus != nil {
startTime := migrationStatus.Start.Format(time.RFC3339)
c.UI.Error(wrapAtLength(fmt.Sprintf("ERROR! Storage migration in progress (started: %s). "+
"Server startup is prevented until the migration completes. Use 'vault operator migrate -reset' "+
"to force clear the migration lock.", startTime)))
return true
}
return false
}
if first {
first = false
c.UI.Warn("\nWARNING! Unable to read migration status.")
// unexpected state, so stop buffering log messages
c.logGate.Flush()
}
c.logger.Warn("migration_check: " + err.Error())
select {
case <-time.After(2 * time.Second):
case <-c.ShutdownCh:
return true
}
}
return false
}
type MigrationStatus struct {
Start time.Time `json:"start"`
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment