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:
Klaus Post 2021-06-16 14:22:55 -07:00 committed by GitHub
parent 33cee9f38a
commit a6cbfc3600
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -231,6 +231,13 @@ func (e *dataUsageEntry) addChild(hash dataUsageHash) {
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.
// Returns nil if not found.
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.
func (d *dataUsageCache) keepRootChildren(list map[dataUsageHash]struct{}) {
if d.root() == nil {
root := d.root()
if root == nil {
return
}
rh := d.rootHash()
@ -320,8 +328,17 @@ func (d *dataUsageCache) keepRootChildren(list map[dataUsageHash]struct{}) {
if _, ok := list[h]; !ok {
delete(d.Cache, k)
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.