Skip to content

Commit

Permalink
services/horizon: Apply and check migrations on ingesting instances o…
Browse files Browse the repository at this point in the history
…nly (#3586)

This commit reverts 7c92b23 and changes the DB migrations behaviour to only
trigger on ingesting instances.

When checking if there are any migrations required Horizon calls
`migrate.PlanMigration` which sends `CREATE TABLE gorp_migrations`. This write
query is forbidden when using read only database (like replica).

The new flag in 7c92b23 added unnecessary complexity. Ingesting instances are
guaranteed to have write access to a DB.

Thanks @jacekn for the idea!
  • Loading branch information
bartekn authored May 5, 2021
1 parent 36f465c commit 67fe4a7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
3 changes: 0 additions & 3 deletions services/horizon/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ type Config struct {
// ApplyMigrations will apply pending migrations to the horizon database
// before starting the horizon service
ApplyMigrations bool
// SkipMigrationsCheck will skip checking if there are any migrations
// required
SkipMigrationsCheck bool
// CheckpointFrequency establishes how many ledgers exist between checkpoints
CheckpointFrequency uint32
// BehindCloudflare determines if Horizon instance is behind Cloudflare. In
Expand Down
24 changes: 7 additions & 17 deletions services/horizon/internal/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,6 @@ func Flags() (*Config, support.ConfigOptions) {
Required: false,
Usage: "applies pending migrations before starting horizon",
},
&support.ConfigOption{
Name: "skip-migrations-check",
ConfigKey: &config.SkipMigrationsCheck,
OptType: types.Bool,
FlagDefault: false,
Required: false,
Usage: "skips checking if there are migrations required",
},
&support.ConfigOption{
Name: "checkpoint-frequency",
ConfigKey: &config.CheckpointFrequency,
Expand Down Expand Up @@ -446,19 +438,17 @@ func ApplyFlags(config *Config, flags support.ConfigOptions) {
flags.Require()
flags.SetValues()

if config.ApplyMigrations {
applyMigrations(*config)
}

// Migrations should be checked as early as possible
if !config.SkipMigrationsCheck {
checkMigrations(*config)
}

// Validate options that should be provided together
validateBothOrNeither("tls-cert", "tls-key")

if config.Ingest {
// Migrations should be checked as early as possible. Apply and check
// only on ingesting instances which are required to have write-access
// to the DB.
if config.ApplyMigrations {
applyMigrations(*config)
}
checkMigrations(*config)

// config.HistoryArchiveURLs contains a single empty value when empty so using
// viper.GetString is easier.
Expand Down

0 comments on commit 67fe4a7

Please sign in to comment.