Skip to content

Commit

Permalink
sql: allow the in-memory version to be the next fence version
Browse files Browse the repository at this point in the history
In `SHOW CLUSTER SETTING version` we wait for the stored version to match
the in-memory version. The in-memory version get pushed to the fence but
the fence is not persisted, so, while migrations are ongoing, we won't see
these values match. In practice this is a problem these days because the
migrations take a long time.

Epic: none

Informs #99894

Release note: None
  • Loading branch information
ajwerner committed Mar 29, 2023
1 parent 7b44120 commit dfd76d5
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion pkg/sql/show_cluster_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ func (p *planner) getCurrentEncodedVersionSettingValue(
}

localRawVal := []byte(s.Get(&st.SV))
if !bytes.Equal(localRawVal, kvRawVal) {
if !bytes.Equal(localRawVal, kvRawVal) &&
!localIsNextFence(localRawVal, kvRawVal) {
// NB: errors.Wrapf(nil, ...) returns nil.
// nolint:errwrap
return errors.Errorf(
Expand All @@ -113,6 +114,28 @@ func (p *planner) getCurrentEncodedVersionSettingValue(
return res, nil
}

// localIsNextFenceVersion returns true if both the arguments are valid encoded
// cluster versions and the local version is a fence version which follows
// the stored KV version.
func localIsNextFence(localRawVal, kvRawVal []byte) bool {
if len(kvRawVal) == 0 || len(localRawVal) == 0 {
return false
}
var decodedLocal, decodedKV clusterversion.ClusterVersion
if err := protoutil.Unmarshal(localRawVal, &decodedLocal); err != nil {
return false
}
if isFence := decodedLocal.Internal%2 == 1; !isFence {
return false
}
if err := protoutil.Unmarshal(kvRawVal, &decodedKV); err != nil {
return false
}
predecessor := decodedLocal
predecessor.Internal--
return predecessor.Equal(decodedKV)
}

func (p *planner) ShowClusterSetting(
ctx context.Context, n *tree.ShowClusterSetting,
) (planNode, error) {
Expand Down

0 comments on commit dfd76d5

Please sign in to comment.