Datastore can delete ranges of series matching a regex

pull/17/head
Paul Dix 2013-10-18 12:02:07 -04:00
parent 605866e18a
commit 930ecf9448
3 changed files with 60 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import (
"os"
"parser"
"protocol"
"regexp"
"testing"
"time"
)
@ -436,6 +437,55 @@ func (self *DatastoreSuite) TestCanDeleteARangeOfData(c *C) {
c.Assert(results, DeepEquals, series)
}
func (self *DatastoreSuite) TestCanDeleteRangeOfDataFromRegex(c *C) {
cleanup(nil)
db := newDatastore(c)
defer cleanup(db)
mock := `{
"points":[
{"values":[{"int_value":3},{"string_value":"paul"}],"sequence_number":2},
{"values":[{"int_value":1},{"string_value":"todd"}],"sequence_number":1}],
"name":"events",
"fields":[{"type":"INT32","name":"count"},{"type":"STRING","name":"name"}]
}`
series := stringToSeries(mock, time.Now().Unix(), c)
err := db.WriteSeriesData("foobar", series)
c.Assert(err, IsNil)
results := executeQuery("foobar", "select count, name from events;", db, c)
c.Assert(results, DeepEquals, series)
mock = `{
"points":[{"values":[{"double_value":10.1}],"sequence_number":23}],
"name":"response_times",
"fields":[{"type":"DOUBLE","name":"ms"}]}`
responseSeries := stringToSeries(mock, time.Now().Unix(), c)
err = db.WriteSeriesData("foobar", responseSeries)
c.Assert(err, IsNil)
results = executeQuery("foobar", "select ms from response_times;", db, c)
c.Assert(results, DeepEquals, responseSeries)
mock = `{
"points":[{"values":[{"double_value":232.1}],"sequence_number":23}, {"values":[{"double_value":10.1}],"sequence_number":20}],
"name":"queue_time",
"fields":[{"type":"DOUBLE","name":"processed_time"}]}`
otherSeries := stringToSeries(mock, time.Now().Unix(), c)
err = db.WriteSeriesData("foobar", otherSeries)
c.Assert(err, IsNil)
results = executeQuery("foobar", "select processed_time from queue_time;", db, c)
c.Assert(results, DeepEquals, otherSeries)
regex, _ := regexp.Compile(".*time.*")
db.DeleteRangeOfRegex("foobar", regex, time.Now().Add(-time.Hour), time.Now())
results = executeQuery("foobar", "select * from events;", db, c)
c.Assert(results, DeepEquals, series)
results = executeQuery("foobar", "select * from response_times;", db, c)
c.Assert(len(results.Points), Equals, 0)
results = executeQuery("foobar", "select * from queue_time;", db, c)
c.Assert(len(results.Points), Equals, 0)
}
func (self *DatastoreSuite) TestCanSelectFromARegex(c *C) {
cleanup(nil)
db := newDatastore(c)

View File

@ -11,6 +11,6 @@ type Datastore interface {
ExecuteQuery(database string, query *parser.Query, yield func(*protocol.Series) error) error
WriteSeriesData(database string, series *protocol.Series) error
DeleteRangeOfSeries(database, series string, startTime, endTime time.Time) error
DeleteRangeOfRegex(database string, regex regexp.Regexp, startTime, endTime time.Time) error
DeleteRangeOfRegex(database string, regex *regexp.Regexp, startTime, endTime time.Time) error
Close()
}

View File

@ -193,8 +193,15 @@ func (self *LevelDbDatastore) DeleteRangeOfSeries(database, series string, start
return nil
}
func (self *LevelDbDatastore) DeleteRangeOfRegex(database string, regex regexp.Regexp, startTime, endTime time.Time) error {
return errors.New("Not implemented yet!")
func (self *LevelDbDatastore) DeleteRangeOfRegex(database string, regex *regexp.Regexp, startTime, endTime time.Time) error {
series := self.getSeriesForDbAndRegex(database, regex)
for _, name := range series {
err := self.DeleteRangeOfSeries(database, name, startTime, endTime)
if err != nil {
return err
}
}
return nil
}
func (self *LevelDbDatastore) byteArraysForStartAndEndTimes(startTime, endTime int64) ([]byte, []byte) {