Skip to content

Commit 282b7c9

Browse files
craig[bot]rafiss
andcommitted
Merge #152634
152634: upgrades: one-time rewrite of all descriptors r=rafiss a=rafiss This will allow us to safely remove the upgradeType logic when we drop 25.3 compatibility. informs #152629 Release note: None Co-authored-by: Rafi Shamim <[email protected]>
2 parents 8977c22 + 0cc42a8 commit 282b7c9

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

pkg/sql/types/types.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,11 +2537,8 @@ func (t *T) Unmarshal(data []byte) error {
25372537
// setting required values. This is necessary to preserve backwards-
25382538
// compatibility with older formats (e.g. restoring database from old backup).
25392539
//
2540-
// This can be removed once we can ensure that all descriptors have been
2541-
// rewritten with the newer format. Note that the migration in first_upgrade.go
2542-
// is not sufficient to ensure that all descriptors have been rewritten, since
2543-
// that migration is only based on post-deserialization changes, but the type
2544-
// upgrade logic happens _during_ deserialization.
2540+
// This can be removed once we no longer need compatibility with v25.3 or
2541+
// earlier. See https://github.com/cockroachdb/cockroach/issues/152629.
25452542
func (t *T) upgradeType() error {
25462543
switch t.Family() {
25472544
case IntFamily:

pkg/upgrade/upgrades/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ go_library(
4343
"//pkg/sql/catalog/descidgen",
4444
"//pkg/sql/catalog/descpb",
4545
"//pkg/sql/catalog/descs",
46-
"//pkg/sql/catalog/lease",
4746
"//pkg/sql/catalog/nstree",
4847
"//pkg/sql/catalog/replication",
4948
"//pkg/sql/catalog/systemschema",

pkg/upgrade/upgrades/first_upgrade.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package upgrades
88
import (
99
"context"
1010
"fmt"
11+
"time"
1112

1213
"github.com/cockroachdb/cockroach/pkg/clusterversion"
1314
"github.com/cockroachdb/cockroach/pkg/kv"
@@ -16,7 +17,6 @@ import (
1617
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
1718
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys"
1819
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descs"
19-
"github.com/cockroachdb/cockroach/pkg/sql/catalog/lease"
2020
"github.com/cockroachdb/cockroach/pkg/sql/catalog/nstree"
2121
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
2222
"github.com/cockroachdb/cockroach/pkg/upgrade"
@@ -79,7 +79,7 @@ func upgradeDescriptors(
7979
batchSize := 100
8080
// Any batch size below this will use high priority.
8181
const HighPriBatchSize = 25
82-
repairBatchTimeLimit := lease.LeaseDuration.Get(&d.Settings.SV)
82+
repairBatchTimeLimit := 1 * time.Minute
8383
currentIdx := 0
8484
idsToRewrite := ids.Ordered()
8585
for currentIdx <= len(idsToRewrite) {
@@ -102,7 +102,18 @@ func upgradeDescriptors(
102102
b := txn.KV().NewBatch()
103103
for _, mut := range muts {
104104
if !mut.GetPostDeserializationChanges().HasChanges() {
105-
continue
105+
// In the upgrade to 25.4, we do a one-time rewrite of all
106+
// descriptors in order to upgrade them to use the new type
107+
// serialization format.
108+
// See https://github.com/cockroachdb/cockroach/issues/152629.
109+
if d.Settings.Version.IsActive(ctx, clusterversion.V25_4) {
110+
continue
111+
}
112+
// Skip the unconditional rewrite if this is a database descriptor,
113+
// as those never reference types.
114+
if mut.DescriptorType() == catalog.Database {
115+
continue
116+
}
106117
}
107118
key := catalogkeys.MakeDescMetadataKey(d.Codec, mut.GetID())
108119
b.CPut(key, mut.DescriptorProto(), mut.GetRawBytesInStorage())
@@ -215,7 +226,7 @@ WHERE
215226
batchSize := 100
216227
// Any batch size below this will use high priority.
217228
const HighPriBatchSize = 25
218-
repairBatchTimeLimit := lease.LeaseDuration.Get(&d.Settings.SV)
229+
repairBatchTimeLimit := 1 * time.Minute
219230
for {
220231
var rowsUpdated tree.DInt
221232
err := timeutil.RunWithTimeout(ctx, "descriptor-repair", repairBatchTimeLimit, func(ctx context.Context) error {

pkg/upgrade/upgrades/first_upgrade_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descs"
2828
"github.com/cockroachdb/cockroach/pkg/sql/catalog/desctestutils"
2929
"github.com/cockroachdb/cockroach/pkg/sql/catalog/funcdesc"
30-
"github.com/cockroachdb/cockroach/pkg/sql/catalog/lease"
3130
"github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc"
3231
"github.com/cockroachdb/cockroach/pkg/sql/sem/eval"
3332
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
@@ -164,7 +163,6 @@ func TestFirstUpgradeRepair(t *testing.T) {
164163
// also holds a lease on the system database descriptor, which we will wait to
165164
// be released. Reducing the lease duration makes this part of the test speed
166165
// up.
167-
lease.LeaseDuration.Override(ctx, &settings.SV, time.Second*30)
168166
require.NoError(t, clusterversion.Initialize(ctx, v0, &settings.SV))
169167
upgradePausePoint := make(chan struct{})
170168
upgradeResumePoint := make(chan struct{})
@@ -377,7 +375,6 @@ func TestFirstUpgradeRepairBatchSize(t *testing.T) {
377375
// also holds a lease on the system database descriptor, which we will wait to
378376
// be released. Reducing the lease duration makes this part of the test speed
379377
// up.
380-
lease.LeaseDuration.Override(ctx, &settings.SV, time.Second*30)
381378
require.NoError(t, clusterversion.Initialize(ctx, v0, &settings.SV))
382379
testServer, sqlDB, _ := serverutils.StartServer(t, base.TestServerArgs{
383380
Settings: settings,

0 commit comments

Comments
 (0)