diff --git a/CHANGELOG.md b/CHANGELOG.md index 7489d50921..3f27934416 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - [#7811](https://github.com/influxdata/influxdb/issues/7811): Kill query not killing query - [#7457](https://github.com/influxdata/influxdb/issues/7457): KILL QUERY should work during all phases of a query - [#8155](https://github.com/influxdata/influxdb/pull/8155): Simplify admin user check. +- [#8118](https://github.com/influxdata/influxdb/issues/8118): Significantly improve DROP DATABASE speed. ## v1.2.2 [2017-03-14] diff --git a/tsdb/meta.go b/tsdb/meta.go index c57f774fc3..4bdf0632eb 100644 --- a/tsdb/meta.go +++ b/tsdb/meta.go @@ -509,39 +509,6 @@ func (d *DatabaseIndex) dropMeasurement(name string) { atomic.AddInt64(&d.stats.NumMeasurementsDropped, 1) } -// DropSeries removes the series keys and their tags from the index. -func (d *DatabaseIndex) DropSeries(keys []string) { - d.mu.Lock() - defer d.mu.Unlock() - - var ( - mToDelete = map[string]struct{}{} - nDeleted int64 - ) - - for _, k := range keys { - series := d.series[k] - if series == nil { - continue - } - series.measurement.DropSeries(series) - delete(d.series, k) - nDeleted++ - - // If there are no more series in the measurement then we'll - // remove it. - if len(series.measurement.seriesByID) == 0 { - mToDelete[series.measurement.Name] = struct{}{} - } - } - - for mname := range mToDelete { - d.dropMeasurement(mname) - } - atomic.AddInt64(&d.stats.NumSeries, -nDeleted) - atomic.AddInt64(&d.stats.NumSeriesDropped, nDeleted) -} - // Dereference removes all references to data within b and moves them to the heap. func (d *DatabaseIndex) Dereference(b []byte) { d.mu.RLock() diff --git a/tsdb/shard.go b/tsdb/shard.go index 8cbde52aec..9f2597bb18 100644 --- a/tsdb/shard.go +++ b/tsdb/shard.go @@ -271,7 +271,7 @@ func (s *Shard) Open() error { return nil }(); err != nil { - s.close() + s.close(true) return NewShardError(s.id, err) } @@ -289,14 +289,28 @@ func (s *Shard) UnloadIndex() { s.index.RemoveShard(s.id) } -// Close shuts down the shard's store. +// Close closes the shard, removing the shard ID and any of the shard's series +// keys from any associated indexes. func (s *Shard) Close() error { s.mu.Lock() defer s.mu.Unlock() - return s.close() + return s.close(true) } -func (s *Shard) close() error { +// CloseFast closes the shard without cleaning up the shard ID or any of the +// shard's series keys from the index it belongs to. +// +// CloseFast can be called when the entire index is being removed, e.g., when +// the database the shard belongs to is being dropped. +func (s *Shard) CloseFast() error { + s.mu.Lock() + defer s.mu.Unlock() + return s.close(false) +} + +// close closes the shard an removes reference to the shard from associated +// indexes, unless clean is false. +func (s *Shard) close(clean bool) error { if s.engine == nil { return nil } @@ -308,8 +322,10 @@ func (s *Shard) close() error { close(s.closing) } - // Don't leak our shard ID and series keys in the index - s.UnloadIndex() + if clean { + // Don't leak our shard ID and series keys in the index + s.UnloadIndex() + } err := s.engine.Close() if err == nil { diff --git a/tsdb/store.go b/tsdb/store.go index 660c85124a..0683cd61dd 100644 --- a/tsdb/store.go +++ b/tsdb/store.go @@ -402,7 +402,7 @@ func (s *Store) DeleteDatabase(name string) error { return nil } - return sh.Close() + return sh.CloseFast() }); err != nil { return err }