Skip to content

Commit 2f54ef3

Browse files
committed
roachtest: allow for missing system table column during MVT fingerprinting
Previously, the MVT backup framework could not unconditionally elide fingerprinting a column introduced in a migration, even if the test writer wrapped the column in the `WithSentinel` custom fingerprint handler. `WithSentinel` used to assume that the column will exist in the backed up cluster and the restored cluster. This patch relaxes that assumption. Fixes #147562 Release note: none
1 parent dd4cfcf commit 2f54ef3

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

pkg/cmd/roachtest/tests/mixed_version_backup.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,9 @@ func (sr *systemTableRow) skip() bool {
694694
// callback will be passed the value associated with that column, if
695695
// found, and its return value overwrites the value for that
696696
// column. The callback is not called if the column name is invalid.
697-
func (sr *systemTableRow) processColumn(column string, fn func(interface{}) interface{}) {
697+
func (sr *systemTableRow) processColumn(
698+
column string, skipMissing bool, fn func(interface{}) interface{},
699+
) {
698700
if sr.skip() {
699701
return
700702
}
@@ -703,6 +705,9 @@ func (sr *systemTableRow) processColumn(column string, fn func(interface{}) inte
703705
hasCol := colIdx < len(sr.columns) && sr.columns[colIdx] == column
704706

705707
if !hasCol {
708+
if skipMissing {
709+
return
710+
}
706711
sr.err = fmt.Errorf("could not find column %s on %s", column, sr.table)
707712
return
708713
}
@@ -713,19 +718,19 @@ func (sr *systemTableRow) processColumn(column string, fn func(interface{}) inte
713718
// Matches allows the caller to only apply certain changes if the
714719
// value of a certain column matches a given value.
715720
func (sr *systemTableRow) Matches(column string, value interface{}) *systemTableRow {
716-
sr.processColumn(column, func(actualValue interface{}) interface{} {
721+
sr.processColumn(column, false /*skipMissing */, func(actualValue interface{}) interface{} {
717722
sr.matches = reflect.DeepEqual(actualValue, value)
718723
return actualValue
719724
})
720725

721726
return sr
722727
}
723728

724-
// WithSentinel replaces the contents of the given columns with a
725-
// fixed sentinel value.
726-
func (sr *systemTableRow) WithSentinel(columns ...string) *systemTableRow {
729+
// WithSentinelIfExists replaces the contents of the given columns with a
730+
// fixed sentinel value, if the column exists.
731+
func (sr *systemTableRow) WithSentinelIfExists(columns ...string) *systemTableRow {
727732
for _, column := range columns {
728-
sr.processColumn(column, func(value interface{}) interface{} {
733+
sr.processColumn(column, true /* skipMissing */, func(value interface{}) interface{} {
729734
return systemTableSentinel
730735
})
731736
}
@@ -820,7 +825,7 @@ func (sc *systemTableContents) settingsHandler(
820825
// `name` column equals 'version'
821826
Matches("name", "version").
822827
// use the sentinel value for every column in the settings table
823-
WithSentinel(columns...).
828+
WithSentinelIfExists(columns...).
824829
Values()
825830
}
826831

@@ -838,7 +843,7 @@ func (sc *systemTableContents) scheduledJobsHandler(
838843
values []interface{}, columns []string,
839844
) ([]interface{}, error) {
840845
return newSystemTableRow(sc.table, values, columns).
841-
WithSentinel("next_run", "schedule_details", "schedule_state").
846+
WithSentinelIfExists("next_run", "schedule_details", "schedule_state").
842847
Values()
843848
}
844849

@@ -849,15 +854,15 @@ func (sc *systemTableContents) usersHandler(
849854
values []interface{}, columns []string,
850855
) ([]interface{}, error) {
851856
return newSystemTableRow(sc.table, values, columns).
852-
WithSentinel("estimated_last_login_time").
857+
WithSentinelIfExists("estimated_last_login_time").
853858
Values()
854859
}
855860

856861
func (sc *systemTableContents) commentsHandler(
857862
values []interface{}, columns []string,
858863
) ([]interface{}, error) {
859864
return newSystemTableRow(sc.table, values, columns).
860-
WithSentinel("object_id"). // object_id is rekeyed
865+
WithSentinelIfExists("object_id"). // object_id is rekeyed
861866
Values()
862867
}
863868

0 commit comments

Comments
 (0)