Skip to content

Commit

Permalink
kvclient: implement MoveToFront in test transport
Browse files Browse the repository at this point in the history
A test transport wasn't implementing the MoveToFront() functionality,
although it's pretty important. This patch implements it. Luckily all
current tests seem fine with and without it.

Release note: None
  • Loading branch information
andreimatei committed Aug 19, 2020
1 parent bf9b93b commit 9c7ef62
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 13 additions & 1 deletion pkg/kv/kvclient/kvcoord/dist_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,19 @@ func (l *simpleTransportAdapter) SkipReplica() {
l.nextReplicaIdx++
}

func (*simpleTransportAdapter) MoveToFront(roachpb.ReplicaDescriptor) {
func (l *simpleTransportAdapter) MoveToFront(replica roachpb.ReplicaDescriptor) {
for i := range l.replicas {
if l.replicas[i] == replica {
// If we've already processed the replica, decrement the current
// index before we swap.
if i < l.nextReplicaIdx {
l.nextReplicaIdx--
}
// Swap the client representing this replica to the front.
l.replicas[i], l.replicas[l.nextReplicaIdx] = l.replicas[l.nextReplicaIdx], l.replicas[i]
return
}
}
}

func makeGossip(t *testing.T, stopper *stop.Stopper, rpcContext *rpc.Context) *gossip.Gossip {
Expand Down
4 changes: 0 additions & 4 deletions pkg/kv/kvclient/kvcoord/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,6 @@ func (gt *grpcTransport) SkipReplica() {
}

func (gt *grpcTransport) MoveToFront(replica roachpb.ReplicaDescriptor) {
gt.moveToFront(replica)
}

func (gt *grpcTransport) moveToFront(replica roachpb.ReplicaDescriptor) {
for i := range gt.replicas {
if gt.replicas[i] == replica {
// If we've already processed the replica, decrement the current
Expand Down

0 comments on commit 9c7ef62

Please sign in to comment.