Skip to content

Commit 6d279ed

Browse files
committed
reorder struct items for alignment
On 32-bit platforms, use of atomic.* 64-bit functions needs to be careful to ensure 64-bit alignment. This was a problem in the rackAwareRR struct, causing panics on 32-bit platforms. https://pkg.go.dev/sync/atomic#pkg-note-BUG notes that the first word in a struct is always 64-bit aligned, to moving the struct member that causes the issue to the beginning of the struct solves the problem. See #1666.
1 parent fe55d80 commit 6d279ed

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

policies.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,10 +904,14 @@ func (d *dcAwareRR) Pick(q ExecutableQuery) NextHost {
904904
// a different rack, before hosts in all other datercentres
905905

906906
type rackAwareRR struct {
907+
// lastUsedHostIdx keeps the index of the last used host.
908+
// It is accessed atomically and needs to be aligned to 64 bits, so we
909+
// keep it first in the struct. Do not move it or add new struct members
910+
// before it.
911+
lastUsedHostIdx uint64
907912
localDC string
908913
localRack string
909914
hosts []cowHostList
910-
lastUsedHostIdx uint64
911915
}
912916

913917
func RackAwareRoundRobinPolicy(localDC string, localRack string) HostSelectionPolicy {

0 commit comments

Comments
 (0)