mirror of
https://github.com/minio/minio.git
synced 2025-01-12 15:33:22 -05:00
fs: fix stale bucket counts in data usage (#12521)
In FS mode bucket count would be incorrect. Children were not removed. Other totals is correct, though. Fixes #12512
This commit is contained in:
parent
33cee9f38a
commit
a6cbfc3600
@ -231,6 +231,13 @@ func (e *dataUsageEntry) addChild(hash dataUsageHash) {
|
|||||||
e.Children[hash.Key()] = struct{}{}
|
e.Children[hash.Key()] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// removeChild will remove a child based on its hash.
|
||||||
|
func (e *dataUsageEntry) removeChild(hash dataUsageHash) {
|
||||||
|
if len(e.Children) > 0 {
|
||||||
|
delete(e.Children, hash.Key())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// find a path in the cache.
|
// find a path in the cache.
|
||||||
// Returns nil if not found.
|
// Returns nil if not found.
|
||||||
func (d *dataUsageCache) find(path string) *dataUsageEntry {
|
func (d *dataUsageCache) find(path string) *dataUsageEntry {
|
||||||
@ -308,7 +315,8 @@ func (d *dataUsageCache) keepBuckets(b []BucketInfo) {
|
|||||||
|
|
||||||
// keepRootChildren will keep the root children specified by delete all others.
|
// keepRootChildren will keep the root children specified by delete all others.
|
||||||
func (d *dataUsageCache) keepRootChildren(list map[dataUsageHash]struct{}) {
|
func (d *dataUsageCache) keepRootChildren(list map[dataUsageHash]struct{}) {
|
||||||
if d.root() == nil {
|
root := d.root()
|
||||||
|
if root == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rh := d.rootHash()
|
rh := d.rootHash()
|
||||||
@ -320,8 +328,17 @@ func (d *dataUsageCache) keepRootChildren(list map[dataUsageHash]struct{}) {
|
|||||||
if _, ok := list[h]; !ok {
|
if _, ok := list[h]; !ok {
|
||||||
delete(d.Cache, k)
|
delete(d.Cache, k)
|
||||||
d.deleteRecursive(h)
|
d.deleteRecursive(h)
|
||||||
|
root.removeChild(h)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Clean up abandoned children.
|
||||||
|
for k := range root.Children {
|
||||||
|
h := dataUsageHash(k)
|
||||||
|
if _, ok := list[h]; !ok {
|
||||||
|
delete(root.Children, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d.Cache[rh.Key()] = *root
|
||||||
}
|
}
|
||||||
|
|
||||||
// dui converts the flattened version of the path to madmin.DataUsageInfo.
|
// dui converts the flattened version of the path to madmin.DataUsageInfo.
|
||||||
|
Loading…
Reference in New Issue
Block a user