Skip to content

Commit

Permalink
add index for faster query to get refballot (#5038)
Browse files Browse the repository at this point in the history
there was a regression in proposal builder that started to use codepath that was used in different domain, which was executed once per epoch. now this is executed on every proposal creation and might be too slow.
  • Loading branch information
dshulyak committed Sep 20, 2023
1 parent f629581 commit 7168825
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
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)
}

0 comments on commit 7168825

Please sign in to comment.