Skip to content

Commit

Permalink
upgrades: refactored some existing functions to be reused later
Browse files Browse the repository at this point in the history
Slightly refactored the function that returns the next table
descriptor to be upgraded.
  • Loading branch information
Xiang-Gu committed Aug 26, 2022
1 parent d0ae428 commit 831bfe7
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pkg/upgrade/upgrades/upgrade_sequence_to_be_referenced_by_ID.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ func upgradeSequenceToBeReferencedByID(
var lastUpgradedID descpb.ID
// Upgrade each table/view, one at a time, until we exhaust all of them.
for {
done, idToUpgrade, err := findNextTableOrViewToUpgrade(ctx, d.InternalExecutor, lastUpgradedID)
done, idToUpgrade, err := findNextTableToUpgrade(ctx, d.InternalExecutor, lastUpgradedID,
func(table *descpb.TableDescriptor) bool {
return table.IsTable() || table.IsView()
})
if err != nil || done {
return err
}
Expand All @@ -53,10 +56,14 @@ func upgradeSequenceToBeReferencedByID(
}
}

// Find the next table or view descriptor ID that is > `lastUpgradedID`.
// Find the next table descriptor ID that is > `lastUpgradedID`
// and satisfy the `tableSelector`.
// If no such ID exists, `done` will be true.
func findNextTableOrViewToUpgrade(
ctx context.Context, ie sqlutil.InternalExecutor, lastUpgradedID descpb.ID,
func findNextTableToUpgrade(
ctx context.Context,
ie sqlutil.InternalExecutor,
lastUpgradedID descpb.ID,
tableSelector func(table *descpb.TableDescriptor) bool,
) (done bool, idToUpgrade descpb.ID, err error) {
var rows sqlutil.InternalRows
rows, err = ie.QueryIterator(ctx, "upgrade-seq-find-desc", nil,
Expand All @@ -82,7 +89,7 @@ func findNextTableOrViewToUpgrade(
}
// Return this descriptor if it's a non-dropped table or view.
tableDesc, _, _, _, _ := descpb.FromDescriptorWithMVCCTimestamp(&desc, ts)
if tableDesc != nil && !tableDesc.Dropped() && (tableDesc.IsTable() || tableDesc.IsView()) {
if tableDesc != nil && !tableDesc.Dropped() && tableSelector(tableDesc) {
return false, id, nil
}
}
Expand Down

0 comments on commit 831bfe7

Please sign in to comment.