-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: add sql.mutations.max_row_size.err guardrail
Addresses: #67400 Add sql.mutations.max_row_size.err, a new cluster setting similar to sql.mutations.max_row_size.log, which limits the size of rows written to the database. Statements trying to write a row larger than this will fail with an error. (Internal queries will not fail with an error, but will log a LargeRowInternal event to the SQL_INTERNAL_PERF channel.) We're reusing eventpb.CommonLargeRowDetails as the error type, out of convenience. Release note (ops change): A new cluster setting, sql.mutations.max_row_size.err, was added, which limits the size of rows written to the database (or individual column families, if multiple column families are in use). Statements trying to write a row larger than this will fail with a code 54000 (program_limit_exceeded) error. (Internal queries writing a row larger than this will not fail, but will log a LargeRowInternal event to the SQL_INTERNAL_PERF channel.) This limit is enforced for INSERT, UPSERT, and UPDATE statements. CREATE TABLE AS, CREATE INDEX, ALTER TABLE, ALTER INDEX, IMPORT, and RESTORE will not fail with an error, but will log LargeRowInternal events to the SQL_INTERNAL_PERF channel. SELECT, DELETE, TRUNCATE, and DROP are not affected by this limit. **Note that existing rows violating the limit will *not* be updatable, unless the update shrinks the size of the row below the limit, but *will* be selectable, deletable, and able to be altered, backed-up, and restored.** For this reason we recommend using the accompanying setting sql.mutations.max_row_size.log in conjunction with SELECT pg_column_size() queries to detect and fix any existing large rows before lowering sql.mutations.max_row_size.err.
- Loading branch information
Showing
9 changed files
with
211 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2021 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 eventpb | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cockroachdb/errors" | ||
) | ||
|
||
var _ error = &CommonLargeRowDetails{} | ||
var _ errors.SafeDetailer = &CommonLargeRowDetails{} | ||
var _ fmt.Formatter = &CommonLargeRowDetails{} | ||
var _ errors.SafeFormatter = &CommonLargeRowDetails{} | ||
|
||
// Error is part of the error interface, which CommonLargeRowDetails implements. | ||
func (r *CommonLargeRowDetails) Error() string { | ||
return fmt.Sprintf( | ||
"row larger than max row size: table %v index %v family %v key %v size %v", | ||
errors.Safe(r.TableID), errors.Safe(r.IndexID), errors.Safe(r.FamilyID), r.Key, | ||
errors.Safe(r.RowSize), | ||
) | ||
} | ||
|
||
// SafeDetails is part of the errors.SafeDetailer interface, which | ||
// CommonLargeRowDetails implements. | ||
func (r *CommonLargeRowDetails) SafeDetails() []string { | ||
return []string{ | ||
fmt.Sprint(r.TableID), | ||
fmt.Sprint(r.IndexID), | ||
fmt.Sprint(r.FamilyID), | ||
fmt.Sprint(r.RowSize), | ||
} | ||
} | ||
|
||
// Format is part of the fmt.Formatter interface, which CommonLargeRowDetails | ||
// implements. | ||
func (r *CommonLargeRowDetails) Format(s fmt.State, verb rune) { errors.FormatError(r, s, verb) } | ||
|
||
// SafeFormatError is part of the errors.SafeFormatter interface, which | ||
// CommonLargeRowDetails implements. | ||
func (r *CommonLargeRowDetails) SafeFormatError(p errors.Printer) (next error) { | ||
if p.Detail() { | ||
p.Printf( | ||
"row larger than max row size: table %v index %v family %v size %v", | ||
errors.Safe(r.TableID), errors.Safe(r.IndexID), errors.Safe(r.FamilyID), | ||
errors.Safe(r.RowSize), | ||
) | ||
} | ||
return nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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