Skip to content

Commit

Permalink
fix #371. Seris index isn't deleted when the series is dropped
Browse files Browse the repository at this point in the history
  • Loading branch information
jvshahid committed Mar 28, 2014
1 parent d37d89d commit e2490a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/datastore/leveldb_shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ package datastore
import (
"bytes"
"cluster"
"code.google.com/p/goprotobuf/proto"
log "code.google.com/p/log4go"
"common"
"encoding/binary"
"errors"
"fmt"
"github.com/jmhodges/levigo"
"math"
"parser"
"protocol"
"regexp"
"strings"
"sync"
"time"

"code.google.com/p/goprotobuf/proto"
log "code.google.com/p/log4go"
"github.com/jmhodges/levigo"
)

type LevelDbShard struct {
Expand Down Expand Up @@ -137,8 +138,6 @@ func (self *LevelDbShard) DropDatabase(database string) error {
log.Error("DropDatabase: ", err)
}

seriesKey := append(DATABASE_SERIES_INDEX_PREFIX, []byte(database+"~")...)
wb.Delete(seriesKey)
}

return self.db.Write(self.writeOptions, wb)
Expand Down Expand Up @@ -375,15 +374,17 @@ func (self *LevelDbShard) dropSeries(database, series string) error {
wb := levigo.NewWriteBatch()
defer wb.Close()

for _, name := range self.getColumnNamesForSeries(database, series) {
if err := self.deleteRangeOfSeriesCommon(database, series, startTimeBytes, endTimeBytes); err != nil {
return err
}
if err := self.deleteRangeOfSeriesCommon(database, series, startTimeBytes, endTimeBytes); err != nil {
return err
}

for _, name := range self.getColumnNamesForSeries(database, series) {
indexKey := append(SERIES_COLUMN_INDEX_PREFIX, []byte(database+"~"+series+"~"+name)...)
wb.Delete(indexKey)
}

wb.Delete(append(DATABASE_SERIES_INDEX_PREFIX, []byte(database+"~"+series)...))

// remove the column indeces for this time series
return self.db.Write(self.writeOptions, wb)
}
Expand Down
7 changes: 7 additions & 0 deletions src/integration/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ func (self *IntegrationSuite) TestExplainsWithPassthrough(c *C) {
c.Assert(series[0].Points[0][6], Equals, float64(2.0))
}

// issue #342, #371
func (self *IntegrationSuite) TestDataResurrectionAfterRestart(c *C) {
s := self.createPoints("data_resurrection", 1, 10)
b, err := json.Marshal(s)
Expand Down Expand Up @@ -387,6 +388,12 @@ func (self *IntegrationSuite) TestDataResurrectionAfterRestart(c *C) {
err = json.Unmarshal(data, &series)
c.Assert(err, IsNil)
c.Assert(series, HasLen, 0)
data, err = self.server.RunQuery("list series", "s")
c.Assert(err, IsNil)
series = []*SerializedSeries{}
err = json.Unmarshal(data, &series)
c.Assert(err, IsNil)
c.Assert(series, HasLen, 0)
}

func (self *IntegrationSuite) TestExplainsWithPassthroughAndLimit(c *C) {
Expand Down

0 comments on commit e2490a2

Please sign in to comment.