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

subcmd_accept_dataloss.go « praefect « cmd - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 026b8e56586407012f9d6b85157d7eb0de505ff2 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main

import (
	"context"
	"flag"
	"fmt"

	"gitlab.com/gitlab-org/gitaly/v15/internal/praefect/config"
	"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)

const (
	acceptDatalossCmdName = "accept-dataloss"
)

type acceptDatalossSubcommand struct {
	virtualStorage       string
	relativePath         string
	authoritativeStorage string
}

func (cmd *acceptDatalossSubcommand) FlagSet() *flag.FlagSet {
	fs := flag.NewFlagSet(acceptDatalossCmdName, flag.ContinueOnError)
	fs.StringVar(&cmd.virtualStorage, paramVirtualStorage, "", "name of the repository's virtual storage")
	fs.StringVar(&cmd.relativePath, paramRelativePath, "", "repository to accept data loss for")
	fs.StringVar(&cmd.authoritativeStorage, paramAuthoritativeStorage, "", "storage with the repository to consider as authoritative")
	return fs
}

func (cmd *acceptDatalossSubcommand) Exec(flags *flag.FlagSet, cfg config.Config) error {
	if flags.NArg() > 0 {
		return unexpectedPositionalArgsError{Command: flags.Name()}
	} else if cmd.virtualStorage == "" {
		return requiredParameterError(paramVirtualStorage)
	} else if cmd.relativePath == "" {
		return requiredParameterError(paramRelativePath)
	} else if cmd.authoritativeStorage == "" {
		return requiredParameterError(paramAuthoritativeStorage)
	}

	nodeAddr, err := getNodeAddress(cfg)
	if err != nil {
		return err
	}
	ctx := context.TODO()

	conn, err := subCmdDial(ctx, nodeAddr, cfg.Auth.Token, defaultDialTimeout)
	if err != nil {
		return fmt.Errorf("error dialing: %w", err)
	}
	defer conn.Close()

	client := gitalypb.NewPraefectInfoServiceClient(conn)
	if _, err := client.SetAuthoritativeStorage(ctx, &gitalypb.SetAuthoritativeStorageRequest{
		VirtualStorage:       cmd.virtualStorage,
		RelativePath:         cmd.relativePath,
		AuthoritativeStorage: cmd.authoritativeStorage,
	}); err != nil {
		return fmt.Errorf("set authoritative storage: %w", err)
	}

	return nil
}