cubefs

Форк
0
103 строки · 2.5 Кб
1
// Copyright 2022 The CubeFS Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
// implied. See the License for the specific language governing
13
// permissions and limitations under the License.
14

15
package proto
16

17
import (
18
	"github.com/cubefs/cubefs/blobstore/util/errors"
19
)
20

21
var ErrInvalidMsg = errors.New("msg is invalid")
22

23
type DeleteStage byte
24

25
const (
26
	InitStage DeleteStage = iota
27
	DeleteStageMarkDelete
28
	DeleteStageDelete
29
)
30

31
type BlobDeleteStage struct {
32
	Stages map[uint8]DeleteStage `json:"stages"`
33
}
34

35
func (s *BlobDeleteStage) SetStage(vuidIdx uint8, stage DeleteStage) {
36
	if s.Stages == nil {
37
		s.Stages = make(map[uint8]DeleteStage)
38
	}
39
	s.Stages[vuidIdx] = stage
40
}
41

42
func (s *BlobDeleteStage) Stage(vuid Vuid) (DeleteStage, bool) {
43
	stage, exist := s.Stages[vuid.Index()]
44
	return stage, exist
45
}
46

47
func (s *BlobDeleteStage) Copy() BlobDeleteStage {
48
	myCopy := BlobDeleteStage{}
49
	myCopy.Stages = make(map[uint8]DeleteStage)
50
	for k, v := range s.Stages {
51
		myCopy.Stages[k] = v
52
	}
53
	return myCopy
54
}
55

56
type DeleteMsg struct {
57
	ClusterID     ClusterID       `json:"cluster_id"`
58
	Bid           BlobID          `json:"bid"`
59
	Vid           Vid             `json:"vid"`
60
	Retry         int             `json:"retry"`
61
	Time          int64           `json:"time"`
62
	ReqId         string          `json:"req_id"`
63
	BlobDelStages BlobDeleteStage `json:"blob_del_stages"`
64
}
65

66
func (msg *DeleteMsg) IsValid() bool {
67
	if msg.Bid == InValidBlobID {
68
		return false
69
	}
70
	if msg.Vid == InvalidVid {
71
		return false
72
	}
73
	return true
74
}
75

76
func (msg *DeleteMsg) SetDeleteStage(stage BlobDeleteStage) {
77
	for idx, s := range stage.Stages {
78
		msg.BlobDelStages.SetStage(idx, s)
79
	}
80
}
81

82
type ShardRepairMsg struct {
83
	ClusterID ClusterID `json:"cluster_id"`
84
	Bid       BlobID    `json:"bid"`
85
	Vid       Vid       `json:"vid"`
86
	BadIdx    []uint8   `json:"bad_idx"`
87
	Retry     int       `json:"retry"`
88
	Reason    string    `json:"reason"`
89
	ReqId     string    `json:"req_id"`
90
}
91

92
func (msg *ShardRepairMsg) IsValid() bool {
93
	if msg.Bid == InValidBlobID {
94
		return false
95
	}
96
	if msg.Vid == InvalidVid {
97
		return false
98
	}
99
	if len(msg.BadIdx) == 0 {
100
		return false
101
	}
102
	return true
103
}
104

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.