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>2021-09-27 06:40:27 +0300
committerJames Fargher <jfargher@gitlab.com>2021-10-04 02:35:36 +0300
commit4d9e4edccb551f8b4952b91cb20163b4b30582d1 (patch)
tree337b2f186507e541d8d62b4542be5d20a981a007
parent6f433e0db7fe80ba2f2422ef52401c4643371a91 (diff)
backup: Write LATEST file for increments
There's no reason to distinguish between a full backup and an increment. So let's just treat all steps an increments.
-rw-r--r--internal/backup/locator.go35
-rw-r--r--internal/backup/locator_test.go26
2 files changed, 36 insertions, 25 deletions
diff --git a/internal/backup/locator.go b/internal/backup/locator.go
index bb9b0eb68..5ef75f7d3 100644
--- a/internal/backup/locator.go
+++ b/internal/backup/locator.go
@@ -59,10 +59,11 @@ func (l LegacyLocator) newFull(repo *gitalypb.Repository) *Step {
// file named LATEST.
//
// Structure:
-// <repo relative path>/<backup id>/full.bundle
-// <repo relative path>/<backup id>/full.refs
-// <repo relative path>/<backup id>/custom_hooks.tar
// <repo relative path>/LATEST
+// <repo relative path>/<backup id>/LATEST
+// <repo relative path>/<backup id>/<nnn>.bundle
+// <repo relative path>/<backup id>/<nnn>.refs
+// <repo relative path>/<backup id>/<nnn>.custom_hooks.tar
type PointerLocator struct {
Sink Sink
Fallback Locator
@@ -73,9 +74,9 @@ func (l PointerLocator) BeginFull(ctx context.Context, repo *gitalypb.Repository
backupPath := strings.TrimSuffix(repo.RelativePath, ".git")
return &Step{
- BundlePath: filepath.Join(backupPath, backupID, "full.bundle"),
- RefPath: filepath.Join(backupPath, backupID, "full.refs"),
- CustomHooksPath: filepath.Join(backupPath, backupID, "custom_hooks.tar"),
+ BundlePath: filepath.Join(backupPath, backupID, "001.bundle"),
+ RefPath: filepath.Join(backupPath, backupID, "001.refs"),
+ CustomHooksPath: filepath.Join(backupPath, backupID, "001.custom_hooks.tar"),
}
}
@@ -84,7 +85,13 @@ func (l PointerLocator) CommitFull(ctx context.Context, full *Step) error {
bundleDir := filepath.Dir(full.BundlePath)
backupID := filepath.Base(bundleDir)
backupPath := filepath.Dir(bundleDir)
- return l.commitLatestID(ctx, backupPath, backupID)
+ if err := l.writeLatest(ctx, bundleDir, "001"); err != nil {
+ return err
+ }
+ if err := l.writeLatest(ctx, backupPath, backupID); err != nil {
+ return err
+ }
+ return nil
}
// FindLatest returns the paths committed by the latest call to CommitFull.
@@ -104,9 +111,9 @@ func (l PointerLocator) FindLatest(ctx context.Context, repo *gitalypb.Repositor
return &Backup{
Steps: []Step{
{
- BundlePath: filepath.Join(backupPath, backupID, "full.bundle"),
- RefPath: filepath.Join(backupPath, backupID, "full.refs"),
- CustomHooksPath: filepath.Join(backupPath, backupID, "custom_hooks.tar"),
+ BundlePath: filepath.Join(backupPath, backupID, "001.bundle"),
+ RefPath: filepath.Join(backupPath, backupID, "001.refs"),
+ CustomHooksPath: filepath.Join(backupPath, backupID, "001.custom_hooks.tar"),
},
},
}, nil
@@ -127,10 +134,10 @@ func (l PointerLocator) findLatestID(ctx context.Context, backupPath string) (st
return text.ChompBytes(latest), nil
}
-func (l PointerLocator) commitLatestID(ctx context.Context, backupPath, backupID string) error {
- latest := strings.NewReader(backupID)
- if err := l.Sink.Write(ctx, filepath.Join(backupPath, "LATEST"), latest); err != nil {
- return fmt.Errorf("commit latest ID: %w", err)
+func (l PointerLocator) writeLatest(ctx context.Context, path, target string) error {
+ latest := strings.NewReader(target)
+ if err := l.Sink.Write(ctx, filepath.Join(path, "LATEST"), latest); err != nil {
+ return fmt.Errorf("write latest: %w", err)
}
return nil
}
diff --git a/internal/backup/locator_test.go b/internal/backup/locator_test.go
index c081e2584..cc39bf66f 100644
--- a/internal/backup/locator_test.go
+++ b/internal/backup/locator_test.go
@@ -68,10 +68,11 @@ func TestPointerLocator(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
+ const expectedIncrement = "001"
expected := &Step{
- BundlePath: filepath.Join(repo.RelativePath, backupID, "full.bundle"),
- RefPath: filepath.Join(repo.RelativePath, backupID, "full.refs"),
- CustomHooksPath: filepath.Join(repo.RelativePath, backupID, "custom_hooks.tar"),
+ BundlePath: filepath.Join(repo.RelativePath, backupID, expectedIncrement+".bundle"),
+ RefPath: filepath.Join(repo.RelativePath, backupID, expectedIncrement+".refs"),
+ CustomHooksPath: filepath.Join(repo.RelativePath, backupID, expectedIncrement+".custom_hooks.tar"),
}
full := l.BeginFull(ctx, repo, backupID)
@@ -79,8 +80,11 @@ func TestPointerLocator(t *testing.T) {
require.NoError(t, l.CommitFull(ctx, full))
- pointer := testhelper.MustReadFile(t, filepath.Join(backupPath, repo.RelativePath, "LATEST"))
- require.Equal(t, backupID, string(pointer))
+ backupPointer := testhelper.MustReadFile(t, filepath.Join(backupPath, repo.RelativePath, "LATEST"))
+ require.Equal(t, backupID, string(backupPointer))
+
+ incrementPointer := testhelper.MustReadFile(t, filepath.Join(backupPath, repo.RelativePath, backupID, "LATEST"))
+ require.Equal(t, expectedIncrement, string(incrementPointer))
})
t.Run("FindLatest", func(t *testing.T) {
@@ -101,9 +105,9 @@ func TestPointerLocator(t *testing.T) {
expected := &Backup{
Steps: []Step{
{
- BundlePath: filepath.Join(repo.RelativePath, backupID, "full.bundle"),
- RefPath: filepath.Join(repo.RelativePath, backupID, "full.refs"),
- CustomHooksPath: filepath.Join(repo.RelativePath, backupID, "custom_hooks.tar"),
+ BundlePath: filepath.Join(repo.RelativePath, backupID, "001.bundle"),
+ RefPath: filepath.Join(repo.RelativePath, backupID, "001.refs"),
+ CustomHooksPath: filepath.Join(repo.RelativePath, backupID, "001.custom_hooks.tar"),
},
},
}
@@ -143,9 +147,9 @@ func TestPointerLocator(t *testing.T) {
expected := &Backup{
Steps: []Step{
{
- BundlePath: filepath.Join(repo.RelativePath, backupID, "full.bundle"),
- RefPath: filepath.Join(repo.RelativePath, backupID, "full.refs"),
- CustomHooksPath: filepath.Join(repo.RelativePath, backupID, "custom_hooks.tar"),
+ BundlePath: filepath.Join(repo.RelativePath, backupID, "001.bundle"),
+ RefPath: filepath.Join(repo.RelativePath, backupID, "001.refs"),
+ CustomHooksPath: filepath.Join(repo.RelativePath, backupID, "001.custom_hooks.tar"),
},
},
}