Skip to content

Commit

Permalink
Add the sentinel values for all db on creation
Browse files Browse the repository at this point in the history
Fix #772
  • Loading branch information
jvshahid committed Jul 21, 2014
1 parent 6dfc2b3 commit afe3f96
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
7 changes: 0 additions & 7 deletions datastore/storage/leveldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package storage
import (
"bytes"
"fmt"
"strings"
"sync"

"github.com/influxdb/influxdb/configuration"
Expand Down Expand Up @@ -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
}

Expand Down
26 changes: 24 additions & 2 deletions datastore/storage/registry.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package storage

import "fmt"
import (
"fmt"
"strings"
)

var engineRegistry = make(map[string]Initializer)

Expand All @@ -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) {
Expand Down
25 changes: 25 additions & 0 deletions integration/single_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit afe3f96

Please sign in to comment.