Skip to content

Commit 32b9b71

Browse files
committed
Include versions in plan & status
1 parent e04caf4 commit 32b9b71

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

client/api.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ type UpgradeStatus struct {
140140
Failed bool `json:"failed"`
141141
// Reasons contains a human readable description of the state
142142
Reason string `json:"reason,omitempty"`
143+
// FromVersions contains all database versions found that will be upgraded.
144+
FromVersions []driver.Version `json:"from_versions"`
145+
// ToVersion contains the database version that will be upgraded to.
146+
ToVersion driver.Version `json:"to_version"`
143147
// ServersUpgraded contains the servers that have been upgraded
144148
ServersUpgraded []UpgradeStatusServer `json:"servers_upgraded"`
145149
// ServersRemaining contains the servers that have not yet been upgraded

service/upgrade_manager.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ type UpgradePlan struct {
117117
Entries []UpgradePlanEntry `json:"entries"`
118118
FinishedEntries []UpgradePlanEntry `json:"finished_entries"`
119119
Finished bool `json:"finished"`
120+
FromVersions []driver.Version `json:"from_versions"`
121+
ToVersion driver.Version `json:"to_version"`
120122
}
121123

122124
// IsReady returns true when all entries have finished.
@@ -224,6 +226,13 @@ func (m *upgradeManager) StartDatabaseUpgrade(ctx context.Context, force bool) e
224226
if err != nil {
225227
return maskAny(err)
226228
}
229+
if len(binaryDBVersions) > 1 {
230+
return maskAny(client.NewBadRequestError(fmt.Sprintf("Found multiple database versions (%v). Make sure all machines have the same version", binaryDBVersions)))
231+
}
232+
if len(binaryDBVersions) == 0 {
233+
return maskAny(client.NewBadRequestError("Found no database versions. This is likely a bug"))
234+
}
235+
toVersion := binaryDBVersions[0]
227236

228237
// Fetch (running) database versions of all starters
229238
runningDBVersions, err := m.fetchRunningDatabaseVersions(ctx)
@@ -233,10 +242,8 @@ func (m *upgradeManager) StartDatabaseUpgrade(ctx context.Context, force bool) e
233242

234243
// Check if we can upgrade from running to binary versions
235244
for _, from := range runningDBVersions {
236-
for _, to := range binaryDBVersions {
237-
if err := upgraderules.CheckUpgradeRules(from, to); err != nil {
238-
return maskAny(errors.Wrap(err, "Found incompatible upgrade versions"))
239-
}
245+
if err := upgraderules.CheckUpgradeRules(from, toVersion); err != nil {
246+
return maskAny(errors.Wrap(err, "Found incompatible upgrade versions"))
240247
}
241248
}
242249

@@ -292,6 +299,8 @@ func (m *upgradeManager) StartDatabaseUpgrade(ctx context.Context, force bool) e
292299
plan = UpgradePlan{
293300
CreatedAt: time.Now(),
294301
LastModifiedAt: time.Now(),
302+
FromVersions: runningDBVersions,
303+
ToVersion: toVersion,
295304
}
296305
// First add all agents
297306
for _, p := range config.AllPeers {
@@ -488,8 +497,10 @@ func (m *upgradeManager) Status(ctx context.Context) (client.UpgradeStatus, erro
488497
return client.UpgradeStatus{}, maskAny(err)
489498
}
490499
result := client.UpgradeStatus{
491-
Ready: plan.IsReady(),
492-
Failed: plan.IsFailed(),
500+
Ready: plan.IsReady(),
501+
Failed: plan.IsFailed(),
502+
FromVersions: plan.FromVersions,
503+
ToVersion: plan.ToVersion,
493504
}
494505
for _, entry := range plan.Entries {
495506
if entry.Failures > 0 && result.Reason == "" {

upgrade.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,31 @@ func runUpgrade(starterEndpoint string, force, retry bool) {
122122
// Create starter client
123123
c := mustCreateStarterClient(starterEndpoint)
124124
ctx := context.Background()
125+
var action string
125126
if retry {
126127
if err := c.RetryDatabaseUpgrade(ctx); err != nil {
127128
log.Fatal().Err(err).Msg("Failed to retry database automatic upgrade")
128129
}
129-
log.Info().Msg("Database automatic upgrade has been restarted")
130+
action = "restarted"
130131
} else {
131132
if err := c.StartDatabaseUpgrade(ctx, force); err != nil {
132133
log.Fatal().Err(err).Msg("Failed to start database automatic upgrade")
133134
}
134-
log.Info().Msg("Database automatic upgrade has been started")
135+
action = "started"
136+
}
137+
status, err := c.UpgradeStatus(ctx)
138+
if err != nil {
139+
log.Info().Msgf("Database automatic upgrade has been %s", action)
140+
} else {
141+
fromVersions := make([]string, 0, len(status.FromVersions))
142+
for _, v := range status.FromVersions {
143+
fromVersions = append(fromVersions, string(v))
144+
}
145+
fromVersionPrefix := "version"
146+
if len(status.FromVersions) > 1 {
147+
fromVersionPrefix = "versions"
148+
}
149+
log.Info().Msgf("Database automatic upgrade from %s %s to version %s has been %s", fromVersionPrefix, strings.Join(fromVersions, ", "), status.ToVersion, action)
135150
}
136151

137152
// Wait for the upgrade to finish

0 commit comments

Comments
 (0)