Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSami Hiltunen <shiltunen@gitlab.com>2021-11-17 19:33:54 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2021-11-18 12:48:03 +0300
commit0ce68fb31ab0ba9da7652605f204eff65328a507 (patch)
tree8340fa0bc32c3c47c697d7bb6e133abd46f46e0f
parent662ea053597d8c6f39f6bbcef9c60cb281d55599 (diff)
Materialize valid_primaries view in RepositoryStoreCollector
RepositoryStoreCollector gathers metrics on repositories which don't have a valid primary candidates available. This indicates the repository is unavailable as the current primary is not valid and ther are no valid candidates to failover to. The query is currently extremely inefficient on some versions of Postgres as it ends up computing the full valid_primaries view for each of the rows it checks. This doesn't seem to occur on all versions of Postgres, namely 12.6 at least manages to push down the search criteria inside the view. This commit fixes the situation by materializing the valid_primaries view prior to querying it. This ensures the full view isn't computed for all of the rows but rather Postgres just uses the pre-computed result. Changelog: performance
-rw-r--r--internal/praefect/datastore/collector.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/internal/praefect/datastore/collector.go b/internal/praefect/datastore/collector.go
index 15bc46394..71f145e67 100644
--- a/internal/praefect/datastore/collector.go
+++ b/internal/praefect/datastore/collector.go
@@ -72,6 +72,11 @@ func (c *RepositoryStoreCollector) Collect(ch chan<- prometheus.Metric) {
// they are either unhealthy or out of date.
func (c *RepositoryStoreCollector) queryMetrics(ctx context.Context) (map[string]int, error) {
rows, err := c.db.QueryContext(ctx, `
+WITH valid_primaries AS MATERIALIZED (
+ SELECT virtual_storage, relative_path
+ FROM valid_primaries
+)
+
SELECT virtual_storage, COUNT(*)
FROM repositories
WHERE NOT EXISTS (