-
Notifications
You must be signed in to change notification settings - Fork 155
/
fspathrgrp.go
270 lines (239 loc) · 7.54 KB
/
fspathrgrp.go
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
// Package ais provides core functionality for the AIStore object storage.
/*
* Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved.
*/
package ais
import (
"fmt"
"sync"
"github.com/NVIDIA/aistore/api/apc"
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/cos"
"github.com/NVIDIA/aistore/cmn/debug"
"github.com/NVIDIA/aistore/cmn/nlog"
"github.com/NVIDIA/aistore/core"
"github.com/NVIDIA/aistore/ext/dsort"
"github.com/NVIDIA/aistore/fs"
"github.com/NVIDIA/aistore/res"
"github.com/NVIDIA/aistore/stats"
"github.com/NVIDIA/aistore/volume"
"github.com/NVIDIA/aistore/xact/xreg"
"github.com/NVIDIA/aistore/xact/xs"
)
type fsprungroup struct {
t *target
newVol bool
}
func (g *fsprungroup) init(t *target, newVol bool) {
g.t = t
g.newVol = newVol
}
//
// add | re-enable
//
// enableMpath enables mountpath and notifies necessary runners about the
// change if mountpath actually was enabled.
func (g *fsprungroup) enableMpath(mpath string) (enabledMi *fs.Mountpath, err error) {
enabledMi, err = fs.EnableMpath(mpath, g.t.SID(), g.redistributeMD)
if err != nil || enabledMi == nil {
return
}
g._postAdd(apc.ActMountpathEnable, enabledMi)
return
}
// attachMpath adds mountpath and notifies necessary runners about the change
// if the mountpath was actually added.
func (g *fsprungroup) attachMpath(mpath string, force bool) (addedMi *fs.Mountpath, err error) {
addedMi, err = fs.AddMpath(mpath, g.t.SID(), g.redistributeMD, force)
if err != nil || addedMi == nil {
return
}
g._postAdd(apc.ActMountpathAttach, addedMi)
return
}
func (g *fsprungroup) _postAdd(action string, mi *fs.Mountpath) {
// NOTE:
// - currently, dsort doesn't handle (add/enable/disable/detach mountpath) at runtime
// - consider integrating via `xreg.LimitedCoexistence`
// - review all xact.IsMountpath(kind) == true
dsort.Managers.AbortAll(fmt.Errorf("%q %s", action, mi))
fspathsConfigAddDel(mi.Path, true /*add*/)
go func() {
if cmn.GCO.Get().Resilver.Enabled {
g.t.runResilver(res.Args{}, nil /*wg*/)
}
xreg.RenewMakeNCopies(cos.GenUUID(), action)
}()
g.checkEnable(action, mi.Path)
tstats := g.t.statsT.(*stats.Trunner)
for _, disk := range mi.Disks {
tstats.RegDiskMetrics(g.t.si, disk)
}
}
//
// remove | disable
//
// disableMpath disables mountpath and notifies necessary runners about the
// change if mountpath actually was disabled.
func (g *fsprungroup) disableMpath(mpath string, dontResilver bool) (*fs.Mountpath, error) {
return g.doDD(apc.ActMountpathDisable, fs.FlagBeingDisabled, mpath, dontResilver)
}
// detachMpath removes mountpath and notifies necessary runners about the
// change if the mountpath was actually removed.
func (g *fsprungroup) detachMpath(mpath string, dontResilver bool) (*fs.Mountpath, error) {
return g.doDD(apc.ActMountpathDetach, fs.FlagBeingDetached, mpath, dontResilver)
}
func (g *fsprungroup) doDD(action string, flags uint64, mpath string, dontResilver bool) (*fs.Mountpath, error) {
rmi, numAvail, noResil, err := fs.BeginDD(action, flags, mpath)
if err != nil || rmi == nil {
return nil, err
}
// NOTE: above
dsort.Managers.AbortAll(fmt.Errorf("%q %s", action, rmi))
if numAvail == 0 {
s := fmt.Sprintf("%s: lost (via %q) the last available mountpath %q", g.t.si, action, rmi)
g.postDD(rmi, action, nil /*xaction*/, nil /*error*/) // go ahead to disable/detach
g.t.disable(s)
return rmi, nil
}
core.UncacheMountpath(rmi)
if noResil || dontResilver || !cmn.GCO.Get().Resilver.Enabled {
nlog.Infof("%s: %q %s: no resilvering (%t, %t, %t)", g.t, action, rmi,
noResil, !dontResilver, cmn.GCO.Get().Resilver.Enabled)
g.postDD(rmi, action, nil /*xaction*/, nil /*error*/) // ditto (compare with the one below)
return rmi, nil
}
prevActive := g.t.res.IsActive(1 /*interval-of-inactivity multiplier*/)
if prevActive {
nlog.Infof("%s: %q %s: starting to resilver when previous (resilvering) is active", g.t, action, rmi)
} else {
nlog.Infof("%s: %q %s: starting to resilver", g.t, action, rmi)
}
args := res.Args{
Rmi: rmi,
Action: action,
PostDD: g.postDD, // callback when done
SingleRmiJogger: !prevActive, // NOTE: optimization for the special/common case
}
wg := &sync.WaitGroup{}
wg.Add(1)
go g.t.runResilver(args, wg)
wg.Wait()
return rmi, nil
}
func (g *fsprungroup) postDD(rmi *fs.Mountpath, action string, xres *xs.Resilver, err error) {
// 1. handle error
if err == nil && xres != nil {
err = xres.AbortErr()
}
if err != nil {
if errCause := cmn.AsErrAborted(err); errCause != nil {
err = errCause
}
if err == cmn.ErrXactUserAbort {
nlog.Errorf("[post-dd interrupted - clearing the state] %s: %q %s %s: %v",
g.t.si, action, rmi, xres, err)
rmi.ClearDD()
} else {
nlog.Errorf("[post-dd interrupted - keeping the state] %s: %q %s %s: %v",
g.t.si, action, rmi, xres, err)
}
return
}
// 2. this action
if action == apc.ActMountpathDetach {
_, err = fs.Remove(rmi.Path, g.redistributeMD)
} else {
debug.Assert(action == apc.ActMountpathDisable)
_, err = fs.Disable(rmi.Path, g.redistributeMD)
}
if err != nil {
nlog.Errorln(err)
return
}
fspathsConfigAddDel(rmi.Path, false /*add*/)
nlog.Infof("%s: %s %q %s done", g.t, rmi, action, xres)
// 3. the case of multiple overlapping detach _or_ disable operations
// (ie., commit previously aborted xs.Resilver, if any)
availablePaths := fs.GetAvail()
for _, mi := range availablePaths {
if !mi.IsAnySet(fs.FlagWaitingDD) {
continue
}
// TODO: assumption that `action` is the same for all
if action == apc.ActMountpathDetach {
_, err = fs.Remove(mi.Path, g.redistributeMD)
} else {
debug.Assert(action == apc.ActMountpathDisable)
_, err = fs.Disable(mi.Path, g.redistributeMD)
}
if err != nil {
nlog.Errorln(err)
return
}
fspathsConfigAddDel(mi.Path, false /*add*/)
nlog.Infof("%s: %s %s %s was previously aborted and now done", g.t, action, mi, xres)
}
}
// store updated fspaths locally as part of the 'OverrideConfigFname'
// and commit new version of the config
func fspathsConfigAddDel(mpath string, add bool) {
if cmn.Rom.TestingEnv() { // since testing fspaths are counted, not enumerated
return
}
config := cmn.GCO.BeginUpdate()
localConfig := &config.LocalConfig
if add {
localConfig.AddPath(mpath)
} else {
localConfig.DelPath(mpath)
}
if err := localConfig.FSP.Validate(config); err != nil {
debug.AssertNoErr(err)
cmn.GCO.DiscardUpdate()
nlog.Errorln(err)
return
}
// do
fspathsSave(config)
}
func fspathsSave(config *cmn.Config) {
toUpdate := &cmn.ConfigToSet{FSP: &config.LocalConfig.FSP}
overrideConfig := cmn.GCO.SetLocalFSPaths(toUpdate)
if err := cmn.SaveOverrideConfig(config.ConfigDir, overrideConfig); err != nil {
debug.AssertNoErr(err)
cmn.GCO.DiscardUpdate()
nlog.Errorln(err)
return
}
cmn.GCO.CommitUpdate(config)
}
// NOTE: executes under mfs lock
func (g *fsprungroup) redistributeMD() {
if !hasEnoughBMDCopies() {
bo := g.t.owner.bmd
if err := bo.persist(bo.get(), nil); err != nil {
cos.ExitLog(err)
}
}
if !hasEnoughEtlMDCopies() {
eo := g.t.owner.etl
if err := eo.persist(eo.get(), nil); err != nil {
cos.ExitLog(err)
}
}
if _, err := volume.NewFromMPI(g.t.SID()); err != nil {
cos.ExitLog(err)
}
}
func (g *fsprungroup) checkEnable(action, mpath string) {
availablePaths := fs.GetAvail()
if len(availablePaths) > 1 {
nlog.Infof("%s mountpath %s", action, mpath)
} else {
nlog.Infof("%s the first mountpath %s", action, mpath)
if err := g.t.enable(); err != nil {
nlog.Errorf("Failed to re-join %s (self), err: %v", g.t, err)
}
}
}