cubefs

Форк
0
/
lifecycle.go 
151 строка · 3.4 Кб
1
// Copyright 2023 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
	"fmt"
19
	"sync"
20
	"time"
21

22
	"github.com/cubefs/cubefs/util/log"
23
)
24

25
type LcConfiguration struct {
26
	VolName string
27
	Rules   []*Rule
28
}
29

30
type Rule struct {
31
	Expire *ExpirationConfig
32
	Filter *FilterConfig
33
	ID     string
34
	Status string
35
}
36

37
type ExpirationConfig struct {
38
	Date *time.Time
39
	Days int
40
}
41

42
type FilterConfig struct {
43
	Prefix string
44
}
45

46
const (
47
	RuleEnabled  string = "Enabled"
48
	RuleDisabled string = "Disabled"
49
)
50

51
func (lcConf *LcConfiguration) GenEnabledRuleTasks() []*RuleTask {
52
	tasks := make([]*RuleTask, 0)
53
	for _, r := range lcConf.Rules {
54
		if r.Status != RuleEnabled {
55
			log.LogDebugf("GenEnabledRuleTasks: skip disabled rule(%v) in volume(%v)", r.ID, lcConf.VolName)
56
			continue
57
		}
58
		task := &RuleTask{
59
			Id:      fmt.Sprintf("%s:%s", lcConf.VolName, r.ID),
60
			VolName: lcConf.VolName,
61
			Rule:    r,
62
		}
63
		tasks = append(tasks, task)
64
		log.LogDebugf("GenEnabledRuleTasks: RuleTask(%v) generated from rule(%v) in volume(%v)", *task, r.ID, lcConf.VolName)
65
	}
66
	return tasks
67
}
68

69
// ----------------------------------------------
70
// lcnode <-> master
71
// LcNodeRuleTask
72

73
type LcNodeRuleTaskRequest struct {
74
	MasterAddr string
75
	LcNodeAddr string
76
	Task       *RuleTask
77
}
78

79
type RuleTask struct {
80
	Id      string
81
	VolName string
82
	Rule    *Rule
83
}
84

85
type LcNodeRuleTaskResponse struct {
86
	ID         string
87
	LcNode     string
88
	StartTime  *time.Time
89
	EndTime    *time.Time
90
	UpdateTime *time.Time
91
	Done       bool
92
	Status     uint8
93
	Result     string
94
	LcNodeRuleTaskStatistics
95
}
96

97
type LcNodeRuleTaskStatistics struct {
98
	Volume               string
99
	RuleId               string
100
	TotalInodeScannedNum int64
101
	FileScannedNum       int64
102
	DirScannedNum        int64
103
	ExpiredNum           int64
104
	ErrorSkippedNum      int64
105
}
106

107
// ----------------------------------
108
// lcnode <-> meta
109

110
type ScanDentry struct {
111
	ParentId uint64 `json:"pid"`   // FileID value of the parent inode.
112
	Inode    uint64 `json:"inode"` // FileID value of the current inode.
113
	Name     string `json:"name"`  // Name of the current dentry.
114
	Path     string `json:"path"`  // Path of the current dentry.
115
	Type     uint32 `json:"type"`  // Type of the current dentry.
116
}
117

118
type BatchDentries struct {
119
	sync.RWMutex
120
	dentries map[uint64]*ScanDentry
121
}
122

123
func NewBatchDentries() *BatchDentries {
124
	return &BatchDentries{
125
		dentries: make(map[uint64]*ScanDentry),
126
	}
127
}
128

129
func (f *BatchDentries) Append(dentry *ScanDentry) {
130
	f.Lock()
131
	defer f.Unlock()
132
	f.dentries[dentry.Inode] = dentry
133
}
134

135
func (f *BatchDentries) Len() int {
136
	f.RLock()
137
	defer f.RUnlock()
138
	return len(f.dentries)
139
}
140

141
func (f *BatchDentries) BatchGetAndClear() (map[uint64]*ScanDentry, []uint64) {
142
	f.Lock()
143
	defer f.Unlock()
144
	dentries := f.dentries
145
	var inodes []uint64
146
	for i := range f.dentries {
147
		inodes = append(inodes, i)
148
	}
149
	f.dentries = make(map[uint64]*ScanDentry)
150
	return dentries, inodes
151
}
152

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

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

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

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