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-04-01 17:57:31 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2021-04-06 15:18:09 +0300
commit7ad78842a63f96cb96619ed92b41c210cdbba435 (patch)
treef37fd2b983dd74f3a187076e1caddb96c10ae309
parent8e62ebd1ba44273e5571b7d8f1088109e99d70f7 (diff)
Remove incorrect pre-allocation from GetConsistentStorages
GetConsistentStorages previously returned only the consistent secondaries. Back then, we were removing the primary from the result set and thus pre-allocated the map to the number of secondaries ancitipating all secondaries to be consistent. This does not make sense anymore. We don't remove the primary from the result set so the initial capacity was wrong, likely resulting in an extra allocation anyway. With variable replication factor, we can't even guess the result count from the storages, so let's just remove the incorrect map pre-allocation. This commit also renames the `consistentSecondaries` map to `consistentStorages` for accuracy. `storages` method is removed as it is no longer used.
-rw-r--r--internal/praefect/datastore/repository_store.go22
1 files changed, 3 insertions, 19 deletions
diff --git a/internal/praefect/datastore/repository_store.go b/internal/praefect/datastore/repository_store.go
index 6e0d6bbb3..f9f4a9a3d 100644
--- a/internal/praefect/datastore/repository_store.go
+++ b/internal/praefect/datastore/repository_store.go
@@ -14,15 +14,6 @@ import (
type storages map[string][]string
-func (s storages) storages(virtualStorage string) ([]string, error) {
- storages, ok := s[virtualStorage]
- if !ok {
- return nil, fmt.Errorf("unknown virtual storage: %q", virtualStorage)
- }
-
- return storages, nil
-}
-
// GenerationUnknown is used to indicate lack of generation number in
// a replication job. Older instances can produce replication jobs
// without a generation number.
@@ -450,34 +441,27 @@ SELECT storage
FROM storage_repositories
JOIN expected_repositories USING (virtual_storage, relative_path, generation)
`
-
- storages, err := rs.storages.storages(virtualStorage)
- if err != nil {
- return nil, err
- }
-
rows, err := rs.db.QueryContext(ctx, q, virtualStorage, relativePath)
if err != nil {
return nil, fmt.Errorf("query: %w", err)
}
defer rows.Close()
- consistentSecondaries := make(map[string]struct{}, len(storages)-1)
-
+ consistentStorages := map[string]struct{}{}
for rows.Next() {
var storage string
if err := rows.Scan(&storage); err != nil {
return nil, fmt.Errorf("scan: %w", err)
}
- consistentSecondaries[storage] = struct{}{}
+ consistentStorages[storage] = struct{}{}
}
if err := rows.Err(); err != nil {
return nil, fmt.Errorf("rows: %w", err)
}
- return consistentSecondaries, nil
+ return consistentStorages, nil
}
func (rs *PostgresRepositoryStore) RepositoryExists(ctx context.Context, virtualStorage, relativePath string) (bool, error) {