Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-generate sysvar documentation from TiDB server source #5720

Draft
wants to merge 56 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f29ab02
system-variables: ensure alphabetical order
morgo May 28, 2021
6ea73ee
fix broken anchors
morgo May 28, 2021
30a9be5
Add WIP script
morgo May 28, 2021
b82868d
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo May 28, 2021
984272a
Add generators and generated file
morgo May 28, 2021
24fc507
fix linter
morgo May 28, 2021
d7877ca
Update to master, manually fix default txn mode
morgo May 31, 2021
6944092
Fetch correctness changes from tidb-master
morgo Jun 1, 2021
0f08b9b
Update for new variables
morgo Jun 3, 2021
2297833
Remove system-variables.md from commit
morgo Jun 3, 2021
a8aa051
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Jun 3, 2021
fdbd7a7
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Jun 5, 2021
5ab0a89
update with units
morgo Jun 5, 2021
8dee833
WIP
morgo Jun 8, 2021
0b4d8b6
Add quotes on range
morgo Jun 8, 2021
5784d50
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Jun 14, 2021
5a2d09b
WIP
morgo Jun 14, 2021
a536480
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Jun 22, 2021
10ff188
update
morgo Jun 22, 2021
f2e6b0f
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Jul 2, 2021
f0ebe10
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Aug 23, 2021
652939b
Update against master
morgo Aug 23, 2021
5ee8613
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Sep 10, 2021
806360d
WIP
morgo Sep 10, 2021
ccdd4bb
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Sep 22, 2021
9d28f5a
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Oct 1, 2021
bb41e30
updates for new sysvars
morgo Oct 1, 2021
d8ea211
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Oct 9, 2021
510d568
WIP
morgo Oct 12, 2021
a8a9311
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Oct 15, 2021
eda0317
WIP
morgo Oct 15, 2021
b33d349
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Oct 25, 2021
f5833c8
update changes
morgo Oct 25, 2021
c75d298
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Nov 1, 2021
8600643
WIP
morgo Nov 2, 2021
b06513f
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Nov 10, 2021
b95bdcd
Wip
morgo Nov 10, 2021
f05991e
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Nov 17, 2021
472d881
WIP
morgo Nov 17, 2021
395ef8e
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Dec 17, 2021
7d5107c
WIP
morgo Dec 17, 2021
16f024a
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Jan 5, 2022
8ae2848
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Jan 18, 2022
c157e5b
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Feb 7, 2022
ba6f2f2
WIP
morgo Mar 2, 2022
136086b
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Mar 22, 2022
42f0d30
WIP
morgo Mar 22, 2022
e8d0aed
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Mar 22, 2022
495bb63
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Apr 14, 2022
fe86242
WIP
morgo Apr 14, 2022
fee3391
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Apr 27, 2022
f23d033
WIP
morgo Apr 27, 2022
76c0809
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo Apr 29, 2022
2c6556e
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo May 19, 2022
031e9fc
WIP
morgo May 19, 2022
12a3512
Merge remote-tracking branch 'upstream/master' into fix-sysvar-correc…
morgo May 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updates for new sysvars
  • Loading branch information
