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
46
47
48
49
|
package info
import (
"context"
"gitlab.com/gitlab-org/gitaly/internal/praefect/config"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
func (s *Server) DatalossCheck(ctx context.Context, req *gitalypb.DatalossCheckRequest) (*gitalypb.DatalossCheckResponse, error) {
outdatedRepos, err := s.rs.GetPartiallyReplicatedRepositories(
ctx, req.GetVirtualStorage(), s.conf.Failover.ElectionStrategy != config.ElectionStrategyPerRepository)
if err != nil {
return nil, err
}
pbRepos := make([]*gitalypb.DatalossCheckResponse_Repository, 0, len(outdatedRepos))
for _, outdatedRepo := range outdatedRepos {
readOnly := true
storages := make([]*gitalypb.DatalossCheckResponse_Repository_Storage, 0, len(outdatedRepo.Storages))
for _, storage := range outdatedRepo.Storages {
if storage.Name == outdatedRepo.Primary && storage.BehindBy == 0 {
readOnly = false
}
storages = append(storages, &gitalypb.DatalossCheckResponse_Repository_Storage{
Name: storage.Name,
BehindBy: int64(storage.BehindBy),
Assigned: storage.Assigned,
})
}
if !req.IncludePartiallyReplicated && !readOnly {
continue
}
pbRepos = append(pbRepos, &gitalypb.DatalossCheckResponse_Repository{
RelativePath: outdatedRepo.RelativePath,
Primary: outdatedRepo.Primary,
ReadOnly: readOnly,
Storages: storages,
})
}
return &gitalypb.DatalossCheckResponse{
Repositories: pbRepos,
}, nil
}
|