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:
authorJames Fargher <jfargher@gitlab.com>2023-06-15 02:35:36 +0300
committerJames Fargher <jfargher@gitlab.com>2023-06-21 03:57:26 +0300
commitb7966eb8a128fc7d0cbf6e83e26fb4dd65efaa05 (patch)
tree7b303441b7fe931d0524a54244ea264a0728e43f
parent5098821844a532eb7936adba0557a475599f3b2b (diff)
backup: Introduce a vanity repository to calculate paths
When we generate a server-side backup, we want to be able to use any arbitrary replica to then stream the backup directly to object storage. The problem is that replicas through praefect have rewritten storages and relative paths. So in order to generate a backup with praefect paths, we need to have both: the repository used to access on the filesystem, and the repository used to generate backup paths.
-rw-r--r--internal/backup/backup.go17
-rw-r--r--internal/backup/backup_test.go15
2 files changed, 23 insertions, 9 deletions
diff --git a/internal/backup/backup.go b/internal/backup/backup.go
index 85e9a5055..25495da48 100644
--- a/internal/backup/backup.go
+++ b/internal/backup/backup.go
@@ -198,13 +198,22 @@ func (mgr *Manager) RemoveAllRepositories(ctx context.Context, req *RemoveAllRep
// CreateRequest is the request to create a backup
type CreateRequest struct {
- Server storage.ServerInfo
- Repository *gitalypb.Repository
+ // Server contains gitaly server connection information required to call
+ // RPCs in the non-local backup.Manager configuration.
+ Server storage.ServerInfo
+ // Repository is the repository to be backed up.
+ Repository *gitalypb.Repository
+ // VanityRepository is used to determine the backup path.
+ VanityRepository *gitalypb.Repository
+ // Incremental when true will create an increment on the specified full backup.
Incremental bool
}
// Create creates a repository backup.
func (mgr *Manager) Create(ctx context.Context, req *CreateRequest) error {
+ if req.VanityRepository == nil {
+ req.VanityRepository = req.Repository
+ }
repo, err := mgr.repositoryFactory(ctx, req.Repository, req.Server)
if err != nil {
return fmt.Errorf("manager: %w", err)
@@ -219,12 +228,12 @@ func (mgr *Manager) Create(ctx context.Context, req *CreateRequest) error {
var step *Step
if req.Incremental {
var err error
- step, err = mgr.locator.BeginIncremental(ctx, req.Repository, mgr.backupID)
+ step, err = mgr.locator.BeginIncremental(ctx, req.VanityRepository, mgr.backupID)
if err != nil {
return fmt.Errorf("manager: %w", err)
}
} else {
- step = mgr.locator.BeginFull(ctx, req.Repository, mgr.backupID)
+ step = mgr.locator.BeginFull(ctx, req.VanityRepository, mgr.backupID)
}
refs, err := repo.ListRefs(ctx)
diff --git a/internal/backup/backup_test.go b/internal/backup/backup_test.go
index 2472da0a5..55631e3ec 100644
--- a/internal/backup/backup_test.go
+++ b/internal/backup/backup_test.go
@@ -159,10 +159,14 @@ func TestManager_Create(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
repo, repoPath := tc.setup(t)
backupRoot := testhelper.TempDir(t)
+ vanityRepo := &gitalypb.Repository{
+ RelativePath: "some/path.git",
+ StorageName: "some_storage",
+ }
- refsPath := joinBackupPath(t, backupRoot, repo, backupID, "001.refs")
- bundlePath := joinBackupPath(t, backupRoot, repo, backupID, "001.bundle")
- customHooksPath := joinBackupPath(t, backupRoot, repo, backupID, "001.custom_hooks.tar")
+ refsPath := joinBackupPath(t, backupRoot, vanityRepo, backupID, "001.refs")
+ bundlePath := joinBackupPath(t, backupRoot, vanityRepo, backupID, "001.bundle")
+ customHooksPath := joinBackupPath(t, backupRoot, vanityRepo, backupID, "001.custom_hooks.tar")
sink := backup.NewFilesystemSink(backupRoot)
locator, err := backup.ResolveLocator("pointer", sink)
@@ -170,8 +174,9 @@ func TestManager_Create(t *testing.T) {
fsBackup := managerTC.setup(t, sink, locator)
err = fsBackup.Create(ctx, &backup.CreateRequest{
- Server: storage.ServerInfo{Address: cfg.SocketPath, Token: cfg.Auth.Token},
- Repository: repo,
+ Server: storage.ServerInfo{Address: cfg.SocketPath, Token: cfg.Auth.Token},
+ Repository: repo,
+ VanityRepository: vanityRepo,
})
if tc.err == nil {
require.NoError(t, err)