Skip to content

Commit

Permalink
Merge pull request #2898 from influxdb/opentsdb_db
Browse files Browse the repository at this point in the history
Ensure openTSDB target database exists
  • Loading branch information
otoolep committed Jun 11, 2015
2 parents f60c816 + 223bf67 commit 9c7f23e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [#2849](https://github.com/influxdb/influxdb/issues/2849): RC32: Frequent write errors
- [#2700](https://github.com/influxdb/influxdb/issues/2700): Incorrect error message in database EncodeFields
- [#2897](https://github.com/influxdb/influxdb/pull/2897): Ensure target Graphite database exists
- [#2898](https://github.com/influxdb/influxdb/pull/2898): Ensure target openTSDB database exists

## v0.9.0-rc33 [2015-06-09]

Expand Down
1 change: 1 addition & 0 deletions cmd/influxd/run/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func (s *Server) appendOpenTSDBService(c opentsdb.Config) error {
return err
}
srv.PointsWriter = s.PointsWriter
srv.MetaStore = s.MetaStore
s.Services = append(s.Services, srv)
return nil
}
Expand Down
10 changes: 10 additions & 0 deletions services/opentsdb/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/influxdb/influxdb/cluster"
"github.com/influxdb/influxdb/meta"
"github.com/influxdb/influxdb/tsdb"
)

Expand All @@ -34,6 +35,9 @@ type Service struct {
PointsWriter interface {
WritePoints(p *cluster.WritePointsRequest) error
}
MetaStore interface {
CreateDatabaseIfNotExists(name string) (*meta.DatabaseInfo, error)
}

Logger *log.Logger
}
Expand All @@ -58,6 +62,12 @@ func NewService(c Config) (*Service, error) {

// Open starts the service
func (s *Service) Open() error {
if _, err := s.MetaStore.CreateDatabaseIfNotExists(s.Database); err != nil {
s.Logger.Printf("failed to ensure target database %s exists: %s", s.Database, err.Error())
return err
}
s.Logger.Printf("ensured target database %s exists", s.Database)

// Open listener.
ln, err := net.Listen("tcp", s.BindAddress)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions services/opentsdb/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/davecgh/go-spew/spew"
"github.com/influxdb/influxdb/cluster"
"github.com/influxdb/influxdb/meta"
"github.com/influxdb/influxdb/services/opentsdb"
"github.com/influxdb/influxdb/tsdb"
)
Expand Down Expand Up @@ -136,6 +137,7 @@ func NewService(database string) *Service {
})
s := &Service{Service: srv}
s.Service.PointsWriter = &s.PointsWriter
s.Service.MetaStore = &DatabaseCreator{}

if !testing.Verbose() {
s.Logger = log.New(ioutil.Discard, "", log.LstdFlags)
Expand All @@ -152,3 +154,10 @@ type PointsWriter struct {
func (w *PointsWriter) WritePoints(p *cluster.WritePointsRequest) error {
return w.WritePointsFn(p)
}

type DatabaseCreator struct {
}

func (d *DatabaseCreator) CreateDatabaseIfNotExists(name string) (*meta.DatabaseInfo, error) {
return nil, nil
}

0 comments on commit 9c7f23e

Please sign in to comment.