lib/storage: fallback to address-based ID

Generate an ID based on storage node address if storage node is not available.
This is needed in order to prevent uneven load distribution if some storage nodes are not available when vminsert is starting.

Signed-off-by: Zakhar Bessarab <z.bessarab@victoriametrics.com>
This commit is contained in:
Zakhar Bessarab 2024-06-25 14:32:13 +04:00
parent 5ac1e77520
commit 7402ee0801
No known key found for this signature in database
GPG key ID: 932B34D6FE062023

View file

@ -419,6 +419,14 @@ func (sn *storageNode) getID() uint64 {
sn.checkHealth()
}
// If the id is still not populated after checkHealth than storage node is not reachable
// build a unique id based on the address
if sn.id.Load() == 0 {
id := xxhash.Sum64String(sn.dialer.Addr())
sn.id.CompareAndSwap(0, id)
return id
}
return sn.id.Load()
}