Skip to content

Commit

Permalink
Merge pull request #18566 from influxdata/fix-tag-key-ref
Browse files Browse the repository at this point in the history
fix(tsdb): Add refs for file-sourced tag keys
  • Loading branch information
benbjohnson authored Jun 18, 2020
2 parents d1f9807 + 171f658 commit 35f577f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tsdb/tsm1/engine_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ func (e *Engine) tagKeysNoPredicate(ctx context.Context, orgID, bucketID influxd
var stats cursors.CursorStats
var canceled bool

var files unrefs
defer func() { files.Unref() }()

e.FileStore.ForEachFile(func(f TSMFile) bool {
// Check the context before touching each tsm file
select {
Expand All @@ -366,6 +369,8 @@ func (e *Engine) tagKeysNoPredicate(ctx context.Context, orgID, bucketID influxd
return false
default:
}

var hasRef bool
if f.OverlapsTimeRange(start, end) && f.OverlapsKeyPrefixRange(tsmKeyPrefix, tsmKeyPrefix) {
// TODO(sgc): create f.TimeRangeIterator(minKey, maxKey, start, end)
iter := f.TimeRangeIterator(tsmKeyPrefix, start, end)
Expand All @@ -384,6 +389,12 @@ func (e *Engine) tagKeysNoPredicate(ctx context.Context, orgID, bucketID influxd

if iter.HasData() {
keyset.UnionKeys(tags)

// Add reference to ensure tags are valid for the outer function.
if !hasRef {
f.Ref()
files, hasRef = append(files, f), true
}
}
}
stats.Add(iter.Stats())
Expand Down

0 comments on commit 35f577f

Please sign in to comment.