Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cursor leak when cur == nil and aux or conds is not empty #8706

Merged
merged 1 commit into from
Aug 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- [#8639](https://github.com/influxdata/influxdb/issues/8639): Parse time literals using the time zone in the select statement.
- [#8694](https://github.com/influxdata/influxdb/issues/8694): Reduce CPU usage when checking series cardinality
- [#8677](https://github.com/influxdata/influxdb/issues/8677): Fix backups when snapshot is empty.
- [#8706](https://github.com/influxdata/influxdb/pull/8706): Cursor leak, resulting in an accumulation of `.tsm.tmp` files after compactions.

## v1.3.4 [unreleased]

Expand Down
2 changes: 2 additions & 0 deletions tsdb/engine/tsm1/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,8 @@ func (e *Engine) createVarRefSeriesIterator(ref *influxql.VarRef, name string, s

// If the field doesn't exist then don't build an iterator.
if cur == nil {
cursorsAt(aux).close()
cursorsAt(conds).close()
return nil, nil
}

Expand Down
40 changes: 10 additions & 30 deletions tsdb/engine/tsm1/iterator.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,9 @@ func (itr *floatIterator) Stats() influxql.IteratorStats {

// Close closes the iterator.
func (itr *floatIterator) Close() error {
for _, c := range itr.aux {
c.close()
}
cursorsAt(itr.aux).close()
itr.aux = nil
for _, c := range itr.conds.curs {
c.close()
}
cursorsAt(itr.conds.curs).close()
itr.conds.curs = nil
if itr.cur != nil {
err := itr.cur.close()
Expand Down Expand Up @@ -654,13 +650,9 @@ func (itr *integerIterator) Stats() influxql.IteratorStats {

// Close closes the iterator.
func (itr *integerIterator) Close() error {
for _, c := range itr.aux {
c.close()
}
cursorsAt(itr.aux).close()
itr.aux = nil
for _, c := range itr.conds.curs {
c.close()
}
cursorsAt(itr.conds.curs).close()
itr.conds.curs = nil
if itr.cur != nil {
err := itr.cur.close()
Expand Down Expand Up @@ -1069,13 +1061,9 @@ func (itr *unsignedIterator) Stats() influxql.IteratorStats {

// Close closes the iterator.
func (itr *unsignedIterator) Close() error {
for _, c := range itr.aux {
c.close()
}
cursorsAt(itr.aux).close()
itr.aux = nil
for _, c := range itr.conds.curs {
c.close()
}
cursorsAt(itr.conds.curs).close()
itr.conds.curs = nil
if itr.cur != nil {
err := itr.cur.close()
Expand Down Expand Up @@ -1484,13 +1472,9 @@ func (itr *stringIterator) Stats() influxql.IteratorStats {

// Close closes the iterator.
func (itr *stringIterator) Close() error {
for _, c := range itr.aux {
c.close()
}
cursorsAt(itr.aux).close()
itr.aux = nil
for _, c := range itr.conds.curs {
c.close()
}
cursorsAt(itr.conds.curs).close()
itr.conds.curs = nil
if itr.cur != nil {
err := itr.cur.close()
Expand Down Expand Up @@ -1899,13 +1883,9 @@ func (itr *booleanIterator) Stats() influxql.IteratorStats {

// Close closes the iterator.
func (itr *booleanIterator) Close() error {
for _, c := range itr.aux {
c.close()
}
cursorsAt(itr.aux).close()
itr.aux = nil
for _, c := range itr.conds.curs {
c.close()
}
cursorsAt(itr.conds.curs).close()
itr.conds.curs = nil
if itr.cur != nil {
err := itr.cur.close()
Expand Down
8 changes: 2 additions & 6 deletions tsdb/engine/tsm1/iterator.gen.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,9 @@ func (itr *{{.name}}Iterator) Stats() influxql.IteratorStats {

// Close closes the iterator.
func (itr *{{.name}}Iterator) Close() error {
for _, c := range itr.aux {
c.close()
}
cursorsAt(itr.aux).close()
itr.aux = nil
for _, c := range itr.conds.curs {
c.close()
}
cursorsAt(itr.conds.curs).close()
itr.conds.curs = nil
if itr.cur != nil {
err := itr.cur.close()
Expand Down
8 changes: 8 additions & 0 deletions tsdb/engine/tsm1/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,11 @@ func (c *stringSliceCursor) nextString() (int64, string) {
c.values = c.values[1:]
return 0, value
}

type cursorsAt []cursorAt

func (c cursorsAt) close() {
for _, cur := range c {
cur.close()
}
}