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

[statspro] Restart drop db #8350

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions go/libraries/doltcore/sqle/statspro/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ func (p *Provider) Load(ctx *sql.Context, fs filesys.Filesys, db dsess.SqlDataba
}
}

p.mu.Lock()
defer p.mu.Unlock()
p.setStatDb(strings.ToLower(db.Name()), statsDb)
return
}
16 changes: 8 additions & 8 deletions go/libraries/doltcore/sqle/statspro/initdbhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ func NewStatsInitDatabaseHook(
denv *env.DoltEnv,
db dsess.SqlDatabase,
) error {
statsDb, err := statsProv.sf.Init(ctx, db, statsProv.pro, denv.FS, env.GetCurrentUserHomeDir)
if err != nil {
ctx.GetLogger().Debugf("statistics load error: %s", err.Error())
return nil
dbName := strings.ToLower(db.Name())
if _, ok := statsProv.getStatDb(dbName); !ok {
statsDb, err := statsProv.sf.Init(ctx, db, statsProv.pro, denv.FS, env.GetCurrentUserHomeDir)
if err != nil {
ctx.GetLogger().Debugf("statistics load error: %s", err.Error())
return nil
}
statsProv.setStatDb(dbName, statsDb)
}
statsProv.mu.Lock()
statsProv.setStatDb(strings.ToLower(db.Name()), statsDb)
statsProv.mu.Unlock()

ctx.GetLogger().Debugf("statistics refresh: initialize %s", name)
return statsProv.InitAutoRefresh(ctxFactory, name, bThreads)
}
Expand Down
2 changes: 2 additions & 0 deletions go/libraries/doltcore/sqle/statspro/stats_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ func (p *Provider) GetTableDoltStats(ctx *sql.Context, branch, db, table string)
}

func (p *Provider) setStatDb(name string, db Database) {
p.mu.Lock()
defer p.mu.Unlock()
p.statDbs[name] = db
}

Expand Down
21 changes: 21 additions & 0 deletions integration-tests/bats/stats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@ teardown() {
[ "$status" -eq 1 ]
}

@test "stats: restart in shell doesn't drop db, issue#8345" {
cd repo2

dolt sql -q "insert into xy values (0,0), (1,1), (2,2), (3,3), (4,4)"
dolt sql -q "insert into ab values (0,0), (1,1), (2,2), (3,3), (4,4)"
dolt sql -q "ANALYZE table xy, ab"
run dolt sql -r csv <<EOF
select count(*) from dolt_statistics;
set @@GLOBAL.dolt_stats_auto_refresh_interval = 2;
call dolt_stats_restart();
select count(*) from dolt_statistics;
select sleep(3);
select count(*) from dolt_statistics;
EOF
[ "${lines[1]}" = "4" ]
[ "${lines[5]}" = "4" ]
[ "${lines[9]}" = "4" ]
[ "$status" -eq 0 ]
}

@test "stats: stats roundtrip restart" {
cd repo2

Expand Down Expand Up @@ -383,6 +403,7 @@ SQL
dolt sql <<SQL
use repo2;
insert into xy values (0,0);
analyze table xy;
SQL

sleep 1
Expand Down
Loading