From 9134d43ba621c4818cf1ace3a406dd63175e5383 Mon Sep 17 00:00:00 2001 From: runner Date: Sun, 31 Jan 2016 13:49:58 +0800 Subject: [PATCH 1/3] fix rename file fail on the windows fix rename file fail on the windows --- node.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/node.go b/node.go index 40cc31ae084..e88f5148b8b 100644 --- a/node.go +++ b/node.go @@ -62,9 +62,13 @@ func (n *Node) Save() error { if err != nil { return err } - defer f.Close() - if err := json.NewEncoder(f).Encode(n); err != nil { + if err = json.NewEncoder(f).Encode(n); err != nil { + f.Close() + return err + } + + if err = f.Close(); nil != err { return err } From 978305a6dd913684e9d0a9092dcbf53f98867440 Mon Sep 17 00:00:00 2001 From: "runner.mei" Date: Sun, 31 Jan 2016 16:33:13 +0800 Subject: [PATCH 2/3] fix unit test of influxd in the windows fix unit test of influxd in the windows --- cmd/influxd/backup/backup.go | 2 +- cmd/influxd/run/backup_restore_test.go | 5 ++++- cmd/influxd/run/server.go | 25 +++++++++---------------- cmd/influxd/run/server_helpers_test.go | 12 +++++++++--- services/meta/config.go | 24 ++++++++++++++++-------- 5 files changed, 39 insertions(+), 29 deletions(-) diff --git a/cmd/influxd/backup/backup.go b/cmd/influxd/backup/backup.go index 6080a454e9c..d79f35db3bc 100644 --- a/cmd/influxd/backup/backup.go +++ b/cmd/influxd/backup/backup.go @@ -358,7 +358,7 @@ Options: // retentionAndShardFromPath will take the shard relative path and split it into the // retention policy name and shard ID. The first part of the path should be the database name. func retentionAndShardFromPath(path string) (retention, shard string, err error) { - a := strings.Split(path, "/") + a := strings.Split(path, string(filepath.Separator)) if len(a) != 3 { return "", "", fmt.Errorf("expected database, retention policy, and shard id in path: %s", path) } diff --git a/cmd/influxd/run/backup_restore_test.go b/cmd/influxd/run/backup_restore_test.go index 1bc94d3eea0..50054cbf3e8 100644 --- a/cmd/influxd/run/backup_restore_test.go +++ b/cmd/influxd/run/backup_restore_test.go @@ -10,6 +10,8 @@ import ( "github.com/influxdb/influxdb/cmd/influxd/backup" "github.com/influxdb/influxdb/cmd/influxd/restore" + "github.com/influxdb/influxdb/cmd/influxd/run" + "github.com/influxdb/influxdb/services/meta" ) func TestServer_BackupAndRestore(t *testing.T) { @@ -56,7 +58,8 @@ func TestServer_BackupAndRestore(t *testing.T) { // now backup cmd := backup.NewCommand() - if err := cmd.Run("-host", config.Meta.BindAddress, "-database", "mydb", backupDir); err != nil { + hostAddress, _ := meta.DefaultHost(run.DefaultHostname, config.Meta.BindAddress) + if err := cmd.Run("-host", hostAddress, "-database", "mydb", backupDir); err != nil { t.Fatalf("error backing up: %s", err.Error()) } }() diff --git a/cmd/influxd/run/server.go b/cmd/influxd/run/server.go index 4d8a1481dbb..f964485d304 100644 --- a/cmd/influxd/run/server.go +++ b/cmd/influxd/run/server.go @@ -30,7 +30,7 @@ import ( "github.com/influxdb/influxdb/services/udp" "github.com/influxdb/influxdb/tcp" "github.com/influxdb/influxdb/tsdb" - "github.com/influxdb/usage-client/v1" + client "github.com/influxdb/usage-client/v1" // Initialize the engine packages _ "github.com/influxdb/influxdb/tsdb/engine" ) @@ -123,8 +123,13 @@ func NewServer(c *Config, buildInfo *BuildInfo) (*Server, error) { } } + nodeAddr, err := meta.DefaultHost(DefaultHostname, c.Meta.HTTPBindAddress) + if err != nil { + return nil, err + } + // load the node information - metaAddresses := []string{c.Meta.HTTPBindAddress} + metaAddresses := []string{nodeAddr} if !c.Meta.Enabled { metaAddresses = c.Meta.JoinPeers } @@ -149,11 +154,11 @@ func NewServer(c *Config, buildInfo *BuildInfo) (*Server, error) { return nil, fmt.Errorf("must run as either meta node or data node or both") } - httpBindAddress, err := defaultHost(DefaultHostname, c.HTTPD.BindAddress) + httpBindAddress, err := meta.DefaultHost(DefaultHostname, c.HTTPD.BindAddress) if err != nil { return nil, err } - tcpBindAddress, err := defaultHost(DefaultHostname, bind) + tcpBindAddress, err := meta.DefaultHost(DefaultHostname, bind) if err != nil { return nil, err } @@ -748,18 +753,6 @@ func stopProfile() { } } -func defaultHost(hostname, addr string) (string, error) { - host, port, err := net.SplitHostPort(addr) - if err != nil { - return "", err - } - - if host == "" { - return net.JoinHostPort(hostname, port), nil - } - return addr, nil -} - type tcpaddr struct{ host string } func (a *tcpaddr) Network() string { return "tcp" } diff --git a/cmd/influxd/run/server_helpers_test.go b/cmd/influxd/run/server_helpers_test.go index 71c8dbb369b..a2a4137607b 100644 --- a/cmd/influxd/run/server_helpers_test.go +++ b/cmd/influxd/run/server_helpers_test.go @@ -99,9 +99,15 @@ func (s *Server) Close() { if err := s.Server.Close(); err != nil { panic(err.Error()) } - os.RemoveAll(s.Config.Meta.Dir) - os.RemoveAll(s.Config.Data.Dir) - os.RemoveAll(s.Config.HintedHandoff.Dir) + if err := os.RemoveAll(s.Config.Meta.Dir); err != nil { + panic(err.Error()) + } + if err := os.RemoveAll(s.Config.Data.Dir); err != nil { + panic(err.Error()) + } + if err := os.RemoveAll(s.Config.HintedHandoff.Dir); err != nil { + panic(err.Error()) + } } // URL returns the base URL for the httpd endpoint. diff --git a/services/meta/config.go b/services/meta/config.go index 70cad918320..4482c9637f2 100644 --- a/services/meta/config.go +++ b/services/meta/config.go @@ -96,15 +96,11 @@ func (c *Config) Validate() error { } func (c *Config) defaultHost(addr string) string { - host, port, err := net.SplitHostPort(addr) - if err != nil { - return addr - } - - if host == "" { - return net.JoinHostPort(DefaultHostname, port) + address, err := DefaultHost(DefaultHostname, addr) + if nil != err { + panic(err) } - return addr + return address } // DefaultedBindAddress returns the BindAddress normalized with the @@ -120,3 +116,15 @@ func (c *Config) DefaultedBindAddress() string { func (c *Config) DefaultedHTTPBindAddress() string { return c.defaultHost(c.HTTPBindAddress) } + +func DefaultHost(hostname, addr string) (string, error) { + host, port, err := net.SplitHostPort(addr) + if err != nil { + return "", err + } + + if host == "" || host == "0.0.0.0" || host == "::" { + return net.JoinHostPort(hostname, port), nil + } + return addr, nil +} From 7c58bf1970247bb69cf12ebc828a9d45f4b1c26e Mon Sep 17 00:00:00 2001 From: "runner.mei" Date: Fri, 5 Feb 2016 10:20:59 +0800 Subject: [PATCH 3/3] don't panic while addr is invalid --- services/meta/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/meta/config.go b/services/meta/config.go index 4482c9637f2..48050253862 100644 --- a/services/meta/config.go +++ b/services/meta/config.go @@ -98,7 +98,7 @@ func (c *Config) Validate() error { func (c *Config) defaultHost(addr string) string { address, err := DefaultHost(DefaultHostname, addr) if nil != err { - panic(err) + return addr } return address }