Skip to content

Commit

Permalink
sql: Record user-provided value to event log when a setting is changed
Browse files Browse the repository at this point in the history
Rather than using the encoded version, which for state-machine settings
(like the cluster version) can be a protocol buffer.

To make this work, I needed parser.StrVal.Format to respect the provided
format strings. To my untrained eye this looked like a bug, but there
may be a reason for it that I'm not aware of.

Fixes #17854
  • Loading branch information
a-robinson committed Aug 23, 2017
1 parent 8839ecc commit 9752ee6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/parser/constant.go
Expand Up @@ -353,7 +353,7 @@ func (expr *StrVal) Format(buf *bytes.Buffer, f FmtFlags) {
if expr.bytesEsc {
encodeSQLBytes(buf, expr.s)
} else {
encodeSQLString(buf, expr.s)
encodeSQLStringWithFlags(buf, expr.s, f)
}
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/sql/set.go
Expand Up @@ -15,6 +15,7 @@
package sql

import (
"bytes"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -113,12 +114,14 @@ func (p *planner) setClusterSetting(
return nil, err
}
case 1:
var buf bytes.Buffer
v[0].Format(&buf, parser.FmtBareStrings)
value = buf.String()
// TODO(dt): validate and properly encode str according to type.
encoded, err := p.toSettingString(ctx, ie, name, typ, v[0])
if err != nil {
return nil, err
}
value = encoded
upsertQ := `UPSERT INTO system.settings (name, value, "lastUpdated", "valueType") VALUES ($1, $2, NOW(), $3)`
if _, err := ie.ExecuteStatementInTransaction(
ctx, "update-setting", p.txn, upsertQ, name, encoded, typ.Typ(),
Expand Down

0 comments on commit 9752ee6

Please sign in to comment.