Skip to content

Commit

Permalink
kvserver: zero out slice before reuse
Browse files Browse the repository at this point in the history
Standard Go error - we were trying to avoid allocations by recycling a
slice but weren't zeroing it out before. The occasional long slice that
would reference a ton of memory would then effectively keep that large
amount of memory alive forever.

Touches #71050.

Release note: None
  • Loading branch information
tbg authored and cameronnunez committed Oct 27, 2021
1 parent 5202f38 commit d9472e5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/kv/kvserver/raft_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,18 @@ func (t *RaftTransport) processQueue(
}

err := stream.Send(batch)
batch.Requests = batch.Requests[:0]

atomic.AddInt64(&stats.clientSent, 1)
if err != nil {
return err
}

// Reuse the Requests slice, but zero out the contents to avoid delaying
// GC of memory referenced from within.
for i := range batch.Requests {
batch.Requests[i] = RaftMessageRequest{}
}
batch.Requests = batch.Requests[:0]

atomic.AddInt64(&stats.clientSent, 1)
}
}
}
Expand Down

0 comments on commit d9472e5

Please sign in to comment.