Skip to content

Commit

Permalink
[stats] limit stats boostrap to server start (#8124)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-hoffman authored Jul 26, 2024
1 parent 27760ea commit de879ef
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions go/cmd/dolt/commands/sqlserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ func ConfigureServices(
var sqlEngine *engine.SqlEngine
InitSqlEngine := &svcs.AnonService{
InitF: func(ctx context.Context) (err error) {
if _, err := mrEnv.Config().GetString(env.SqlServerGlobalsPrefix + "." + dsess.DoltStatsBootstrapEnabled); err != nil {
// unless otherwise specified by config, enable server bootstrapping
sql.SystemVariables.SetGlobal(dsess.DoltStatsBootstrapEnabled, 1)
}
sqlEngine, err = engine.NewSqlEngine(
ctx,
mrEnv,
Expand Down
2 changes: 1 addition & 1 deletion go/libraries/doltcore/sqle/system_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func AddDoltSystemVariables() {
Dynamic: true,
Scope: sql.GetMysqlScope(sql.SystemVariableScope_Global),
Type: types.NewSystemBoolType(dsess.DoltStatsBootstrapEnabled),
Default: int8(1),
Default: int8(0),
},
&sql.MysqlSystemVariable{
Name: dsess.DoltStatsMemoryOnly,
Expand Down
21 changes: 19 additions & 2 deletions integration-tests/bats/stats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,31 @@ teardown() {
[ "${lines[1]}" = "8" ]
}

@test "stats: bootrap on engine startup" {
@test "stats: bootrap on server startup" {
cd repo2

dolt sql -q "set @@PERSIST.dolt_stats_bootstrap_enabled = 1;"
dolt sql -q "insert into xy values (0,0), (1,1)"

start_sql_server
stop_sql_server

run dolt sql -r csv -q "select count(*) from dolt_statistics"
[ "$status" -eq 0 ]
[ "${lines[1]}" = "2" ]
}

@test "stats: only bootrap server startup" {
cd repo2

dolt sql -q "insert into xy values (0,0), (1,1)"

dolt gc

run dolt sql -r csv -q "select count(*) from dolt_statistics"
[ "$status" -eq 0 ]
[ "${lines[1]}" = "0" ]
}

@test "stats: deletes refresh" {
cd repo2

Expand Down Expand Up @@ -368,6 +383,8 @@ EOF
dolt sql -q "create table f (id int primary key, hostname int)"
dolt table import -u --continue f data.csv

dolt sql -q "set @@PERSIST.dolt_stats_bootstrap_enabled = 1;"

run dolt sql -r csv -q "select count(*) from dolt_statistics"
[ "$status" -eq 0 ]
[[ "${lines[0]}" =~ "stats bootstrap aborted" ]] || false
Expand Down

0 comments on commit de879ef

Please sign in to comment.