mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #2595 from yichengq/revert-upgrade-related
Revert upgrade related commits
This commit is contained in:
commit
e1df265dc5
@ -44,7 +44,6 @@ The full documentation is contained in the [API docs](https://github.com/coreos/
|
||||
* `-cors` - A comma separated white list of origins for cross-origin resource sharing.
|
||||
* `-cpuprofile` - The path to a file to output CPU profile data. Enables CPU profiling when present.
|
||||
* `-data-dir` - The directory to store log and snapshot. Defaults to the current working directory.
|
||||
* `-internal-binary-dir` - The path to the etcd internal binary directory. Defaults to `/usr/libexec/etcd/internal_versions/`.
|
||||
* `-max-result-buffer` - The max size of result buffer. Defaults to `1024`.
|
||||
* `-max-retry-attempts` - The max retry attempts when trying to join a cluster. Defaults to `3`.
|
||||
* `-peer-addr` - The advertised public hostname:port for server communication. Defaults to `127.0.0.1:7001`.
|
||||
@ -116,7 +115,6 @@ sync_interval = 5.0
|
||||
* `ETCD_CLUSTER_HTTP_READ_TIMEOUT`
|
||||
* `ETCD_CLUSTER_HTTP_WRITE_TIMEOUT`
|
||||
* `ETCD_KEY_FILE`
|
||||
* `ETCD_INTERNAL_BINARY_DIR`
|
||||
* `ETCD_PEERS`
|
||||
* `ETCD_PEERS_FILE`
|
||||
* `ETCD_MAX_CLUSTER_SIZE`
|
||||
|
@ -24,9 +24,6 @@ import (
|
||||
// The default location for the etcd configuration file.
|
||||
const DefaultSystemConfigPath = "/etc/etcd/etcd.conf"
|
||||
|
||||
// The default location of the etcd internal binary directory.
|
||||
const DefaultInternalBinaryDir = "/usr/libexec/etcd/internal_versions/"
|
||||
|
||||
// A lookup of deprecated flags to their new flag name.
|
||||
var newFlagNameLookup = map[string]string{
|
||||
"C": "peers",
|
||||
@ -55,33 +52,32 @@ var newFlagNameLookup = map[string]string{
|
||||
type Config struct {
|
||||
SystemPath string
|
||||
|
||||
Addr string `toml:"addr" env:"ETCD_ADDR"`
|
||||
BindAddr string `toml:"bind_addr" env:"ETCD_BIND_ADDR"`
|
||||
CAFile string `toml:"ca_file" env:"ETCD_CA_FILE"`
|
||||
CertFile string `toml:"cert_file" env:"ETCD_CERT_FILE"`
|
||||
CPUProfileFile string
|
||||
CorsOrigins []string `toml:"cors" env:"ETCD_CORS"`
|
||||
DataDir string `toml:"data_dir" env:"ETCD_DATA_DIR"`
|
||||
Discovery string `toml:"discovery" env:"ETCD_DISCOVERY"`
|
||||
Force bool
|
||||
KeyFile string `toml:"key_file" env:"ETCD_KEY_FILE"`
|
||||
HTTPReadTimeout float64 `toml:"http_read_timeout" env:"ETCD_HTTP_READ_TIMEOUT"`
|
||||
HTTPWriteTimeout float64 `toml:"http_write_timeout" env:"ETCD_HTTP_WRITE_TIMEOUT"`
|
||||
InternalBinaryDir string `toml:"internal_binary_dir" env:"ETCD_INTERNAL_BINARY_DIR"`
|
||||
Peers []string `toml:"peers" env:"ETCD_PEERS"`
|
||||
PeersFile string `toml:"peers_file" env:"ETCD_PEERS_FILE"`
|
||||
MaxResultBuffer int `toml:"max_result_buffer" env:"ETCD_MAX_RESULT_BUFFER"`
|
||||
MaxRetryAttempts int `toml:"max_retry_attempts" env:"ETCD_MAX_RETRY_ATTEMPTS"`
|
||||
RetryInterval float64 `toml:"retry_interval" env:"ETCD_RETRY_INTERVAL"`
|
||||
Name string `toml:"name" env:"ETCD_NAME"`
|
||||
Snapshot bool `toml:"snapshot" env:"ETCD_SNAPSHOT"`
|
||||
SnapshotCount int `toml:"snapshot_count" env:"ETCD_SNAPSHOTCOUNT"`
|
||||
ShowHelp bool
|
||||
ShowVersion bool
|
||||
Verbose bool `toml:"verbose" env:"ETCD_VERBOSE"`
|
||||
VeryVerbose bool `toml:"very_verbose" env:"ETCD_VERY_VERBOSE"`
|
||||
VeryVeryVerbose bool `toml:"very_very_verbose" env:"ETCD_VERY_VERY_VERBOSE"`
|
||||
Peer struct {
|
||||
Addr string `toml:"addr" env:"ETCD_ADDR"`
|
||||
BindAddr string `toml:"bind_addr" env:"ETCD_BIND_ADDR"`
|
||||
CAFile string `toml:"ca_file" env:"ETCD_CA_FILE"`
|
||||
CertFile string `toml:"cert_file" env:"ETCD_CERT_FILE"`
|
||||
CPUProfileFile string
|
||||
CorsOrigins []string `toml:"cors" env:"ETCD_CORS"`
|
||||
DataDir string `toml:"data_dir" env:"ETCD_DATA_DIR"`
|
||||
Discovery string `toml:"discovery" env:"ETCD_DISCOVERY"`
|
||||
Force bool
|
||||
KeyFile string `toml:"key_file" env:"ETCD_KEY_FILE"`
|
||||
HTTPReadTimeout float64 `toml:"http_read_timeout" env:"ETCD_HTTP_READ_TIMEOUT"`
|
||||
HTTPWriteTimeout float64 `toml:"http_write_timeout" env:"ETCD_HTTP_WRITE_TIMEOUT"`
|
||||
Peers []string `toml:"peers" env:"ETCD_PEERS"`
|
||||
PeersFile string `toml:"peers_file" env:"ETCD_PEERS_FILE"`
|
||||
MaxResultBuffer int `toml:"max_result_buffer" env:"ETCD_MAX_RESULT_BUFFER"`
|
||||
MaxRetryAttempts int `toml:"max_retry_attempts" env:"ETCD_MAX_RETRY_ATTEMPTS"`
|
||||
RetryInterval float64 `toml:"retry_interval" env:"ETCD_RETRY_INTERVAL"`
|
||||
Name string `toml:"name" env:"ETCD_NAME"`
|
||||
Snapshot bool `toml:"snapshot" env:"ETCD_SNAPSHOT"`
|
||||
SnapshotCount int `toml:"snapshot_count" env:"ETCD_SNAPSHOTCOUNT"`
|
||||
ShowHelp bool
|
||||
ShowVersion bool
|
||||
Verbose bool `toml:"verbose" env:"ETCD_VERBOSE"`
|
||||
VeryVerbose bool `toml:"very_verbose" env:"ETCD_VERY_VERBOSE"`
|
||||
VeryVeryVerbose bool `toml:"very_very_verbose" env:"ETCD_VERY_VERY_VERBOSE"`
|
||||
Peer struct {
|
||||
Addr string `toml:"addr" env:"ETCD_PEER_ADDR"`
|
||||
BindAddr string `toml:"bind_addr" env:"ETCD_PEER_BIND_ADDR"`
|
||||
CAFile string `toml:"ca_file" env:"ETCD_PEER_CA_FILE"`
|
||||
@ -120,7 +116,6 @@ func New() *Config {
|
||||
c.Cluster.ActiveSize = server.DefaultActiveSize
|
||||
c.Cluster.RemoveDelay = server.DefaultRemoveDelay
|
||||
c.Cluster.SyncInterval = server.DefaultSyncInterval
|
||||
c.InternalBinaryDir = DefaultInternalBinaryDir
|
||||
return c
|
||||
}
|
||||
|
||||
@ -268,7 +263,6 @@ func (c *Config) LoadFlags(arguments []string) error {
|
||||
f.Float64Var(&c.HTTPWriteTimeout, "http-write-timeout", c.HTTPReadTimeout, "")
|
||||
|
||||
f.StringVar(&c.DataDir, "data-dir", c.DataDir, "")
|
||||
f.StringVar(&c.InternalBinaryDir, "internal-binary-dir", c.InternalBinaryDir, "")
|
||||
f.IntVar(&c.MaxResultBuffer, "max-result-buffer", c.MaxResultBuffer, "")
|
||||
f.IntVar(&c.MaxRetryAttempts, "max-retry-attempts", c.MaxRetryAttempts, "")
|
||||
f.Float64Var(&c.RetryInterval, "retry-interval", c.RetryInterval, "")
|
||||
|
@ -19,7 +19,6 @@ func TestConfigTOML(t *testing.T) {
|
||||
cpu_profile_file = "XXX"
|
||||
data_dir = "/tmp/data"
|
||||
discovery = "http://example.com/foobar"
|
||||
internal_binary_dir = "/tmp/etcd/internal_versions"
|
||||
key_file = "/tmp/file.key"
|
||||
bind_addr = "127.0.0.1:4003"
|
||||
peers = ["coreos.com:4001", "coreos.com:4002"]
|
||||
@ -55,7 +54,6 @@ func TestConfigTOML(t *testing.T) {
|
||||
assert.Equal(t, c.CorsOrigins, []string{"*"}, "")
|
||||
assert.Equal(t, c.DataDir, "/tmp/data", "")
|
||||
assert.Equal(t, c.Discovery, "http://example.com/foobar", "")
|
||||
assert.Equal(t, c.InternalBinaryDir, "/tmp/etcd/internal_versions", "")
|
||||
assert.Equal(t, c.HTTPReadTimeout, 2.34, "")
|
||||
assert.Equal(t, c.HTTPWriteTimeout, 1.23, "")
|
||||
assert.Equal(t, c.KeyFile, "/tmp/file.key", "")
|
||||
@ -88,7 +86,6 @@ func TestConfigEnv(t *testing.T) {
|
||||
os.Setenv("ETCD_DISCOVERY", "http://example.com/foobar")
|
||||
os.Setenv("ETCD_HTTP_READ_TIMEOUT", "2.34")
|
||||
os.Setenv("ETCD_HTTP_WRITE_TIMEOUT", "1.23")
|
||||
os.Setenv("ETCD_INTERNAL_BINARY_DIR", "/tmp/etcd/internal_versions")
|
||||
os.Setenv("ETCD_KEY_FILE", "/tmp/file.key")
|
||||
os.Setenv("ETCD_BIND_ADDR", "127.0.0.1:4003")
|
||||
os.Setenv("ETCD_PEERS", "coreos.com:4001,coreos.com:4002")
|
||||
@ -118,7 +115,6 @@ func TestConfigEnv(t *testing.T) {
|
||||
assert.Equal(t, c.Discovery, "http://example.com/foobar", "")
|
||||
assert.Equal(t, c.HTTPReadTimeout, 2.34, "")
|
||||
assert.Equal(t, c.HTTPWriteTimeout, 1.23, "")
|
||||
assert.Equal(t, c.InternalBinaryDir, "/tmp/etcd/internal_versions", "")
|
||||
assert.Equal(t, c.KeyFile, "/tmp/file.key", "")
|
||||
assert.Equal(t, c.BindAddr, "127.0.0.1:4003", "")
|
||||
assert.Equal(t, c.Peers, []string{"coreos.com:4001", "coreos.com:4002"}, "")
|
||||
|
@ -309,7 +309,6 @@ func (e *Etcd) runServer() {
|
||||
for {
|
||||
if e.mode == PeerMode {
|
||||
log.Infof("%v starting in peer mode", e.Config.Name)
|
||||
go registerAvailableInternalVersions(e.Config.InternalBinaryDir, e.Config.Name, e.Config.Addr, e.Config.EtcdTLSInfo())
|
||||
// Starting peer server should be followed close by listening on its port
|
||||
// If not, it may leave many requests unaccepted, or cannot receive heartbeat from the cluster.
|
||||
// One severe problem caused if failing receiving heartbeats is when the second node joins one-node cluster,
|
||||
|
@ -1,48 +0,0 @@
|
||||
package etcd
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/etcd/log"
|
||||
"github.com/coreos/etcd/server"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
|
||||
)
|
||||
|
||||
func registerAvailableInternalVersions(internalBinaryDir, name, addr string, tls *server.TLSInfo) {
|
||||
var c *etcd.Client
|
||||
if tls.Scheme() == "http" {
|
||||
c = etcd.NewClient([]string{addr})
|
||||
} else {
|
||||
var err error
|
||||
c, err = etcd.NewTLSClient([]string{addr}, tls.CertFile, tls.KeyFile, tls.CAFile)
|
||||
if err != nil {
|
||||
log.Fatalf("client TLS error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
vers, err := getInternalVersions(internalBinaryDir)
|
||||
if err != nil {
|
||||
log.Infof("failed to get local etcd versions: %v", err)
|
||||
return
|
||||
}
|
||||
for _, v := range vers {
|
||||
for {
|
||||
_, err := c.Set("/_etcd/available-internal-versions/"+v+"/"+name, "ok", 0)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}
|
||||
log.Infof("%s: available_internal_versions %s is registered into key space successfully.", name, vers)
|
||||
}
|
||||
|
||||
func getInternalVersions(internalBinaryDir string) ([]string, error) {
|
||||
dir, err := os.Open(internalBinaryDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer dir.Close()
|
||||
return dir.Readdirnames(-1)
|
||||
}
|
@ -6,7 +6,6 @@ import (
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -293,7 +292,6 @@ func (s *PeerServer) Start(snapshot bool, clusterConfig *ClusterConfig) error {
|
||||
s.startRoutine(s.monitorTimeoutThreshold)
|
||||
s.startRoutine(s.monitorActiveSize)
|
||||
s.startRoutine(s.monitorPeerActivity)
|
||||
s.startRoutine(s.monitorVersion)
|
||||
|
||||
// open the snapshot
|
||||
if snapshot {
|
||||
@ -372,7 +370,6 @@ func (s *PeerServer) HTTPHandler() http.Handler {
|
||||
router.HandleFunc("/v2/admin/machines", s.getMachinesHttpHandler).Methods("GET")
|
||||
router.HandleFunc("/v2/admin/machines/{name}", s.getMachineHttpHandler).Methods("GET")
|
||||
router.HandleFunc("/v2/admin/machines/{name}", s.RemoveHttpHandler).Methods("DELETE")
|
||||
router.HandleFunc("/v2/admin/next-internal-version", s.NextInternalVersionHandler).Methods("GET")
|
||||
|
||||
return router
|
||||
}
|
||||
@ -898,30 +895,3 @@ func (s *PeerServer) monitorPeerActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PeerServer) monitorVersion() {
|
||||
for {
|
||||
select {
|
||||
case <-s.closeChan:
|
||||
return
|
||||
case <-time.After(time.Second):
|
||||
}
|
||||
|
||||
resp, err := s.store.Get("/_etcd/next-internal-version", false, false)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
// only support upgrading to etcd2
|
||||
if *resp.Node.Value == "2" {
|
||||
log.Infof("%s: detected next internal version 2, exit after 10 seconds.", s.Config.Name)
|
||||
} else {
|
||||
log.Infof("%s: detected invaild next internal version %s", s.Config.Name, *resp.Node.Value)
|
||||
continue
|
||||
}
|
||||
time.Sleep(10 * time.Second)
|
||||
// be nice to raft. try not to corrupt log file.
|
||||
go s.raftServer.Stop()
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package server
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"path"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@ -310,48 +309,6 @@ func (ps *PeerServer) UpgradeHttpHandler(w http.ResponseWriter, req *http.Reques
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func (ps *PeerServer) NextInternalVersionHandler(w http.ResponseWriter, req *http.Request) {
|
||||
for i := 0; i < 50; i++ {
|
||||
if ps.raftServer.State() != raft.Leader {
|
||||
l := ps.raftServer.Leader()
|
||||
if l == "" {
|
||||
time.Sleep(5 * time.Second)
|
||||
continue
|
||||
}
|
||||
url, _ := ps.registry.PeerURL(l)
|
||||
uhttp.Redirect(url, w, req)
|
||||
return
|
||||
}
|
||||
resp, err := ps.store.Get("/_etcd/available-internal-versions/2", true, true)
|
||||
if err != nil {
|
||||
time.Sleep(5 * time.Second)
|
||||
continue
|
||||
}
|
||||
available := make(map[string]bool)
|
||||
for _, n := range resp.Node.Nodes {
|
||||
available[path.Base(n.Key)] = true
|
||||
}
|
||||
|
||||
notfound := false
|
||||
for _, n := range ps.registry.Names() {
|
||||
if !available[n] {
|
||||
notfound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if notfound {
|
||||
time.Sleep(5 * time.Second)
|
||||
continue
|
||||
}
|
||||
c := ps.store.CommandFactory().CreateSetCommand("/_etcd/next-internal-version", false, "2", store.Permanent)
|
||||
_, err = ps.raftServer.Do(c)
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
}
|
||||
|
||||
// machineMessage represents information about a peer or standby in the registry.
|
||||
type machineMessage struct {
|
||||
Name string `json:"name"`
|
||||
|
3
server/release_version.go
Normal file
3
server/release_version.go
Normal file
@ -0,0 +1,3 @@
|
||||
package server
|
||||
|
||||
const ReleaseVersion = "0.4.8+git"
|
@ -285,7 +285,7 @@ func (s *Server) Dispatch(c raft.Command, w http.ResponseWriter, req *http.Reque
|
||||
// Handler to return the current version of etcd.
|
||||
func (s *Server) GetVersionHandler(w http.ResponseWriter, req *http.Request) error {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(w, `{"releaseVersion":"%s","internalVersion":"%s"}`, ReleaseVersion, InternalVersion)
|
||||
fmt.Fprintf(w, "etcd %s", ReleaseVersion)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -187,14 +187,6 @@ func (s *StandbyServer) monitorCluster() {
|
||||
case <-ticker.C:
|
||||
}
|
||||
|
||||
ok, err := s.checkMemberInternalVersionIsV2()
|
||||
if err != nil {
|
||||
log.Warnf("fail checking internal version(%v): %v", s.ClusterURLs(), err)
|
||||
} else if ok {
|
||||
log.Infof("Detect the cluster has been upgraded to v2. Exit now.")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if err := s.syncCluster(nil); err != nil {
|
||||
log.Warnf("fail syncing cluster(%v): %v", s.ClusterURLs(), err)
|
||||
continue
|
||||
@ -224,39 +216,6 @@ func (s *StandbyServer) monitorCluster() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *StandbyServer) checkMemberInternalVersionIsV2() (bool, error) {
|
||||
c := &http.Client{Transport: s.client.Client.Transport}
|
||||
for _, memb := range s.Cluster {
|
||||
url := memb.ClientURL
|
||||
resp, err := c.Get(url + "/version")
|
||||
if err != nil {
|
||||
log.Debugf("failed to get /version from %s", url)
|
||||
continue
|
||||
}
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Debugf("failed to read body from %s", url)
|
||||
continue
|
||||
}
|
||||
|
||||
var m map[string]string
|
||||
err = json.Unmarshal(b, &m)
|
||||
if err != nil {
|
||||
log.Debugf("failed to unmarshal body %s from %s", b, url)
|
||||
continue
|
||||
}
|
||||
switch m["internalVersion"] {
|
||||
case "1":
|
||||
return false, nil
|
||||
case "2":
|
||||
return true, nil
|
||||
default:
|
||||
log.Warnf("unrecognized internal version %s from %s", m["internalVersion"], url)
|
||||
}
|
||||
}
|
||||
return false, fmt.Errorf("failed to get version")
|
||||
}
|
||||
|
||||
func (s *StandbyServer) syncCluster(peerURLs []string) error {
|
||||
peerURLs = append(s.ClusterURLs(), peerURLs...)
|
||||
|
||||
|
@ -15,16 +15,15 @@ Usage:
|
||||
etcd -version
|
||||
|
||||
Options:
|
||||
-h -help Show this screen.
|
||||
--version Show version.
|
||||
-f -force Force a new configuration to be used.
|
||||
-config=<path> Path to configuration file.
|
||||
-name=<name> Name of this node in the etcd cluster.
|
||||
-data-dir=<path> Path to the data directory.
|
||||
-internal-binary-dir=<path> Path to the etcd internal binary directory.
|
||||
-cors=<origins> Comma-separated list of CORS origins.
|
||||
-v Enabled verbose logging.
|
||||
-vv Enabled very verbose logging.
|
||||
-h -help Show this screen.
|
||||
--version Show version.
|
||||
-f -force Force a new configuration to be used.
|
||||
-config=<path> Path to configuration file.
|
||||
-name=<name> Name of this node in the etcd cluster.
|
||||
-data-dir=<path> Path to the data directory.
|
||||
-cors=<origins> Comma-separated list of CORS origins.
|
||||
-v Enabled verbose logging.
|
||||
-vv Enabled very verbose logging.
|
||||
|
||||
Cluster Configuration Options:
|
||||
-discovery=<url> Discovery service used to find a peer list.
|
||||
|
@ -1,5 +1,3 @@
|
||||
package server
|
||||
|
||||
const ReleaseVersion = "0.4.8+git"
|
||||
const InternalVersion = "1"
|
||||
const Version = "v2"
|
||||
|
Loading…
x
Reference in New Issue
Block a user