Skip to content

Commit

Permalink
sql: clean up large row errors and events
Browse files Browse the repository at this point in the history
Addresses: cockroachdb#67400, cockroachdb#69477

Remove ViolatesMaxRowSizeErr from CommonLargeRowDetails, as was done
for CommonTxnRowsLimitDetails in cockroachdb#69945.

Also remove the SafeDetails methods from CommonLargeRowDetails,
txnRowsReadLimitErr, and txnRowsWrittenLimitErr, as I don't think we
need them.

Release note: None (there was no release between the introduction of the
LargeRow and LargeRowInternal events and this commit).
  • Loading branch information
michae2 committed Sep 13, 2021
1 parent 394e35c commit 309c3cb
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 180 deletions.
8 changes: 3 additions & 5 deletions docs/generated/eventlog.md
Original file line number Diff line number Diff line change
Expand Up @@ -1882,7 +1882,7 @@ Events in this category are logged to the `SQL_PERF` channel.
### `large_row`

An event of type `large_row` is recorded when a statement tries to write a row larger than
cluster setting `sql.mutations.max_row_size.log` to the database. Multiple
cluster setting `sql.guardrails.max_row_size_log` to the database. Multiple
LargeRow events will be recorded for statements writing multiple large rows.
LargeRow events are recorded before the transaction commits, so in the case
of transaction abort there will not be a corresponding row in the database.
Expand All @@ -1900,7 +1900,6 @@ of transaction abort there will not be a corresponding row in the database.
| `TableID` | | no |
| `FamilyID` | | no |
| `PrimaryKey` | | yes |
| `ViolatesMaxRowSizeErr` | | no |

### `slow_query`

Expand Down Expand Up @@ -2008,8 +2007,8 @@ Events in this category are logged to the `SQL_INTERNAL_PERF` channel.
### `large_row_internal`

An event of type `large_row_internal` is recorded when an internal query tries to write a row
larger than cluster settings `sql.mutations.max_row_size.log` or
`sql.mutations.max_row_size.err` to the database.
larger than cluster settings `sql.guardrails.max_row_size_log` or
`sql.guardrails.max_row_size_err` to the database.



Expand All @@ -2024,7 +2023,6 @@ larger than cluster settings `sql.mutations.max_row_size.log` or
| `TableID` | | no |
| `FamilyID` | | no |
| `PrimaryKey` | | yes |
| `ViolatesMaxRowSizeErr` | | no |

### `slow_query_internal`

Expand Down
14 changes: 0 additions & 14 deletions pkg/sql/conn_executor_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,6 @@ type txnRowsWrittenLimitErr struct {
}

var _ error = &txnRowsWrittenLimitErr{}
var _ errors.SafeDetailer = &txnRowsWrittenLimitErr{}
var _ fmt.Formatter = &txnRowsWrittenLimitErr{}
var _ errors.SafeFormatter = &txnRowsWrittenLimitErr{}

Expand All @@ -1110,12 +1109,6 @@ func (e *txnRowsWrittenLimitErr) Error() string {
return e.CommonTxnRowsLimitDetails.Error("written")
}

// SafeDetails is part of the errors.SafeDetailer interface, which
// txnRowsWrittenLimitErr implements.
func (e *txnRowsWrittenLimitErr) SafeDetails() []string {
return e.CommonTxnRowsLimitDetails.SafeDetails("written")
}

