Merge pull request #8121 from influxdata/er-drop-db

Speed up DROP DATABASE
pull/8182/head
Edd Robinson 2017-03-21 12:39:06 +00:00 committed by GitHub
commit 4665e39ccf
4 changed files with 24 additions and 40 deletions

View File

@ -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]

View File

@ -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()

View File

@ -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 {

View File

@ -402,7 +402,7 @@ func (s *Store) DeleteDatabase(name string) error {
return nil
}
return sh.Close()
return sh.CloseFast()
}); err != nil {
return err
}