Skip to content

Commit

Permalink
[no-release-notes] more stats logging (#8346)
Browse files Browse the repository at this point in the history
* [no-release-notes] more stats logging

* more

* fix args
  • Loading branch information
max-hoffman authored Sep 12, 2024
1 parent 01bd340 commit 0c9cbf0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
7 changes: 5 additions & 2 deletions go/libraries/doltcore/sqle/statsnoms/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,23 +231,26 @@ func (n *NomsStatsDatabase) initMutable(ctx context.Context, i int) error {
return nil
}

func (n *NomsStatsDatabase) DeleteStats(branch string, quals ...sql.StatQualifier) {
func (n *NomsStatsDatabase) DeleteStats(ctx *sql.Context, branch string, quals ...sql.StatQualifier) {
n.mu.Lock()
defer n.mu.Unlock()

for i, b := range n.branches {
if strings.EqualFold(b, branch) {
for _, qual := range quals {
ctx.GetLogger().Debugf("statistics refresh: deleting index statistics: %s/%s", branch, qual)
delete(n.stats[i], qual)
}
}
}
}

func (n *NomsStatsDatabase) DeleteBranchStats(ctx context.Context, branch string, flush bool) error {
func (n *NomsStatsDatabase) DeleteBranchStats(ctx *sql.Context, branch string, flush bool) error {
n.mu.Lock()
defer n.mu.Unlock()

ctx.GetLogger().Debugf("statistics refresh: deleting branch statistics: %s", branch)

for i, b := range n.branches {
if strings.EqualFold(b, branch) {
n.branches = append(n.branches[:i], n.branches[i+1:]...)
Expand Down
4 changes: 2 additions & 2 deletions go/libraries/doltcore/sqle/statspro/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ func (p *Provider) BootstrapDatabaseStats(ctx *sql.Context, db string) error {
}

func (p *Provider) RefreshTableStatsWithBranch(ctx *sql.Context, table sql.Table, db string, branch string) error {
if !p.TryLockForUpdate(table.Name(), db, branch) {
if !p.TryLockForUpdate(branch, db, table.Name()) {
return fmt.Errorf("already updating statistics")
}
defer p.UnlockTable(table.Name(), db, branch)
defer p.UnlockTable(branch, db, table.Name())

dSess := dsess.DSessFromSess(ctx.Session)

Expand Down
16 changes: 9 additions & 7 deletions go/libraries/doltcore/sqle/statspro/auto_refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ func (p *Provider) InitAutoRefreshWithParams(ctxFactory func(ctx context.Context
}

func (p *Provider) checkRefresh(ctx *sql.Context, sqlDb sql.Database, dbName, branch string, updateThresh float64) error {
if !p.TryLockForUpdate("", dbName, branch) {
return nil
if !p.TryLockForUpdate(branch, dbName, "") {
return fmt.Errorf("database already being updated: %s/%s", branch, dbName)
}
defer p.UnlockTable("", dbName, branch)
defer p.UnlockTable(branch, dbName, "")

// Iterate all dbs, tables, indexes. Each db will collect
// []indexMeta above refresh threshold. We read and process those
Expand All @@ -133,10 +133,12 @@ func (p *Provider) checkRefresh(ctx *sql.Context, sqlDb sql.Database, dbName, br
}

for _, table := range tables {
if !p.TryLockForUpdate(table, dbName, branch) {
continue
if !p.TryLockForUpdate(branch, dbName, table) {
ctx.GetLogger().Debugf("statistics refresh: table is already being updated: %s/%s.%s", branch, dbName, table)
return fmt.Errorf("table already being updated: %s", table)
}
defer p.UnlockTable(table, dbName, branch)
defer p.UnlockTable(branch, dbName, table)

sqlTable, dTab, err := GetLatestTable(ctx, table, sqlDb)
if err != nil {
return err
Expand Down Expand Up @@ -240,7 +242,7 @@ func (p *Provider) checkRefresh(ctx *sql.Context, sqlDb sql.Database, dbName, br
}
}

statDb.DeleteStats(branch, deletedStats...)
statDb.DeleteStats(ctx, branch, deletedStats...)

if err := statDb.Flush(ctx, branch); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions go/libraries/doltcore/sqle/statspro/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ type Database interface {
LoadBranchStats(ctx *sql.Context, branch string) error
// DeleteBranchStats removes references to in memory index statistics.
// If |flush| is true delete the data from storage.
DeleteBranchStats(ctx context.Context, branch string, flush bool) error
DeleteBranchStats(ctx *sql.Context, branch string, flush bool) error
// GetStat returns a branch's index statistics.
GetStat(branch string, qual sql.StatQualifier) (*DoltStats, bool)
//SetStat bulk replaces the statistic, deleting any previous version
SetStat(ctx context.Context, branch string, qual sql.StatQualifier, stats *DoltStats) error
//DeleteStats deletes a list of index statistics.
DeleteStats(branch string, quals ...sql.StatQualifier)
DeleteStats(ctx *sql.Context, branch string, quals ...sql.StatQualifier)
// ReplaceChunks is an update interface that lets a stats implementation
// decide how to edit stats for a stats refresh.
ReplaceChunks(ctx context.Context, branch string, qual sql.StatQualifier, targetHashes []hash.Hash, dropChunks, newChunks []sql.HistogramBucket) error
Expand Down
10 changes: 5 additions & 5 deletions go/libraries/doltcore/sqle/statspro/stats_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,21 @@ func newDbStats(dbName string) *dbToStats {

var _ sql.StatsProvider = (*Provider)(nil)

func (p *Provider) TryLockForUpdate(table string, db string, branch string) bool {
func (p *Provider) TryLockForUpdate(branch, db, table string) bool {
p.mu.Lock()
defer p.mu.Unlock()
lockId := fmt.Sprintf("%s.%s.%s", db, branch, table)
lockId := fmt.Sprintf("%s.%s.%s", branch, db, table)
if ok := p.lockedTables[lockId]; ok {
return false
}
p.lockedTables[lockId] = true
return true
}

func (p *Provider) UnlockTable(table string, db string, branch string) {
func (p *Provider) UnlockTable(branch, db, table string) {
p.mu.Lock()
defer p.mu.Unlock()
lockId := fmt.Sprintf("%s.%s.%s", db, branch, table)
lockId := fmt.Sprintf("%s.%s.%s", branch, db, table)
p.lockedTables[lockId] = false
return
}
Expand Down Expand Up @@ -279,7 +279,7 @@ func (p *Provider) DropStats(ctx *sql.Context, qual sql.StatQualifier, _ []strin
}

if _, ok := statDb.GetStat(branch, qual); ok {
statDb.DeleteStats(branch, qual)
statDb.DeleteStats(ctx, branch, qual)
p.UpdateStatus(qual.Db(), fmt.Sprintf("dropped statisic: %s", qual.String()))
}

Expand Down

0 comments on commit 0c9cbf0

Please sign in to comment.