morgo committed Oct 1, 2021
commit bb41e30a04c32e390728ce75a03808533ff425a7
94 changes: 81 additions & 13 deletions scripts/generate-system-variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func formatDefaultValue(sv *variable.SysVar) string {
return fmt.Sprintf("`%s` (%s)", sv.Value, ByteCountIEC(sv.Value))
case variable.DataDir:
return "/tmp/tidb"
case variable.LastInsertID:
return "`0`"
case variable.PluginDir:
return `""`
}
if sv.Value == "" {
return `""` // make it easier to read that it's an empty string default
Expand All @@ -66,26 +70,25 @@ func skipSv(sv *variable.SysVar) bool {
}
// These svs have no documentation yet.
switch sv.Name {
case variable.BlockEncryptionMode, variable.CollationConnection, variable.CollationDatabase,
variable.CollationServer, variable.DefaultWeekFormat, variable.ErrorCount, variable.GroupConcatMaxLen,
"have_openssl", "have_ssl", "last_insert_id", variable.LowerCaseTableNames, variable.MaxAllowedPacket, variable.MaxConnections,
variable.MaxPreparedStmtCount, variable.PluginDir, variable.PluginLoad, variable.SQLLogBin, "ssl_ca", "ssl_cert", "ssl_key",
case variable.ErrorCount,
variable.LowerCaseTableNames, variable.MaxConnections,
variable.MaxPreparedStmtCount,
variable.TiDBBatchCommit, variable.TiDBBatchDelete, variable.TiDBBatchInsert, variable.TiDBEnableChangeMultiSchema,
variable.TiDBEnableExchangePartition, variable.TiDBEnableExtendedStats, variable.TiDBEnablePointGetCache,
variable.TiDBEnableStreaming, variable.TiDBGuaranteeLinearizability, variable.TiDBTxnScope, variable.TiDBTxnReadTS,
variable.TxnIsolationOneShot, variable.Timestamp, variable.TiDBLastQueryInfo, variable.TiDBLastTxnInfo,
variable.TxnIsolationOneShot, variable.TiDBLastQueryInfo, variable.TiDBLastTxnInfo,
variable.TiDBMemQuotaHashJoin, variable.TiDBStreamAggConcurrency, variable.TiDBTrackAggregateMemoryUsage, variable.TiDBOptBCJ,
variable.TiDBOptConcurrencyFactor, variable.TiDBOptCopCPUFactor, variable.TiDBEnableIndexMergeJoin,
variable.TiDBMemQuotaIndexLookupJoin, variable.TiDBMemQuotaIndexLookupReader, variable.TiDBMemQuotaMergeJoin,
variable.TiDBEnableAlterPlacement, variable.TiDBSlowLogMasking, variable.TiDBShardAllocateStep, variable.TiDBMemQuotaTopn,
variable.TiDBMemQuotaSort, variable.TiDBMergeJoinConcurrency, variable.TiDBOptCPUFactor, variable.TiDBOptDescScanFactor,
variable.TiDBOptDiskFactor, variable.TiDBOptJoinReorderThreshold, variable.TiDBOptMemoryFactor, variable.TiDBOptNetworkFactor,
variable.TiDBOptScanFactor, variable.TiDBOptTiFlashConcurrencyFactor, variable.TiDBOptimizerSelectivityLevel,
variable.TiDBOptSeekFactor, variable.LogBin, variable.TiDBEnableTopSQL, variable.TiDBTopSQLAgentAddress, variable.TiDBTopSQLPrecisionSeconds,
variable.TiDBOptSeekFactor, variable.TiDBEnableTopSQL, variable.TiDBTopSQLPrecisionSeconds,
variable.TiDBTopSQLMaxStatementCount, variable.TiDBEnableGlobalTemporaryTable, variable.TiDBEnablePipelinedWindowFunction, variable.TiDBOptCartesianBCJ,
variable.TiDBEnableLocalTxn, variable.TiDBTopSQLMaxCollect, variable.TiDBTopSQLReportIntervalSeconds, variable.SkipNameResolve, variable.TMPTableSize,
variable.TiDBEnableLocalTxn, variable.TiDBTopSQLMaxCollect, variable.TiDBTopSQLReportIntervalSeconds,
variable.TiDBOptMPPOuterJoinFixedBuildSide, variable.TiDBRestrictedReadOnly, variable.TiDBMPPStoreFailTTL, variable.TiDBHashExchangeWithNewCollation,
variable.TiDBEnableOrderedResultMode:
variable.TiDBEnableOrderedResultMode, variable.TiDBReadStaleness:

return true
}
Expand Down Expand Up @@ -115,7 +118,7 @@ func printWarning(sv *variable.SysVar) string {

func printUnits(sv *variable.SysVar) string {
switch sv.Name {
case variable.TiDBMemQuotaApplyCache, variable.TiDBMemQuotaQuery, variable.TiDBQueryLogMaxLen, variable.TiDBBCJThresholdSize:
case variable.TiDBMemQuotaApplyCache, variable.TiDBMemQuotaQuery, variable.TiDBQueryLogMaxLen, variable.TiDBBCJThresholdSize, variable.TMPTableSize:
return "- Unit: Bytes\n"
case variable.TiDBSlowLogThreshold, variable.MaxExecutionTime:
return "- Unit: Milliseconds\n"
Expand All @@ -128,8 +131,10 @@ func printUnits(sv *variable.SysVar) string {
func formatScope(sv *variable.SysVar) string {
// Manually cater for "INSTANCE" scope, which is not a native concept.
switch sv.Name {
case variable.TiDBDDLSlowOprThreshold, variable.TiDBCheckMb4ValueInUTF8, variable.TiDBEnableCollectExecutionInfo, variable.TiDBEnableSlowLog, variable.TiDBExpensiveQueryTimeThreshold,
variable.TiDBForcePriority, variable.TiDBGeneralLog, variable.TiDBSlowLogThreshold, variable.TiDBPProfSQLCPU, variable.TiDBQueryLogMaxLen, variable.TiDBRecordPlanInSlowLog, variable.TiDBMemoryUsageAlarmRatio:
case variable.TiDBDDLSlowOprThreshold, variable.TiDBCheckMb4ValueInUTF8, variable.TiDBEnableCollectExecutionInfo,
variable.TiDBEnableSlowLog, variable.TiDBExpensiveQueryTimeThreshold, variable.TiDBForcePriority, variable.TiDBGeneralLog,
variable.TiDBSlowLogThreshold, variable.TiDBPProfSQLCPU, variable.TiDBQueryLogMaxLen, variable.TiDBRecordPlanInSlowLog,
variable.TiDBMemoryUsageAlarmRatio, variable.PluginDir, variable.PluginLoad:
return "INSTANCE"
case variable.TiDBStoreLimit:
return "INSTANCE | GLOBAL"
Expand Down Expand Up @@ -187,6 +192,8 @@ func formatSpecialVersionComment(sv *variable.SysVar) string {
return ` <span class="version-mark">New in v5.1</span>`
case variable.TiDBAnalyzeVersion:
return ` <span class="version-mark">New in v5.1.0</span>`
case variable.SkipNameResolve:
return ` <span class="version-mark">New in v5.2.0</span>`
default:
return ""
}
Expand Down Expand Up @@ -418,7 +425,7 @@ func getExtendedDescription(sv *variable.SysVar) string {
" * `CREATE TEMPORARY TABLE` syntax\n" +
" * `DROP TEMPORARY TABLE` syntax\n" +
" * `START TRANSACTION READ ONLY` and `SET TRANSACTION READ ONLY` syntax\n" +
" * The `tx_read_only`, `transaction_read_only`, `offline_mode`, `super_read_only` and `read_only` system variables\n" +
" * The `tx_read_only`, `transaction_read_only`, `offline_mode`, `super_read_only`, `read_only` and `sql_auto_is_null` system variables\n" +
"\n" +
"> **Warning:**\n" +
">\n" +
Expand Down Expand Up @@ -804,7 +811,7 @@ func getExtendedDescription(sv *variable.SysVar) string {
case variable.CharacterSetResults:
return "- The character set that is used when data is sent to the client."
case variable.CharacterSetServer:
return "- The character set used for new schemas when no character set is specified in the `CREATE SCHEMA` statement."
return "- The default character set for the server."
case variable.DataDir:
return "- This variable indicates the location where data is stored. This location can be a local path or point to a PD server if the data is stored on TiKV.\n" +
"- A value in the format of `ip_address:port` indicates the PD server that TiDB connects to on startup."
Expand All @@ -823,6 +830,62 @@ func getExtendedDescription(sv *variable.SysVar) string {
return "- This variable is used to control whether the optimizer estimates the number of rows based on column order correlation"
case variable.TiDBEnableAutoIncrementInGenerated:
return "- This variable is used to determine whether to include the `AUTO_INCREMENT` columns when creating a generated column or an expression index."
case variable.TMPTableSize:
return "- Indicates the maximum size of a temporary table."
case variable.Timestamp:
return "- A non-empty value of this variable indicates the UNIX epoch that is used as the timestamp for `CURRENT_TIMESTAMP()`, `NOW()`, and other functions. This variable might be used in data restore or replication."
case "ssl_key":
return "- The location of the private key file (if there is one) that is used for SSL/TLS connections."
case "ssl_cert":
return "- The location of the certificate file (if there is a file) that is used for SSL/TLS connections."
case variable.MaxAllowedPacket:
return "- The maximum size of a packet for the MySQL protocol."
case variable.BlockEncryptionMode:
return "- Defines the encryption mode for the `AES_ENCRYPT()` and `AES_DECRYPT()` functions."
case variable.CollationConnection:
return "- This variable indicates the collation for string literals that do not have a specified collation."
case variable.CollationDatabase:
return "- This variable indicates the collation of the default database in use. **It is NOT recommended to set this variable**. When a new default database is selected, the server changes the variable value."
case variable.CollationServer:
return "- The default collation for the server."
case variable.DefaultWeekFormat:
return "- Sets the week format used by the `WEEK()` function."
case variable.GroupConcatMaxLen:
return "- The maximum buffer size for items in the `GROUP_CONCAT()` function."
case "have_openssl":
return "- A read-only variable for MySQL compatibility. Set to `YES` by the server when the server has TLS enabled."
case "have_ssl":
return "- A read-only variable for MySQL compatibility. Set to `YES` by the server when the server has TLS enabled."
case variable.PluginDir:
return "- Indicates the directory to load plugins as specified by a command-line flag."
case variable.PluginLoad:
return "- Indicates the plugins to load when TiDB is started. These plugins are specified by a command-line flag and separated by commas."
case variable.SkipNameResolve:
return "- This variable controls whether the `tidb-server` instance resolves hostnames as a part of the connection handshake.\n" +
"- When the DNS is unreliable, you can enable this option to improve network performance.\n" +
"\n" +
"> **Note:**\n" +
">\n" +
"> When `skip_name_resolve=ON`, users with a hostname in their identity will no longer be able to log into the server. For example:\n" +
">\n" +
"> ```sql\n" +
"> CREATE USER 'appuser'@'apphost' IDENTIFIED BY 'app-password';\n" +
"> ```\n" +
">\n" +
"> In this example, it is recommended to replace `apphost` with an IP address or the wildcard (`%`)."
case variable.LogBin:
return "- This variable indicates whether [TiDB Binlog](/tidb-binlog/tidb-binlog-overview.md) is used."
case variable.LastInsertID:
return "- This variable returns the last `AUTO_INCREMENT` or `AUTO_RANDOM` value generated by an insert statement.\n" +
"- The value of `last_insert_id` is the same as the value returned by the function `LAST_INSERT_ID()`."
case variable.SQLLogBin:
return "- Indicates whether to write changes to [TiDB Binlog](/tidb-binlog/tidb-binlog-overview.md) or not.\n" +
"\n" +
"> **Note:**\n" +
">\n" +
"> It is not recommended to set `sql_log_bin` as a global variable because the future versions of TiDB might only allow setting this as a session variable."
case "ssl_ca":
return "- The location of the certificate authority file (if there is one)."
default:
return "- No documentation is currently available for this variable."
}
Expand Down Expand Up @@ -895,6 +958,11 @@ func main() {
fmt.Println("")
continue
}
if sv.Name == variable.Identity {
fmt.Println("This variable is an alias for _last_insert_id_.")
fmt.Println("")
continue
}

fmt.Printf("- Scope: %s\n", formatScope(sv))
fmt.Printf("- Default value: %s\n", formatDefaultValue(sv))
Expand Down
30 changes: 29 additions & 1 deletion scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,35 @@ module github.com/morgo/docs/scripts

go 1.16

require github.com/pingcap/tidb v1.1.0-beta.0.20210910144639-8e25f8eee42f // indirect
require (
github.com/BurntSushi/toml v0.4.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/danjacques/gofslock v0.0.0-20200623023034-5d0bd0fa6ef0 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00 // indirect
github.com/pingcap/kvproto v0.0.0-20210927053809-df38c15b57b3 // indirect
github.com/pingcap/tidb v1.1.0-beta.0.20210930110847-5f797c3f241c // indirect
github.com/pingcap/tidb-tools v5.2.1+incompatible // indirect
github.com/pingcap/tipb v0.0.0-20210917081614-311f2369c5f7 // indirect
github.com/prometheus/common v0.31.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/shirou/gopsutil v3.21.8+incompatible // indirect
github.com/twmb/murmur3 v1.1.6 // indirect
github.com/uber-go/atomic v1.4.0 // indirect
github.com/uber/jaeger-client-go v2.29.1+incompatible // indirect
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/net v0.0.0-20210929193557-e81a3d93ecf6 // indirect
golang.org/x/sys v0.0.0-20210930141918-969570ce7c6c // indirect
google.golang.org/genproto v0.0.0-20210930144712-2e2e1008e8a3 // indirect
google.golang.org/grpc v1.41.0 // indirect
)

replace (
github.com/coreos/etcd => github.com/coreos/etcd v3.3.13+incompatible
Expand Down
Loading