Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
38028: sql: fix the auto-retry counter in stats + log it in statement/audit logs r=knz a=knz ### sql: fix the retry counter in the statement statistics The statement statistics contain a column `max_retries` intended to show the maximum number of times a statement was retried. Due to a bug, this counter was previously always zero, *even for statements that were actually retried*. We hadn't noticed because there was no test to ensure that the value would increase. This patch fixes the bugs and verifies that the value does indeed increase. Release note (bug fix): The `max_retries` column in the statement statistics now properly displays the maximum number of times a statement was retried. ### sql: display the nr of server-side auto retries in exec/audit logs As originally implemented, the logic that produces the statement execution logs and the audit logs produces one line of logging for every statement *executed by the server*. If a statement is retried automatically, there is one line of log per retry attempt. This level of detail is desirable for troubleshooting because it enables to analyze different things: - the details of the transaction during the retry failures (the text of the retry error contains useful troubleshooting details). - how long each individual attempt lasted (in the latency column); - if/when the number of rows affected changes (in the rows affected column; this is needed for auditing). However, this amount of detail introduces an element of surprise: a user who does not understand how to distinguish "work sent by the client" and "work executed by the server" (because, for example, traditional databases usually conflate the two), may be surprised by this behavior. For example, to count how many stastements were sent by a client, the user would need to be taught how to ignore those log entries that report a retry error, and possibly be taught about the internals of the execution machinery. This amount of effort is indesirable. To alleviate this effort, and generally increase the readability of the statement log files, this patch introduces an additional column at the end of each log line, containing the current value of the auto-retry counter. With this patch implemented, all the log lines with this value set to zero correspond to the work that was sent by a client, prior to any retry attempt. Release note (sql change): The logging format for statement execution (as enabled by `sql.trace.log_statement_execute`) and audit logs (as enabled by `ALTER TABLE .. EXPERIMENTAL AUDIT SET ...`) is extended with one column that reports internal execution retries performed automatically by the server. The value zero is logged for the first retry attempt and thus corresponds to statements directly receivd from a client. Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
- Loading branch information