diff options
author | Pavlo Strokov <pstrokov@gitlab.com> | 2020-05-20 12:55:31 +0300 |
---|---|---|
committer | Pavlo Strokov <pstrokov@gitlab.com> | 2020-05-20 17:39:08 +0300 |
commit | 28a1bcf811892ad13263da82809bcca8c21f8d43 (patch) | |
tree | a0bf15c6149ddf26656ce9219b7b370786f35163 | |
parent | 8ad922024fbe6e73e0e49849a0eb1612b5a8ac89 (diff) |
Praefect: Enable database replication queue by default
Thew PostgreSQL based implementation of the replication queue
is enabled by default.
In order to simplify unit testing the in-memory implementation
resides and can be used in case `memory_queue_enabled = true`
configuration option provided.
Closes: https://gitlab.com/gitlab-org/gitaly/-/issues/2615
-rw-r--r-- | changelogs/unreleased/ps-sql-queue-enabled.yml | 5 | ||||
-rw-r--r-- | cmd/praefect/main.go | 6 | ||||
-rw-r--r-- | internal/praefect/config/config.go | 6 | ||||
-rw-r--r-- | internal/praefect/config/config_test.go | 16 | ||||
-rw-r--r-- | internal/praefect/config/testdata/config.toml | 2 | ||||
-rw-r--r-- | internal/testhelper/testserver.go | 1 |
6 files changed, 21 insertions, 15 deletions
diff --git a/changelogs/unreleased/ps-sql-queue-enabled.yml b/changelogs/unreleased/ps-sql-queue-enabled.yml new file mode 100644 index 000000000..d61da8bb4 --- /dev/null +++ b/changelogs/unreleased/ps-sql-queue-enabled.yml @@ -0,0 +1,5 @@ +--- +title: 'Praefect: Enable database replication queue by default' +merge_request: 2193 +author: +type: changed diff --git a/cmd/praefect/main.go b/cmd/praefect/main.go index 7c42fb18a..322ae28b5 100644 --- a/cmd/praefect/main.go +++ b/cmd/praefect/main.go @@ -232,10 +232,10 @@ func run(cfgs []starter.Config, conf config.Config) error { } ds := datastore.Datastore{ReplicasDatastore: datastore.NewInMemory(conf)} - if conf.PostgresQueueEnabled { - ds.ReplicationEventQueue = datastore.NewPostgresReplicationEventQueue(db) - } else { + if conf.MemoryQueueEnabled { ds.ReplicationEventQueue = datastore.NewMemoryReplicationEventQueue(conf) + } else { + ds.ReplicationEventQueue = datastore.NewPostgresReplicationEventQueue(db) } nodeManager, err := nodes.NewManager(logger, conf, db, ds, nodeLatencyHistogram) diff --git a/internal/praefect/config/config.go b/internal/praefect/config/config.go index 510eada28..adfd183dc 100644 --- a/internal/praefect/config/config.go +++ b/internal/praefect/config/config.go @@ -34,8 +34,8 @@ type Config struct { DB `toml:"database"` Failover Failover `toml:"failover"` // Keep for legacy reasons: remove after Omnibus has switched - FailoverEnabled bool `toml:"failover_enabled"` - PostgresQueueEnabled bool `toml:"postgres_queue_enabled"` + FailoverEnabled bool `toml:"failover_enabled"` + MemoryQueueEnabled bool `toml:"memory_queue_enabled"` } // VirtualStorage represents a set of nodes for a storage @@ -145,7 +145,7 @@ func (c Config) Validate() error { // NeedsSQL returns true if the driver for SQL needs to be initialized func (c Config) NeedsSQL() bool { - return c.PostgresQueueEnabled || (c.Failover.Enabled && c.Failover.ElectionStrategy == "sql") + return !c.MemoryQueueEnabled || (c.Failover.Enabled && c.Failover.ElectionStrategy == "sql") } // DB holds Postgres client configuration data. diff --git a/internal/praefect/config/config_test.go b/internal/praefect/config/config_test.go index 0077e6094..c85894b08 100644 --- a/internal/praefect/config/config_test.go +++ b/internal/praefect/config/config_test.go @@ -257,7 +257,7 @@ func TestConfigParsing(t *testing.T) { SSLKey: "/path/to/key", SSLRootCert: "/path/to/root-cert", }, - PostgresQueueEnabled: true, + MemoryQueueEnabled: true, }, }, } @@ -318,17 +318,17 @@ func TestNeedsSQL(t *testing.T) { { desc: "default", config: Config{}, - expected: false, + expected: true, }, { - desc: "PostgreSQL queue enabled", - config: Config{PostgresQueueEnabled: true}, - expected: true, + desc: "Memory queue enabled", + config: Config{MemoryQueueEnabled: true}, + expected: false, }, { desc: "Failover enabled with default election strategy", config: Config{Failover: Failover{Enabled: true}}, - expected: false, + expected: true, }, { desc: "Failover enabled with SQL election strategy", @@ -337,12 +337,12 @@ func TestNeedsSQL(t *testing.T) { }, { desc: "Both PostgresQL and SQL election strategy enabled", - config: Config{PostgresQueueEnabled: true, Failover: Failover{Enabled: true, ElectionStrategy: "sql"}}, + config: Config{Failover: Failover{Enabled: true, ElectionStrategy: "sql"}}, expected: true, }, { desc: "Both PostgresQL and SQL election strategy enabled but failover disabled", - config: Config{PostgresQueueEnabled: true, Failover: Failover{Enabled: false, ElectionStrategy: "sql"}}, + config: Config{Failover: Failover{Enabled: false, ElectionStrategy: "sql"}}, expected: true, }, } diff --git a/internal/praefect/config/testdata/config.toml b/internal/praefect/config/testdata/config.toml index c871972a4..a11918cb0 100644 --- a/internal/praefect/config/testdata/config.toml +++ b/internal/praefect/config/testdata/config.toml @@ -1,7 +1,7 @@ listen_addr = "" socket_path = "" prometheus_listen_addr = "" -postgres_queue_enabled = true +memory_queue_enabled = true distributed_reads_enabled = true [logging] diff --git a/internal/testhelper/testserver.go b/internal/testhelper/testserver.go index 8d259c995..017e2dbc0 100644 --- a/internal/testhelper/testserver.go +++ b/internal/testhelper/testserver.go @@ -160,6 +160,7 @@ func (p *TestServer) Start() error { Auth: auth.Config{ Token: p.token, }, + MemoryQueueEnabled: true, } for _, storage := range p.storages { |