From 4f0322af8665a8ab9f50610b2146de21dd941fa6 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 7 Aug 2026 00:44:30 -0700 Subject: [PATCH] perf(weed/topology): log writable-state changes, not every check (#10612) * perf(weed/topology): log writable-state changes, not every check ensureCorrectWritables ran its three diagnostics whenever it was asked, so a volume that had always been read-only re-announced that on every registration. A volume server reconnecting with 550k read-only volumes made the master format over a million log lines before it could serve anything, which is exactly when it is already at its memory peak rebuilding the topology. removeFromWritable already reports the transition, and only when there is one. Explain it only then. Dropped the separate 'remove from writable' line, which said nothing that 'becomes unwritable' does not. BenchmarkRegisterReadOnlyVolumes, 100k volumes 285791480 B/op 1902069 allocs/op -> 234592088 B/op 1302572 allocs/op * Update weed/topology/volume_layout.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- weed/topology/volume_layout.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/weed/topology/volume_layout.go b/weed/topology/volume_layout.go index 6cc58f1b6..77821c154 100644 --- a/weed/topology/volume_layout.go +++ b/weed/topology/volume_layout.go @@ -343,18 +343,22 @@ func (vl *VolumeLayout) ensureCorrectWritables(vid needle.VolumeId) { isOversizedVolume := vl.oversizedVolumes.IsTrue(vid) if isEnoughCopies && isAllWritable && !isOversizedVolume { vl.setVolumeWritable(vid) - } else { - if !isEnoughCopies { - glog.V(0).Infof("volume %d does not have enough copies", vid) - } - if !isAllWritable { - glog.V(0).Infof("volume %d are not all writable", vid) - } - if isOversizedVolume { - glog.V(1).Infof("volume %d are oversized", vid) - } - glog.V(0).Infof("volume %d remove from writable", vid) - vl.removeFromWritable(vid) + return + } + // removeFromWritable reports the transition itself, and only when there is + // one. Explain it only then: every heartbeat re-runs this for every volume, + // so a volume that is simply staying read-only must not log. + if !vl.removeFromWritable(vid) { + return + } + if !isEnoughCopies { + glog.V(0).Infof("volume %d does not have enough copies", vid) + } + if !isAllWritable { + glog.V(0).Infof("volume %d is not fully writable", vid) + } + if isOversizedVolume { + glog.V(0).Infof("volume %d is oversized", vid) } }