Skip to content

Commit

Permalink
descs: fix GetAllFromStorageUnvalidated method
Browse files Browse the repository at this point in the history
This commit fixes a bug in which persisted catalog changes were not
visible in the results of this descs.Collection's method when the
transation already involved a full catalog scan before those changes.

Release note: None
  • Loading branch information
Marius Posta committed Dec 15, 2022
1 parent 6a1a2d1 commit f62d2aa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
10 changes: 5 additions & 5 deletions pkg/sql/catalog/descs/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,14 +710,14 @@ func (tc *Collection) GetAll(ctx context.Context, txn *kv.Txn) (nstree.Catalog,
return ret.Catalog, nil
}

// GetAllFromStorageUnvalidated delegates to the catkv.CatalogReader's ScanAll.
// Nothing is validated or hydrated. This is to be used sparingly and only in
// situations which warrant it, where an unmediated view of the stored catalog
// is explicitly desired for some purpose of observability.
// GetAllFromStorageUnvalidated delegates to an uncached catkv.CatalogReader's
// ScanAll method. Nothing is cached, validated or hydrated. This is to be used
// sparingly and only in situations which warrant it, where an unmediated view
// of the stored catalog is explicitly desired for observability.
func (tc *Collection) GetAllFromStorageUnvalidated(
ctx context.Context, txn *kv.Txn,
) (nstree.Catalog, error) {
return tc.cr.ScanAll(ctx, txn)
return catkv.NewUncachedCatalogReader(tc.codec()).ScanAll(ctx, txn)
}

// GetAllDatabases is like GetAll but filtered to non-dropped databases.
Expand Down
5 changes: 2 additions & 3 deletions pkg/sql/catalog/internal/catkv/catalog_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,9 @@ type CatalogReader interface {
) (nstree.Catalog, error)
}

// NewTestingUncachedCatalogReader is the constructor for the default
// NewUncachedCatalogReader is the constructor for the default
// CatalogReader implementation without a SystemDatabaseCache.
// This should not be used outside of testing purposes.
func NewTestingUncachedCatalogReader(codec keys.SQLCodec) CatalogReader {
func NewUncachedCatalogReader(codec keys.SQLCodec) CatalogReader {
return &catalogReader{
codec: codec,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/catalog/internal/catkv/catalog_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestDataDriven(t *testing.T) {
v := execCfg.Settings.Version.ActiveVersion(ctx)
sdc := catkv.NewSystemDatabaseCache(execCfg.Codec, execCfg.Settings)
ccr := catkv.NewCatalogReader(execCfg.Codec, v, sdc, nil /* maybeMonitor */)
ucr := catkv.NewTestingUncachedCatalogReader(execCfg.Codec)
ucr := catkv.NewUncachedCatalogReader(execCfg.Codec)

datadriven.RunTest(t, path, func(t *testing.T, d *datadriven.TestData) (ret string) {
h := testHelper{
Expand Down

0 comments on commit f62d2aa

Please sign in to comment.