Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dataloss.go « info « service « praefect « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5ce72ce7feda928b7a9a62d880e75d31c5ba5e3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package info

import (
	"context"
	"sort"

	"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)

func (s *Server) DatalossCheck(ctx context.Context, req *gitalypb.DatalossCheckRequest) (*gitalypb.DatalossCheckResponse, error) {
	shard, err := s.nodeMgr.GetShard(req.GetVirtualStorage())
	if err != nil {
		return nil, err
	}

	outdatedRepos, err := s.rs.GetOutdatedRepositories(ctx, req.GetVirtualStorage())
	if err != nil {
		return nil, err
	}

	pbRepos := make([]*gitalypb.DatalossCheckResponse_Repository, 0, len(outdatedRepos))
	for relativePath, storages := range outdatedRepos {
		pbStorages := make([]*gitalypb.DatalossCheckResponse_Repository_Storage, 0, len(storages))
		for name, behindBy := range storages {
			pbStorages = append(pbStorages, &gitalypb.DatalossCheckResponse_Repository_Storage{
				Name:     name,
				BehindBy: int64(behindBy),
			})
		}

		sort.Slice(pbStorages, func(i, j int) bool { return pbStorages[i].Name < pbStorages[j].Name })

		pbRepos = append(pbRepos, &gitalypb.DatalossCheckResponse_Repository{
			RelativePath: relativePath,
			Storages:     pbStorages,
		})
	}

	sort.Slice(pbRepos, func(i, j int) bool { return pbRepos[i].RelativePath < pbRepos[j].RelativePath })

	return &gitalypb.DatalossCheckResponse{
		Primary:      shard.Primary.GetStorage(),
		Repositories: pbRepos,
	}, nil
}