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:53:41 +0300
commitdf6b165f328449043f84ef9314f7b133aa3a3aa4 (patch)
tree968b6eabc97cd3be9083624e6b25d17b2e4250d9
parent57bef77949125cf60bb479f5b37c77c9f1692c68 (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 (