Skip to content

Commit

Permalink
storage: clear *cmd references in cmdQ buffers before re-use
Browse files Browse the repository at this point in the history
This commit ensures that the *cmd references in the overlaps buffer that
the CommandQueue uses to avoid repeat allocations are cleared after use.
This prevents the buffer from accidentally holding references to *cmd
objects and preventing them from being GCed.

Release note (bug fix): The CommandQueue makes sure to clear references
to objects in its buffers to allow those objects to be reclaimed by the
garbage collector.
  • Loading branch information
nvanbenschoten committed Dec 4, 2019
1 parent ff9f774 commit 315781d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/storage/command_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ func (cq *CommandQueue) getPrereqs(
restart = cq.expand(c, true /* isInserted */) || restart
}
if restart {
// Clear all *cmd references in overlaps, per the getOverlaps contract.
for j := range overlaps {
overlaps[j] = nil
}
i--
continue
}
Expand Down Expand Up @@ -614,7 +618,9 @@ func (cq *CommandQueue) getPrereqs(
}

// getOverlaps returns a slice of values which overlap the specified
// interval. The slice is only valid until the next call to getOverlaps.
// interval. The slice is only valid until the next call to getOverlaps
// and all elements should be nil-ed out to avoid holding references to
// *cmd objects and preventing GC.
func (cq *CommandQueue) getOverlaps(
readOnly bool, timestamp hlc.Timestamp, rng interval.Range,
) []*cmd {
Expand Down Expand Up @@ -680,6 +686,7 @@ func (o *overlapHeap) Push(x interface{}) {
func (o *overlapHeap) Pop() interface{} {
n := len(*o) - 1
x := (*o)[n]
(*o)[n] = nil // for gc
*o = (*o)[:n]
return x
}
Expand Down

0 comments on commit 315781d

Please sign in to comment.