diff --git a/pkg/roachpb/version.go b/pkg/roachpb/version.go index 782b4ca3523e..6fb5baaf773c 100644 --- a/pkg/roachpb/version.go +++ b/pkg/roachpb/version.go @@ -49,9 +49,9 @@ func (v Version) LessEq(otherV Version) bool { return v.Equal(otherV) || v.Less(otherV) } -// AtLeast returns true if the receiver is greater than or requal to the parameter. +// AtLeast returns true if the receiver is greater than or equal to the parameter. func (v Version) AtLeast(otherV Version) bool { - return !otherV.Less(v) + return !v.Less(otherV) } // String implements the fmt.Stringer interface. diff --git a/pkg/roachpb/version_test.go b/pkg/roachpb/version_test.go index 29328e88b70b..162443cb5971 100644 --- a/pkg/roachpb/version_test.go +++ b/pkg/roachpb/version_test.go @@ -16,7 +16,7 @@ import ( "github.com/kr/pretty" ) -func TestVersionLess(t *testing.T) { +func TestVersionCmp(t *testing.T) { v := func(major, minor, patch, internal int32) Version { return Version{ Major: major, @@ -51,6 +51,12 @@ func TestVersionLess(t *testing.T) { if a, e := test.v1.Less(test.v2), test.less; a != e { t.Errorf("expected %s < %s? %t; got %t", pretty.Sprint(test.v1), pretty.Sprint(test.v2), e, a) } + if a, e := test.v1.Equal(test.v2), test.v1 == test.v2; a != e { + t.Errorf("expected %s = %s? %t; got %t", pretty.Sprint(test.v1), pretty.Sprint(test.v2), e, a) + } + if a, e := test.v1.AtLeast(test.v2), test.v1 == test.v2 || !test.less; a != e { + t.Errorf("expected %s >= %s? %t; got %t", pretty.Sprint(test.v1), pretty.Sprint(test.v2), e, a) + } }) } } diff --git a/pkg/storage/pebble.go b/pkg/storage/pebble.go index 41ee3d36a79d..e714f8982821 100644 --- a/pkg/storage/pebble.go +++ b/pkg/storage/pebble.go @@ -843,14 +843,10 @@ func (p *Pebble) SetStoreID(ctx context.Context, storeID int32) error { if p == nil { return nil } - if p.storeIDPebbleLog != nil { - p.storeIDPebbleLog.Set(ctx, storeID) - } + p.storeIDPebbleLog.Set(ctx, storeID) // Note that SetCreatorID only does something if shared storage is configured // in the pebble options. The version gate protects against accidentally // setting the creator ID on an older store. - // TODO(radu): we don't yet have a complete story about how we will transition - // an existing store to use shared storage. if storeID != base.TempStoreID && p.minVersion.AtLeast(clusterversion.ByKey(clusterversion.V23_1SetPebbleCreatorID)) { if err := p.db.SetCreatorID(uint64(storeID)); err != nil { return err @@ -1999,6 +1995,15 @@ func (p *Pebble) SetMinVersion(version roachpb.Version) error { return err } + // Set the shared object creator ID if the version is high enough. See SetStoreID(). + if version.AtLeast(clusterversion.ByKey(clusterversion.V23_1SetPebbleCreatorID)) { + if storeID := p.storeIDPebbleLog.Get(); storeID != 0 && storeID != base.TempStoreID { + if err := p.db.SetCreatorID(uint64(storeID)); err != nil { + return err + } + } + } + // Pebble has a concept of format major versions, similar to cluster // versions. Backwards incompatible changes to Pebble's on-disk // format are gated behind new format major versions. Bumping the