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-03-26 13:12:29 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2021-04-01 12:50:49 +0300
commit54f0de751b48b23424640cd851a8222b5025f6bc (patch)
tree29fd9d9aebee872680e38faf48fa5f6a97abd95d /internal/praefect/assignment.go
parent6f68e2cb582b272336963761181d1b0759fb5b22 (diff)
Add DisabledAssignmentStore to use when assignments are disabled
Praefect can still be configured to run without the database. To support such a configuration, this commit adds a DisabledAssignmentStore which can be plugged in if the database is not used. It simply returns all storages as assigned and doesn't allow for configuring replication factors.
Diffstat (limited to 'internal/praefect/assignment.go')
-rw-r--r--internal/praefect/assignment.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/internal/praefect/assignment.go b/internal/praefect/assignment.go
new file mode 100644
index 000000000..f0f38e5af
--- /dev/null
+++ b/internal/praefect/assignment.go
@@ -0,0 +1,33 @@
+package praefect
+
+import (
+ "context"
+ "errors"
+)
+
+// AssignmentStore is the interface which Praefect uses to operate on repository assignments.
+type AssignmentStore interface {
+ AssignmentGetter
+ // SetReplicationFactor sets a repository's replication factor to the desired value and returns the
+ // resulting assignments.
+ SetReplicationFactor(ctx context.Context, virtualStorage, relativePath string, replicationFactor int) ([]string, error)
+}
+
+type disabledAssignments map[string][]string
+
+// NewDisabledAssignmentStore returns an assignments store that can be used if no
+// database is configured. It returns every configured storage as assigned and
+// errors when trying to set assignments.
+func NewDisabledAssignmentStore(storages map[string][]string) AssignmentStore {
+ return disabledAssignments(storages)
+}
+
+// GetHostAssigments simply returns all of the storages configured for the virtual storage.
+func (storages disabledAssignments) GetHostAssignments(ctx context.Context, virtualStorage, relativePath string) ([]string, error) {
+ return storages[virtualStorage], nil
+}
+
+// SetReplicationFactor errors when attempting to set assignments.
+func (disabledAssignments) SetReplicationFactor(context.Context, string, string, int) ([]string, error) {
+ return nil, errors.New("assignments are disabled")
+}