Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlinstance: write backwards compatible binary version #123520

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 28 additions & 1 deletion pkg/clusterversion/cockroach_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

package clusterversion

import "github.com/cockroachdb/cockroach/pkg/roachpb"
import (
"fmt"

"github.com/cockroachdb/cockroach/pkg/roachpb"
)

// Key is a unique identifier for a version of CockroachDB.
type Key int
Expand Down Expand Up @@ -426,3 +430,26 @@ func ListBetween(from, to roachpb.Version) []roachpb.Version {
}
return cvs
}

// StringForPersistence returns the string representation of the given
// version in cases where that version needs to be persisted. This
// takes backwards compatibility into account, making sure that we use
// the old version formatting if we need to continue supporting
// releases that don't understand it.
//
// TODO(renato): remove this function once MinSupported is at least 24.1.
func StringForPersistence(v roachpb.Version) string {
return stringForPersistenceWithMinSupported(v, MinSupported.Version())
}

func stringForPersistenceWithMinSupported(v, minSupported roachpb.Version) string {
// newFormattingVersion is the version in which the new version
// formatting (#115223) was introduced.
newFormattingVersion := roachpb.Version{Major: 24, Minor: 1}

if minSupported.AtLeast(newFormattingVersion) || v.IsFinal() {
return v.String()
}

return fmt.Sprintf("%d.%d-%d", v.Major, v.Minor, v.Internal)
}
35 changes: 35 additions & 0 deletions pkg/clusterversion/cockroach_versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,38 @@ func TestReleaseSeries(t *testing.T) {
require.Equalf(t, expected, k.ReleaseSeries(), "version: %s", k)
}
}

func TestStringForPersistence(t *testing.T) {
testCases := []struct {
v roachpb.Version
minSupported roachpb.Version
expected string
}{
{
v: roachpb.Version{Major: 23, Minor: 2},
minSupported: roachpb.Version{Major: 23, Minor: 2},
expected: "23.2",
},
{
v: roachpb.Version{Major: 24, Minor: 1},
minSupported: roachpb.Version{Major: 23, Minor: 2},
expected: "24.1",
},
{
v: roachpb.Version{Major: 24, Minor: 1, Internal: 10},
minSupported: roachpb.Version{Major: 23, Minor: 2},
expected: "24.1-10",
},
{
v: roachpb.Version{Major: 24, Minor: 1, Internal: 10},
minSupported: roachpb.Version{Major: 24, Minor: 1},
expected: "24.1-upgrading-step-010",
},
}

for _, tc := range testCases {
t.Run("", func(t *testing.T) {
require.Equal(t, tc.expected, stringForPersistenceWithMinSupported(tc.v, tc.minSupported))
})
}
}
1 change: 1 addition & 0 deletions pkg/sql/sqlinstance/instancestorage/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/base",
"//pkg/clusterversion",
"//pkg/keys",
"//pkg/kv",
"//pkg/kv/kvclient/rangefeed",
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/sqlinstance/instancestorage/row_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"bytes"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/clusterversion"
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
Expand Down Expand Up @@ -244,7 +245,7 @@ func (d *rowCodec) encodeValue(
return tree.NewDString(sqlAddr)
},
binaryVersionColumnIdx: func() tree.Datum {
return tree.NewDString(binaryVersion.String())
return tree.NewDString(clusterversion.StringForPersistence(binaryVersion))
},
}
for i, f := range columnsToEncode {
Expand Down