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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-11-30 18:16:58 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-12-01 08:52:27 +0300
commite5f11a2ed2372718b5653dc45614b5b4cc401780 (patch)
treeb3e1153dfcdcc8c5140c961ab8f4e48f9283440a
parent2fef39bc3aa78810f776c5c0f3683bf836b486e3 (diff)
git/stats: Get rid of spawning git-count-objects(1)
We have now converted almost all of the information and more about objects to be derived via in-process logic instead of relying on the external git-count-objects(1) command. There are only two pieces of information left, both of which aren't used anywhere: - Prunable objects are objects that exist both as a loose and as a packed object. Theoretically speaking we shouldn't ever generate such objects in the first place as we also `git repack -d`, and this command will remove objects we're putting into a packfile. - Packed objects is the number of objects that exist in total. This is a bit unfortunate to go away, but we still expose the total packfile size. While the second information could be useful, it doesn't feel useful enough to argue for a whole invocation of git-count-objects(1). Stop executing git-count-objects(1) and remove those two bits of info. This should make it a whole less taxing to derive this information from the repository. Ultimately, this will allow us to just use `ObjectsInfo` for our housekeeping logic to feed into the heuristical optimization strategy.
-rw-r--r--internal/git/stats/objects_info.go62
-rw-r--r--internal/git/stats/objects_info_test.go4
2 files changed, 3 insertions, 63 deletions
diff --git a/internal/git/stats/objects_info.go b/internal/git/stats/objects_info.go
index f4d9e5ebf..f0822139a 100644
--- a/internal/git/stats/objects_info.go
+++ b/internal/git/stats/objects_info.go
@@ -1,19 +1,16 @@
package stats
import (
- "bufio"
"context"
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
- "strconv"
"strings"
"time"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
- "gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/text"
)
@@ -88,17 +85,8 @@ type ObjectsInfo struct {
LooseObjects LooseObjectsInfo `json:"loose_objects"`
// Packfiles contains information about packfiles.
Packfiles PackfilesInfo `json:"packfiles"`
-
- // PrunableObjects is the number of objects that exist both as loose and as packed objects.
- // The loose objects may be pruned in that case.
- PruneableObjects uint64 `json:"prunable_objects"`
-
- // PackedObjects is the count of packed objects.
- PackedObjects uint64 `json:"packed_objects"`
-
// CommitGraph contains information about the repository's commit-graphs.
CommitGraph CommitGraphInfo `json:"commit_graph"`
-
// Alternates is the list of absolute paths of alternate object databases this repository is
// connected to.
Alternates []string `json:"alternates"`
@@ -106,58 +94,14 @@ type ObjectsInfo struct {
// ObjectsInfoForRepository computes the ObjectsInfo for a repository.
func ObjectsInfoForRepository(ctx context.Context, repo *localrepo.Repo) (ObjectsInfo, error) {
+ var info ObjectsInfo
+ var err error
+
repoPath, err := repo.Path()
if err != nil {
return ObjectsInfo{}, err
}
- countObjects, err := repo.Exec(ctx, git.SubCmd{
- Name: "count-objects",
- Flags: []git.Option{git.Flag{Name: "--verbose"}},
- })
- if err != nil {
- return ObjectsInfo{}, fmt.Errorf("running git-count-objects: %w", err)
- }
-
- var info ObjectsInfo
-
- // The expected format is:
- //
- // count: 12
- // packs: 2
- // size-garbage: 934
- // alternate: /some/path/to/.git/objects
- // alternate: "/some/other path/to/.git/objects"
- scanner := bufio.NewScanner(countObjects)
- for scanner.Scan() {
- line := scanner.Text()
-
- parts := strings.SplitN(line, ": ", 2)
- if len(parts) != 2 {
- continue
- }
-
- var err error
- switch parts[0] {
- case "in-pack":
- info.PackedObjects, err = strconv.ParseUint(parts[1], 10, 64)
- case "prune-packable":
- info.PruneableObjects, err = strconv.ParseUint(parts[1], 10, 64)
- }
-
- if err != nil {
- return ObjectsInfo{}, fmt.Errorf("parsing %q: %w", parts[0], err)
- }
- }
-
- if err := scanner.Err(); err != nil {
- return ObjectsInfo{}, fmt.Errorf("scanning object info: %w", err)
- }
-
- if err := countObjects.Wait(); err != nil {
- return ObjectsInfo{}, fmt.Errorf("counting objects: %w", err)
- }
-
info.LooseObjects, err = LooseObjectsInfoForRepository(repo, time.Now().Add(StaleObjectsGracePeriod))
if err != nil {
return ObjectsInfo{}, fmt.Errorf("counting loose objects: %w", err)
diff --git a/internal/git/stats/objects_info_test.go b/internal/git/stats/objects_info_test.go
index 884fa5c73..d62195b5e 100644
--- a/internal/git/stats/objects_info_test.go
+++ b/internal/git/stats/objects_info_test.go
@@ -201,7 +201,6 @@ func TestObjectsInfoForRepository(t *testing.T) {
gittest.Exec(t, cfg, "-C", repoPath, "repack", "-Ad")
},
expectedObjectsInfo: ObjectsInfo{
- PackedObjects: 1,
Packfiles: PackfilesInfo{
Count: 1,
Size: hashDependentSize(42, 54),
@@ -219,7 +218,6 @@ func TestObjectsInfoForRepository(t *testing.T) {
gittest.Exec(t, cfg, "-C", repoPath, "repack", "-a")
},
expectedObjectsInfo: ObjectsInfo{
- PackedObjects: 1,
LooseObjects: LooseObjectsInfo{
Count: 1,
Size: 16,
@@ -229,7 +227,6 @@ func TestObjectsInfoForRepository(t *testing.T) {
Size: hashDependentSize(42, 54),
HasBitmap: true,
},
- PruneableObjects: 1,
},
},
{
@@ -317,7 +314,6 @@ func TestObjectsInfoForRepository(t *testing.T) {
Count: 2,
Size: 32,
},
- PackedObjects: 1,
Packfiles: PackfilesInfo{
Count: 1,
Size: hashDependentSize(42, 54),