Skip to content

Commit

Permalink
[CLIENT-3156] Fix as issue where rack policy always returns the maste…
Browse files Browse the repository at this point in the history
…r node
  • Loading branch information
khaf committed Nov 1, 2024
1 parent 751ae9d commit 8ffe7be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change History

## November 1 2024: v7.7.2

Minor fix release.

- **Fixes**
- [CLIENT-3156] Fix an issue where rack policy always returns the master node. Resolves #455

## September 18 2024: v7.7.1

Hot Fix release. This version fixes a major bug introduced in v7.7.0. You should use this release instead.
Expand Down
8 changes: 6 additions & 2 deletions partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,21 +249,25 @@ func (ptn *Partition) getSequenceNode(cluster *Cluster) (*Node, Error) {
func (ptn *Partition) getRackNode(cluster *Cluster) (*Node, Error) {
replicas := ptn.partitions.Replicas

// Try to find a node on the same rack first:
for _, rackId := range cluster.clientPolicy.RackIds {
seq := ptn.sequence
for range replicas {
index := ptn.sequence % len(replicas)
index := seq % len(replicas)
node := replicas[index][ptn.PartitionId]

if node != nil && node != ptn.prevNode && node.hasRack(ptn.Namespace, rackId) && node.IsActive() {
ptn.prevNode = node
ptn.sequence = seq
ptn.sequence = seq + 1 // start from the next node and save a comparison
return node, nil
}
seq++
}
}

// A node on the same Rack was not found, so try other options.
// Same node as the previous will be the last option,
// since it is the least desirable.
for range replicas {
index := ptn.sequence % len(replicas)
node := replicas[index][ptn.PartitionId]
Expand Down

0 comments on commit 8ffe7be

Please sign in to comment.