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

[Merged by Bors] - add index for faster query to get refballot #5038

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ func (app *App) setupDBs(ctx context.Context, lg log.Log) error {
sqlDB, err := sql.Open("file:"+filepath.Join(dbPath, dbFile),
sql.WithConnections(app.Config.DatabaseConnections),
sql.WithLatencyMetering(app.Config.DatabaseLatencyMetering),
sql.WithV4Migration(util.ExtractActiveSet),
sql.WithV5Migration(util.ExtractActiveSet),
)
if err != nil {
return fmt.Errorf("open sqlite db %w", err)
Expand Down
12 changes: 6 additions & 6 deletions sql/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type conf struct {
enableLatency bool

// TODO: remove after state is pruned for majority
v4Migration func(Executor) error
v5Migration func(Executor) error
}

// WithConnections overwrites number of pooled connections.
Expand All @@ -78,9 +78,9 @@ func WithMigrations(migrations Migrations) Opt {
}
}

func WithV4Migration(cb func(Executor) error) Opt {
func WithV5Migration(cb func(Executor) error) Opt {
return func(c *conf) {
c.v4Migration = cb
c.v5Migration = cb
}
}

Expand Down Expand Up @@ -145,9 +145,9 @@ func Open(uri string, opts ...Opt) (*Database, error) {
if err != nil {
return nil, err
}
if before <= 3 && after == 4 && config.v4Migration != nil {
// v4 migration (active set extraction) needs the 3rd migration to execute first
if err := config.v4Migration(db); err != nil {
if before <= 4 && after == 5 && config.v5Migration != nil {
// v5 migration (active set extraction) needs the 4rd migration to execute first
if err := config.v5Migration(db); err != nil {
return nil, err
}
if err := Vacuum(db); err != nil {
Expand Down
1 change: 1 addition & 0 deletions sql/migrations/0004_v1.1.7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE INDEX ballots_by_atx_by_layer ON ballots (atx, layer asc);
File renamed without changes.
2 changes: 1 addition & 1 deletion sql/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ func TestMigrationsAppliedOnce(t *testing.T) {
return true
})
require.NoError(t, err)
require.Equal(t, version, 4)
require.Equal(t, version, 5)
}