// Format is part of the fmt.Formatter interface, which txnRowsWrittenLimitErr
// implements.
func (e *txnRowsWrittenLimitErr) Format(s fmt.State, verb rune) {
Expand All @@ -1133,7 +1126,6 @@ type txnRowsReadLimitErr struct {
}

var _ error = &txnRowsReadLimitErr{}
var _ errors.SafeDetailer = &txnRowsReadLimitErr{}
var _ fmt.Formatter = &txnRowsReadLimitErr{}
var _ errors.SafeFormatter = &txnRowsReadLimitErr{}

Expand All @@ -1142,12 +1134,6 @@ func (e *txnRowsReadLimitErr) Error() string {
return e.CommonTxnRowsLimitDetails.Error("read")
}

// SafeDetails is part of the errors.SafeDetailer interface, which
// txnRowsReadLimitErr implements.
func (e *txnRowsReadLimitErr) SafeDetails() []string {
return e.CommonTxnRowsLimitDetails.SafeDetails("read")
}

// Format is part of the fmt.Formatter interface, which txnRowsReadLimitErr
// implements.
func (e *txnRowsReadLimitErr) Format(s fmt.State, verb rune) {
Expand Down
18 changes: 9 additions & 9 deletions pkg/sql/event_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestPerfLogging(t *testing.T) {
{
query: `INSERT INTO t VALUES (5, false, repeat('x', 2048))`,
errRe: `row larger than max row size: table \d+ family 0 primary key /Table/\d+/1/5/0 size \d+`,
logRe: `"EventType":"large_row","RowSize":\d+,"TableID":\d+,"PrimaryKey":"‹/Table/\d+/1/5/0›","ViolatesMaxRowSizeErr":true`,
logRe: `"EventType":"large_row","RowSize":\d+,"TableID":\d+,"PrimaryKey":"‹/Table/\d+/1/5/0›"`,
logExpected: true,
channel: channel.SQL_PERF,
},
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestPerfLogging(t *testing.T) {
{
query: `INSERT INTO t VALUES (2, false, 'x') ON CONFLICT (i) DO UPDATE SET s = repeat('x', 2048)`,
errRe: `row larger than max row size: table \d+ family 0 primary key /Table/\d+/1/2/0 size \d+`,
logRe: `"EventType":"large_row","RowSize":\d+,"TableID":\d+,"PrimaryKey":"‹/Table/\d+/1/2/0›","ViolatesMaxRowSizeErr":true`,
logRe: `"EventType":"large_row","RowSize":\d+,"TableID":\d+,"PrimaryKey":"‹/Table/\d+/1/2/0›"`,
logExpected: true,
channel: channel.SQL_PERF,
},
Expand All @@ -225,7 +225,7 @@ func TestPerfLogging(t *testing.T) {
{
query: `UPSERT INTO t VALUES (2, false, repeat('x', 2048))`,
errRe: `row larger than max row size: table \d+ family 0 primary key /Table/\d+/1/2/0 size \d+`,
logRe: `"EventType":"large_row","RowSize":\d+,"TableID":\d+,"PrimaryKey":"‹/Table/\d+/1/2/0›","ViolatesMaxRowSizeErr":true`,
logRe: `"EventType":"large_row","RowSize":\d+,"TableID":\d+,"PrimaryKey":"‹/Table/\d+/1/2/0›"`,
logExpected: true,
channel: channel.SQL_PERF,
},
Expand All @@ -246,7 +246,7 @@ func TestPerfLogging(t *testing.T) {
{
query: `UPDATE t SET s = repeat('x', 2048) WHERE i = 2`,
errRe: `row larger than max row size: table \d+ family 0 primary key /Table/\d+/1/2/0 size \d+`,
logRe: `"EventType":"large_row","RowSize":\d+,"TableID":\d+,"PrimaryKey":"‹/Table/\d+/1/2/0›","ViolatesMaxRowSizeErr":true`,
logRe: `"EventType":"large_row","RowSize":\d+,"TableID":\d+,"PrimaryKey":"‹/Table/\d+/1/2/0›"`,
logExpected: true,
channel: channel.SQL_PERF,
},
Expand Down Expand Up @@ -288,7 +288,7 @@ func TestPerfLogging(t *testing.T) {
{
query: `ALTER TABLE t2 ADD COLUMN z STRING DEFAULT repeat('z', 2048)`,
errRe: ``,
logRe: `"EventType":"large_row_internal","RowSize":\d+,"TableID":\d+,"PrimaryKey":"‹/Table/\d+/1/4/0›","ViolatesMaxRowSizeErr":true`,
logRe: `"EventType":"large_row_internal","RowSize":\d+,"TableID":\d+,"PrimaryKey":"‹/Table/\d+/1/4/0›"`,
logExpected: true,
channel: channel.SQL_INTERNAL_PERF,
},
Expand Down Expand Up @@ -323,7 +323,7 @@ func TestPerfLogging(t *testing.T) {
{
query: `INSERT INTO u VALUES (2, 2, repeat('x', 2048))`,
errRe: `pq: row larger than max row size: table \d+ family 1 primary key /Table/\d+/1/2/1/1 size \d+`,
logRe: `"EventType":"large_row","RowSize":\d+,"TableID":\d+,"FamilyID":1,"PrimaryKey":"‹/Table/\d+/1/2/1/1›","ViolatesMaxRowSizeErr":true`,
logRe: `"EventType":"large_row","RowSize":\d+,"TableID":\d+,"FamilyID":1,"PrimaryKey":"‹/Table/\d+/1/2/1/1›"`,
logExpected: true,
channel: channel.SQL_PERF,
},
Expand Down Expand Up @@ -351,14 +351,14 @@ func TestPerfLogging(t *testing.T) {
{
query: `UPDATE u SET s = repeat('x', 2048) WHERE i = 2`,
errRe: `pq: row larger than max row size: table \d+ family 1 primary key /Table/\d+/1/2/1/1 size \d+`,
logRe: `"EventType":"large_row","RowSize":\d+,"TableID":\d+,"FamilyID":1,"PrimaryKey":"‹/Table/\d+/1/2/1/1›","ViolatesMaxRowSizeErr":true`,
logRe: `"EventType":"large_row","RowSize":\d+,"TableID":\d+,"FamilyID":1,"PrimaryKey":"‹/Table/\d+/1/2/1/1›"`,
logExpected: true,
channel: channel.SQL_PERF,
},
{
query: `CREATE TABLE u2 (i, j, s, PRIMARY KEY (i), FAMILY f1 (i, j), FAMILY f2 (s)) AS SELECT i, j, repeat(s, 2048) FROM u`,
errRe: ``,
logRe: `"EventType":"large_row_internal","RowSize":\d+,"TableID":\d+,"FamilyID":1,"PrimaryKey":"‹/Table/\d+/1/2/1/1›","ViolatesMaxRowSizeErr":true`,
logRe: `"EventType":"large_row_internal","RowSize":\d+,"TableID":\d+,"FamilyID":1,"PrimaryKey":"‹/Table/\d+/1/2/1/1›"`,
logExpected: true,
channel: channel.SQL_INTERNAL_PERF,
},
Expand All @@ -372,7 +372,7 @@ func TestPerfLogging(t *testing.T) {
{
query: `UPDATE u2 SET i = i + 1 WHERE i = 2`,
errRe: `row larger than max row size: table \d+ family 1 primary key /Table/\d+/1/3/1/1 size \d+`,
logRe: `"EventType":"large_row","RowSize":\d+,"TableID":\d+,"FamilyID":1,"PrimaryKey":"‹/Table/\d+/1/3/1/1›","ViolatesMaxRowSizeErr":true`,
logRe: `"EventType":"large_row","RowSize":\d+,"TableID":\d+,"FamilyID":1,"PrimaryKey":"‹/Table/\d+/1/3/1/1›"`,
logExpected: true,
channel: channel.SQL_PERF,
},
Expand Down
9 changes: 4 additions & 5 deletions pkg/sql/row/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,10 @@ func (rh *rowHelper) checkRowSize(
return nil
}
details := eventpb.CommonLargeRowDetails{
RowSize: size,
TableID: uint32(rh.TableDesc.GetID()),
FamilyID: uint32(family),
PrimaryKey: keys.PrettyPrint(rh.primIndexValDirs, *key),
ViolatesMaxRowSizeErr: shouldErr,
RowSize: size,
TableID: uint32(rh.TableDesc.GetID()),
FamilyID: uint32(family),
PrimaryKey: keys.PrettyPrint(rh.primIndexValDirs, *key),
}
if rh.internal && shouldErr {
// Internal work should never err and always log if violating either limit.
Expand Down
8 changes: 0 additions & 8 deletions pkg/util/log/eventpb/json_encode_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 14 additions & 33 deletions pkg/util/log/eventpb/sql_audit_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,67 +18,48 @@ import (
)

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 family %v primary key %v size %v",
errors.Safe(r.TableID), errors.Safe(r.FamilyID), r.PrimaryKey, errors.Safe(r.RowSize),
r.TableID, r.FamilyID, r.PrimaryKey, 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.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 family %v size %v",
errors.Safe(r.TableID), errors.Safe(r.FamilyID), errors.Safe(r.RowSize),
)
}
p.Printf(
"row larger than max row size: table %v family %v size %v",
r.TableID, r.FamilyID, r.RowSize,
)
return nil
}

// Error helps other structs embedding CommonTxnRowsLimitDetails implement the
// error interface.
// error interface. (Note that it does not implement the error interface
// itself.)
func (d *CommonTxnRowsLimitDetails) Error(kind string) string {
return fmt.Sprintf(
"txn has %s %d rows, which is above the limit: TxnID %v SessionID %v",
kind, d.NumRows, redact.SafeString(d.TxnID), redact.SafeString(d.SessionID),
kind, d.NumRows, d.TxnID, d.SessionID,
)
}

// SafeDetails helps other structs embedding CommonTxnRowsLimitDetails implement
// the errors.SafeDetailer interface.
func (d *CommonTxnRowsLimitDetails) SafeDetails(kind string) []string {
return []string{d.TxnID, d.SessionID, fmt.Sprintf("%d", d.NumRows), kind}
}

// SafeFormatError helps other structs embedding CommonTxnRowsLimitDetails
// implement the errors.SafeFormatter interface.
// implement the errors.SafeFormatter interface. (Note that it does not
// implement the errors.SafeFormatter interface itself.)
func (d *CommonTxnRowsLimitDetails) SafeFormatError(p errors.Printer, kind string) (next error) {
if p.Detail() {
p.Printf(
"txn has %s %d rows, which is above the limit: TxnID %v SessionID %v",
kind, d.NumRows, redact.SafeString(d.TxnID), redact.SafeString(d.SessionID),
)
}
p.Printf(
"txn has %s %d rows, which is above the limit: TxnID %v SessionID %v",
kind, d.NumRows, redact.SafeString(d.TxnID), redact.SafeString(d.SessionID),
)
return nil
}
Loading

0 comments on commit 309c3cb

Please sign in to comment.