Skip to content

Commit

Permalink
remoteobjcat: move assertions behind invariants.Enabled
Browse files Browse the repository at this point in the history
We recently added some assertions when applying a VersionEdit.
Unfortunately we used to have a bug where when we rotate a catalog
file, we dump the up-to-date state *and* the last version edit. This
was a no-op, but now when we upgrade a node we can hit these
assertions.

Fixes cockroachdb#2894.
  • Loading branch information
RaduBerinde committed Sep 13, 2023
1 parent 1efa535 commit 3db8edc
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions objstorage/objstorageprovider/remoteobjcat/version_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/cockroachdb/errors"
"github.com/cockroachdb/pebble/internal/base"
"github.com/cockroachdb/pebble/internal/invariants"
"github.com/cockroachdb/pebble/objstorage"
"github.com/cockroachdb/pebble/objstorage/remote"
)
Expand Down Expand Up @@ -234,14 +235,18 @@ func (v *VersionEdit) Apply(
*creatorID = v.CreatorID
}
for _, meta := range v.NewObjects {
if _, exists := objects[meta.FileNum]; exists {
return errors.AssertionFailedf("version edit adds existing object %s", meta.FileNum)
if invariants.Enabled {
if _, exists := objects[meta.FileNum]; exists {
return errors.AssertionFailedf("version edit adds existing object %s", meta.FileNum)
}
}
objects[meta.FileNum] = meta
}
for _, fileNum := range v.DeletedObjects {
if _, exists := objects[fileNum]; !exists {
return errors.AssertionFailedf("version edit deletes non-existent object %s", fileNum)
if invariants.Enabled {
if _, exists := objects[fileNum]; !exists {
return errors.AssertionFailedf("version edit deletes non-existent object %s", fileNum)
}
}
delete(objects, fileNum)
}
Expand Down

0 comments on commit 3db8edc

Please sign in to comment.