-
-
Notifications
You must be signed in to change notification settings - Fork 526
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
Stats auto refresh #7424
Merged
Merged
Stats auto refresh #7424
Changes from 16 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
cc82f99
Stats auto refresh prototype
max-hoffman 0cf91c9
fix bugs
max-hoffman 340e43c
test stats update
max-hoffman f180d20
add tests, fix bugs
max-hoffman b17bdcf
fix test
max-hoffman 023cf59
fmt
max-hoffman 97d8a04
delete test
max-hoffman 49d78e9
more tests
max-hoffman 81dba2b
delete table test
max-hoffman 5edf046
[ga-format-pr] Run go/utils/repofmt/format_repo.sh and go/Godeps/upda…
max-hoffman adbcabc
add and delete stats hooks
max-hoffman 641ca04
fmt
max-hoffman 38392dd
Merge branch 'max/stats-refresh' of github.com:dolthub/dolt into max/…
max-hoffman b5c93ad
concurrency improvements
max-hoffman 5288c1b
[ga-format-pr] Run go/utils/repofmt/format_repo.sh and go/Godeps/upda…
max-hoffman bfcff4f
write bug
max-hoffman 9393f63
more tests and stats functions
max-hoffman 88690cb
Merge branch 'max/stats-refresh' of github.com:dolthub/dolt into max/…
max-hoffman ad35847
Merge branch 'main' into max/stats-refresh
max-hoffman 49b59b2
working dolt_stat funcs
max-hoffman 1d8830f
test fixes
max-hoffman e61f88e
merge main
max-hoffman dedbf19
bump
max-hoffman 7198173
fmt
max-hoffman 1979f9b
fix wg panic
max-hoffman bbfbc36
merge main
max-hoffman 18fd075
[ga-format-pr] Run go/utils/repofmt/format_repo.sh and go/Godeps/upda…
max-hoffman f3e6243
merge main
max-hoffman be41ce9
Merge branch 'max/stats-refresh' of github.com:dolthub/dolt into max/…
max-hoffman f09626b
nick comments
max-hoffman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,123 @@ | ||||||
// Copyright 2024 Dolthub, Inc. | ||||||
// | ||||||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
// you may not use this file except in compliance with the License. | ||||||
// You may obtain a copy of the License at | ||||||
// | ||||||
// http://www.apache.org/licenses/LICENSE-2.0 | ||||||
// | ||||||
// Unless required by applicable law or agreed to in writing, software | ||||||
// distributed under the License is distributed on an "AS IS" BASIS, | ||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
// See the License for the specific language governing permissions and | ||||||
// limitations under the License. | ||||||
|
||||||
package dprocedures | ||||||
|
||||||
import ( | ||||||
"fmt" | ||||||
"strings" | ||||||
|
||||||
"github.com/dolthub/go-mysql-server/sql" | ||||||
|
||||||
"github.com/dolthub/dolt/go/libraries/doltcore/env" | ||||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref" | ||||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess" | ||||||
) | ||||||
|
||||||
func statsFunc(name string) func(ctx *sql.Context, args ...string) (sql.RowIter, error) { | ||||||
var fn func(*sql.Context) (interface{}, error) | ||||||
switch name { | ||||||
case "drop": | ||||||
fn = statsDrop | ||||||
case "restart": | ||||||
fn = statsRestart | ||||||
case "stop": | ||||||
fn = statsStop | ||||||
case "status": | ||||||
fn = statsStatus | ||||||
} | ||||||
return func(ctx *sql.Context, args ...string) (sql.RowIter, error) { | ||||||
res, err := fn(ctx) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
return rowToIter(res), nil | ||||||
} | ||||||
} | ||||||
|
||||||
// AutoRefreshStatsProvider is a sql.StatsProvider that exposes hooks for | ||||||
// observing and manipulating background database auto refresh threads. | ||||||
type AutoRefreshStatsProvider interface { | ||||||
sql.StatsProvider | ||||||
CancelRefreshThread(string) | ||||||
StartRefreshThread(*sql.Context, dsess.DoltDatabaseProvider, string, *env.DoltEnv) error | ||||||
ThreadStatus(string) string | ||||||
} | ||||||
|
||||||
// statsRestart tries to stop and then start a refresh thread | ||||||
func statsRestart(ctx *sql.Context) (interface{}, error) { | ||||||
dSess := dsess.DSessFromSess(ctx.Session) | ||||||
statsPro := dSess.StatsProvider() | ||||||
dbName := strings.ToLower(ctx.GetCurrentDatabase()) | ||||||
|
||||||
if afp, ok := statsPro.(AutoRefreshStatsProvider); ok { | ||||||
pro := dSess.Provider() | ||||||
newFs, err := pro.FileSystem().WithWorkingDir(dbName) | ||||||
if err != nil { | ||||||
return nil, fmt.Errorf("failed to restart stats collection: %w", err) | ||||||
} | ||||||
|
||||||
dEnv := env.Load(ctx, env.GetCurrentUserHomeDir, newFs, pro.DbFactoryUrl(), "TODO") | ||||||
|
||||||
afp.CancelRefreshThread(dbName) | ||||||
|
||||||
err = afp.StartRefreshThread(ctx, pro, dbName, dEnv) | ||||||
if err != nil { | ||||||
return nil, fmt.Errorf("failed to restart collection: %w", err) | ||||||
} | ||||||
return fmt.Sprintf("restarted stats collection: %s", ref.StatsRef{}.String()), nil | ||||||
} | ||||||
return nil, nil | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
// statsStatus returns the last update for a stats thread | ||||||
func statsStatus(ctx *sql.Context) (interface{}, error) { | ||||||
dSess := dsess.DSessFromSess(ctx.Session) | ||||||
dbName := strings.ToLower(ctx.GetCurrentDatabase()) | ||||||
pro := dSess.StatsProvider() | ||||||
if afp, ok := pro.(AutoRefreshStatsProvider); ok { | ||||||
return afp.ThreadStatus(dbName), nil | ||||||
} | ||||||
return nil, fmt.Errorf("provider does not implement AutoRefreshStatsProvider") | ||||||
} | ||||||
|
||||||
// statsStop cancels a refresh thread | ||||||
func statsStop(ctx *sql.Context) (interface{}, error) { | ||||||
dSess := dsess.DSessFromSess(ctx.Session) | ||||||
statsPro := dSess.StatsProvider() | ||||||
dbName := strings.ToLower(ctx.GetCurrentDatabase()) | ||||||
|
||||||
if afp, ok := statsPro.(AutoRefreshStatsProvider); ok { | ||||||
afp.CancelRefreshThread(dbName) | ||||||
return fmt.Sprintf("stopped thread: %s", dbName), nil | ||||||
} | ||||||
return nil, fmt.Errorf("provider does not implement AutoRefreshStatsProvider") | ||||||
} | ||||||
|
||||||
// statsDrop deletes the stats ref | ||||||
func statsDrop(ctx *sql.Context) (interface{}, error) { | ||||||
dSess := dsess.DSessFromSess(ctx.Session) | ||||||
pro := dSess.StatsProvider() | ||||||
dbName := strings.ToLower(ctx.GetCurrentDatabase()) | ||||||
|
||||||
if afp, ok := pro.(AutoRefreshStatsProvider); ok { | ||||||
// currently unsafe to drop stats while running refresh | ||||||
afp.CancelRefreshThread(dbName) | ||||||
} | ||||||
err := pro.DropDbStats(ctx, dbName, true) | ||||||
if err != nil { | ||||||
return nil, fmt.Errorf("failed to drop stats: %w", err) | ||||||
} | ||||||
return fmt.Sprintf("deleted stats ref for %s", dbName), nil | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switching on the string here feels unnecessary. Can't DoltProcedures just do something like:
{Name: "dolt_stats_drop", Schema: doltMergeSchema, Function: statsFunc(statsDrop)},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep good idea