Skip to content

Commit

Permalink
[PLAT-16641] Skip updates to the state file if no changes are made
Browse files Browse the repository at this point in the history
Summary:
We do not need to write to the state file if all migrations have already
been preformed, skip "StoreState" if no migrations get run

Test Plan:
tested that status (and other LoadState)  no longer writes to the state file unless
migrations have been performed

Reviewers: muthu, sanketh

Reviewed By: muthu

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D41625
  • Loading branch information
shubin-yb committed Feb 3, 2025
1 parent d8b0b4f commit 3ddfdf8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions managed/yba-installer/pkg/ybactlstate/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func handleMigration(state *State) error {
}
nextSchema := 0
endSchema := getSchemaVersion()
updateMade := false
for nextSchema < endSchema {
nextSchema++
if slices.Contains(state._internalFields.RunSchemas, nextSchema) {
Expand All @@ -43,11 +44,16 @@ func handleMigration(state *State) error {
log.Debug("skipping migration " + strconv.Itoa(nextSchema) + " as it is not defined")
continue
}
updateMade = true
if err := migrate(state); err != nil {
return err
}
state._internalFields.RunSchemas = append(state._internalFields.RunSchemas, nextSchema)
}
if !updateMade {
log.DebugLF("no migrations run")
return nil
}
// StoreState in order to persist migration SchemaVersion
return StoreState(state)
}
Expand Down

0 comments on commit 3ddfdf8

Please sign in to comment.