Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: upgrade etcd to master #1101

Merged
merged 9 commits into from
Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
61 changes: 44 additions & 17 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

[[constraint]]
name = "github.com/coreos/etcd"
version = "=3.3.4"
branch = "master"

[[override]]
name = "github.com/coreos/bbolt"
version = "=v1.3.1-coreos.6"

[[override]]
name = "github.com/grpc-ecosystem/grpc-gateway"
version = "~1.3"
version = "~1.4"

[[constraint]]
name = "google.golang.org/grpc"
Expand Down
1 change: 1 addition & 0 deletions pd-client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
)

func TestClient(t *testing.T) {
server.EnableZap = true
TestingT(t)
}

Expand Down
1 change: 0 additions & 1 deletion pd-client/leader_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func (s *testLeaderChangeSuite) prepareClusterN(c *C, n int) (svrs map[string]*s

for i := 0; i < n; i++ {
cfg := cfgs[i]

go func() {
svr, err := server.CreateServer(cfg, api.NewHandler)
c.Assert(err, IsNil)
Expand Down
2 changes: 1 addition & 1 deletion pkg/etcdutil/etcdutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func CheckClusterID(localClusterID types.ID, um types.URLsMap, tlsConfig *tls.Co
trp := &http.Transport{
TLSClientConfig: tlsConfig,
}
remoteCluster, gerr := etcdserver.GetClusterFromRemotePeers([]string{u}, trp)
remoteCluster, gerr := etcdserver.GetClusterFromRemotePeers(nil, []string{u}, trp)
trp.CloseIdleConnections()
if gerr != nil {
// Do not return error, because other members may be not ready.
Expand Down
2 changes: 2 additions & 0 deletions pkg/etcdutil/etcdutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func newTestSingleConfig() *embed.Config {
cfg.Name = "test_etcd"
cfg.Dir, _ = ioutil.TempDir("/tmp", "test_etcd")
cfg.WalDir = ""
cfg.Logger = "zap"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we use zap in production?

Copy link
Contributor Author

@nolouch nolouch Jun 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

etcd plan to use zap replace the capnslog logging. and we only enable it in the test.

cfg.LogOutputs = []string{"stdout"}

pu, _ := url.Parse(tempurl.Alloc())
cfg.LPUrls = []url.URL{*pu}
Expand Down
1 change: 1 addition & 0 deletions server/api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var (
)

func TestAPIServer(t *testing.T) {
server.EnableZap = true
TestingT(t)
}

Expand Down
8 changes: 4 additions & 4 deletions server/api/store_ns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ func (s *testStoreNsSuite) SetUpSuite(c *C) {

cfg := server.NewTestSingleConfig()
cfg.NamespaceClassifier = "table"
srv, err := server.CreateServer(cfg, NewHandler)
svr, err := server.CreateServer(cfg, NewHandler)
c.Assert(err, IsNil)
c.Assert(srv.Run(), IsNil)
s.svr = srv
c.Assert(svr.Run(), IsNil)
s.svr = svr
s.cleanup = func() {
srv.Close()
svr.Close()
cleanServer(cfg)
}

Expand Down
21 changes: 19 additions & 2 deletions server/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ package server

import (
"fmt"
"os"
"path"
"strings"

"github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/embed"
"github.com/coreos/etcd/wal"
"github.com/juju/errors"
"github.com/pingcap/pd/pkg/etcdutil"
log "github.com/sirupsen/logrus"
)

// PrepareJoinCluster sends MemberAdd command to PD cluster,
Expand Down Expand Up @@ -74,7 +75,7 @@ func PrepareJoinCluster(cfg *Config) error {

// Cases with data directory.
initialCluster := ""
if wal.Exist(path.Join(cfg.DataDir, "member")) {
if isDataExist(path.Join(cfg.DataDir, "member")) {
cfg.InitialCluster = initialCluster
cfg.InitialClusterState = embed.ClusterStateFlagExisting
return nil
Expand Down Expand Up @@ -139,3 +140,19 @@ func PrepareJoinCluster(cfg *Config) error {
cfg.InitialClusterState = embed.ClusterStateFlagExisting
return nil
}

func isDataExist(d string) bool {
dir, err := os.Open(d)
if err != nil {
log.Error("failed to open:", err)
return false
}
defer dir.Close()

names, err := dir.Readdirnames(-1)
if err != nil {
log.Error("failed to list:", err)
return false
}
return len(names) != 0
}
8 changes: 3 additions & 5 deletions server/leader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ type testGetLeaderSuite struct {
func (s *testGetLeaderSuite) SetUpSuite(c *C) {
cfg := NewTestSingleConfig()

// Send requests before server has started.
s.wg.Add(1)
s.done = make(chan bool)
go s.sendRequest(c, cfg.ClientUrls)
time.Sleep(100 * time.Millisecond)

svr, err := CreateServer(cfg, nil)
c.Assert(err, IsNil)

err = svr.Run()
// Send requests after server has started.
go s.sendRequest(c, cfg.ClientUrls)
time.Sleep(100 * time.Millisecond)
c.Assert(err, IsNil)

s.svr = svr
Expand Down
11 changes: 10 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ const (
pdClusterIDPath = "/pd/cluster_id"
)

// EnableZap enable the zap logger in embed etcd.
var EnableZap = false

// Server is the pd server.
type Server struct {
// Server state.
Expand Down Expand Up @@ -114,7 +117,13 @@ func CreateServer(cfg *Config, apiRegister func(*Server) http.Handler) (*Server,
}
etcdCfg.ServiceRegister = func(gs *grpc.Server) { pdpb.RegisterPDServer(gs, s) }
s.etcdCfg = etcdCfg

if EnableZap {
// The etcd master version has removed embed.Config.SetupLogging.
// Now logger is set up automatically based on embed.Config.Logger, embed.Config.LogOutputs, embed.Config.Debug fields.
// Use zap logger in the test, otherwise will panic. Reference: https://github.com/coreos/etcd/blob/master/embed/config_logging.go#L45
s.etcdCfg.Logger = "zap"
s.etcdCfg.LogOutputs = []string{"stdout"}
}
return s, nil
}

Expand Down
1 change: 1 addition & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
)

func TestServer(t *testing.T) {
EnableZap = true
TestingT(t)
}

Expand Down
14 changes: 0 additions & 14 deletions vendor/github.com/BurntSushi/toml/COPYING

This file was deleted.

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions vendor/github.com/BurntSushi/toml/cmd/tomlv/COPYING

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions vendor/github.com/coreos/etcd/NOTICE

This file was deleted.

Loading