fix: tiering statistics handling a bug in clone() implementation (#18342)

Tiering statistics have been broken for some time now, a regression
was introduced in 6f2406b0b6

Bonus fixes an issue where the objects are not assumed to be
of the 'STANDARD' storage-class for the objects that have
not yet tiered, this should be conditional based on the object's
metadata not a default assumption.

This PR also does some cleanup in terms of implementation,

fixes #18070
This commit is contained in:
Harshavardhana
2023-10-30 09:59:51 -07:00
committed by GitHub
parent ef67c39910
commit 877e0cac03
7 changed files with 71 additions and 63 deletions

View File

@@ -78,8 +78,8 @@ func newAllTierStats() *allTierStats {
}
}
func (ats *allTierStats) addSizes(sz sizeSummary) {
for tier, st := range sz.tiers {
func (ats *allTierStats) addSizes(tiers map[string]tierStats) {
for tier, st := range tiers {
ats.Tiers[tier] = ats.Tiers[tier].add(st)
}
}
@@ -95,18 +95,16 @@ func (ats *allTierStats) clone() *allTierStats {
return nil
}
dst := *ats
if dst.Tiers != nil {
dst.Tiers = make(map[string]tierStats, len(dst.Tiers))
for tier, st := range dst.Tiers {
dst.Tiers[tier] = st
}
dst.Tiers = make(map[string]tierStats, len(ats.Tiers))
for tier, st := range ats.Tiers {
dst.Tiers[tier] = st
}
return &dst
}
func (ats *allTierStats) adminStats(stats map[string]madmin.TierStats) map[string]madmin.TierStats {
func (ats *allTierStats) populateStats(stats map[string]madmin.TierStats) {
if ats == nil {
return stats
return
}
// Update stats for tiers as they become available.
@@ -117,7 +115,7 @@ func (ats *allTierStats) adminStats(stats map[string]madmin.TierStats) map[strin
NumObjects: st.NumObjects,
}
}
return stats
return
}
// tierStats holds per-tier stats of a remote tier.
@@ -128,10 +126,11 @@ type tierStats struct {
}
func (ts tierStats) add(u tierStats) tierStats {
ts.TotalSize += u.TotalSize
ts.NumVersions += u.NumVersions
ts.NumObjects += u.NumObjects
return ts
return tierStats{
TotalSize: ts.TotalSize + u.TotalSize,
NumVersions: ts.NumVersions + u.NumVersions,
NumObjects: ts.NumObjects + u.NumObjects,
}
}
//msgp:tuple replicationStatsV1
@@ -197,12 +196,11 @@ func (r *replicationAllStats) clone() *replicationAllStats {
dst := *r
// Copy individual targets.
if dst.Targets != nil {
dst.Targets = make(map[string]replicationStats, len(dst.Targets))
for k, v := range r.Targets {
dst.Targets[k] = v
}
dst.Targets = make(map[string]replicationStats, len(r.Targets))
for k, v := range r.Targets {
dst.Targets[k] = v
}
return &dst
}
@@ -360,11 +358,11 @@ func (e *dataUsageEntry) addSizes(summary sizeSummary) {
tgtStat.PendingCount += st.pendingCount
e.ReplicationStats.Targets[arn] = tgtStat
}
if summary.tiers != nil {
if len(summary.tiers) != 0 {
if e.AllTierStats == nil {
e.AllTierStats = newAllTierStats()
}
e.AllTierStats.addSizes(summary)
e.AllTierStats.addSizes(summary.tiers)
}
}
@@ -403,7 +401,7 @@ func (e *dataUsageEntry) merge(other dataUsageEntry) {
e.ObjVersions[i] += v
}
if other.AllTierStats != nil {
if other.AllTierStats != nil && len(other.AllTierStats.Tiers) != 0 {
if e.AllTierStats == nil {
e.AllTierStats = newAllTierStats()
}