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

Remove a double lock in the tsm1 index writer #6882

Merged
merged 1 commit into from
Jun 21, 2016
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 @@ -69,6 +69,7 @@ With this release the systemd configuration files for InfluxDB will use the syst
- [#6824](https://github.com/influxdata/influxdb/issues/6824): Remove systemd output redirection.
- [#6859](https://github.com/influxdata/influxdb/issues/6859): Set the condition cursor instead of aux iterator when creating a nil condition cursor.
- [#6869](https://github.com/influxdata/influxdb/issues/6869): Remove FieldCodec from tsdb package.
- [#6882](https://github.com/influxdata/influxdb/pull/6882): Remove a double lock in the tsm1 index writer.

## v0.13.0 [2016-05-12]

Expand Down
23 changes: 15 additions & 8 deletions tsdb/engine/tsm1/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,22 +257,26 @@ func (d *directIndex) Add(key string, blockType byte, minTime, maxTime int64, of
d.size += indexEntrySize
}

func (d *directIndex) Entries(key string) []IndexEntry {
d.mu.RLock()
defer d.mu.RUnlock()

func (d *directIndex) entries(key string) []IndexEntry {
entries := d.blocks[key]
if entries == nil {
return nil
}
return d.blocks[key].entries
return entries.entries
}

func (d *directIndex) Entries(key string) []IndexEntry {
d.mu.RLock()
defer d.mu.RUnlock()

return d.entries(key)
}

func (d *directIndex) Entry(key string, t int64) *IndexEntry {
d.mu.RLock()
defer d.mu.RUnlock()

entries := d.Entries(key)
entries := d.entries(key)
for _, entry := range entries {
if entry.Contains(t) {
return &entry
Expand All @@ -294,7 +298,10 @@ func (d *directIndex) Keys() []string {
}

func (d *directIndex) KeyCount() int {
return len(d.blocks)
d.mu.RLock()
n := len(d.blocks)
d.mu.RUnlock()
return n
}

func (d *directIndex) addEntries(key string, entries *indexEntries) {
Expand All @@ -311,7 +318,7 @@ func (d *directIndex) WriteTo(w io.Writer) (int64, error) {
defer d.mu.RUnlock()

// Index blocks are writtens sorted by key
var keys []string
keys := make([]string, 0, len(d.blocks))
for k := range d.blocks {
keys = append(keys, k)
}
Expand Down