forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql,descs: add & adopt descriptor_validation session var
This commit removes the `sql.catalog.descs.validate_on_write.enabled` cluster setting and replaces it with the `descriptor_validation` session variable. The default value is 'on' which indicates that catalog descriptors are to be validated when both read from- and written to the system.descriptor table. Other possible values are 'off' which disables validation entirely and 'read_only' which disables it for writes. This commit therefore plumbs the session data into the descs.Collection object and for this purpose defines a new DescriptorSessionDataProvider interface, which is implemented in a new catsessiondata package. Informs cockroachdb#50651. Release note (sql change): added a new 'descriptor_validation' session variable which can be set to 'read_only' or 'off' to disable descriptor validation, which may be useful when mitigating or recovering from catalog corruption.
- Loading branch information
Marius Posta
committed
Oct 28, 2022
1 parent
5ff234c
commit 0becdf9
Showing
58 changed files
with
631 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
load("//build/bazelutil/unused_checker:unused.bzl", "get_x_data") | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "catsessiondata", | ||
srcs = ["descriptor_session_data_provider.go"], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/sql/catalog/catsessiondata", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/sql/catalog/descpb", | ||
"//pkg/sql/catalog/descs", | ||
"//pkg/sql/sessiondata", | ||
"//pkg/sql/sessiondatapb", | ||
], | ||
) | ||
|
||
get_x_data(name = "get_x_data") |
130 changes: 130 additions & 0 deletions
130
pkg/sql/catalog/catsessiondata/descriptor_session_data_provider.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package catsessiondata | ||
|
||
import ( | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descs" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sessiondata" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sessiondatapb" | ||
) | ||
|
||
type sessionData sessiondata.SessionData | ||
type sessionDataStack sessiondata.Stack | ||
|
||
func (sds *sessionDataStack) top() *sessionData { | ||
if sds == nil { | ||
return nil | ||
} | ||
return (*sessionData)((*sessiondata.Stack)(sds).Top()) | ||
} | ||
|
||
// DefaultDescriptorSessionDataProvider is the default implementation of | ||
// descs.DescriptorSessionDataProvider | ||
var DefaultDescriptorSessionDataProvider descs.DescriptorSessionDataProvider = (*sessionData)(nil) | ||
var _ descs.DescriptorSessionDataProvider = (*sessionDataStack)(nil) | ||
|
||
// NewDescriptorSessionDataProvider constructs a | ||
// descs.DescriptorSessionDataProvider instance given session data. | ||
// The pointer may be nil. | ||
func NewDescriptorSessionDataProvider( | ||
sd *sessiondata.SessionData, | ||
) descs.DescriptorSessionDataProvider { | ||
return (*sessionData)(sd) | ||
} | ||
|
||
// NewDescriptorSessionDataStackProvider constructs a | ||
// descs.DescriptorSessionDataProvider instance given a pointer to a session | ||
// data stack. The pointer may be nil. | ||
func NewDescriptorSessionDataStackProvider( | ||
sds *sessiondata.Stack, | ||
) descs.DescriptorSessionDataProvider { | ||
return (*sessionDataStack)(sds) | ||
} | ||
|
||
// HasTemporarySchema implements descs.TemporarySchemaProvider. | ||
func (sd *sessionData) HasTemporarySchema() bool { | ||
return sd != nil | ||
} | ||
|
||
// HasTemporarySchema implements descs.TemporarySchemaProvider. | ||
func (sds *sessionDataStack) HasTemporarySchema() bool { | ||
return sds.top() != nil | ||
} | ||
|
||
// GetTemporarySchemaName implements descs.TemporarySchemaProvider. | ||
func (sd *sessionData) GetTemporarySchemaName() string { | ||
if sd == nil { | ||
return "" | ||
} | ||
return (*sessiondata.SessionData)(sd).SearchPath.GetTemporarySchemaName() | ||
} | ||
|
||
// GetTemporarySchemaName implements descs.TemporarySchemaProvider. | ||
func (sds *sessionDataStack) GetTemporarySchemaName() string { | ||
return sds.top().GetTemporarySchemaName() | ||
} | ||
|
||
// GetTemporarySchemaIDForDB implements descs.TemporarySchemaProvider. | ||
func (sd *sessionData) GetTemporarySchemaIDForDB(dbID descpb.ID) descpb.ID { | ||
if sd == nil { | ||
return descpb.InvalidID | ||
} | ||
ret, _ := (*sessiondata.SessionData)(sd).GetTemporarySchemaIDForDB(uint32(dbID)) | ||
return descpb.ID(ret) | ||
} | ||
|
||
// GetTemporarySchemaIDForDB implements descs.TemporarySchemaProvider. | ||
func (sds *sessionDataStack) GetTemporarySchemaIDForDB(dbID descpb.ID) descpb.ID { | ||
return sds.top().GetTemporarySchemaIDForDB(dbID) | ||
} | ||
|
||
// MaybeGetDatabaseForTemporarySchemaID implements descs.TemporarySchemaProvider. | ||
func (sd *sessionData) MaybeGetDatabaseForTemporarySchemaID(id descpb.ID) descpb.ID { | ||
if sd == nil { | ||
return descpb.InvalidID | ||
} | ||
ret, _ := (*sessiondata.SessionData)(sd).MaybeGetDatabaseForTemporarySchemaID(uint32(id)) | ||
return descpb.ID(ret) | ||
} | ||
|
||
// MaybeGetDatabaseForTemporarySchemaID implements descs.TemporarySchemaProvider. | ||
func (sds *sessionDataStack) MaybeGetDatabaseForTemporarySchemaID(id descpb.ID) descpb.ID { | ||
return sds.top().MaybeGetDatabaseForTemporarySchemaID(id) | ||
} | ||
|
||
// ValidateDescriptorsOnRead implements descs.DescriptorValidationModeProvider. | ||
func (sd *sessionData) ValidateDescriptorsOnRead() bool { | ||
var mode sessiondatapb.DescriptorValidationMode | ||
if sd != nil { | ||
mode = sd.DescriptorValidationMode | ||
} | ||
return mode != sessiondatapb.DescriptorValidationOff | ||
} | ||
|
||
// ValidateDescriptorsOnRead implements descs.DescriptorValidationModeProvider. | ||
func (sds *sessionDataStack) ValidateDescriptorsOnRead() bool { | ||
return sds.top().ValidateDescriptorsOnRead() | ||
} | ||
|
||
// ValidateDescriptorsOnWrite implements descs.DescriptorValidationModeProvider. | ||
func (sd *sessionData) ValidateDescriptorsOnWrite() bool { | ||
var mode sessiondatapb.DescriptorValidationMode | ||
if sd != nil { | ||
mode = sd.DescriptorValidationMode | ||
} | ||
return mode == sessiondatapb.DescriptorValidationOn | ||
} | ||
|
||
// ValidateDescriptorsOnWrite implements descs.DescriptorValidationModeProvider. | ||
func (sds *sessionDataStack) ValidateDescriptorsOnWrite() bool { | ||
return sds.top().ValidateDescriptorsOnWrite() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.