@@ -166,54 +166,58 @@ func FetchDescVersionModificationTime(
166166 t .Fatal (pErr .GoError ())
167167 }
168168 for _ , file := range res .(* kvpb.ExportResponse ).Files {
169- it , err := storage .NewMemSSTIterator (file .SST , false /* verify */ , storage.IterOptions {
170- KeyTypes : storage .IterKeyTypePointsAndRanges ,
171- LowerBound : keys .MinKey ,
172- UpperBound : keys .MaxKey ,
173- })
174- if err != nil {
175- t .Fatal (err )
176- }
177- //nolint:deferloop TODO(#137605)
178- defer it .Close ()
179- for it .SeekGE (storage .NilKey ); ; it .Next () {
180- if ok , err := it .Valid (); err != nil {
181- t .Fatal (err )
182- } else if ! ok {
183- continue
184- }
185- k := it .UnsafeKey ()
186- if _ , hasRange := it .HasPointAndRange (); hasRange {
187- t .Fatalf ("unexpected MVCC range key at %s" , k )
188- }
189- remaining , _ , _ , err := s .Codec ().DecodeIndexPrefix (k .Key )
190- if err != nil {
191- t .Fatal (err )
192- }
193- _ , tableID , err := encoding .DecodeUvarintAscending (remaining )
169+ ts , found := func () (hlc.Timestamp , bool ) {
170+ it , err := storage .NewMemSSTIterator (file .SST , false /* verify */ , storage.IterOptions {
171+ KeyTypes : storage .IterKeyTypePointsAndRanges ,
172+ LowerBound : keys .MinKey ,
173+ UpperBound : keys .MaxKey ,
174+ })
194175 if err != nil {
195176 t .Fatal (err )
196177 }
197- if tableID != uint64 (dropColTblID ) {
198- continue
199- }
200- unsafeValue , err := it .UnsafeValue ()
201- require .NoError (t , err )
202- if unsafeValue == nil {
203- t .Fatal (errors .New (`value was dropped or truncated` ))
204- }
205- value := roachpb.Value {RawBytes : unsafeValue , Timestamp : k .Timestamp }
206- b , err := descbuilder .FromSerializedValue (& value )
207- if err != nil {
208- t .Fatal (err )
209- }
210- require .NotNil (t , b )
211- if b .DescriptorType () == catalog .Table {
212- tbl := b .BuildImmutable ().(catalog.TableDescriptor )
213- if int (tbl .GetVersion ()) == version {
214- return tbl .GetModificationTime ()
178+ defer it .Close ()
179+ for it .SeekGE (storage .NilKey ); ; it .Next () {
180+ if ok , err := it .Valid (); err != nil {
181+ t .Fatal (err )
182+ } else if ! ok {
183+ return hlc.Timestamp {}, false
184+ }
185+ k := it .UnsafeKey ()
186+ if _ , hasRange := it .HasPointAndRange (); hasRange {
187+ t .Fatalf ("unexpected MVCC range key at %s" , k )
188+ }
189+ remaining , _ , _ , err := s .Codec ().DecodeIndexPrefix (k .Key )
190+ if err != nil {
191+ t .Fatal (err )
192+ }
193+ _ , tableID , err := encoding .DecodeUvarintAscending (remaining )
194+ if err != nil {
195+ t .Fatal (err )
196+ }
197+ if tableID != uint64 (dropColTblID ) {
198+ continue
199+ }
200+ unsafeValue , err := it .UnsafeValue ()
201+ require .NoError (t , err )
202+ if unsafeValue == nil {
203+ t .Fatal (errors .New (`value was dropped or truncated` ))
204+ }
205+ value := roachpb.Value {RawBytes : unsafeValue , Timestamp : k .Timestamp }
206+ b , err := descbuilder .FromSerializedValue (& value )
207+ if err != nil {
208+ t .Fatal (err )
209+ }
210+ require .NotNil (t , b )
211+ if b .DescriptorType () == catalog .Table {
212+ tbl := b .BuildImmutable ().(catalog.TableDescriptor )
213+ if int (tbl .GetVersion ()) == version {
214+ return tbl .GetModificationTime (), true
215+ }
215216 }
216217 }
218+ }()
219+ if found {
220+ return ts
217221 }
218222 }
219223 t .Fatal (errors .New (`couldn't find table desc for given version` ))
0 commit comments