diff --git a/_support/benchmarking/roles/client/files/queries/BackupRepository/git.git.json b/_support/benchmarking/roles/client/files/queries/BackupRepository/git.git.json new file mode 100644 index 0000000000000000000000000000000000000000..12c702619a38f5a980411abf1890f36642caf21a --- /dev/null +++ b/_support/benchmarking/roles/client/files/queries/BackupRepository/git.git.json @@ -0,0 +1,17 @@ +{ + "repository": { + "storageName": "default", + "relativePath": "git.git", + "gitAlternateObjectDirectories": [], + "glRepository": "git", + "glProjectPath": "git/git" + }, + "vanityRepository": { + "storageName": "default", + "relativePath": "git.git", + "gitAlternateObjectDirectories": [], + "glRepository": "git", + "glProjectPath": "git/git" + }, + "backupId": "abc123" +} diff --git a/_support/benchmarking/roles/deploy/templates/all.yml.j2 b/_support/benchmarking/roles/deploy/templates/all.yml.j2 index d5c4c43ba973fd8353b55d887323c395e505643f..e6eab95072accbeb95b96b8b4e85d02fbcdec896 100644 --- a/_support/benchmarking/roles/deploy/templates/all.yml.j2 +++ b/_support/benchmarking/roles/deploy/templates/all.yml.j2 @@ -7,3 +7,9 @@ rpcs: proto: commit.proto repos: - git.git + - description: Create a backup + rpc: BackupRepository + service: gitaly.RepositoryService + proto: repository.proto + repos: + - git.git diff --git a/_support/benchmarking/roles/gitaly/templates/config.toml.j2 b/_support/benchmarking/roles/gitaly/templates/config.toml.j2 index 4e50eaa1db8cea3a4f15aab66ca4a2d5f55810da..ea18437f083576dbdc306eb98f12ad5fe7e7aafc 100644 --- a/_support/benchmarking/roles/gitaly/templates/config.toml.j2 +++ b/_support/benchmarking/roles/gitaly/templates/config.toml.j2 @@ -50,3 +50,5 @@ enabled = true dir = "/mnt/git-repositories/+gitaly/PackObjectsCache" max_age = '5m' +[backup] +go_cloud_url = "/var/opt/gitaly/backups" diff --git a/internal/backup/backup.go b/internal/backup/backup.go index 267ec5f9990aa2939db15f31d1fd071aaaa217d1..cad8cefd9357ca99dc1b6ec8651711980341006b 100644 --- a/internal/backup/backup.go +++ b/internal/backup/backup.go @@ -1,6 +1,7 @@ package backup import ( + "bufio" "bytes" "context" "errors" @@ -354,9 +355,11 @@ func (mgr *Manager) writeBundle(ctx context.Context, repo Repository, step *Step } }() - w := NewLazyWriter(func() (io.WriteCloser, error) { - return mgr.sink.GetWriter(ctx, step.BundlePath) - }) + w, err := mgr.sink.GetWriter(ctx, step.BundlePath) + if err != nil { + return fmt.Errorf("write bundle: %w", err) + } + defer func() { if err := w.Close(); err != nil && returnErr == nil { returnErr = fmt.Errorf("write bundle: %w", err) @@ -390,6 +393,7 @@ func (mgr *Manager) negatedKnownRefs(ctx context.Context, step *Step) (io.ReadCl } defer reader.Close() + buf := bufio.NewWriter(w) d := git.NewShowRefDecoder(reader) for { var ref git.Reference @@ -401,11 +405,16 @@ func (mgr *Manager) negatedKnownRefs(ctx context.Context, step *Step) (io.ReadCl return } - if _, err := fmt.Fprintf(w, "^%s\n", ref.Target); err != nil { + if _, err := fmt.Fprintf(buf, "^%s\n", ref.Target); err != nil { _ = w.CloseWithError(err) return } } + + if err := buf.Flush(); err != nil { + _ = w.CloseWithError(err) + return + } }() return r, nil @@ -493,13 +502,19 @@ func (mgr *Manager) writeRefs(ctx context.Context, path string, refs []git.Refer } }() + buf := bufio.NewWriter(w) + for _, ref := range refs { - _, err = fmt.Fprintf(w, "%s %s\n", ref.Target, ref.Name) + _, err = fmt.Fprintf(buf, "%s %s\n", ref.Target, ref.Name) if err != nil { return fmt.Errorf("write refs: %w", err) } } + if err := buf.Flush(); err != nil { + return fmt.Errorf("write refs: %w", err) + } + return nil }