Skip to content

Commit

Permalink
util: wrong memory count when use Tracker.ReplaceChild() (#14513) (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored Jan 19, 2020
1 parent 69dc332 commit 82b8b7a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion util/memory/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (t *Tracker) remove(oldChild *Tracker) {
continue
}

atomic.AddInt64(&t.bytesConsumed, -oldChild.BytesConsumed())
t.Consume(-oldChild.BytesConsumed())
oldChild.parent = nil
t.mu.children = append(t.mu.children[:i], t.mu.children[i+1:]...)
break
Expand Down
11 changes: 11 additions & 0 deletions util/memory/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ func (s *testSuite) TestReplaceChild(c *C) {
c.Assert(len(parent.mu.children), Equals, 0)
c.Assert(newChild.parent, IsNil)
c.Assert(oldChild.parent, IsNil)

node1 := NewTracker(stringutil.StringerStr("Node1"), -1)
node2 := NewTracker(stringutil.StringerStr("Node2"), -1)
node3 := NewTracker(stringutil.StringerStr("Node3"), -1)
node2.AttachTo(node1)
node3.AttachTo(node2)
node3.Consume(100)
c.Assert(node1.BytesConsumed(), Equals, int64(100))
node2.ReplaceChild(node3, nil)
c.Assert(node2.BytesConsumed(), Equals, int64(0))
c.Assert(node1.BytesConsumed(), Equals, int64(0))
}

func (s *testSuite) TestToString(c *C) {
Expand Down

0 comments on commit 82b8b7a

Please sign in to comment.