Skip to content

Commit

Permalink
Optimize shard index loading
Browse files Browse the repository at this point in the history
On data sets with many series and potentially large series keys,
the cost of parsing the key and re-indexing can be high.

Loading the TSM keys into the index was being done repeatedly for
series that were already index by an earlier TSM file.  This was
wasted worked and slows down shard loading.

Parsing the key was also innefficient and allocated a new string
slice.  This was simplified to remove that allocation.
  • Loading branch information
jwilder committed May 12, 2016
1 parent 9840d6f commit 0dbd489
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
### Bugfixes

- [#6604](https://github.com/influxdata/influxdb/pull/6604): Remove old cluster code
- [#6618](https://github.com/influxdata/influxdb/pull/6618): Optimize shard loading

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

Expand Down
15 changes: 11 additions & 4 deletions tsdb/engine/tsm1/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,12 @@ func (e *Engine) readFileFromBackup(tr *tar.Reader, shardRelativePath string) er
// database index and measurement fields
func (e *Engine) addToIndexFromKey(shardID uint64, key string, fieldType influxql.DataType, index *tsdb.DatabaseIndex) error {
seriesKey, field := seriesAndFieldFromCompositeKey(key)
// Have we already indexed this series?
ss := index.Series(seriesKey)
if ss != nil {
return nil
}

measurement := tsdb.MeasurementFromSeriesKey(seriesKey)

m := index.CreateMeasurementIndexIfNotExists(measurement)
Expand Down Expand Up @@ -1230,9 +1236,10 @@ func tsmFieldTypeToInfluxQLDataType(typ byte) (influxql.DataType, error) {
}

func seriesAndFieldFromCompositeKey(key string) (string, string) {
parts := strings.Split(key, keyFieldSeparator)
if len(parts) != 0 {
return parts[0], strings.Join(parts[1:], keyFieldSeparator)
sep := strings.Index(key, keyFieldSeparator)
if sep == -1 {
// No field???
return key, ""
}
return parts[0], parts[1]
return key[:sep], key[sep+len(keyFieldSeparator):]
}

0 comments on commit 0dbd489

Please sign in to comment.