Browse Source

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
pull/7609/head
chrislu 2 days ago
parent
commit
41b1d9ad70
  1. 9
      weed/topology/rack.go

9
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

Loading…
Cancel
Save