diff --git a/datastore/storage/leveldb.go b/datastore/storage/leveldb.go index c69cb781f07..a8e6ea70a30 100644 --- a/datastore/storage/leveldb.go +++ b/datastore/storage/leveldb.go @@ -3,7 +3,6 @@ package storage import ( "bytes" "fmt" - "strings" "sync" "github.com/influxdb/influxdb/configuration" @@ -73,12 +72,6 @@ func NewLevelDB(path string, config interface{}) (Engine, error) { wopts := levigo.NewWriteOptions() ropts := levigo.NewReadOptions() - // these sentinel values are here so that we can seek to the end of - // the keyspace and have the iterator still be valid. this is for - // the series that is at either end of the keyspace. - db.Put(wopts, []byte(strings.Repeat("\x00", 24)), []byte{}) - db.Put(wopts, []byte(strings.Repeat("\xff", 24)), []byte{}) - return LevelDB{db, opts, wopts, ropts, path}, err } diff --git a/datastore/storage/registry.go b/datastore/storage/registry.go index 3af6b1b302c..2c0a0cb2e59 100644 --- a/datastore/storage/registry.go +++ b/datastore/storage/registry.go @@ -1,6 +1,9 @@ package storage -import "fmt" +import ( + "fmt" + "strings" +) var engineRegistry = make(map[string]Initializer) @@ -9,11 +12,30 @@ type Initializer struct { Initialize func(path string, config interface{}) (Engine, error) } +func wrapInitializer(initializer Initializer) Initializer { + var init Initializer + init.Initialize = func(path string, config interface{}) (Engine, error) { + engine, err := initializer.Initialize(path, config) + if err != nil { + return nil, err + } + + // these sentinel values are here so that we can seek to the end of + // the keyspace and have the iterator still be valid. this is for + // the series that is at either end of the keyspace. + engine.Put([]byte(strings.Repeat("\x00", 24)), []byte{}) + engine.Put([]byte(strings.Repeat("\xff", 24)), []byte{}) + return engine, nil + } + init.NewConfig = initializer.NewConfig + return init +} + func registerEngine(name string, init Initializer) { if _, ok := engineRegistry[name]; ok { panic(fmt.Errorf("Engine '%s' already exists", name)) } - engineRegistry[name] = init + engineRegistry[name] = wrapInitializer(init) } func GetInitializer(name string) (Initializer, error) { diff --git a/integration/single_server_test.go b/integration/single_server_test.go index 981ec46e7e8..066e8f694ca 100644 --- a/integration/single_server_test.go +++ b/integration/single_server_test.go @@ -51,6 +51,31 @@ func (self *SingleServerSuite) TestWritesToNonExistentDb(c *C) { c.Assert(client.WriteSeries(s), ErrorMatches, ".*doesn't exist.*") } +func (self *SingleServerSuite) TestMultiplePoints(c *C) { + client := self.server.GetClient("test_string_columns", c) + c.Assert(client.CreateDatabase("test_string_columns"), IsNil) + err := client.WriteSeries( + []*influxdb.Series{ + { + Name: "events", + Columns: []string{"column1", "column2"}, + Points: [][]interface{}{ + {"value1", "value2"}, + }, + }, + }, + ) + c.Assert(err, IsNil) + s, err := client.Query("select * from events;") + c.Assert(err, IsNil) + c.Assert(s, HasLen, 1) + maps := ToMap(s[0]) + c.Assert(maps, HasLen, 1) + fmt.Printf("WTF: %#v\n", maps) + c.Assert(maps[0]["column1"], Equals, "value1") + c.Assert(maps[0]["column2"], Equals, "value2") +} + func (self *SingleServerSuite) TestAdministrationOperation(c *C) { client := self.server.GetClient("", c) c.Assert(client.CreateDatabase("test_admin_operations"), IsNil)