From 1da50fdbd01ce785c58414085f5c453d24df4602 Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Thu, 7 Apr 2022 10:44:38 -0400 Subject: [PATCH] sql/catalog/descs: enforce invariant that OriginalVersion does not change It's a bug any time we increment a version more than once in the context of a single descriptor collection. Let's enforce it. Release note: None --- pkg/sql/catalog/descs/uncommitted_descriptors.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/sql/catalog/descs/uncommitted_descriptors.go b/pkg/sql/catalog/descs/uncommitted_descriptors.go index 0577aa51f1d4..fda0f2fa80ba 100644 --- a/pkg/sql/catalog/descs/uncommitted_descriptors.go +++ b/pkg/sql/catalog/descs/uncommitted_descriptors.go @@ -164,6 +164,13 @@ func (ud *uncommittedDescriptors) add( for _, n := range uNew.immutable.GetDrainingNames() { ud.descNames.Add(n) } + if prev, ok := ud.descs.GetByID(mut.GetID()).(*uncommittedDescriptor); ok { + if prev.mutable.OriginalVersion() != mut.OriginalVersion() { + return nil, errors.AssertionFailedf( + "cannot add a version of descriptor with a different original version" + + " than it was previously added with") + } + } ud.descs.Upsert(uNew) return uNew.immutable, err }