From 41b1d9ad70a19e88dd6bf0161391a995075f3034 Mon Sep 17 00:00:00 2001 From: chrislu Date: Tue, 2 Dec 2025 21:25:56 -0800 Subject: [PATCH] fix: add id normalization and address change logging - Normalize id parameter at function boundary (trim whitespace) - Log when DataNode IP:Port changes (helps debug K8s pod rescheduling) Ref: https://github.com/seaweedfs/seaweedfs/issues/7487 --- weed/topology/rack.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/weed/topology/rack.go b/weed/topology/rack.go index 91c3b266c..1e5c8b632 100644 --- a/weed/topology/rack.go +++ b/weed/topology/rack.go @@ -50,13 +50,20 @@ func (r *Rack) GetOrCreateDataNode(ip string, port int, grpcPort int, publicUrl r.Lock() defer r.Unlock() + // Normalize the id parameter (trim whitespace) + id = strings.TrimSpace(id) + // Determine the node ID: use provided id, or fall back to ip:port for backward compatibility nodeId := util.GetVolumeServerId(id, ip, port) // First, try to find by node ID using O(1) map lookup (stable identity) if c, ok := r.children[NodeId(nodeId)]; ok { dn := c.(*DataNode) - // Update the IP/Port in case they changed (e.g., pod rescheduled in K8s) + // Log if IP or Port changed (e.g., pod rescheduled in K8s) + if dn.Ip != ip || dn.Port != port { + glog.V(0).Infof("DataNode %s address changed from %s:%d to %s:%d", nodeId, dn.Ip, dn.Port, ip, port) + } + // Update the IP/Port in case they changed dn.Ip = ip dn.Port = port dn.GrpcPort = grpcPort