-
Notifications
You must be signed in to change notification settings - Fork 155
/
tgtspace.go
141 lines (133 loc) · 3.83 KB
/
tgtspace.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
// Package ais provides core functionality for the AIStore object storage.
/*
* Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved.
*/
package ais
import (
"sync"
"time"
"github.com/NVIDIA/aistore/api/apc"
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/atomic"
"github.com/NVIDIA/aistore/cmn/cos"
"github.com/NVIDIA/aistore/cmn/debug"
"github.com/NVIDIA/aistore/cmn/mono"
"github.com/NVIDIA/aistore/cmn/nlog"
"github.com/NVIDIA/aistore/core"
"github.com/NVIDIA/aistore/fs"
"github.com/NVIDIA/aistore/ios"
"github.com/NVIDIA/aistore/nl"
"github.com/NVIDIA/aistore/space"
"github.com/NVIDIA/aistore/xact"
"github.com/NVIDIA/aistore/xact/xreg"
)
const (
// - note that an API call (e.g. CLI) will go through anyway
// - compare with cmn/cos/oom.go
minAutoDetectInterval = 10 * time.Minute
)
var (
lastTrigOOS atomic.Int64
)
// triggers by an out-of-space condition or a suspicion of thereof
func (t *target) OOS(csRefreshed *fs.CapStatus) (cs fs.CapStatus) {
var errCap error
if csRefreshed != nil {
cs = *csRefreshed
errCap = cs.Err()
} else {
var err error
cs, err, errCap = fs.CapRefresh(nil, nil)
if err != nil {
nlog.Errorln(t.String(), "failed to update capacity stats:", err)
return
}
}
if errCap == nil {
return // unlikely; nothing to do
}
if prev := lastTrigOOS.Load(); mono.Since(prev) < minAutoDetectInterval {
nlog.Warningf("%s: _not_ running store cleanup: (%v, %v), %s", t, prev, minAutoDetectInterval, cs.String())
return
}
nlog.Warningln(t.String(), "running store cleanup:", cs.String())
// run serially, cleanup first and LRU second, iff out-of-space persists
go func() {
cs := t.runStoreCleanup("" /*uuid*/, nil /*wg*/)
lastTrigOOS.Store(mono.NanoTime())
if cs.Err() != nil {
nlog.Warningln(t.String(), "still out of space, running LRU eviction now:", cs.String())
t.runLRU("" /*uuid*/, nil /*wg*/, false)
}
}()
return
}
func (t *target) runLRU(id string, wg *sync.WaitGroup, force bool, bcks ...cmn.Bck) {
regToIC := id == ""
if regToIC {
id = cos.GenUUID()
}
rns := xreg.RenewLRU(id)
if rns.Err != nil || rns.IsRunning() {
debug.Assert(rns.Err == nil || cmn.IsErrXactUsePrev(rns.Err))
if wg != nil {
wg.Done()
}
return
}
xlru := rns.Entry.Get()
if regToIC && xlru.ID() == id {
// pre-existing UUID: notify IC members
regMsg := xactRegMsg{UUID: id, Kind: apc.ActLRU, Srcs: []string{t.SID()}}
msg := t.newAmsgActVal(apc.ActRegGlobalXaction, regMsg)
t.bcastAsyncIC(msg)
}
ini := space.IniLRU{
Xaction: xlru.(*space.XactLRU),
Config: cmn.GCO.Get(),
StatsT: t.statsT,
Buckets: bcks,
GetFSUsedPercentage: ios.GetFSUsedPercentage,
GetFSStats: ios.GetFSStats,
WG: wg,
Force: force,
}
xlru.AddNotif(&xact.NotifXact{
Base: nl.Base{When: core.UponTerm, Dsts: []string{equalIC}, F: t.notifyTerm},
Xact: xlru,
})
space.RunLRU(&ini)
}
func (t *target) runStoreCleanup(id string, wg *sync.WaitGroup, bcks ...cmn.Bck) fs.CapStatus {
regToIC := id == ""
if regToIC {
id = cos.GenUUID()
}
rns := xreg.RenewStoreCleanup(id)
if rns.Err != nil || rns.IsRunning() {
debug.Assert(rns.Err == nil || cmn.IsErrXactUsePrev(rns.Err))
if wg != nil {
wg.Done()
}
return fs.CapStatus{}
}
xcln := rns.Entry.Get()
if regToIC && xcln.ID() == id {
// pre-existing UUID: notify IC members
regMsg := xactRegMsg{UUID: id, Kind: apc.ActStoreCleanup, Srcs: []string{t.SID()}}
msg := t.newAmsgActVal(apc.ActRegGlobalXaction, regMsg)
t.bcastAsyncIC(msg)
}
ini := space.IniCln{
Xaction: xcln.(*space.XactCln),
Config: cmn.GCO.Get(),
StatsT: t.statsT,
Buckets: bcks,
WG: wg,
}
xcln.AddNotif(&xact.NotifXact{
Base: nl.Base{When: core.UponTerm, Dsts: []string{equalIC}, F: t.notifyTerm},
Xact: xcln,
})
return space.RunCleanup(&ini)
}