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-07-27 17:25:10 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2021-08-31 15:57:48 +0300
commit1836583ff226a634932a9e2f424acc3e8882d9d9 (patch)
treef31db9b1b4b695def91d5bdf9720db95a3f1f0f2 /internal/praefect/router_per_repository.go
parentec619962966cc59d889c7792b1613b3ac4c0968f (diff)
Reserve repository ids when routing repository creations
When Praefect is routing a repository creation, it needs to reserve a repository ID in order to generate later a relative path for the repository. This commit changes the PerRepositoryRouter to reserve a repository ID and return in the route. The ID reservation also acts as a fail fast check to see whether there already exists a repository with the given virtual storage and relative path.
Diffstat (limited to 'internal/praefect/router_per_repository.go')
-rw-r--r--internal/praefect/router_per_repository.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/internal/praefect/router_per_repository.go b/internal/praefect/router_per_repository.go
index 3a1a98f4e..326d375cb 100644
--- a/internal/praefect/router_per_repository.go
+++ b/internal/praefect/router_per_repository.go
@@ -63,11 +63,20 @@ type PerRepositoryRouter struct {
rand Random
hc HealthChecker
csg datastore.ConsistentStoragesGetter
+ rs datastore.RepositoryStore
defaultReplicationFactors map[string]int
}
// NewPerRepositoryRouter returns a new PerRepositoryRouter using the passed configuration.
-func NewPerRepositoryRouter(conns Connections, pg PrimaryGetter, hc HealthChecker, rand Random, csg datastore.ConsistentStoragesGetter, ag AssignmentGetter, defaultReplicationFactors map[string]int) *PerRepositoryRouter {
+func NewPerRepositoryRouter(
+ conns Connections,
+ pg PrimaryGetter,
+ hc HealthChecker,
+ rand Random,
+ csg datastore.ConsistentStoragesGetter,
+ ag AssignmentGetter,
+ rs datastore.RepositoryStore,
+ defaultReplicationFactors map[string]int) *PerRepositoryRouter {
return &PerRepositoryRouter{
conns: conns,
pg: pg,
@@ -75,6 +84,7 @@ func NewPerRepositoryRouter(conns Connections, pg PrimaryGetter, hc HealthChecke
hc: hc,
csg: csg,
ag: ag,
+ rs: rs,
defaultReplicationFactors: defaultReplicationFactors,
}
}
@@ -248,9 +258,17 @@ func (r *PerRepositoryRouter) RouteRepositoryCreation(ctx context.Context, virtu
return RepositoryMutatorRoute{}, err
}
+ id, err := r.rs.ReserveRepositoryID(ctx, virtualStorage, relativePath)
+ if err != nil {
+ return RepositoryMutatorRoute{}, fmt.Errorf("reserve repository id: %w", err)
+ }
+
replicationFactor := r.defaultReplicationFactors[virtualStorage]
if replicationFactor == 1 {
- return RepositoryMutatorRoute{Primary: primary}, nil
+ return RepositoryMutatorRoute{
+ RepositoryID: id,
+ Primary: primary,
+ }, nil
}
var secondaryNodes []RouterNode
@@ -296,6 +314,7 @@ func (r *PerRepositoryRouter) RouteRepositoryCreation(ctx context.Context, virtu
}
return RepositoryMutatorRoute{
+ RepositoryID: id,
Primary: primary,
Secondaries: secondaries,
ReplicationTargets: replicationTargets,