diff --git a/go.mod b/go.mod index 2ed6326d0..3ec9f41fe 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,9 @@ require ( github.com/soheilhy/cmux v0.1.5 github.com/stretchr/testify v1.9.0 github.com/urfave/cli/v2 v2.27.1 - go.etcd.io/etcd v0.5.0-alpha.5.0.20230414071934-94593e63d45c + go.etcd.io/etcd/client/pkg/v3 v3.5.12 + go.etcd.io/etcd/raft/v3 v3.5.12 + go.etcd.io/etcd/server/v3 v3.5.12 go.opentelemetry.io/contrib/instrumentation/host v0.49.0 go.opentelemetry.io/contrib/instrumentation/runtime v0.49.0 go.opentelemetry.io/otel v1.24.0 @@ -53,9 +55,7 @@ require ( github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect - github.com/coreos/go-semver v0.2.0 // indirect - github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7 // indirect - github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf // indirect + github.com/coreos/go-semver v0.3.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dustin/go-humanize v1.0.0 // indirect @@ -104,6 +104,8 @@ require ( github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect github.com/yusufpapurcu/wmi v1.2.3 // indirect + go.etcd.io/etcd/api/v3 v3.5.12 // indirect + go.etcd.io/etcd/pkg/v3 v3.5.12 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect go.opentelemetry.io/proto/otlp v1.1.0 // indirect golang.org/x/mod v0.15.0 // indirect diff --git a/go.sum b/go.sum index ebaccc136..35cfba6db 100644 --- a/go.sum +++ b/go.sum @@ -68,12 +68,8 @@ github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwP github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ= -github.com/coreos/go-semver v0.2.0 h1:3Jm3tLmsgAYcjC+4Up7hJrFBPr+n7rAqYeSw/SZazuY= -github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7 h1:u9SHYsPQNyt5tgDm3YN7+9dYrpK96E5wFilTFWIDZOM= -github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf h1:CAKfRE2YtTUIjjh1bkBtyYFaUT/WmOqsJjgtihT0vMI= -github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= @@ -352,8 +348,16 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= -go.etcd.io/etcd v0.5.0-alpha.5.0.20230414071934-94593e63d45c h1:xYeZLnj1ySxkOQdrbQXM4AFqljQ7KmiXWejLs9dqhAA= -go.etcd.io/etcd v0.5.0-alpha.5.0.20230414071934-94593e63d45c/go.mod h1:LqihLF/IXb/G+G+NO6ckb61fypTb6GX99mPSztt+lkU= +go.etcd.io/etcd/api/v3 v3.5.12 h1:W4sw5ZoU2Juc9gBWuLk5U6fHfNVyY1WC5g9uiXZio/c= +go.etcd.io/etcd/api/v3 v3.5.12/go.mod h1:Ot+o0SWSyT6uHhA56al1oCED0JImsRiU9Dc26+C2a+4= +go.etcd.io/etcd/client/pkg/v3 v3.5.12 h1:EYDL6pWwyOsylrQyLp2w+HkQ46ATiOvoEdMarindU2A= +go.etcd.io/etcd/client/pkg/v3 v3.5.12/go.mod h1:seTzl2d9APP8R5Y2hFL3NVlD6qC/dOT+3kvrqPyTas4= +go.etcd.io/etcd/pkg/v3 v3.5.12 h1:OK2fZKI5hX/+BTK76gXSTyZMrbnARyX9S643GenNGb8= +go.etcd.io/etcd/pkg/v3 v3.5.12/go.mod h1:UVwg/QIMoJncyeb/YxvJBJCE/NEwtHWashqc8A1nj/M= +go.etcd.io/etcd/raft/v3 v3.5.12 h1:7r22RufdDsq2z3STjoR7Msz6fYH8tmbkdheGfwJNRmU= +go.etcd.io/etcd/raft/v3 v3.5.12/go.mod h1:ERQuZVe79PI6vcC3DlKBukDCLja/L7YMu29B74Iwj4U= +go.etcd.io/etcd/server/v3 v3.5.12 h1:EtMjsbfyfkwZuA2JlKOiBfuGkFCekv5H178qjXypbG8= +go.etcd.io/etcd/server/v3 v3.5.12/go.mod h1:axB0oCjMy+cemo5290/CutIjoxlfA6KVYKD1w0uue10= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= diff --git a/internal/metarepos/raft.go b/internal/metarepos/raft.go index ee937e32b..6a29ae62d 100644 --- a/internal/metarepos/raft.go +++ b/internal/metarepos/raft.go @@ -12,15 +12,15 @@ import ( "sync/atomic" "time" - "go.etcd.io/etcd/etcdserver/api/rafthttp" - "go.etcd.io/etcd/etcdserver/api/snap" - stats "go.etcd.io/etcd/etcdserver/api/v2stats" - "go.etcd.io/etcd/pkg/fileutil" - "go.etcd.io/etcd/pkg/types" - "go.etcd.io/etcd/raft" - "go.etcd.io/etcd/raft/raftpb" - "go.etcd.io/etcd/wal" - "go.etcd.io/etcd/wal/walpb" + "go.etcd.io/etcd/client/pkg/v3/fileutil" + "go.etcd.io/etcd/client/pkg/v3/types" + "go.etcd.io/etcd/raft/v3" + "go.etcd.io/etcd/raft/v3/raftpb" + "go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp" + "go.etcd.io/etcd/server/v3/etcdserver/api/snap" + stats "go.etcd.io/etcd/server/v3/etcdserver/api/v2stats" + "go.etcd.io/etcd/server/v3/wal" + "go.etcd.io/etcd/server/v3/wal/walpb" "go.uber.org/zap" vtypes "github.com/kakao/varlog/pkg/types" @@ -101,7 +101,8 @@ func newRaftNode(cfg raftConfig, proposeC chan []byte, confChangeC chan raftpb.ConfChange, tmStub *telemetryStub, - logger *zap.Logger) *raftNode { + logger *zap.Logger, +) *raftNode { commitC := make(chan *raftCommittedEntry) snapshotC := make(chan struct{}) @@ -130,8 +131,9 @@ func (rc *raftNode) saveSnap(snap raftpb.Snapshot) error { // wal at previously-saved snapshot indexes. _, err := rc.withTelemetry(context.TODO(), "save_snap", func(ctx context.Context) (interface{}, error) { walSnap := walpb.Snapshot{ - Index: snap.Metadata.Index, - Term: snap.Metadata.Term, + Index: snap.Metadata.Index, + Term: snap.Metadata.Term, + ConfState: &snap.Metadata.ConfState, } if err := rc.wal.SaveSnapshot(walSnap); err != nil { @@ -243,7 +245,7 @@ func (rc *raftNode) publishEntries(ctx context.Context, ents []raftpb.Entry) boo } if shutdown { - //TODO:: shutdown mr + // TODO:: shutdown mr return false } @@ -344,7 +346,7 @@ func (rc *raftNode) replayWAL(snapshot *raftpb.Snapshot) *wal.WAL { } rc.raftStorage.SetHardState(st) //nolint:errcheck,revive // TODO:: Handle an error returned. - //TODO:: WAL replay to state machine + // TODO:: WAL replay to state machine // append to storage so raft starts at the right place in log rc.raftStorage.Append(ents) //nolint:errcheck,revive // TODO:: Handle an error returned. @@ -359,7 +361,7 @@ func (rc *raftNode) replayWAL(snapshot *raftpb.Snapshot) *wal.WAL { zap.Uint64("lastIndex", rc.lastIndex), ) - //TODO:: check necessary whether send signal replay WAL complete + // TODO:: check necessary whether send signal replay WAL complete return w } @@ -428,7 +430,7 @@ func (rc *raftNode) start() { Raft: rc, Snapshotter: rc.snapshotter, ServerStats: stats.NewServerStats("", ""), - LeaderStats: stats.NewLeaderStats(strconv.FormatUint(uint64(rc.nodeID), 10)), + LeaderStats: stats.NewLeaderStats(rc.logger, strconv.FormatUint(uint64(rc.nodeID), 10)), ErrorC: make(chan error), } @@ -591,7 +593,7 @@ func (rc *raftNode) processMessages(ms []raftpb.Message) []raftpb.Message { zap.Int("size", snapshot.Size()), ) - //TODO:: concurrency limit + // TODO:: concurrency limit rc.runner.Run(func(context.Context) { //nolint:errcheck,revive // TODO:: Handle an error returned. rc.transport.SendSnapshot(*sm) }) diff --git a/internal/metarepos/raft_metadata_repository.go b/internal/metarepos/raft_metadata_repository.go index e60ef876f..035414a71 100644 --- a/internal/metarepos/raft_metadata_repository.go +++ b/internal/metarepos/raft_metadata_repository.go @@ -13,9 +13,9 @@ import ( "time" "github.com/gogo/status" - "go.etcd.io/etcd/pkg/fileutil" - "go.etcd.io/etcd/raft" - "go.etcd.io/etcd/raft/raftpb" + "go.etcd.io/etcd/client/pkg/v3/fileutil" + "go.etcd.io/etcd/raft/v3" + "go.etcd.io/etcd/raft/v3/raftpb" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -207,10 +207,10 @@ func (mr *RaftMetadataRepository) Run() { mr.healthServer.SetServingStatus("", grpc_health_v1.HealthCheckResponse_SERVING) - //TODO:: graceful shutdown + // TODO:: graceful shutdown if err := mr.server.Serve(lis); err != nil && err != verrors.ErrStopped { mr.logger.Panic("could not serve", zap.Error(err)) - //r.Close() + // r.Close() } }); err != nil { mr.logger.Panic("could not run", zap.Error(err)) @@ -219,7 +219,8 @@ func (mr *RaftMetadataRepository) Run() { func (mr *RaftMetadataRepository) runDebugServer(ctx context.Context) { httpMux := http.NewServeMux() - mr.debugServer = &http.Server{Addr: mr.debugAddr, Handler: httpMux, + mr.debugServer = &http.Server{ + Addr: mr.debugAddr, Handler: httpMux, ReadTimeout: 5 * time.Second, WriteTimeout: 5 * time.Second, IdleTimeout: 30 * time.Second, @@ -854,7 +855,7 @@ func (mr *RaftMetadataRepository) applyCommit(r *mrpb.Commit, appliedIndex uint6 committedOffset := types.InvalidGLSN - //TODO:: apply topic + // TODO:: apply topic for idx, topicLSID := range topicLSIDs { beginTopic, endTopic := topicBoundary(topicLSIDs, idx) @@ -967,7 +968,7 @@ func (mr *RaftMetadataRepository) applyCommit(r *mrpb.Commit, appliedIndex uint6 mr.reportCollector.Commit() - //TODO:: trigger next commit + // TODO:: trigger next commit return nil, nil }) @@ -1054,11 +1055,11 @@ func (mr *RaftMetadataRepository) numCommitSince(topicID types.TopicID, lsID typ } func (mr *RaftMetadataRepository) calculateCommit(reports *mrpb.LogStreamUncommitReports) (types.Version, types.Version, types.GLSN, uint64) { - var trimVer = types.MaxVersion - var knownVer = types.InvalidVersion - var beginLLSN = types.InvalidLLSN - var endLLSN = types.InvalidLLSN - var highWatermark = types.InvalidGLSN + trimVer := types.MaxVersion + knownVer := types.InvalidVersion + beginLLSN := types.InvalidLLSN + endLLSN := types.InvalidLLSN + highWatermark := types.InvalidGLSN if reports == nil { return types.InvalidVersion, types.InvalidVersion, types.InvalidGLSN, 0 diff --git a/internal/metarepos/raft_metadata_repository_test.go b/internal/metarepos/raft_metadata_repository_test.go index 276217b0d..e334ad77a 100644 --- a/internal/metarepos/raft_metadata_repository_test.go +++ b/internal/metarepos/raft_metadata_repository_test.go @@ -11,7 +11,7 @@ import ( "github.com/pkg/errors" . "github.com/smartystreets/goconvey/convey" - "go.etcd.io/etcd/raft/raftpb" + "go.etcd.io/etcd/raft/v3/raftpb" "go.uber.org/goleak" "go.uber.org/multierr" "go.uber.org/zap" @@ -2504,7 +2504,7 @@ func TestMRProposeRetry(t *testing.T) { Convey("Then it should be success", func(ctx C) { So(err, ShouldBeNil) - //So(atomic.LoadUint64(&clus.nodes[leader].requestNum), ShouldBeGreaterThan, 1) + // So(atomic.LoadUint64(&clus.nodes[leader].requestNum), ShouldBeGreaterThan, 1) }) }) }) @@ -2921,7 +2921,6 @@ func TestMRTopicLastHighWatermark(t *testing.T) { } } }) - }) } @@ -3060,7 +3059,6 @@ func TestMRCatchupUnsealedLogstream(t *testing.T) { }), ShouldBeTrue) }) }) - }) } diff --git a/internal/metarepos/raft_test.go b/internal/metarepos/raft_test.go index 993cc1a59..07b1d4f20 100644 --- a/internal/metarepos/raft_test.go +++ b/internal/metarepos/raft_test.go @@ -9,7 +9,7 @@ import ( "testing" . "github.com/smartystreets/goconvey/convey" - "go.etcd.io/etcd/raft/raftpb" + "go.etcd.io/etcd/raft/v3/raftpb" "go.uber.org/multierr" "go.uber.org/zap" @@ -19,8 +19,10 @@ import ( "github.com/kakao/varlog/vtesting" ) -type stopFunc func(bool) -type leaderFunc func() uint64 +type ( + stopFunc func(bool) + leaderFunc func() uint64 +) type cluster struct { peers []string @@ -68,7 +70,7 @@ func newCluster(n int) *cluster { os.RemoveAll(fmt.Sprintf("raftdata/snap/%d", nodeID)) //nolint:errcheck,revive // TODO:: Handle an error returned. clus.proposeC[i] = make(chan []byte, 1) clus.confChangeC[i] = make(chan raftpb.ConfChange, 1) - //logger, _ := zap.NewDevelopment() + // logger, _ := zap.NewDevelopment() logger := zap.NewNop() options := raftConfig{ diff --git a/internal/metarepos/storage.go b/internal/metarepos/storage.go index 382468ed5..8339843f6 100644 --- a/internal/metarepos/storage.go +++ b/internal/metarepos/storage.go @@ -11,8 +11,8 @@ import ( "github.com/gogo/protobuf/proto" "github.com/gogo/status" - "go.etcd.io/etcd/raft" - "go.etcd.io/etcd/raft/raftpb" + "go.etcd.io/etcd/raft/v3" + "go.etcd.io/etcd/raft/v3/raftpb" "go.uber.org/zap" "google.golang.org/grpc/codes" @@ -1250,7 +1250,7 @@ func (ms *MetadataStorage) AppendLogStreamCommitHistory(cr *mrpb.LogStreamCommit return } - //ms.logger.Info("append commit", zap.String("logstreams", cr.String())) + // ms.logger.Info("append commit", zap.String("logstreams", cr.String())) _, cur := ms.getStateMachine() @@ -1694,7 +1694,7 @@ func (ms *MetadataStorage) createMetadataCache(job *jobMetadataCache) { defer ms.mtMu.RUnlock() for _, sn := range ms.diffStateMachine.Metadata.StorageNodes { - //TODO:: UpdateStorageNode + // TODO:: UpdateStorageNode if sn.Status.Deleted() { cache.DeleteStorageNode(sn.StorageNodeID) //nolint:errcheck,revive // TODO:: Handle an error returned. } else { @@ -1736,7 +1736,7 @@ func (ms *MetadataStorage) mergeMetadata() { defer ms.mtMu.Unlock() for _, sn := range ms.diffStateMachine.Metadata.StorageNodes { - //TODO:: UpdateStorageNode + // TODO:: UpdateStorageNode if sn.Status.Deleted() { ms.origStateMachine.Metadata.DeleteStorageNode(sn.StorageNodeID) //nolint:errcheck,revive // TODO:: Handle an error returned. } else { diff --git a/internal/metarepos/storage_test.go b/internal/metarepos/storage_test.go index 219f81197..548130428 100644 --- a/internal/metarepos/storage_test.go +++ b/internal/metarepos/storage_test.go @@ -9,7 +9,7 @@ import ( . "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/require" - "go.etcd.io/etcd/raft/raftpb" + "go.etcd.io/etcd/raft/v3/raftpb" "go.uber.org/zap" "go.uber.org/zap/zaptest" "google.golang.org/grpc/codes" diff --git a/vendor/github.com/coreos/go-systemd/NOTICE b/vendor/github.com/coreos/go-semver/NOTICE similarity index 100% rename from vendor/github.com/coreos/go-systemd/NOTICE rename to vendor/github.com/coreos/go-semver/NOTICE diff --git a/vendor/github.com/coreos/go-semver/semver/semver.go b/vendor/github.com/coreos/go-semver/semver/semver.go index 110fc23e1..76cf4852c 100644 --- a/vendor/github.com/coreos/go-semver/semver/semver.go +++ b/vendor/github.com/coreos/go-semver/semver/semver.go @@ -19,6 +19,7 @@ import ( "bytes" "errors" "fmt" + "regexp" "strconv" "strings" ) @@ -76,6 +77,14 @@ func (v *Version) Set(version string) error { return fmt.Errorf("%s is not in dotted-tri format", version) } + if err := validateIdentifier(string(preRelease)); err != nil { + return fmt.Errorf("failed to validate pre-release: %v", err) + } + + if err := validateIdentifier(metadata); err != nil { + return fmt.Errorf("failed to validate metadata: %v", err) + } + parsed := make([]int64, 3, 3) for i, v := range dotParts[:3] { @@ -224,6 +233,13 @@ func recursivePreReleaseCompare(versionA []string, versionB []string) int { bInt = true } + // Numeric identifiers always have lower precedence than non-numeric identifiers. + if aInt && !bInt { + return -1 + } else if !aInt && bInt { + return 1 + } + // Handle Integer Comparison if aInt && bInt { if aI > bI { @@ -266,3 +282,15 @@ func (v *Version) BumpPatch() { v.PreRelease = PreRelease("") v.Metadata = "" } + +// validateIdentifier makes sure the provided identifier satisfies semver spec +func validateIdentifier(id string) error { + if id != "" && !reIdentifier.MatchString(id) { + return fmt.Errorf("%s is not a valid semver identifier", id) + } + return nil +} + +// reIdentifier is a regular expression used to check that pre-release and metadata +// identifiers satisfy the spec requirements +var reIdentifier = regexp.MustCompile(`^[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*$`) diff --git a/vendor/github.com/coreos/go-systemd/LICENSE b/vendor/github.com/coreos/go-systemd/LICENSE deleted file mode 100644 index 37ec93a14..000000000 --- a/vendor/github.com/coreos/go-systemd/LICENSE +++ /dev/null @@ -1,191 +0,0 @@ -Apache License -Version 2.0, January 2004 -http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - -"License" shall mean the terms and conditions for use, reproduction, and -distribution as defined by Sections 1 through 9 of this document. - -"Licensor" shall mean the copyright owner or entity authorized by the copyright -owner that is granting the License. - -"Legal Entity" shall mean the union of the acting entity and all other entities -that control, are controlled by, or are under common control with that entity. -For the purposes of this definition, "control" means (i) the power, direct or -indirect, to cause the direction or management of such entity, whether by -contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the -outstanding shares, or (iii) beneficial ownership of such entity. - -"You" (or "Your") shall mean an individual or Legal Entity exercising -permissions granted by this License. - -"Source" form shall mean the preferred form for making modifications, including -but not limited to software source code, documentation source, and configuration -files. - -"Object" form shall mean any form resulting from mechanical transformation or -translation of a Source form, including but not limited to compiled object code, -generated documentation, and conversions to other media types. - -"Work" shall mean the work of authorship, whether in Source or Object form, made -available under the License, as indicated by a copyright notice that is included -in or attached to the work (an example is provided in the Appendix below). - -"Derivative Works" shall mean any work, whether in Source or Object form, that -is based on (or derived from) the Work and for which the editorial revisions, -annotations, elaborations, or other modifications represent, as a whole, an -original work of authorship. For the purposes of this License, Derivative Works -shall not include works that remain separable from, or merely link (or bind by -name) to the interfaces of, the Work and Derivative Works thereof. - -"Contribution" shall mean any work of authorship, including the original version -of the Work and any modifications or additions to that Work or Derivative Works -thereof, that is intentionally submitted to Licensor for inclusion in the Work -by the copyright owner or by an individual or Legal Entity authorized to submit -on behalf of the copyright owner. For the purposes of this definition, -"submitted" means any form of electronic, verbal, or written communication sent -to the Licensor or its representatives, including but not limited to -communication on electronic mailing lists, source code control systems, and -issue tracking systems that are managed by, or on behalf of, the Licensor for -the purpose of discussing and improving the Work, but excluding communication -that is conspicuously marked or otherwise designated in writing by the copyright -owner as "Not a Contribution." - -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf -of whom a Contribution has been received by Licensor and subsequently -incorporated within the Work. - -2. Grant of Copyright License. - -Subject to the terms and conditions of this License, each Contributor hereby -grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, -irrevocable copyright license to reproduce, prepare Derivative Works of, -publicly display, publicly perform, sublicense, and distribute the Work and such -Derivative Works in Source or Object form. - -3. Grant of Patent License. - -Subject to the terms and conditions of this License, each Contributor hereby -grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, -irrevocable (except as stated in this section) patent license to make, have -made, use, offer to sell, sell, import, and otherwise transfer the Work, where -such license applies only to those patent claims licensable by such Contributor -that are necessarily infringed by their Contribution(s) alone or by combination -of their Contribution(s) with the Work to which such Contribution(s) was -submitted. If You institute patent litigation against any entity (including a -cross-claim or counterclaim in a lawsuit) alleging that the Work or a -Contribution incorporated within the Work constitutes direct or contributory -patent infringement, then any patent licenses granted to You under this License -for that Work shall terminate as of the date such litigation is filed. - -4. Redistribution. - -You may reproduce and distribute copies of the Work or Derivative Works thereof -in any medium, with or without modifications, and in Source or Object form, -provided that You meet the following conditions: - -You must give any other recipients of the Work or Derivative Works a copy of -this License; and -You must cause any modified files to carry prominent notices stating that You -changed the files; and -You must retain, in the Source form of any Derivative Works that You distribute, -all copyright, patent, trademark, and attribution notices from the Source form -of the Work, excluding those notices that do not pertain to any part of the -Derivative Works; and -If the Work includes a "NOTICE" text file as part of its distribution, then any -Derivative Works that You distribute must include a readable copy of the -attribution notices contained within such NOTICE file, excluding those notices -that do not pertain to any part of the Derivative Works, in at least one of the -following places: within a NOTICE text file distributed as part of the -Derivative Works; within the Source form or documentation, if provided along -with the Derivative Works; or, within a display generated by the Derivative -Works, if and wherever such third-party notices normally appear. The contents of -the NOTICE file are for informational purposes only and do not modify the -License. You may add Your own attribution notices within Derivative Works that -You distribute, alongside or as an addendum to the NOTICE text from the Work, -provided that such additional attribution notices cannot be construed as -modifying the License. -You may add Your own copyright statement to Your modifications and may provide -additional or different license terms and conditions for use, reproduction, or -distribution of Your modifications, or for any such Derivative Works as a whole, -provided Your use, reproduction, and distribution of the Work otherwise complies -with the conditions stated in this License. - -5. Submission of Contributions. - -Unless You explicitly state otherwise, any Contribution intentionally submitted -for inclusion in the Work by You to the Licensor shall be under the terms and -conditions of this License, without any additional terms or conditions. -Notwithstanding the above, nothing herein shall supersede or modify the terms of -any separate license agreement you may have executed with Licensor regarding -such Contributions. - -6. Trademarks. - -This License does not grant permission to use the trade names, trademarks, -service marks, or product names of the Licensor, except as required for -reasonable and customary use in describing the origin of the Work and -reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. - -Unless required by applicable law or agreed to in writing, Licensor provides the -Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, -including, without limitation, any warranties or conditions of TITLE, -NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are -solely responsible for determining the appropriateness of using or -redistributing the Work and assume any risks associated with Your exercise of -permissions under this License. - -8. Limitation of Liability. - -In no event and under no legal theory, whether in tort (including negligence), -contract, or otherwise, unless required by applicable law (such as deliberate -and grossly negligent acts) or agreed to in writing, shall any Contributor be -liable to You for damages, including any direct, indirect, special, incidental, -or consequential damages of any character arising as a result of this License or -out of the use or inability to use the Work (including but not limited to -damages for loss of goodwill, work stoppage, computer failure or malfunction, or -any and all other commercial damages or losses), even if such Contributor has -been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. - -While redistributing the Work or Derivative Works thereof, You may choose to -offer, and charge a fee for, acceptance of support, warranty, indemnity, or -other liability obligations and/or rights consistent with this License. However, -in accepting such obligations, You may act only on Your own behalf and on Your -sole responsibility, not on behalf of any other Contributor, and only if You -agree to indemnify, defend, and hold each Contributor harmless for any liability -incurred by, or claims asserted against, such Contributor by reason of your -accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work - -To apply the Apache License to your work, attach the following boilerplate -notice, with the fields enclosed by brackets "[]" replaced with your own -identifying information. (Don't include the brackets!) The text should be -enclosed in the appropriate comment syntax for the file format. We also -recommend that a file or class name and description of purpose be included on -the same "printed page" as the copyright notice for easier identification within -third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/github.com/coreos/go-systemd/journal/journal.go b/vendor/github.com/coreos/go-systemd/journal/journal.go deleted file mode 100644 index ef85a3ba2..000000000 --- a/vendor/github.com/coreos/go-systemd/journal/journal.go +++ /dev/null @@ -1,182 +0,0 @@ -// Copyright 2015 CoreOS, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package journal provides write bindings to the local systemd journal. -// It is implemented in pure Go and connects to the journal directly over its -// unix socket. -// -// To read from the journal, see the "sdjournal" package, which wraps the -// sd-journal a C API. -// -// http://www.freedesktop.org/software/systemd/man/systemd-journald.service.html -package journal - -import ( - "bytes" - "encoding/binary" - "errors" - "fmt" - "io" - "io/ioutil" - "net" - "os" - "strconv" - "strings" - "syscall" -) - -// Priority of a journal message -type Priority int - -const ( - PriEmerg Priority = iota - PriAlert - PriCrit - PriErr - PriWarning - PriNotice - PriInfo - PriDebug -) - -var conn net.Conn - -func init() { - var err error - conn, err = net.Dial("unixgram", "/run/systemd/journal/socket") - if err != nil { - conn = nil - } -} - -// Enabled returns true if the local systemd journal is available for logging -func Enabled() bool { - return conn != nil -} - -// Send a message to the local systemd journal. vars is a map of journald -// fields to values. Fields must be composed of uppercase letters, numbers, -// and underscores, but must not start with an underscore. Within these -// restrictions, any arbitrary field name may be used. Some names have special -// significance: see the journalctl documentation -// (http://www.freedesktop.org/software/systemd/man/systemd.journal-fields.html) -// for more details. vars may be nil. -func Send(message string, priority Priority, vars map[string]string) error { - if conn == nil { - return journalError("could not connect to journald socket") - } - - data := new(bytes.Buffer) - appendVariable(data, "PRIORITY", strconv.Itoa(int(priority))) - appendVariable(data, "MESSAGE", message) - for k, v := range vars { - appendVariable(data, k, v) - } - - _, err := io.Copy(conn, data) - if err != nil && isSocketSpaceError(err) { - file, err := tempFd() - if err != nil { - return journalError(err.Error()) - } - defer file.Close() - _, err = io.Copy(file, data) - if err != nil { - return journalError(err.Error()) - } - - rights := syscall.UnixRights(int(file.Fd())) - - /* this connection should always be a UnixConn, but better safe than sorry */ - unixConn, ok := conn.(*net.UnixConn) - if !ok { - return journalError("can't send file through non-Unix connection") - } - _, _, err = unixConn.WriteMsgUnix([]byte{}, rights, nil) - if err != nil { - return journalError(err.Error()) - } - } else if err != nil { - return journalError(err.Error()) - } - return nil -} - -// Print prints a message to the local systemd journal using Send(). -func Print(priority Priority, format string, a ...interface{}) error { - return Send(fmt.Sprintf(format, a...), priority, nil) -} - -func appendVariable(w io.Writer, name, value string) { - if !validVarName(name) { - journalError("variable name contains invalid character, ignoring") - } - if strings.ContainsRune(value, '\n') { - /* When the value contains a newline, we write: - * - the variable name, followed by a newline - * - the size (in 64bit little endian format) - * - the data, followed by a newline - */ - fmt.Fprintln(w, name) - binary.Write(w, binary.LittleEndian, uint64(len(value))) - fmt.Fprintln(w, value) - } else { - /* just write the variable and value all on one line */ - fmt.Fprintf(w, "%s=%s\n", name, value) - } -} - -func validVarName(name string) bool { - /* The variable name must be in uppercase and consist only of characters, - * numbers and underscores, and may not begin with an underscore. (from the docs) - */ - - valid := name[0] != '_' - for _, c := range name { - valid = valid && ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || c == '_' - } - return valid -} - -func isSocketSpaceError(err error) bool { - opErr, ok := err.(*net.OpError) - if !ok { - return false - } - - sysErr, ok := opErr.Err.(syscall.Errno) - if !ok { - return false - } - - return sysErr == syscall.EMSGSIZE || sysErr == syscall.ENOBUFS -} - -func tempFd() (*os.File, error) { - file, err := ioutil.TempFile("/dev/shm/", "journal.XXXXX") - if err != nil { - return nil, err - } - err = syscall.Unlink(file.Name()) - if err != nil { - return nil, err - } - return file, nil -} - -func journalError(s string) error { - s = "journal error: " + s - fmt.Fprintln(os.Stderr, s) - return errors.New(s) -} diff --git a/vendor/github.com/coreos/pkg/NOTICE b/vendor/github.com/coreos/pkg/NOTICE deleted file mode 100644 index b39ddfa5c..000000000 --- a/vendor/github.com/coreos/pkg/NOTICE +++ /dev/null @@ -1,5 +0,0 @@ -CoreOS Project -Copyright 2014 CoreOS, Inc - -This product includes software developed at CoreOS, Inc. -(http://www.coreos.com/). diff --git a/vendor/github.com/coreos/pkg/capnslog/README.md b/vendor/github.com/coreos/pkg/capnslog/README.md deleted file mode 100644 index 81efb1fb6..000000000 --- a/vendor/github.com/coreos/pkg/capnslog/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# capnslog, the CoreOS logging package - -There are far too many logging packages out there, with varying degrees of licenses, far too many features (colorization, all sorts of log frameworks) or are just a pain to use (lack of `Fatalln()`?). -capnslog provides a simple but consistent logging interface suitable for all kinds of projects. - -### Design Principles - -##### `package main` is the place where logging gets turned on and routed - -A library should not touch log options, only generate log entries. Libraries are silent until main lets them speak. - -##### All log options are runtime-configurable. - -Still the job of `main` to expose these configurations. `main` may delegate this to, say, a configuration webhook, but does so explicitly. - -##### There is one log object per package. It is registered under its repository and package name. - -`main` activates logging for its repository and any dependency repositories it would also like to have output in its logstream. `main` also dictates at which level each subpackage logs. - -##### There is *one* output stream, and it is an `io.Writer` composed with a formatter. - -Splitting streams is probably not the job of your program, but rather, your log aggregation framework. If you must split output streams, again, `main` configures this and you can write a very simple two-output struct that satisfies io.Writer. - -Fancy colorful formatting and JSON output are beyond the scope of a basic logging framework -- they're application/log-collector dependant. These are, at best, provided as options, but more likely, provided by your application. - -##### Log objects are an interface - -An object knows best how to print itself. Log objects can collect more interesting metadata if they wish, however, because text isn't going away anytime soon, they must all be marshalable to text. The simplest log object is a string, which returns itself. If you wish to do more fancy tricks for printing your log objects, see also JSON output -- introspect and write a formatter which can handle your advanced log interface. Making strings is the only thing guaranteed. - -##### Log levels have specific meanings: - - * Critical: Unrecoverable. Must fail. - * Error: Data has been lost, a request has failed for a bad reason, or a required resource has been lost - * Warning: (Hopefully) Temporary conditions that may cause errors, but may work fine. A replica disappearing (that may reconnect) is a warning. - * Notice: Normal, but important (uncommon) log information. - * Info: Normal, working log information, everything is fine, but helpful notices for auditing or common operations. - * Debug: Everything is still fine, but even common operations may be logged, and less helpful but more quantity of notices. - * Trace: Anything goes, from logging every function call as part of a common operation, to tracing execution of a query. - diff --git a/vendor/github.com/coreos/pkg/capnslog/formatters.go b/vendor/github.com/coreos/pkg/capnslog/formatters.go deleted file mode 100644 index b305a845f..000000000 --- a/vendor/github.com/coreos/pkg/capnslog/formatters.go +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright 2015 CoreOS, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package capnslog - -import ( - "bufio" - "fmt" - "io" - "log" - "runtime" - "strings" - "time" -) - -type Formatter interface { - Format(pkg string, level LogLevel, depth int, entries ...interface{}) - Flush() -} - -func NewStringFormatter(w io.Writer) Formatter { - return &StringFormatter{ - w: bufio.NewWriter(w), - } -} - -type StringFormatter struct { - w *bufio.Writer -} - -func (s *StringFormatter) Format(pkg string, l LogLevel, i int, entries ...interface{}) { - now := time.Now().UTC() - s.w.WriteString(now.Format(time.RFC3339)) - s.w.WriteByte(' ') - writeEntries(s.w, pkg, l, i, entries...) - s.Flush() -} - -func writeEntries(w *bufio.Writer, pkg string, _ LogLevel, _ int, entries ...interface{}) { - if pkg != "" { - w.WriteString(pkg + ": ") - } - str := fmt.Sprint(entries...) - endsInNL := strings.HasSuffix(str, "\n") - w.WriteString(str) - if !endsInNL { - w.WriteString("\n") - } -} - -func (s *StringFormatter) Flush() { - s.w.Flush() -} - -func NewPrettyFormatter(w io.Writer, debug bool) Formatter { - return &PrettyFormatter{ - w: bufio.NewWriter(w), - debug: debug, - } -} - -type PrettyFormatter struct { - w *bufio.Writer - debug bool -} - -func (c *PrettyFormatter) Format(pkg string, l LogLevel, depth int, entries ...interface{}) { - now := time.Now() - ts := now.Format("2006-01-02 15:04:05") - c.w.WriteString(ts) - ms := now.Nanosecond() / 1000 - c.w.WriteString(fmt.Sprintf(".%06d", ms)) - if c.debug { - _, file, line, ok := runtime.Caller(depth) // It's always the same number of frames to the user's call. - if !ok { - file = "???" - line = 1 - } else { - slash := strings.LastIndex(file, "/") - if slash >= 0 { - file = file[slash+1:] - } - } - if line < 0 { - line = 0 // not a real line number - } - c.w.WriteString(fmt.Sprintf(" [%s:%d]", file, line)) - } - c.w.WriteString(fmt.Sprint(" ", l.Char(), " | ")) - writeEntries(c.w, pkg, l, depth, entries...) - c.Flush() -} - -func (c *PrettyFormatter) Flush() { - c.w.Flush() -} - -// LogFormatter emulates the form of the traditional built-in logger. -type LogFormatter struct { - logger *log.Logger - prefix string -} - -// NewLogFormatter is a helper to produce a new LogFormatter struct. It uses the -// golang log package to actually do the logging work so that logs look similar. -func NewLogFormatter(w io.Writer, prefix string, flag int) Formatter { - return &LogFormatter{ - logger: log.New(w, "", flag), // don't use prefix here - prefix: prefix, // save it instead - } -} - -// Format builds a log message for the LogFormatter. The LogLevel is ignored. -func (lf *LogFormatter) Format(pkg string, _ LogLevel, _ int, entries ...interface{}) { - str := fmt.Sprint(entries...) - prefix := lf.prefix - if pkg != "" { - prefix = fmt.Sprintf("%s%s: ", prefix, pkg) - } - lf.logger.Output(5, fmt.Sprintf("%s%v", prefix, str)) // call depth is 5 -} - -// Flush is included so that the interface is complete, but is a no-op. -func (lf *LogFormatter) Flush() { - // noop -} - -// NilFormatter is a no-op log formatter that does nothing. -type NilFormatter struct { -} - -// NewNilFormatter is a helper to produce a new LogFormatter struct. It logs no -// messages so that you can cause part of your logging to be silent. -func NewNilFormatter() Formatter { - return &NilFormatter{} -} - -// Format does nothing. -func (_ *NilFormatter) Format(_ string, _ LogLevel, _ int, _ ...interface{}) { - // noop -} - -// Flush is included so that the interface is complete, but is a no-op. -func (_ *NilFormatter) Flush() { - // noop -} diff --git a/vendor/github.com/coreos/pkg/capnslog/glog_formatter.go b/vendor/github.com/coreos/pkg/capnslog/glog_formatter.go deleted file mode 100644 index 426603ef3..000000000 --- a/vendor/github.com/coreos/pkg/capnslog/glog_formatter.go +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2015 CoreOS, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package capnslog - -import ( - "bufio" - "bytes" - "io" - "os" - "runtime" - "strconv" - "strings" - "time" -) - -var pid = os.Getpid() - -type GlogFormatter struct { - StringFormatter -} - -func NewGlogFormatter(w io.Writer) *GlogFormatter { - g := &GlogFormatter{} - g.w = bufio.NewWriter(w) - return g -} - -func (g GlogFormatter) Format(pkg string, level LogLevel, depth int, entries ...interface{}) { - g.w.Write(GlogHeader(level, depth+1)) - g.StringFormatter.Format(pkg, level, depth+1, entries...) -} - -func GlogHeader(level LogLevel, depth int) []byte { - // Lmmdd hh:mm:ss.uuuuuu threadid file:line] - now := time.Now().UTC() - _, file, line, ok := runtime.Caller(depth) // It's always the same number of frames to the user's call. - if !ok { - file = "???" - line = 1 - } else { - slash := strings.LastIndex(file, "/") - if slash >= 0 { - file = file[slash+1:] - } - } - if line < 0 { - line = 0 // not a real line number - } - buf := &bytes.Buffer{} - buf.Grow(30) - _, month, day := now.Date() - hour, minute, second := now.Clock() - buf.WriteString(level.Char()) - twoDigits(buf, int(month)) - twoDigits(buf, day) - buf.WriteByte(' ') - twoDigits(buf, hour) - buf.WriteByte(':') - twoDigits(buf, minute) - buf.WriteByte(':') - twoDigits(buf, second) - buf.WriteByte('.') - buf.WriteString(strconv.Itoa(now.Nanosecond() / 1000)) - buf.WriteByte('Z') - buf.WriteByte(' ') - buf.WriteString(strconv.Itoa(pid)) - buf.WriteByte(' ') - buf.WriteString(file) - buf.WriteByte(':') - buf.WriteString(strconv.Itoa(line)) - buf.WriteByte(']') - buf.WriteByte(' ') - return buf.Bytes() -} - -const digits = "0123456789" - -func twoDigits(b *bytes.Buffer, d int) { - c2 := digits[d%10] - d /= 10 - c1 := digits[d%10] - b.WriteByte(c1) - b.WriteByte(c2) -} diff --git a/vendor/github.com/coreos/pkg/capnslog/init.go b/vendor/github.com/coreos/pkg/capnslog/init.go deleted file mode 100644 index 44b8cd361..000000000 --- a/vendor/github.com/coreos/pkg/capnslog/init.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2015 CoreOS, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// +build !windows - -package capnslog - -import ( - "io" - "os" - "syscall" -) - -// Here's where the opinionation comes in. We need some sensible defaults, -// especially after taking over the log package. Your project (whatever it may -// be) may see things differently. That's okay; there should be no defaults in -// the main package that cannot be controlled or overridden programatically, -// otherwise it's a bug. Doing so is creating your own init_log.go file much -// like this one. - -func init() { - initHijack() - - // Go `log` pacakge uses os.Stderr. - SetFormatter(NewDefaultFormatter(os.Stderr)) - SetGlobalLogLevel(INFO) -} - -func NewDefaultFormatter(out io.Writer) Formatter { - if syscall.Getppid() == 1 { - // We're running under init, which may be systemd. - f, err := NewJournaldFormatter() - if err == nil { - return f - } - } - return NewPrettyFormatter(out, false) -} diff --git a/vendor/github.com/coreos/pkg/capnslog/init_windows.go b/vendor/github.com/coreos/pkg/capnslog/init_windows.go deleted file mode 100644 index 455305065..000000000 --- a/vendor/github.com/coreos/pkg/capnslog/init_windows.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2015 CoreOS, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package capnslog - -import "os" - -func init() { - initHijack() - - // Go `log` package uses os.Stderr. - SetFormatter(NewPrettyFormatter(os.Stderr, false)) - SetGlobalLogLevel(INFO) -} diff --git a/vendor/github.com/coreos/pkg/capnslog/journald_formatter.go b/vendor/github.com/coreos/pkg/capnslog/journald_formatter.go deleted file mode 100644 index 72e05207c..000000000 --- a/vendor/github.com/coreos/pkg/capnslog/journald_formatter.go +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2015 CoreOS, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// +build !windows - -package capnslog - -import ( - "errors" - "fmt" - "os" - "path/filepath" - - "github.com/coreos/go-systemd/journal" -) - -func NewJournaldFormatter() (Formatter, error) { - if !journal.Enabled() { - return nil, errors.New("No systemd detected") - } - return &journaldFormatter{}, nil -} - -type journaldFormatter struct{} - -func (j *journaldFormatter) Format(pkg string, l LogLevel, _ int, entries ...interface{}) { - var pri journal.Priority - switch l { - case CRITICAL: - pri = journal.PriCrit - case ERROR: - pri = journal.PriErr - case WARNING: - pri = journal.PriWarning - case NOTICE: - pri = journal.PriNotice - case INFO: - pri = journal.PriInfo - case DEBUG: - pri = journal.PriDebug - case TRACE: - pri = journal.PriDebug - default: - panic("Unhandled loglevel") - } - msg := fmt.Sprint(entries...) - tags := map[string]string{ - "PACKAGE": pkg, - "SYSLOG_IDENTIFIER": filepath.Base(os.Args[0]), - } - err := journal.Send(msg, pri, tags) - if err != nil { - fmt.Fprintln(os.Stderr, err) - } -} - -func (j *journaldFormatter) Flush() {} diff --git a/vendor/github.com/coreos/pkg/capnslog/logmap.go b/vendor/github.com/coreos/pkg/capnslog/logmap.go deleted file mode 100644 index 849544883..000000000 --- a/vendor/github.com/coreos/pkg/capnslog/logmap.go +++ /dev/null @@ -1,240 +0,0 @@ -// Copyright 2015 CoreOS, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package capnslog - -import ( - "errors" - "strings" - "sync" -) - -// LogLevel is the set of all log levels. -type LogLevel int8 - -const ( - // CRITICAL is the lowest log level; only errors which will end the program will be propagated. - CRITICAL LogLevel = iota - 1 - // ERROR is for errors that are not fatal but lead to troubling behavior. - ERROR - // WARNING is for errors which are not fatal and not errors, but are unusual. Often sourced from misconfigurations. - WARNING - // NOTICE is for normal but significant conditions. - NOTICE - // INFO is a log level for common, everyday log updates. - INFO - // DEBUG is the default hidden level for more verbose updates about internal processes. - DEBUG - // TRACE is for (potentially) call by call tracing of programs. - TRACE -) - -// Char returns a single-character representation of the log level. -func (l LogLevel) Char() string { - switch l { - case CRITICAL: - return "C" - case ERROR: - return "E" - case WARNING: - return "W" - case NOTICE: - return "N" - case INFO: - return "I" - case DEBUG: - return "D" - case TRACE: - return "T" - default: - panic("Unhandled loglevel") - } -} - -// String returns a multi-character representation of the log level. -func (l LogLevel) String() string { - switch l { - case CRITICAL: - return "CRITICAL" - case ERROR: - return "ERROR" - case WARNING: - return "WARNING" - case NOTICE: - return "NOTICE" - case INFO: - return "INFO" - case DEBUG: - return "DEBUG" - case TRACE: - return "TRACE" - default: - panic("Unhandled loglevel") - } -} - -// Update using the given string value. Fulfills the flag.Value interface. -func (l *LogLevel) Set(s string) error { - value, err := ParseLevel(s) - if err != nil { - return err - } - - *l = value - return nil -} - -// ParseLevel translates some potential loglevel strings into their corresponding levels. -func ParseLevel(s string) (LogLevel, error) { - switch s { - case "CRITICAL", "C": - return CRITICAL, nil - case "ERROR", "0", "E": - return ERROR, nil - case "WARNING", "1", "W": - return WARNING, nil - case "NOTICE", "2", "N": - return NOTICE, nil - case "INFO", "3", "I": - return INFO, nil - case "DEBUG", "4", "D": - return DEBUG, nil - case "TRACE", "5", "T": - return TRACE, nil - } - return CRITICAL, errors.New("couldn't parse log level " + s) -} - -type RepoLogger map[string]*PackageLogger - -type loggerStruct struct { - sync.Mutex - repoMap map[string]RepoLogger - formatter Formatter -} - -// logger is the global logger -var logger = new(loggerStruct) - -// SetGlobalLogLevel sets the log level for all packages in all repositories -// registered with capnslog. -func SetGlobalLogLevel(l LogLevel) { - logger.Lock() - defer logger.Unlock() - for _, r := range logger.repoMap { - r.setRepoLogLevelInternal(l) - } -} - -// GetRepoLogger may return the handle to the repository's set of packages' loggers. -func GetRepoLogger(repo string) (RepoLogger, error) { - logger.Lock() - defer logger.Unlock() - r, ok := logger.repoMap[repo] - if !ok { - return nil, errors.New("no packages registered for repo " + repo) - } - return r, nil -} - -// MustRepoLogger returns the handle to the repository's packages' loggers. -func MustRepoLogger(repo string) RepoLogger { - r, err := GetRepoLogger(repo) - if err != nil { - panic(err) - } - return r -} - -// SetRepoLogLevel sets the log level for all packages in the repository. -func (r RepoLogger) SetRepoLogLevel(l LogLevel) { - logger.Lock() - defer logger.Unlock() - r.setRepoLogLevelInternal(l) -} - -func (r RepoLogger) setRepoLogLevelInternal(l LogLevel) { - for _, v := range r { - v.level = l - } -} - -// ParseLogLevelConfig parses a comma-separated string of "package=loglevel", in -// order, and returns a map of the results, for use in SetLogLevel. -func (r RepoLogger) ParseLogLevelConfig(conf string) (map[string]LogLevel, error) { - setlist := strings.Split(conf, ",") - out := make(map[string]LogLevel) - for _, setstring := range setlist { - setting := strings.Split(setstring, "=") - if len(setting) != 2 { - return nil, errors.New("oddly structured `pkg=level` option: " + setstring) - } - l, err := ParseLevel(setting[1]) - if err != nil { - return nil, err - } - out[setting[0]] = l - } - return out, nil -} - -// SetLogLevel takes a map of package names within a repository to their desired -// loglevel, and sets the levels appropriately. Unknown packages are ignored. -// "*" is a special package name that corresponds to all packages, and will be -// processed first. -func (r RepoLogger) SetLogLevel(m map[string]LogLevel) { - logger.Lock() - defer logger.Unlock() - if l, ok := m["*"]; ok { - r.setRepoLogLevelInternal(l) - } - for k, v := range m { - l, ok := r[k] - if !ok { - continue - } - l.level = v - } -} - -// SetFormatter sets the formatting function for all logs. -func SetFormatter(f Formatter) { - logger.Lock() - defer logger.Unlock() - logger.formatter = f -} - -// NewPackageLogger creates a package logger object. -// This should be defined as a global var in your package, referencing your repo. -func NewPackageLogger(repo string, pkg string) (p *PackageLogger) { - logger.Lock() - defer logger.Unlock() - if logger.repoMap == nil { - logger.repoMap = make(map[string]RepoLogger) - } - r, rok := logger.repoMap[repo] - if !rok { - logger.repoMap[repo] = make(RepoLogger) - r = logger.repoMap[repo] - } - p, pok := r[pkg] - if !pok { - r[pkg] = &PackageLogger{ - pkg: pkg, - level: INFO, - } - p = r[pkg] - } - return -} diff --git a/vendor/github.com/coreos/pkg/capnslog/pkg_logger.go b/vendor/github.com/coreos/pkg/capnslog/pkg_logger.go deleted file mode 100644 index 612d55c66..000000000 --- a/vendor/github.com/coreos/pkg/capnslog/pkg_logger.go +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright 2015 CoreOS, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package capnslog - -import ( - "fmt" - "os" -) - -type PackageLogger struct { - pkg string - level LogLevel -} - -const calldepth = 2 - -func (p *PackageLogger) internalLog(depth int, inLevel LogLevel, entries ...interface{}) { - logger.Lock() - defer logger.Unlock() - if inLevel != CRITICAL && p.level < inLevel { - return - } - if logger.formatter != nil { - logger.formatter.Format(p.pkg, inLevel, depth+1, entries...) - } -} - -func (p *PackageLogger) LevelAt(l LogLevel) bool { - logger.Lock() - defer logger.Unlock() - return p.level >= l -} - -// Log a formatted string at any level between ERROR and TRACE -func (p *PackageLogger) Logf(l LogLevel, format string, args ...interface{}) { - p.internalLog(calldepth, l, fmt.Sprintf(format, args...)) -} - -// Log a message at any level between ERROR and TRACE -func (p *PackageLogger) Log(l LogLevel, args ...interface{}) { - p.internalLog(calldepth, l, fmt.Sprint(args...)) -} - -// log stdlib compatibility - -func (p *PackageLogger) Println(args ...interface{}) { - p.internalLog(calldepth, INFO, fmt.Sprintln(args...)) -} - -func (p *PackageLogger) Printf(format string, args ...interface{}) { - p.Logf(INFO, format, args...) -} - -func (p *PackageLogger) Print(args ...interface{}) { - p.internalLog(calldepth, INFO, fmt.Sprint(args...)) -} - -// Panic and fatal - -func (p *PackageLogger) Panicf(format string, args ...interface{}) { - s := fmt.Sprintf(format, args...) - p.internalLog(calldepth, CRITICAL, s) - panic(s) -} - -func (p *PackageLogger) Panic(args ...interface{}) { - s := fmt.Sprint(args...) - p.internalLog(calldepth, CRITICAL, s) - panic(s) -} - -func (p *PackageLogger) Fatalf(format string, args ...interface{}) { - p.Logf(CRITICAL, format, args...) - os.Exit(1) -} - -func (p *PackageLogger) Fatal(args ...interface{}) { - s := fmt.Sprint(args...) - p.internalLog(calldepth, CRITICAL, s) - os.Exit(1) -} - -func (p *PackageLogger) Fatalln(args ...interface{}) { - s := fmt.Sprintln(args...) - p.internalLog(calldepth, CRITICAL, s) - os.Exit(1) -} - -// Error Functions - -func (p *PackageLogger) Errorf(format string, args ...interface{}) { - p.Logf(ERROR, format, args...) -} - -func (p *PackageLogger) Error(entries ...interface{}) { - p.internalLog(calldepth, ERROR, entries...) -} - -// Warning Functions - -func (p *PackageLogger) Warningf(format string, args ...interface{}) { - p.Logf(WARNING, format, args...) -} - -func (p *PackageLogger) Warning(entries ...interface{}) { - p.internalLog(calldepth, WARNING, entries...) -} - -// Notice Functions - -func (p *PackageLogger) Noticef(format string, args ...interface{}) { - p.Logf(NOTICE, format, args...) -} - -func (p *PackageLogger) Notice(entries ...interface{}) { - p.internalLog(calldepth, NOTICE, entries...) -} - -// Info Functions - -func (p *PackageLogger) Infof(format string, args ...interface{}) { - p.Logf(INFO, format, args...) -} - -func (p *PackageLogger) Info(entries ...interface{}) { - p.internalLog(calldepth, INFO, entries...) -} - -// Debug Functions - -func (p *PackageLogger) Debugf(format string, args ...interface{}) { - if p.level < DEBUG { - return - } - p.Logf(DEBUG, format, args...) -} - -func (p *PackageLogger) Debug(entries ...interface{}) { - if p.level < DEBUG { - return - } - p.internalLog(calldepth, DEBUG, entries...) -} - -// Trace Functions - -func (p *PackageLogger) Tracef(format string, args ...interface{}) { - if p.level < TRACE { - return - } - p.Logf(TRACE, format, args...) -} - -func (p *PackageLogger) Trace(entries ...interface{}) { - if p.level < TRACE { - return - } - p.internalLog(calldepth, TRACE, entries...) -} - -func (p *PackageLogger) Flush() { - logger.Lock() - defer logger.Unlock() - logger.formatter.Flush() -} diff --git a/vendor/github.com/coreos/pkg/capnslog/syslog_formatter.go b/vendor/github.com/coreos/pkg/capnslog/syslog_formatter.go deleted file mode 100644 index 4be5a1f2d..000000000 --- a/vendor/github.com/coreos/pkg/capnslog/syslog_formatter.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2015 CoreOS, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// +build !windows - -package capnslog - -import ( - "fmt" - "log/syslog" -) - -func NewSyslogFormatter(w *syslog.Writer) Formatter { - return &syslogFormatter{w} -} - -func NewDefaultSyslogFormatter(tag string) (Formatter, error) { - w, err := syslog.New(syslog.LOG_DEBUG, tag) - if err != nil { - return nil, err - } - return NewSyslogFormatter(w), nil -} - -type syslogFormatter struct { - w *syslog.Writer -} - -func (s *syslogFormatter) Format(pkg string, l LogLevel, _ int, entries ...interface{}) { - for _, entry := range entries { - str := fmt.Sprint(entry) - switch l { - case CRITICAL: - s.w.Crit(str) - case ERROR: - s.w.Err(str) - case WARNING: - s.w.Warning(str) - case NOTICE: - s.w.Notice(str) - case INFO: - s.w.Info(str) - case DEBUG: - s.w.Debug(str) - case TRACE: - s.w.Debug(str) - default: - panic("Unhandled loglevel") - } - } -} - -func (s *syslogFormatter) Flush() { -} diff --git a/vendor/go.etcd.io/etcd/NOTICE b/vendor/go.etcd.io/etcd/NOTICE deleted file mode 100644 index b39ddfa5c..000000000 --- a/vendor/go.etcd.io/etcd/NOTICE +++ /dev/null @@ -1,5 +0,0 @@ -CoreOS Project -Copyright 2014 CoreOS, Inc - -This product includes software developed at CoreOS, Inc. -(http://www.coreos.com/). diff --git a/vendor/go.etcd.io/etcd/LICENSE b/vendor/go.etcd.io/etcd/api/v3/LICENSE similarity index 100% rename from vendor/go.etcd.io/etcd/LICENSE rename to vendor/go.etcd.io/etcd/api/v3/LICENSE diff --git a/vendor/go.etcd.io/etcd/version/version.go b/vendor/go.etcd.io/etcd/api/v3/version/version.go similarity index 98% rename from vendor/go.etcd.io/etcd/version/version.go rename to vendor/go.etcd.io/etcd/api/v3/version/version.go index ac57e070d..4858a08bf 100644 --- a/vendor/go.etcd.io/etcd/version/version.go +++ b/vendor/go.etcd.io/etcd/api/v3/version/version.go @@ -26,7 +26,7 @@ import ( var ( // MinClusterVersion is the min cluster version this etcd binary is compatible with. MinClusterVersion = "3.0.0" - Version = "3.4.25" + Version = "3.5.12" APIVersion = "unknown" // Git SHA Value will be set during build diff --git a/vendor/github.com/coreos/pkg/LICENSE b/vendor/go.etcd.io/etcd/client/pkg/v3/LICENSE similarity index 99% rename from vendor/github.com/coreos/pkg/LICENSE rename to vendor/go.etcd.io/etcd/client/pkg/v3/LICENSE index e06d20818..d64569567 100644 --- a/vendor/github.com/coreos/pkg/LICENSE +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/LICENSE @@ -1,4 +1,5 @@ -Apache License + + Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -178,7 +179,7 @@ Apache License APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" + boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a @@ -186,7 +187,7 @@ Apache License same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright {yyyy} {name of copyright owner} + Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -199,4 +200,3 @@ Apache License WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/dir_unix.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/dir_unix.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/fileutil/dir_unix.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/dir_unix.go diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/dir_windows.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/dir_windows.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/fileutil/dir_windows.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/dir_windows.go diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/doc.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/doc.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/fileutil/doc.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/doc.go diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/filereader.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/filereader.go new file mode 100644 index 000000000..55248888c --- /dev/null +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/filereader.go @@ -0,0 +1,60 @@ +// Copyright 2022 The etcd Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package fileutil + +import ( + "bufio" + "io" + "io/fs" + "os" +) + +// FileReader is a wrapper of io.Reader. It also provides file info. +type FileReader interface { + io.Reader + FileInfo() (fs.FileInfo, error) +} + +type fileReader struct { + *os.File +} + +func NewFileReader(f *os.File) FileReader { + return &fileReader{f} +} + +func (fr *fileReader) FileInfo() (fs.FileInfo, error) { + return fr.Stat() +} + +// FileBufReader is a wrapper of bufio.Reader. It also provides file info. +type FileBufReader struct { + *bufio.Reader + fi fs.FileInfo +} + +func NewFileBufReader(fr FileReader) *FileBufReader { + bufReader := bufio.NewReader(fr) + fi, err := fr.FileInfo() + if err != nil { + // This should never happen. + panic(err) + } + return &FileBufReader{bufReader, fi} +} + +func (fbr *FileBufReader) FileInfo() fs.FileInfo { + return fbr.fi +} diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/fileutil.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/fileutil.go similarity index 88% rename from vendor/go.etcd.io/etcd/pkg/fileutil/fileutil.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/fileutil.go index 7052a8084..d31ece3e2 100644 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/fileutil.go +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/fileutil.go @@ -16,13 +16,12 @@ package fileutil import ( "fmt" - "go.uber.org/zap" "io" "io/ioutil" "os" "path/filepath" - "github.com/coreos/pkg/capnslog" + "go.uber.org/zap" ) const ( @@ -30,12 +29,13 @@ const ( PrivateFileMode = 0600 ) -var plog = capnslog.NewPackageLogger("go.etcd.io/etcd", "pkg/fileutil") - // IsDirWriteable checks if dir is writable by writing and removing a file // to dir. It returns nil if dir is writable. func IsDirWriteable(dir string) error { - f := filepath.Join(dir, ".touch") + f, err := filepath.Abs(filepath.Join(dir, ".touch")) + if err != nil { + return err + } if err := ioutil.WriteFile(f, []byte(""), PrivateFileMode); err != nil { return err } @@ -44,13 +44,13 @@ func IsDirWriteable(dir string) error { // TouchDirAll is similar to os.MkdirAll. It creates directories with 0700 permission if any directory // does not exists. TouchDirAll also ensures the given directory is writable. -func TouchDirAll(dir string) error { +func TouchDirAll(lg *zap.Logger, dir string) error { // If path is already a directory, MkdirAll does nothing and returns nil, so, // first check if dir exist with an expected permission mode. if Exist(dir) { err := CheckDirPermission(dir, PrivateDirMode) if err != nil { - plog.Warningf("check file permission: %v", err) + lg.Warn("check file permission", zap.Error(err)) } } else { err := os.MkdirAll(dir, PrivateDirMode) @@ -66,8 +66,8 @@ func TouchDirAll(dir string) error { // CreateDirAll is similar to TouchDirAll but returns error // if the deepest directory was not empty. -func CreateDirAll(dir string) error { - err := TouchDirAll(dir) +func CreateDirAll(lg *zap.Logger, dir string) error { + err := TouchDirAll(lg, dir) if err == nil { var ns []string ns, err = ReadDir(dir) @@ -87,6 +87,12 @@ func Exist(name string) bool { return err == nil } +// DirEmpty returns true if a directory empty and can access. +func DirEmpty(name string) bool { + ns, err := ReadDir(name) + return len(ns) == 0 && err == nil +} + // ZeroToEnd zeros a file starting from SEEK_CUR to its SEEK_END. May temporarily // shorten the length of the file. func ZeroToEnd(f *os.File) error { @@ -114,7 +120,7 @@ func ZeroToEnd(f *os.File) error { // Returns error if dir is empty or exist with a different permission than specified. func CheckDirPermission(dir string, perm os.FileMode) error { if !Exist(dir) { - return fmt.Errorf("directory %q empty, cannot check permission.", dir) + return fmt.Errorf("directory %q empty, cannot check permission", dir) } //check the existing permission on the directory dirInfo, err := os.Stat(dir) @@ -123,7 +129,7 @@ func CheckDirPermission(dir string, perm os.FileMode) error { } dirMode := dirInfo.Mode().Perm() if dirMode != perm { - err = fmt.Errorf("directory %q exist, but the permission is %q. The recommended permission is %q to prevent possible unprivileged access to the data.", dir, dirInfo.Mode(), os.FileMode(PrivateDirMode)) + err = fmt.Errorf("directory %q exist, but the permission is %q. The recommended permission is %q to prevent possible unprivileged access to the data", dir, dirInfo.Mode(), os.FileMode(PrivateDirMode)) return err } return nil @@ -151,6 +157,7 @@ func RemoveMatchFile(lg *zap.Logger, dir string, matchFunc func(fileName string) lg.Error("remove file failed", zap.String("file", file), zap.Error(err)) + continue } } } diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/lock.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/fileutil/lock.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock.go diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/lock_flock.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_flock.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/fileutil/lock_flock.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_flock.go diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/lock_linux.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_linux.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/fileutil/lock_linux.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_linux.go diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/lock_plan9.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_plan9.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/fileutil/lock_plan9.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_plan9.go diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/lock_solaris.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_solaris.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/fileutil/lock_solaris.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_solaris.go diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/lock_unix.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_unix.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/fileutil/lock_unix.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_unix.go diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/lock_windows.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_windows.go similarity index 96% rename from vendor/go.etcd.io/etcd/pkg/fileutil/lock_windows.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_windows.go index 323a96e74..5cbf2bc3d 100644 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/lock_windows.go +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_windows.go @@ -29,7 +29,7 @@ var ( modkernel32 = syscall.NewLazyDLL("kernel32.dll") procLockFileEx = modkernel32.NewProc("LockFileEx") - errLocked = errors.New("The process cannot access the file because another process has locked a portion of the file.") + errLocked = errors.New("the process cannot access the file because another process has locked a portion of the file") ) const ( diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/preallocate.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/fileutil/preallocate.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate.go diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/preallocate_darwin.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate_darwin.go similarity index 82% rename from vendor/go.etcd.io/etcd/pkg/fileutil/preallocate_darwin.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate_darwin.go index e6011f1dc..caab143dd 100644 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/preallocate_darwin.go +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate_darwin.go @@ -20,7 +20,8 @@ package fileutil import ( "os" "syscall" - "unsafe" + + "golang.org/x/sys/unix" ) func preallocExtend(f *os.File, sizeInBytes int64) error { @@ -33,18 +34,18 @@ func preallocExtend(f *os.File, sizeInBytes int64) error { func preallocFixed(f *os.File, sizeInBytes int64) error { // allocate all requested space or no space at all // TODO: allocate contiguous space on disk with F_ALLOCATECONTIG flag - fstore := &syscall.Fstore_t{ - Flags: syscall.F_ALLOCATEALL, - Posmode: syscall.F_PEOFPOSMODE, - Length: sizeInBytes} - p := unsafe.Pointer(fstore) - _, _, errno := syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), uintptr(syscall.F_PREALLOCATE), uintptr(p)) - if errno == 0 || errno == syscall.ENOTSUP { + fstore := &unix.Fstore_t{ + Flags: unix.F_ALLOCATEALL, + Posmode: unix.F_PEOFPOSMODE, + Length: sizeInBytes, + } + err := unix.FcntlFstore(f.Fd(), unix.F_PREALLOCATE, fstore) + if err == nil || err == unix.ENOTSUP { return nil } // wrong argument to fallocate syscall - if errno == syscall.EINVAL { + if err == unix.EINVAL { // filesystem "st_blocks" are allocated in the units of // "Allocation Block Size" (run "diskutil info /" command) var stat syscall.Stat_t @@ -62,5 +63,5 @@ func preallocFixed(f *os.File, sizeInBytes int64) error { return nil } } - return errno + return err } diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/preallocate_unix.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate_unix.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/fileutil/preallocate_unix.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate_unix.go diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/preallocate_unsupported.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate_unsupported.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/fileutil/preallocate_unsupported.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate_unsupported.go diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/purge.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/purge.go similarity index 66% rename from vendor/go.etcd.io/etcd/pkg/fileutil/purge.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/purge.go index 50a1f08c1..b314e068f 100644 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/purge.go +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/purge.go @@ -25,28 +25,33 @@ import ( ) func PurgeFile(lg *zap.Logger, dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) <-chan error { - return purgeFile(lg, dirname, suffix, max, interval, stop, nil, nil) + return purgeFile(lg, dirname, suffix, max, interval, stop, nil, nil, true) } func PurgeFileWithDoneNotify(lg *zap.Logger, dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) (<-chan struct{}, <-chan error) { doneC := make(chan struct{}) - errC := purgeFile(lg, dirname, suffix, max, interval, stop, nil, doneC) + errC := purgeFile(lg, dirname, suffix, max, interval, stop, nil, doneC, true) + return doneC, errC +} + +func PurgeFileWithoutFlock(lg *zap.Logger, dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) (<-chan struct{}, <-chan error) { + doneC := make(chan struct{}) + errC := purgeFile(lg, dirname, suffix, max, interval, stop, nil, doneC, false) return doneC, errC } // purgeFile is the internal implementation for PurgeFile which can post purged files to purgec if non-nil. // if donec is non-nil, the function closes it to notify its exit. -func purgeFile(lg *zap.Logger, dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}, purgec chan<- string, donec chan<- struct{}) <-chan error { - errC := make(chan error, 1) - if lg != nil { - lg.Info("started to purge file", - zap.String("dir", dirname), - zap.String("suffix", suffix), - zap.Uint("max", max), - zap.Duration("interval", interval)) - } else { - plog.Infof("started to purge file, dir: %s, suffix: %s, max: %d, interval: %v", dirname, suffix, max, interval) +func purgeFile(lg *zap.Logger, dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}, purgec chan<- string, donec chan<- struct{}, flock bool) <-chan error { + if lg == nil { + lg = zap.NewNop() } + errC := make(chan error, 1) + lg.Info("started to purge file", + zap.String("dir", dirname), + zap.String("suffix", suffix), + zap.Uint("max", max), + zap.Duration("interval", interval)) go func() { if donec != nil { @@ -55,11 +60,6 @@ func purgeFile(lg *zap.Logger, dirname string, suffix string, max uint, interval for { fnames, err := ReadDir(dirname) if err != nil { - if lg != nil { - lg.Warn("failed to read files", zap.String("dir", dirname), zap.Error(err)) - } else { - plog.Warningf("failed to read files, dir: %s, error: %v", dirname, err) - } errC <- err return } @@ -73,38 +73,27 @@ func purgeFile(lg *zap.Logger, dirname string, suffix string, max uint, interval fnames = newfnames for len(newfnames) > int(max) { f := filepath.Join(dirname, newfnames[0]) - l, err := TryLockFile(f, os.O_WRONLY, PrivateFileMode) - if err != nil { - if lg != nil { + var l *LockedFile + if flock { + l, err = TryLockFile(f, os.O_WRONLY, PrivateFileMode) + if err != nil { lg.Warn("failed to lock file", zap.String("path", f), zap.Error(err)) - } else { - plog.Warningf("failed to lock file, path: %s, error: %v", f, err) + break } - break } if err = os.Remove(f); err != nil { - if lg != nil { - lg.Error("failed to remove file", zap.String("path", f), zap.Error(err)) - } else { - plog.Errorf("failed to remove file, path: %s, error: %v", f, err) - } + lg.Error("failed to remove file", zap.String("path", f), zap.Error(err)) errC <- err return } - if err = l.Close(); err != nil { - if lg != nil { + if flock { + if err = l.Close(); err != nil { lg.Error("failed to unlock/close", zap.String("path", l.Name()), zap.Error(err)) - } else { - plog.Errorf("error unlocking %s when purging file (%v)", l.Name(), err) + errC <- err + return } - errC <- err - return - } - if lg != nil { - lg.Info("purged", zap.String("path", f)) - } else { - plog.Infof("purged file %s successfully", f) } + lg.Info("purged", zap.String("path", f)) newfnames = newfnames[1:] } if purgec != nil { diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/read_dir.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/read_dir.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/fileutil/read_dir.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/read_dir.go diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/sync.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/sync.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/fileutil/sync.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/sync.go diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/sync_darwin.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/sync_darwin.go similarity index 87% rename from vendor/go.etcd.io/etcd/pkg/fileutil/sync_darwin.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/sync_darwin.go index 1a2a0abca..1923b276e 100644 --- a/vendor/go.etcd.io/etcd/pkg/fileutil/sync_darwin.go +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/sync_darwin.go @@ -19,7 +19,8 @@ package fileutil import ( "os" - "syscall" + + "golang.org/x/sys/unix" ) // Fsync on HFS/OSX flushes the data on to the physical drive but the drive @@ -27,11 +28,8 @@ import ( // written in out-of-order sequence. Using F_FULLFSYNC ensures that the // physical drive's buffer will also get flushed to the media. func Fsync(f *os.File) error { - _, _, errno := syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), uintptr(syscall.F_FULLFSYNC), uintptr(0)) - if errno == 0 { - return nil - } - return errno + _, err := unix.FcntlInt(f.Fd(), unix.F_FULLFSYNC, 0) + return err } // Fdatasync on darwin platform invokes fcntl(F_FULLFSYNC) for actual persistence diff --git a/vendor/go.etcd.io/etcd/pkg/fileutil/sync_linux.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/sync_linux.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/fileutil/sync_linux.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/sync_linux.go diff --git a/vendor/go.etcd.io/etcd/pkg/tlsutil/cipher_suites.go b/vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/cipher_suites.go similarity index 95% rename from vendor/go.etcd.io/etcd/pkg/tlsutil/cipher_suites.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/cipher_suites.go index d1f1bab94..e1f21755d 100644 --- a/vendor/go.etcd.io/etcd/pkg/tlsutil/cipher_suites.go +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/cipher_suites.go @@ -41,7 +41,7 @@ func GetCipherSuite(s string) (uint16, bool) { return 0, false } -// GetCipherSuites returns a list of corresponding cipher suite IDs. +// GetCipherSuites returns list of corresponding cipher suite IDs. func GetCipherSuites(ss []string) ([]uint16, error) { cs := make([]uint16, len(ss)) for i, s := range ss { diff --git a/vendor/go.etcd.io/etcd/pkg/tlsutil/doc.go b/vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/doc.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/tlsutil/doc.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/doc.go diff --git a/vendor/go.etcd.io/etcd/pkg/tlsutil/tlsutil.go b/vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/tlsutil.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/tlsutil/tlsutil.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/tlsutil.go diff --git a/vendor/go.etcd.io/etcd/pkg/tlsutil/versions.go b/vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/versions.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/tlsutil/versions.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/versions.go diff --git a/vendor/go.etcd.io/etcd/pkg/transport/doc.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/doc.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/transport/doc.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/transport/doc.go diff --git a/vendor/go.etcd.io/etcd/pkg/transport/keepalive_listener.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/keepalive_listener.go similarity index 65% rename from vendor/go.etcd.io/etcd/pkg/transport/keepalive_listener.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/transport/keepalive_listener.go index 4ff8e7f00..2241d8823 100644 --- a/vendor/go.etcd.io/etcd/pkg/transport/keepalive_listener.go +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/keepalive_listener.go @@ -21,26 +21,29 @@ import ( "time" ) -type keepAliveConn interface { - SetKeepAlive(bool) error - SetKeepAlivePeriod(d time.Duration) error -} - // NewKeepAliveListener returns a listener that listens on the given address. // Be careful when wrap around KeepAliveListener with another Listener if TLSInfo is not nil. // Some pkgs (like go/http) might expect Listener to return TLSConn type to start TLS handshake. // http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html +// +// Note(ahrtr): +// only `net.TCPConn` supports `SetKeepAlive` and `SetKeepAlivePeriod` +// by default, so if you want to wrap multiple layers of net.Listener, +// the `keepaliveListener` should be the one which is closest to the +// original `net.Listener` implementation, namely `TCPListener`. func NewKeepAliveListener(l net.Listener, scheme string, tlscfg *tls.Config) (net.Listener, error) { + kal := &keepaliveListener{ + Listener: l, + } + if scheme == "https" { if tlscfg == nil { return nil, fmt.Errorf("cannot listen on TLS for given listener: KeyFile and CertFile are not presented") } - return newTLSKeepaliveListener(l, tlscfg), nil + return newTLSKeepaliveListener(kal, tlscfg), nil } - return &keepaliveListener{ - Listener: l, - }, nil + return kal, nil } type keepaliveListener struct{ net.Listener } @@ -50,13 +53,43 @@ func (kln *keepaliveListener) Accept() (net.Conn, error) { if err != nil { return nil, err } - kac := c.(keepAliveConn) + + kac, err := createKeepaliveConn(c) + if err != nil { + return nil, fmt.Errorf("create keepalive connection failed, %w", err) + } // detection time: tcp_keepalive_time + tcp_keepalive_probes + tcp_keepalive_intvl // default on linux: 30 + 8 * 30 // default on osx: 30 + 8 * 75 - kac.SetKeepAlive(true) - kac.SetKeepAlivePeriod(30 * time.Second) - return c, nil + if err := kac.SetKeepAlive(true); err != nil { + return nil, fmt.Errorf("SetKeepAlive failed, %w", err) + } + if err := kac.SetKeepAlivePeriod(30 * time.Second); err != nil { + return nil, fmt.Errorf("SetKeepAlivePeriod failed, %w", err) + } + return kac, nil +} + +func createKeepaliveConn(c net.Conn) (*keepAliveConn, error) { + tcpc, ok := c.(*net.TCPConn) + if !ok { + return nil, ErrNotTCP + } + return &keepAliveConn{tcpc}, nil +} + +type keepAliveConn struct { + *net.TCPConn +} + +// SetKeepAlive sets keepalive +func (l *keepAliveConn) SetKeepAlive(doKeepAlive bool) error { + return l.TCPConn.SetKeepAlive(doKeepAlive) +} + +// SetKeepAlivePeriod sets keepalive period +func (l *keepAliveConn) SetKeepAlivePeriod(d time.Duration) error { + return l.TCPConn.SetKeepAlivePeriod(d) } // A tlsKeepaliveListener implements a network listener (net.Listener) for TLS connections. @@ -72,12 +105,6 @@ func (l *tlsKeepaliveListener) Accept() (c net.Conn, err error) { if err != nil { return } - kac := c.(keepAliveConn) - // detection time: tcp_keepalive_time + tcp_keepalive_probes + tcp_keepalive_intvl - // default on linux: 30 + 8 * 30 - // default on osx: 30 + 8 * 75 - kac.SetKeepAlive(true) - kac.SetKeepAlivePeriod(30 * time.Second) c = tls.Server(c, l.config) return c, nil } diff --git a/vendor/go.etcd.io/etcd/pkg/transport/limit_listen.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/limit_listen.go similarity index 90% rename from vendor/go.etcd.io/etcd/pkg/transport/limit_listen.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/transport/limit_listen.go index 930c54206..404722ba7 100644 --- a/vendor/go.etcd.io/etcd/pkg/transport/limit_listen.go +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/limit_listen.go @@ -63,6 +63,9 @@ func (l *limitListenerConn) Close() error { return err } +// SetKeepAlive sets keepalive +// +// Deprecated: use (*keepAliveConn) SetKeepAlive instead. func (l *limitListenerConn) SetKeepAlive(doKeepAlive bool) error { tcpc, ok := l.Conn.(*net.TCPConn) if !ok { @@ -71,6 +74,9 @@ func (l *limitListenerConn) SetKeepAlive(doKeepAlive bool) error { return tcpc.SetKeepAlive(doKeepAlive) } +// SetKeepAlivePeriod sets keepalive period +// +// Deprecated: use (*keepAliveConn) SetKeepAlivePeriod instead. func (l *limitListenerConn) SetKeepAlivePeriod(d time.Duration) error { tcpc, ok := l.Conn.(*net.TCPConn) if !ok { diff --git a/vendor/go.etcd.io/etcd/pkg/transport/listener.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener.go similarity index 70% rename from vendor/go.etcd.io/etcd/pkg/transport/listener.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener.go index 7bc6b5ad0..150545d08 100644 --- a/vendor/go.etcd.io/etcd/pkg/transport/listener.go +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener.go @@ -15,6 +15,7 @@ package transport import ( + "context" "crypto/ecdsa" "crypto/elliptic" "crypto/rand" @@ -31,26 +32,87 @@ import ( "strings" "time" - "go.etcd.io/etcd/pkg/fileutil" - "go.etcd.io/etcd/pkg/tlsutil" + "go.etcd.io/etcd/client/pkg/v3/fileutil" + "go.etcd.io/etcd/client/pkg/v3/tlsutil" "go.uber.org/zap" ) // NewListener creates a new listner. func NewListener(addr, scheme string, tlsinfo *TLSInfo) (l net.Listener, err error) { - if l, err = newListener(addr, scheme); err != nil { - return nil, err - } - return wrapTLS(scheme, tlsinfo, l) + return newListener(addr, scheme, WithTLSInfo(tlsinfo)) } -func newListener(addr string, scheme string) (net.Listener, error) { +// NewListenerWithOpts creates a new listener which accpets listener options. +func NewListenerWithOpts(addr, scheme string, opts ...ListenerOption) (net.Listener, error) { + return newListener(addr, scheme, opts...) +} + +func newListener(addr, scheme string, opts ...ListenerOption) (net.Listener, error) { if scheme == "unix" || scheme == "unixs" { // unix sockets via unix://laddr return NewUnixListener(addr) } - return net.Listen("tcp", addr) + + lnOpts := newListenOpts(opts...) + + switch { + case lnOpts.IsSocketOpts(): + // new ListenConfig with socket options. + config, err := newListenConfig(lnOpts.socketOpts) + if err != nil { + return nil, err + } + lnOpts.ListenConfig = config + // check for timeout + fallthrough + case lnOpts.IsTimeout(), lnOpts.IsSocketOpts(): + // timeout listener with socket options. + ln, err := newKeepAliveListener(&lnOpts.ListenConfig, addr) + if err != nil { + return nil, err + } + lnOpts.Listener = &rwTimeoutListener{ + Listener: ln, + readTimeout: lnOpts.readTimeout, + writeTimeout: lnOpts.writeTimeout, + } + case lnOpts.IsTimeout(): + ln, err := newKeepAliveListener(nil, addr) + if err != nil { + return nil, err + } + lnOpts.Listener = &rwTimeoutListener{ + Listener: ln, + readTimeout: lnOpts.readTimeout, + writeTimeout: lnOpts.writeTimeout, + } + default: + ln, err := newKeepAliveListener(nil, addr) + if err != nil { + return nil, err + } + lnOpts.Listener = ln + } + + // only skip if not passing TLSInfo + if lnOpts.skipTLSInfoCheck && !lnOpts.IsTLS() { + return lnOpts.Listener, nil + } + return wrapTLS(scheme, lnOpts.tlsInfo, lnOpts.Listener) +} + +func newKeepAliveListener(cfg *net.ListenConfig, addr string) (ln net.Listener, err error) { + if cfg != nil { + ln, err = cfg.Listen(context.TODO(), "tcp", addr) + } else { + ln, err = net.Listen("tcp", addr) + } + if err != nil { + return + } + + return NewKeepAliveListener(ln, "tcp", nil) } func wrapTLS(scheme string, tlsinfo *TLSInfo, l net.Listener) (net.Listener, error) { @@ -63,9 +125,28 @@ func wrapTLS(scheme string, tlsinfo *TLSInfo, l net.Listener) (net.Listener, err return newTLSListener(l, tlsinfo, checkSAN) } +func newListenConfig(sopts *SocketOpts) (net.ListenConfig, error) { + lc := net.ListenConfig{} + if sopts != nil { + ctls := getControls(sopts) + if len(ctls) > 0 { + lc.Control = ctls.Control + } + } + return lc, nil +} + type TLSInfo struct { - CertFile string - KeyFile string + // CertFile is the _server_ cert, it will also be used as a _client_ certificate if ClientCertFile is empty + CertFile string + // KeyFile is the key for the CertFile + KeyFile string + // ClientCertFile is a _client_ cert for initiating connections when ClientCertAuth is defined. If ClientCertAuth + // is true but this value is empty, the CertFile will be used instead. + ClientCertFile string + // ClientKeyFile is the key for the ClientCertFile + ClientKeyFile string + TrustedCAFile string ClientCertAuth bool CRLFile string @@ -115,16 +196,24 @@ type TLSInfo struct { } func (info TLSInfo) String() string { - return fmt.Sprintf("cert = %s, key = %s, trusted-ca = %s, client-cert-auth = %v, crl-file = %s", info.CertFile, info.KeyFile, info.TrustedCAFile, info.ClientCertAuth, info.CRLFile) + return fmt.Sprintf("cert = %s, key = %s, client-cert=%s, client-key=%s, trusted-ca = %s, client-cert-auth = %v, crl-file = %s", info.CertFile, info.KeyFile, info.ClientCertFile, info.ClientKeyFile, info.TrustedCAFile, info.ClientCertAuth, info.CRLFile) } func (info TLSInfo) Empty() bool { return info.CertFile == "" && info.KeyFile == "" } -func SelfCert(lg *zap.Logger, dirpath string, hosts []string, additionalUsages ...x509.ExtKeyUsage) (info TLSInfo, err error) { +func SelfCert(lg *zap.Logger, dirpath string, hosts []string, selfSignedCertValidity uint, additionalUsages ...x509.ExtKeyUsage) (info TLSInfo, err error) { info.Logger = lg - err = fileutil.TouchDirAll(dirpath) + if selfSignedCertValidity == 0 { + err = fmt.Errorf("selfSignedCertValidity is invalid,it should be greater than 0") + info.Logger.Warn( + "cannot generate cert", + zap.Error(err), + ) + return + } + err = fileutil.TouchDirAll(lg, dirpath) if err != nil { if info.Logger != nil { info.Logger.Warn( @@ -135,13 +224,21 @@ func SelfCert(lg *zap.Logger, dirpath string, hosts []string, additionalUsages . return } - certPath := filepath.Join(dirpath, "cert.pem") - keyPath := filepath.Join(dirpath, "key.pem") + certPath, err := filepath.Abs(filepath.Join(dirpath, "cert.pem")) + if err != nil { + return + } + keyPath, err := filepath.Abs(filepath.Join(dirpath, "key.pem")) + if err != nil { + return + } _, errcert := os.Stat(certPath) _, errkey := os.Stat(keyPath) if errcert == nil && errkey == nil { info.CertFile = certPath info.KeyFile = keyPath + info.ClientCertFile = certPath + info.ClientKeyFile = keyPath info.selfCert = true return } @@ -162,13 +259,20 @@ func SelfCert(lg *zap.Logger, dirpath string, hosts []string, additionalUsages . SerialNumber: serialNumber, Subject: pkix.Name{Organization: []string{"etcd"}}, NotBefore: time.Now(), - NotAfter: time.Now().Add(365 * (24 * time.Hour)), + NotAfter: time.Now().Add(time.Duration(selfSignedCertValidity) * 365 * (24 * time.Hour)), KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, ExtKeyUsage: append([]x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, additionalUsages...), BasicConstraintsValid: true, } + if info.Logger != nil { + info.Logger.Warn( + "automatically generate certificates", + zap.Time("certificate-validity-bound-not-after", tmpl.NotAfter), + ) + } + for _, host := range hosts { h, _, _ := net.SplitHostPort(host) if ip := net.ParseIP(h); ip != nil { @@ -235,7 +339,7 @@ func SelfCert(lg *zap.Logger, dirpath string, hosts []string, additionalUsages . if info.Logger != nil { info.Logger.Info("created key file", zap.String("path", keyPath)) } - return SelfCert(lg, dirpath, hosts) + return SelfCert(lg, dirpath, hosts, selfSignedCertValidity) } // baseConfig is called on initial TLS handshake start. @@ -271,6 +375,17 @@ func (info TLSInfo) baseConfig() (*tls.Config, error) { return nil, err } + // Perform prevalidation of client cert and key if either are provided. This makes sure we crash before accepting any connections. + if (info.ClientKeyFile == "") != (info.ClientCertFile == "") { + return nil, fmt.Errorf("ClientKeyFile and ClientCertFile must both be present or both absent: key: %v, cert: %v]", info.ClientKeyFile, info.ClientCertFile) + } + if info.ClientCertFile != "" { + _, err := tlsutil.NewCert(info.ClientCertFile, info.ClientKeyFile, info.parseFunc) + if err != nil { + return nil, err + } + } + var minVersion uint16 if info.MinVersion != 0 { minVersion = info.MinVersion @@ -344,13 +459,17 @@ func (info TLSInfo) baseConfig() (*tls.Config, error) { return cert, err } cfg.GetClientCertificate = func(unused *tls.CertificateRequestInfo) (cert *tls.Certificate, err error) { - cert, err = tlsutil.NewCert(info.CertFile, info.KeyFile, info.parseFunc) + certfile, keyfile := info.CertFile, info.KeyFile + if info.ClientCertFile != "" { + certfile, keyfile = info.ClientCertFile, info.ClientKeyFile + } + cert, err = tlsutil.NewCert(certfile, keyfile, info.parseFunc) if os.IsNotExist(err) { if info.Logger != nil { info.Logger.Warn( "failed to find client cert files", - zap.String("cert-file", info.CertFile), - zap.String("key-file", info.KeyFile), + zap.String("cert-file", certfile), + zap.String("key-file", keyfile), zap.Error(err), ) } @@ -358,8 +477,8 @@ func (info TLSInfo) baseConfig() (*tls.Config, error) { if info.Logger != nil { info.Logger.Warn( "failed to create client certificate", - zap.String("cert-file", info.CertFile), - zap.String("key-file", info.KeyFile), + zap.String("cert-file", certfile), + zap.String("key-file", keyfile), zap.Error(err), ) } @@ -385,6 +504,10 @@ func (info TLSInfo) ServerConfig() (*tls.Config, error) { return nil, err } + if info.Logger == nil { + info.Logger = zap.NewNop() + } + cfg.ClientAuth = tls.NoClientCert if info.TrustedCAFile != "" || info.ClientCertAuth { cfg.ClientAuth = tls.RequireAndVerifyClientCert @@ -392,6 +515,8 @@ func (info TLSInfo) ServerConfig() (*tls.Config, error) { cs := info.cafiles() if len(cs) > 0 { + info.Logger.Info("Loading cert pool", zap.Strings("cs", cs), + zap.Any("tlsinfo", info)) cp, err := tlsutil.NewCertPool(cs) if err != nil { return nil, err @@ -435,7 +560,7 @@ func (info TLSInfo) ClientConfig() (*tls.Config, error) { if info.EmptyCN { hasNonEmptyCN := false cn := "" - tlsutil.NewCert(info.CertFile, info.KeyFile, func(certPEMBlock []byte, keyPEMBlock []byte) (tls.Certificate, error) { + _, err := tlsutil.NewCert(info.CertFile, info.KeyFile, func(certPEMBlock []byte, keyPEMBlock []byte) (tls.Certificate, error) { var block *pem.Block block, _ = pem.Decode(certPEMBlock) cert, err := x509.ParseCertificate(block.Bytes) @@ -448,8 +573,11 @@ func (info TLSInfo) ClientConfig() (*tls.Config, error) { } return tls.X509KeyPair(certPEMBlock, keyPEMBlock) }) + if err != nil { + return nil, err + } if hasNonEmptyCN { - return nil, fmt.Errorf("cert has non empty Common Name (%s)", cn) + return nil, fmt.Errorf("cert has non empty Common Name (%s): %s", cn, info.CertFile) } } diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener_opts.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener_opts.go new file mode 100644 index 000000000..ad4f6904d --- /dev/null +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener_opts.go @@ -0,0 +1,76 @@ +package transport + +import ( + "net" + "time" +) + +type ListenerOptions struct { + Listener net.Listener + ListenConfig net.ListenConfig + + socketOpts *SocketOpts + tlsInfo *TLSInfo + skipTLSInfoCheck bool + writeTimeout time.Duration + readTimeout time.Duration +} + +func newListenOpts(opts ...ListenerOption) *ListenerOptions { + lnOpts := &ListenerOptions{} + lnOpts.applyOpts(opts) + return lnOpts +} + +func (lo *ListenerOptions) applyOpts(opts []ListenerOption) { + for _, opt := range opts { + opt(lo) + } +} + +// IsTimeout returns true if the listener has a read/write timeout defined. +func (lo *ListenerOptions) IsTimeout() bool { return lo.readTimeout != 0 || lo.writeTimeout != 0 } + +// IsSocketOpts returns true if the listener options includes socket options. +func (lo *ListenerOptions) IsSocketOpts() bool { + if lo.socketOpts == nil { + return false + } + return lo.socketOpts.ReusePort || lo.socketOpts.ReuseAddress +} + +// IsTLS returns true if listner options includes TLSInfo. +func (lo *ListenerOptions) IsTLS() bool { + if lo.tlsInfo == nil { + return false + } + return !lo.tlsInfo.Empty() +} + +// ListenerOption are options which can be applied to the listener. +type ListenerOption func(*ListenerOptions) + +// WithTimeout allows for a read or write timeout to be applied to the listener. +func WithTimeout(read, write time.Duration) ListenerOption { + return func(lo *ListenerOptions) { + lo.writeTimeout = write + lo.readTimeout = read + } +} + +// WithSocketOpts defines socket options that will be applied to the listener. +func WithSocketOpts(s *SocketOpts) ListenerOption { + return func(lo *ListenerOptions) { lo.socketOpts = s } +} + +// WithTLSInfo adds TLS credentials to the listener. +func WithTLSInfo(t *TLSInfo) ListenerOption { + return func(lo *ListenerOptions) { lo.tlsInfo = t } +} + +// WithSkipTLSInfoCheck when true a transport can be created with an https scheme +// without passing TLSInfo, circumventing not presented error. Skipping this check +// also requires that TLSInfo is not passed. +func WithSkipTLSInfoCheck(skip bool) ListenerOption { + return func(lo *ListenerOptions) { lo.skipTLSInfoCheck = skip } +} diff --git a/vendor/go.etcd.io/etcd/pkg/transport/listener_tls.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener_tls.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/transport/listener_tls.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener_tls.go diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt.go new file mode 100644 index 000000000..fe028c613 --- /dev/null +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt.go @@ -0,0 +1,45 @@ +package transport + +import ( + "syscall" +) + +type Controls []func(network, addr string, conn syscall.RawConn) error + +func (ctls Controls) Control(network, addr string, conn syscall.RawConn) error { + for _, s := range ctls { + if err := s(network, addr, conn); err != nil { + return err + } + } + return nil +} + +type SocketOpts struct { + // ReusePort enables socket option SO_REUSEPORT [1] which allows rebind of + // a port already in use. User should keep in mind that flock can fail + // in which case lock on data file could result in unexpected + // condition. User should take caution to protect against lock race. + // [1] https://man7.org/linux/man-pages/man7/socket.7.html + ReusePort bool `json:"reuse-port"` + // ReuseAddress enables a socket option SO_REUSEADDR which allows + // binding to an address in `TIME_WAIT` state. Useful to improve MTTR + // in cases where etcd slow to restart due to excessive `TIME_WAIT`. + // [1] https://man7.org/linux/man-pages/man7/socket.7.html + ReuseAddress bool `json:"reuse-address"` +} + +func getControls(sopts *SocketOpts) Controls { + ctls := Controls{} + if sopts.ReuseAddress { + ctls = append(ctls, setReuseAddress) + } + if sopts.ReusePort { + ctls = append(ctls, setReusePort) + } + return ctls +} + +func (sopts *SocketOpts) Empty() bool { + return !sopts.ReuseAddress && !sopts.ReusePort +} diff --git a/vendor/github.com/coreos/pkg/capnslog/log_hijack.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt_solaris.go similarity index 55% rename from vendor/github.com/coreos/pkg/capnslog/log_hijack.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt_solaris.go index 970086b9f..495c73636 100644 --- a/vendor/github.com/coreos/pkg/capnslog/log_hijack.go +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt_solaris.go @@ -1,4 +1,4 @@ -// Copyright 2015 CoreOS, Inc. +// Copyright 2021 The etcd Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,28 +12,24 @@ // See the License for the specific language governing permissions and // limitations under the License. -package capnslog +//go:build solaris +// +build solaris + +package transport import ( - "log" -) + "fmt" + "syscall" -func initHijack() { - pkg := NewPackageLogger("log", "") - w := packageWriter{pkg} - log.SetFlags(0) - log.SetPrefix("") - log.SetOutput(w) -} + "golang.org/x/sys/unix" +) -type packageWriter struct { - pl *PackageLogger +func setReusePort(network, address string, c syscall.RawConn) error { + return fmt.Errorf("port reuse is not supported on Solaris") } -func (p packageWriter) Write(b []byte) (int, error) { - if p.pl.level < INFO { - return 0, nil - } - p.pl.internalLog(calldepth+2, INFO, string(b)) - return len(b), nil +func setReuseAddress(network, address string, conn syscall.RawConn) error { + return conn.Control(func(fd uintptr) { + syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, unix.SO_REUSEADDR, 1) + }) } diff --git a/vendor/go.etcd.io/etcd/pkg/systemd/journal.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt_unix.go similarity index 50% rename from vendor/go.etcd.io/etcd/pkg/systemd/journal.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt_unix.go index b861c6942..e2cc6f482 100644 --- a/vendor/go.etcd.io/etcd/pkg/systemd/journal.go +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt_unix.go @@ -1,4 +1,4 @@ -// Copyright 2018 The etcd Authors +// Copyright 2021 The etcd Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,18 +12,25 @@ // See the License for the specific language governing permissions and // limitations under the License. -package systemd +//go:build !windows && !solaris +// +build !windows,!solaris -import "net" +package transport -// DialJournal returns no error if the process can dial journal socket. -// Returns an error if dial failed, whichi indicates journald is not available -// (e.g. run embedded etcd as docker daemon). -// Reference: https://github.com/coreos/go-systemd/blob/master/journal/journal.go. -func DialJournal() error { - conn, err := net.Dial("unixgram", "/run/systemd/journal/socket") - if conn != nil { - defer conn.Close() - } - return err +import ( + "syscall" + + "golang.org/x/sys/unix" +) + +func setReusePort(network, address string, conn syscall.RawConn) error { + return conn.Control(func(fd uintptr) { + syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1) + }) +} + +func setReuseAddress(network, address string, conn syscall.RawConn) error { + return conn.Control(func(fd uintptr) { + syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, unix.SO_REUSEADDR, 1) + }) } diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt_windows.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt_windows.go new file mode 100644 index 000000000..4e5af70b1 --- /dev/null +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt_windows.go @@ -0,0 +1,19 @@ +//go:build windows +// +build windows + +package transport + +import ( + "fmt" + "syscall" +) + +func setReusePort(network, address string, c syscall.RawConn) error { + return fmt.Errorf("port reuse is not supported on Windows") +} + +// Windows supports SO_REUSEADDR, but it may cause undefined behavior, as +// there is no protection against port hijacking. +func setReuseAddress(network, addr string, conn syscall.RawConn) error { + return fmt.Errorf("address reuse is not supported on Windows") +} diff --git a/vendor/go.etcd.io/etcd/pkg/transport/timeout_conn.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_conn.go similarity index 77% rename from vendor/go.etcd.io/etcd/pkg/transport/timeout_conn.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_conn.go index 7e8c02030..80e329394 100644 --- a/vendor/go.etcd.io/etcd/pkg/transport/timeout_conn.go +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_conn.go @@ -21,13 +21,13 @@ import ( type timeoutConn struct { net.Conn - wtimeoutd time.Duration - rdtimeoutd time.Duration + writeTimeout time.Duration + readTimeout time.Duration } func (c timeoutConn) Write(b []byte) (n int, err error) { - if c.wtimeoutd > 0 { - if err := c.SetWriteDeadline(time.Now().Add(c.wtimeoutd)); err != nil { + if c.writeTimeout > 0 { + if err := c.SetWriteDeadline(time.Now().Add(c.writeTimeout)); err != nil { return 0, err } } @@ -35,8 +35,8 @@ func (c timeoutConn) Write(b []byte) (n int, err error) { } func (c timeoutConn) Read(b []byte) (n int, err error) { - if c.rdtimeoutd > 0 { - if err := c.SetReadDeadline(time.Now().Add(c.rdtimeoutd)); err != nil { + if c.readTimeout > 0 { + if err := c.SetReadDeadline(time.Now().Add(c.readTimeout)); err != nil { return 0, err } } diff --git a/vendor/go.etcd.io/etcd/pkg/transport/timeout_dialer.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_dialer.go similarity index 91% rename from vendor/go.etcd.io/etcd/pkg/transport/timeout_dialer.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_dialer.go index 6ae39ecfc..9c0245d31 100644 --- a/vendor/go.etcd.io/etcd/pkg/transport/timeout_dialer.go +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_dialer.go @@ -28,9 +28,9 @@ type rwTimeoutDialer struct { func (d *rwTimeoutDialer) Dial(network, address string) (net.Conn, error) { conn, err := d.Dialer.Dial(network, address) tconn := &timeoutConn{ - rdtimeoutd: d.rdtimeoutd, - wtimeoutd: d.wtimeoutd, - Conn: conn, + readTimeout: d.rdtimeoutd, + writeTimeout: d.wtimeoutd, + Conn: conn, } return tconn, err } diff --git a/vendor/go.etcd.io/etcd/pkg/transport/timeout_listener.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_listener.go similarity index 70% rename from vendor/go.etcd.io/etcd/pkg/transport/timeout_listener.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_listener.go index 273e99fe0..5d74bd70c 100644 --- a/vendor/go.etcd.io/etcd/pkg/transport/timeout_listener.go +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_listener.go @@ -22,26 +22,14 @@ import ( // NewTimeoutListener returns a listener that listens on the given address. // If read/write on the accepted connection blocks longer than its time limit, // it will return timeout error. -func NewTimeoutListener(addr string, scheme string, tlsinfo *TLSInfo, rdtimeoutd, wtimeoutd time.Duration) (net.Listener, error) { - ln, err := newListener(addr, scheme) - if err != nil { - return nil, err - } - ln = &rwTimeoutListener{ - Listener: ln, - rdtimeoutd: rdtimeoutd, - wtimeoutd: wtimeoutd, - } - if ln, err = wrapTLS(scheme, tlsinfo, ln); err != nil { - return nil, err - } - return ln, nil +func NewTimeoutListener(addr string, scheme string, tlsinfo *TLSInfo, readTimeout, writeTimeout time.Duration) (net.Listener, error) { + return newListener(addr, scheme, WithTimeout(readTimeout, writeTimeout), WithTLSInfo(tlsinfo)) } type rwTimeoutListener struct { net.Listener - wtimeoutd time.Duration - rdtimeoutd time.Duration + writeTimeout time.Duration + readTimeout time.Duration } func (rwln *rwTimeoutListener) Accept() (net.Conn, error) { @@ -50,8 +38,8 @@ func (rwln *rwTimeoutListener) Accept() (net.Conn, error) { return nil, err } return timeoutConn{ - Conn: c, - wtimeoutd: rwln.wtimeoutd, - rdtimeoutd: rwln.rdtimeoutd, + Conn: c, + writeTimeout: rwln.writeTimeout, + readTimeout: rwln.readTimeout, }, nil } diff --git a/vendor/go.etcd.io/etcd/pkg/transport/timeout_transport.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_transport.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/transport/timeout_transport.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_transport.go diff --git a/vendor/go.etcd.io/etcd/pkg/transport/tls.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/tls.go similarity index 91% rename from vendor/go.etcd.io/etcd/pkg/transport/tls.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/transport/tls.go index 62fe0d385..8c3a35b14 100644 --- a/vendor/go.etcd.io/etcd/pkg/transport/tls.go +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/tls.go @@ -15,6 +15,7 @@ package transport import ( + "context" "fmt" "strings" "time" @@ -27,6 +28,8 @@ func ValidateSecureEndpoints(tlsInfo TLSInfo, eps []string) ([]string, error) { if err != nil { return nil, err } + defer t.CloseIdleConnections() + var errs []string var endpoints []string for _, ep := range eps { @@ -34,7 +37,7 @@ func ValidateSecureEndpoints(tlsInfo TLSInfo, eps []string) ([]string, error) { errs = append(errs, fmt.Sprintf("%q is insecure", ep)) continue } - conn, cerr := t.Dial("tcp", ep[len("https://"):]) + conn, cerr := t.DialContext(context.Background(), "tcp", ep[len("https://"):]) if cerr != nil { errs = append(errs, fmt.Sprintf("%q failed to dial (%v)", ep, cerr)) continue diff --git a/vendor/go.etcd.io/etcd/pkg/transport/transport.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/transport.go similarity index 74% rename from vendor/go.etcd.io/etcd/pkg/transport/transport.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/transport/transport.go index 4a7fe69d2..648512772 100644 --- a/vendor/go.etcd.io/etcd/pkg/transport/transport.go +++ b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/transport.go @@ -15,6 +15,7 @@ package transport import ( + "context" "net" "net/http" "strings" @@ -31,29 +32,34 @@ func NewTransport(info TLSInfo, dialtimeoutd time.Duration) (*http.Transport, er t := &http.Transport{ Proxy: http.ProxyFromEnvironment, - Dial: (&net.Dialer{ + DialContext: (&net.Dialer{ Timeout: dialtimeoutd, // value taken from http.DefaultTransport KeepAlive: 30 * time.Second, - }).Dial, + }).DialContext, // value taken from http.DefaultTransport TLSHandshakeTimeout: 10 * time.Second, TLSClientConfig: cfg, } - dialer := (&net.Dialer{ + dialer := &net.Dialer{ Timeout: dialtimeoutd, KeepAlive: 30 * time.Second, - }) - dial := func(net, addr string) (net.Conn, error) { - return dialer.Dial("unix", addr) } + dialContext := func(ctx context.Context, net, addr string) (net.Conn, error) { + return dialer.DialContext(ctx, "unix", addr) + } tu := &http.Transport{ Proxy: http.ProxyFromEnvironment, - Dial: dial, + DialContext: dialContext, TLSHandshakeTimeout: 10 * time.Second, TLSClientConfig: cfg, + // Cost of reopening connection on sockets is low, and they are mostly used in testing. + // Long living unix-transport connections were leading to 'leak' test flakes. + // Alternativly the returned Transport (t) should override CloseIdleConnections to + // forward it to 'tu' as well. + IdleConnTimeout: time.Microsecond, } ut := &unixTransport{tu} diff --git a/vendor/go.etcd.io/etcd/pkg/transport/unix_listener.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/unix_listener.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/transport/unix_listener.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/transport/unix_listener.go diff --git a/vendor/go.etcd.io/etcd/pkg/types/doc.go b/vendor/go.etcd.io/etcd/client/pkg/v3/types/doc.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/types/doc.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/types/doc.go diff --git a/vendor/go.etcd.io/etcd/pkg/types/id.go b/vendor/go.etcd.io/etcd/client/pkg/v3/types/id.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/types/id.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/types/id.go diff --git a/vendor/go.etcd.io/etcd/pkg/types/set.go b/vendor/go.etcd.io/etcd/client/pkg/v3/types/set.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/types/set.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/types/set.go diff --git a/vendor/go.etcd.io/etcd/pkg/types/slice.go b/vendor/go.etcd.io/etcd/client/pkg/v3/types/slice.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/types/slice.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/types/slice.go diff --git a/vendor/go.etcd.io/etcd/pkg/types/urls.go b/vendor/go.etcd.io/etcd/client/pkg/v3/types/urls.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/types/urls.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/types/urls.go diff --git a/vendor/go.etcd.io/etcd/pkg/types/urlsmap.go b/vendor/go.etcd.io/etcd/client/pkg/v3/types/urlsmap.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/types/urlsmap.go rename to vendor/go.etcd.io/etcd/client/pkg/v3/types/urlsmap.go diff --git a/vendor/go.etcd.io/etcd/pkg/logutil/discard_logger.go b/vendor/go.etcd.io/etcd/pkg/logutil/discard_logger.go deleted file mode 100644 index 81b0a9d03..000000000 --- a/vendor/go.etcd.io/etcd/pkg/logutil/discard_logger.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package logutil - -import ( - "log" - - "google.golang.org/grpc/grpclog" -) - -// assert that "discardLogger" satisfy "Logger" interface -var _ Logger = &discardLogger{} - -// NewDiscardLogger returns a new Logger that discards everything except "fatal". -func NewDiscardLogger() Logger { return &discardLogger{} } - -type discardLogger struct{} - -func (l *discardLogger) Info(args ...interface{}) {} -func (l *discardLogger) Infoln(args ...interface{}) {} -func (l *discardLogger) Infof(format string, args ...interface{}) {} -func (l *discardLogger) Warning(args ...interface{}) {} -func (l *discardLogger) Warningln(args ...interface{}) {} -func (l *discardLogger) Warningf(format string, args ...interface{}) {} -func (l *discardLogger) Error(args ...interface{}) {} -func (l *discardLogger) Errorln(args ...interface{}) {} -func (l *discardLogger) Errorf(format string, args ...interface{}) {} -func (l *discardLogger) Fatal(args ...interface{}) { log.Fatal(args...) } -func (l *discardLogger) Fatalln(args ...interface{}) { log.Fatalln(args...) } -func (l *discardLogger) Fatalf(format string, args ...interface{}) { log.Fatalf(format, args...) } -func (l *discardLogger) V(lvl int) bool { - return false -} -func (l *discardLogger) Lvl(lvl int) grpclog.LoggerV2 { return l } diff --git a/vendor/go.etcd.io/etcd/pkg/logutil/doc.go b/vendor/go.etcd.io/etcd/pkg/logutil/doc.go deleted file mode 100644 index e919f2499..000000000 --- a/vendor/go.etcd.io/etcd/pkg/logutil/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package logutil includes utilities to facilitate logging. -package logutil diff --git a/vendor/go.etcd.io/etcd/pkg/logutil/log_level.go b/vendor/go.etcd.io/etcd/pkg/logutil/log_level.go deleted file mode 100644 index d57e17394..000000000 --- a/vendor/go.etcd.io/etcd/pkg/logutil/log_level.go +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2019 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package logutil - -import ( - "fmt" - - "github.com/coreos/pkg/capnslog" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" -) - -var DefaultLogLevel = "info" - -// ConvertToZapLevel converts log level string to zapcore.Level. -func ConvertToZapLevel(lvl string) zapcore.Level { - switch lvl { - case "debug": - return zap.DebugLevel - case "info": - return zap.InfoLevel - case "warn": - return zap.WarnLevel - case "error": - return zap.ErrorLevel - case "dpanic": - return zap.DPanicLevel - case "panic": - return zap.PanicLevel - case "fatal": - return zap.FatalLevel - default: - panic(fmt.Sprintf("unknown level %q", lvl)) - } -} - -// ConvertToCapnslogLogLevel convert log level string to capnslog.LogLevel. -// TODO: deprecate this in 3.5 -func ConvertToCapnslogLogLevel(lvl string) capnslog.LogLevel { - switch lvl { - case "debug": - return capnslog.DEBUG - case "info": - return capnslog.INFO - case "warn": - return capnslog.WARNING - case "error": - return capnslog.ERROR - case "dpanic": - return capnslog.CRITICAL - case "panic": - return capnslog.CRITICAL - case "fatal": - return capnslog.CRITICAL - default: - panic(fmt.Sprintf("unknown level %q", lvl)) - } -} diff --git a/vendor/go.etcd.io/etcd/pkg/logutil/logger.go b/vendor/go.etcd.io/etcd/pkg/logutil/logger.go deleted file mode 100644 index ab7e469bc..000000000 --- a/vendor/go.etcd.io/etcd/pkg/logutil/logger.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package logutil - -import "google.golang.org/grpc/grpclog" - -// Logger defines logging interface. -// TODO: deprecate in v3.5. -type Logger interface { - grpclog.LoggerV2 - - // Lvl returns logger if logger's verbosity level >= "lvl". - // Otherwise, logger that discards everything. - Lvl(lvl int) grpclog.LoggerV2 -} - -// assert that "defaultLogger" satisfy "Logger" interface -var _ Logger = &defaultLogger{} - -// NewLogger wraps "grpclog.LoggerV2" that implements "Logger" interface. -// -// For example: -// -// var defaultLogger Logger -// g := grpclog.NewLoggerV2WithVerbosity(os.Stderr, os.Stderr, os.Stderr, 4) -// defaultLogger = NewLogger(g) -func NewLogger(g grpclog.LoggerV2) Logger { return &defaultLogger{g: g} } - -type defaultLogger struct { - g grpclog.LoggerV2 -} - -func (l *defaultLogger) Info(args ...interface{}) { l.g.Info(args...) } -func (l *defaultLogger) Infoln(args ...interface{}) { l.g.Info(args...) } -func (l *defaultLogger) Infof(format string, args ...interface{}) { l.g.Infof(format, args...) } -func (l *defaultLogger) Warning(args ...interface{}) { l.g.Warning(args...) } -func (l *defaultLogger) Warningln(args ...interface{}) { l.g.Warning(args...) } -func (l *defaultLogger) Warningf(format string, args ...interface{}) { l.g.Warningf(format, args...) } -func (l *defaultLogger) Error(args ...interface{}) { l.g.Error(args...) } -func (l *defaultLogger) Errorln(args ...interface{}) { l.g.Error(args...) } -func (l *defaultLogger) Errorf(format string, args ...interface{}) { l.g.Errorf(format, args...) } -func (l *defaultLogger) Fatal(args ...interface{}) { l.g.Fatal(args...) } -func (l *defaultLogger) Fatalln(args ...interface{}) { l.g.Fatal(args...) } -func (l *defaultLogger) Fatalf(format string, args ...interface{}) { l.g.Fatalf(format, args...) } -func (l *defaultLogger) V(lvl int) bool { return l.g.V(lvl) } -func (l *defaultLogger) Lvl(lvl int) grpclog.LoggerV2 { - if l.g.V(lvl) { - return l - } - return &discardLogger{} -} diff --git a/vendor/go.etcd.io/etcd/pkg/logutil/merge_logger.go b/vendor/go.etcd.io/etcd/pkg/logutil/merge_logger.go deleted file mode 100644 index 866b6f7a8..000000000 --- a/vendor/go.etcd.io/etcd/pkg/logutil/merge_logger.go +++ /dev/null @@ -1,194 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package logutil - -import ( - "fmt" - "sync" - "time" - - "github.com/coreos/pkg/capnslog" -) - -var ( - defaultMergePeriod = time.Second - defaultTimeOutputScale = 10 * time.Millisecond - - outputInterval = time.Second -) - -// line represents a log line that can be printed out -// through capnslog.PackageLogger. -type line struct { - level capnslog.LogLevel - str string -} - -func (l line) append(s string) line { - return line{ - level: l.level, - str: l.str + " " + s, - } -} - -// status represents the merge status of a line. -type status struct { - period time.Duration - - start time.Time // start time of latest merge period - count int // number of merged lines from starting -} - -func (s *status) isInMergePeriod(now time.Time) bool { - return s.period == 0 || s.start.Add(s.period).After(now) -} - -func (s *status) isEmpty() bool { return s.count == 0 } - -func (s *status) summary(now time.Time) string { - ts := s.start.Round(defaultTimeOutputScale) - took := now.Round(defaultTimeOutputScale).Sub(ts) - return fmt.Sprintf("[merged %d repeated lines in %s]", s.count, took) -} - -func (s *status) reset(now time.Time) { - s.start = now - s.count = 0 -} - -// MergeLogger supports merge logging, which merges repeated log lines -// and prints summary log lines instead. -// -// For merge logging, MergeLogger prints out the line when the line appears -// at the first time. MergeLogger holds the same log line printed within -// defaultMergePeriod, and prints out summary log line at the end of defaultMergePeriod. -// It stops merging when the line doesn't appear within the -// defaultMergePeriod. -type MergeLogger struct { - *capnslog.PackageLogger - - mu sync.Mutex // protect statusm - statusm map[line]*status -} - -func NewMergeLogger(logger *capnslog.PackageLogger) *MergeLogger { - l := &MergeLogger{ - PackageLogger: logger, - statusm: make(map[line]*status), - } - go l.outputLoop() - return l -} - -func (l *MergeLogger) MergeInfo(entries ...interface{}) { - l.merge(line{ - level: capnslog.INFO, - str: fmt.Sprint(entries...), - }) -} - -func (l *MergeLogger) MergeInfof(format string, args ...interface{}) { - l.merge(line{ - level: capnslog.INFO, - str: fmt.Sprintf(format, args...), - }) -} - -func (l *MergeLogger) MergeNotice(entries ...interface{}) { - l.merge(line{ - level: capnslog.NOTICE, - str: fmt.Sprint(entries...), - }) -} - -func (l *MergeLogger) MergeNoticef(format string, args ...interface{}) { - l.merge(line{ - level: capnslog.NOTICE, - str: fmt.Sprintf(format, args...), - }) -} - -func (l *MergeLogger) MergeWarning(entries ...interface{}) { - l.merge(line{ - level: capnslog.WARNING, - str: fmt.Sprint(entries...), - }) -} - -func (l *MergeLogger) MergeWarningf(format string, args ...interface{}) { - l.merge(line{ - level: capnslog.WARNING, - str: fmt.Sprintf(format, args...), - }) -} - -func (l *MergeLogger) MergeError(entries ...interface{}) { - l.merge(line{ - level: capnslog.ERROR, - str: fmt.Sprint(entries...), - }) -} - -func (l *MergeLogger) MergeErrorf(format string, args ...interface{}) { - l.merge(line{ - level: capnslog.ERROR, - str: fmt.Sprintf(format, args...), - }) -} - -func (l *MergeLogger) merge(ln line) { - l.mu.Lock() - - // increase count if the logger is merging the line - if status, ok := l.statusm[ln]; ok { - status.count++ - l.mu.Unlock() - return - } - - // initialize status of the line - l.statusm[ln] = &status{ - period: defaultMergePeriod, - start: time.Now(), - } - // release the lock before IO operation - l.mu.Unlock() - // print out the line at its first time - l.PackageLogger.Logf(ln.level, ln.str) -} - -func (l *MergeLogger) outputLoop() { - for now := range time.Tick(outputInterval) { - var outputs []line - - l.mu.Lock() - for ln, status := range l.statusm { - if status.isInMergePeriod(now) { - continue - } - if status.isEmpty() { - delete(l.statusm, ln) - continue - } - outputs = append(outputs, ln.append(status.summary(now))) - status.reset(now) - } - l.mu.Unlock() - - for _, o := range outputs { - l.PackageLogger.Logf(o.level, o.str) - } - } -} diff --git a/vendor/go.etcd.io/etcd/pkg/logutil/package_logger.go b/vendor/go.etcd.io/etcd/pkg/logutil/package_logger.go deleted file mode 100644 index d3f8cb2bf..000000000 --- a/vendor/go.etcd.io/etcd/pkg/logutil/package_logger.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package logutil - -import ( - "github.com/coreos/pkg/capnslog" - "google.golang.org/grpc/grpclog" -) - -// assert that "packageLogger" satisfy "Logger" interface -var _ Logger = &packageLogger{} - -// NewPackageLogger wraps "*capnslog.PackageLogger" that implements "Logger" interface. -// -// For example: -// -// var defaultLogger Logger -// defaultLogger = NewPackageLogger("go.etcd.io/etcd", "snapshot") -func NewPackageLogger(repo, pkg string) Logger { - return &packageLogger{p: capnslog.NewPackageLogger(repo, pkg)} -} - -type packageLogger struct { - p *capnslog.PackageLogger -} - -func (l *packageLogger) Info(args ...interface{}) { l.p.Info(args...) } -func (l *packageLogger) Infoln(args ...interface{}) { l.p.Info(args...) } -func (l *packageLogger) Infof(format string, args ...interface{}) { l.p.Infof(format, args...) } -func (l *packageLogger) Warning(args ...interface{}) { l.p.Warning(args...) } -func (l *packageLogger) Warningln(args ...interface{}) { l.p.Warning(args...) } -func (l *packageLogger) Warningf(format string, args ...interface{}) { l.p.Warningf(format, args...) } -func (l *packageLogger) Error(args ...interface{}) { l.p.Error(args...) } -func (l *packageLogger) Errorln(args ...interface{}) { l.p.Error(args...) } -func (l *packageLogger) Errorf(format string, args ...interface{}) { l.p.Errorf(format, args...) } -func (l *packageLogger) Fatal(args ...interface{}) { l.p.Fatal(args...) } -func (l *packageLogger) Fatalln(args ...interface{}) { l.p.Fatal(args...) } -func (l *packageLogger) Fatalf(format string, args ...interface{}) { l.p.Fatalf(format, args...) } -func (l *packageLogger) V(lvl int) bool { - return l.p.LevelAt(capnslog.LogLevel(lvl)) -} -func (l *packageLogger) Lvl(lvl int) grpclog.LoggerV2 { - if l.p.LevelAt(capnslog.LogLevel(lvl)) { - return l - } - return &discardLogger{} -} diff --git a/vendor/go.etcd.io/etcd/pkg/logutil/zap.go b/vendor/go.etcd.io/etcd/pkg/logutil/zap.go deleted file mode 100644 index f88b12158..000000000 --- a/vendor/go.etcd.io/etcd/pkg/logutil/zap.go +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2019 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package logutil - -import ( - "sort" - "time" - - "go.uber.org/zap" - "go.uber.org/zap/zapcore" -) - -// DefaultZapLoggerConfig defines default zap logger configuration. -var DefaultZapLoggerConfig = zap.Config{ - Level: zap.NewAtomicLevelAt(ConvertToZapLevel(DefaultLogLevel)), - - Development: false, - Sampling: &zap.SamplingConfig{ - Initial: 100, - Thereafter: 100, - }, - - Encoding: "json", - - // copied from "zap.NewProductionEncoderConfig" with some updates - EncoderConfig: zapcore.EncoderConfig{ - TimeKey: "ts", - LevelKey: "level", - NameKey: "logger", - CallerKey: "caller", - MessageKey: "msg", - StacktraceKey: "stacktrace", - LineEnding: zapcore.DefaultLineEnding, - EncodeLevel: zapcore.LowercaseLevelEncoder, - - // Custom EncodeTime function to ensure we match format and precision of historic capnslog timestamps - EncodeTime: func(t time.Time, enc zapcore.PrimitiveArrayEncoder) { - enc.AppendString(t.Format("2006-01-02T15:04:05.999999Z0700")) - }, - - EncodeDuration: zapcore.StringDurationEncoder, - EncodeCaller: zapcore.ShortCallerEncoder, - }, - - // Use "/dev/null" to discard all - OutputPaths: []string{"stderr"}, - ErrorOutputPaths: []string{"stderr"}, -} - -// MergeOutputPaths merges logging output paths, resolving conflicts. -func MergeOutputPaths(cfg zap.Config) zap.Config { - outputs := make(map[string]struct{}) - for _, v := range cfg.OutputPaths { - outputs[v] = struct{}{} - } - outputSlice := make([]string, 0) - if _, ok := outputs["/dev/null"]; ok { - // "/dev/null" to discard all - outputSlice = []string{"/dev/null"} - } else { - for k := range outputs { - outputSlice = append(outputSlice, k) - } - } - cfg.OutputPaths = outputSlice - sort.Strings(cfg.OutputPaths) - - errOutputs := make(map[string]struct{}) - for _, v := range cfg.ErrorOutputPaths { - errOutputs[v] = struct{}{} - } - errOutputSlice := make([]string, 0) - if _, ok := errOutputs["/dev/null"]; ok { - // "/dev/null" to discard all - errOutputSlice = []string{"/dev/null"} - } else { - for k := range errOutputs { - errOutputSlice = append(errOutputSlice, k) - } - } - cfg.ErrorOutputPaths = errOutputSlice - sort.Strings(cfg.ErrorOutputPaths) - - return cfg -} diff --git a/vendor/go.etcd.io/etcd/pkg/logutil/zap_grpc.go b/vendor/go.etcd.io/etcd/pkg/logutil/zap_grpc.go deleted file mode 100644 index 3f48d813d..000000000 --- a/vendor/go.etcd.io/etcd/pkg/logutil/zap_grpc.go +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package logutil - -import ( - "go.uber.org/zap" - "go.uber.org/zap/zapcore" - "google.golang.org/grpc/grpclog" -) - -// NewGRPCLoggerV2 converts "*zap.Logger" to "grpclog.LoggerV2". -// It discards all INFO level logging in gRPC, if debug level -// is not enabled in "*zap.Logger". -func NewGRPCLoggerV2(lcfg zap.Config) (grpclog.LoggerV2, error) { - lg, err := lcfg.Build(zap.AddCallerSkip(1)) // to annotate caller outside of "logutil" - if err != nil { - return nil, err - } - return &zapGRPCLogger{lg: lg, sugar: lg.Sugar()}, nil -} - -// NewGRPCLoggerV2FromZapCore creates "grpclog.LoggerV2" from "zap.Core" -// and "zapcore.WriteSyncer". It discards all INFO level logging in gRPC, -// if debug level is not enabled in "*zap.Logger". -func NewGRPCLoggerV2FromZapCore(cr zapcore.Core, syncer zapcore.WriteSyncer) grpclog.LoggerV2 { - // "AddCallerSkip" to annotate caller outside of "logutil" - lg := zap.New(cr, zap.AddCaller(), zap.AddCallerSkip(1), zap.ErrorOutput(syncer)) - return &zapGRPCLogger{lg: lg, sugar: lg.Sugar()} -} - -type zapGRPCLogger struct { - lg *zap.Logger - sugar *zap.SugaredLogger -} - -func (zl *zapGRPCLogger) Info(args ...interface{}) { - if !zl.lg.Core().Enabled(zapcore.DebugLevel) { - return - } - zl.sugar.Info(args...) -} - -func (zl *zapGRPCLogger) Infoln(args ...interface{}) { - if !zl.lg.Core().Enabled(zapcore.DebugLevel) { - return - } - zl.sugar.Info(args...) -} - -func (zl *zapGRPCLogger) Infof(format string, args ...interface{}) { - if !zl.lg.Core().Enabled(zapcore.DebugLevel) { - return - } - zl.sugar.Infof(format, args...) -} - -func (zl *zapGRPCLogger) Warning(args ...interface{}) { - zl.sugar.Warn(args...) -} - -func (zl *zapGRPCLogger) Warningln(args ...interface{}) { - zl.sugar.Warn(args...) -} - -func (zl *zapGRPCLogger) Warningf(format string, args ...interface{}) { - zl.sugar.Warnf(format, args...) -} - -func (zl *zapGRPCLogger) Error(args ...interface{}) { - zl.sugar.Error(args...) -} - -func (zl *zapGRPCLogger) Errorln(args ...interface{}) { - zl.sugar.Error(args...) -} - -func (zl *zapGRPCLogger) Errorf(format string, args ...interface{}) { - zl.sugar.Errorf(format, args...) -} - -func (zl *zapGRPCLogger) Fatal(args ...interface{}) { - zl.sugar.Fatal(args...) -} - -func (zl *zapGRPCLogger) Fatalln(args ...interface{}) { - zl.sugar.Fatal(args...) -} - -func (zl *zapGRPCLogger) Fatalf(format string, args ...interface{}) { - zl.sugar.Fatalf(format, args...) -} - -func (zl *zapGRPCLogger) V(l int) bool { - // infoLog == 0 - if l <= 0 { // debug level, then we ignore info level in gRPC - return !zl.lg.Core().Enabled(zapcore.DebugLevel) - } - return true -} diff --git a/vendor/go.etcd.io/etcd/pkg/logutil/zap_journal.go b/vendor/go.etcd.io/etcd/pkg/logutil/zap_journal.go deleted file mode 100644 index b995f9e5e..000000000 --- a/vendor/go.etcd.io/etcd/pkg/logutil/zap_journal.go +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build !windows -// +build !windows - -package logutil - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - "os" - "path/filepath" - - "go.etcd.io/etcd/pkg/systemd" - - "github.com/coreos/go-systemd/journal" - "go.uber.org/zap/zapcore" -) - -// NewJournalWriter wraps "io.Writer" to redirect log output -// to the local systemd journal. If journald send fails, it fails -// back to writing to the original writer. -// The decode overhead is only <30µs per write. -// Reference: https://github.com/coreos/pkg/blob/master/capnslog/journald_formatter.go -func NewJournalWriter(wr io.Writer) (io.Writer, error) { - return &journalWriter{Writer: wr}, systemd.DialJournal() -} - -type journalWriter struct { - io.Writer -} - -// WARN: assume that etcd uses default field names in zap encoder config -// make sure to keep this up-to-date! -type logLine struct { - Level string `json:"level"` - Caller string `json:"caller"` -} - -func (w *journalWriter) Write(p []byte) (int, error) { - line := &logLine{} - if err := json.NewDecoder(bytes.NewReader(p)).Decode(line); err != nil { - return 0, err - } - - var pri journal.Priority - switch line.Level { - case zapcore.DebugLevel.String(): - pri = journal.PriDebug - case zapcore.InfoLevel.String(): - pri = journal.PriInfo - - case zapcore.WarnLevel.String(): - pri = journal.PriWarning - case zapcore.ErrorLevel.String(): - pri = journal.PriErr - - case zapcore.DPanicLevel.String(): - pri = journal.PriCrit - case zapcore.PanicLevel.String(): - pri = journal.PriCrit - case zapcore.FatalLevel.String(): - pri = journal.PriCrit - - default: - panic(fmt.Errorf("unknown log level: %q", line.Level)) - } - - err := journal.Send(string(p), pri, map[string]string{ - "PACKAGE": filepath.Dir(line.Caller), - "SYSLOG_IDENTIFIER": filepath.Base(os.Args[0]), - }) - if err != nil { - // "journal" also falls back to stderr - // "fmt.Fprintln(os.Stderr, s)" - return w.Writer.Write(p) - } - return 0, nil -} diff --git a/vendor/go.etcd.io/etcd/pkg/logutil/zap_raft.go b/vendor/go.etcd.io/etcd/pkg/logutil/zap_raft.go deleted file mode 100644 index f016b3054..000000000 --- a/vendor/go.etcd.io/etcd/pkg/logutil/zap_raft.go +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package logutil - -import ( - "errors" - - "go.etcd.io/etcd/raft" - - "go.uber.org/zap" - "go.uber.org/zap/zapcore" -) - -// NewRaftLogger builds "raft.Logger" from "*zap.Config". -func NewRaftLogger(lcfg *zap.Config) (raft.Logger, error) { - if lcfg == nil { - return nil, errors.New("nil zap.Config") - } - lg, err := lcfg.Build(zap.AddCallerSkip(1)) // to annotate caller outside of "logutil" - if err != nil { - return nil, err - } - return &zapRaftLogger{lg: lg, sugar: lg.Sugar()}, nil -} - -// NewRaftLoggerZap converts "*zap.Logger" to "raft.Logger". -func NewRaftLoggerZap(lg *zap.Logger) raft.Logger { - return &zapRaftLogger{lg: lg, sugar: lg.Sugar()} -} - -// NewRaftLoggerFromZapCore creates "raft.Logger" from "zap.Core" -// and "zapcore.WriteSyncer". -func NewRaftLoggerFromZapCore(cr zapcore.Core, syncer zapcore.WriteSyncer) raft.Logger { - // "AddCallerSkip" to annotate caller outside of "logutil" - lg := zap.New(cr, zap.AddCaller(), zap.AddCallerSkip(1), zap.ErrorOutput(syncer)) - return &zapRaftLogger{lg: lg, sugar: lg.Sugar()} -} - -type zapRaftLogger struct { - lg *zap.Logger - sugar *zap.SugaredLogger -} - -func (zl *zapRaftLogger) Debug(args ...interface{}) { - zl.sugar.Debug(args...) -} - -func (zl *zapRaftLogger) Debugf(format string, args ...interface{}) { - zl.sugar.Debugf(format, args...) -} - -func (zl *zapRaftLogger) Error(args ...interface{}) { - zl.sugar.Error(args...) -} - -func (zl *zapRaftLogger) Errorf(format string, args ...interface{}) { - zl.sugar.Errorf(format, args...) -} - -func (zl *zapRaftLogger) Info(args ...interface{}) { - zl.sugar.Info(args...) -} - -func (zl *zapRaftLogger) Infof(format string, args ...interface{}) { - zl.sugar.Infof(format, args...) -} - -func (zl *zapRaftLogger) Warning(args ...interface{}) { - zl.sugar.Warn(args...) -} - -func (zl *zapRaftLogger) Warningf(format string, args ...interface{}) { - zl.sugar.Warnf(format, args...) -} - -func (zl *zapRaftLogger) Fatal(args ...interface{}) { - zl.sugar.Fatal(args...) -} - -func (zl *zapRaftLogger) Fatalf(format string, args ...interface{}) { - zl.sugar.Fatalf(format, args...) -} - -func (zl *zapRaftLogger) Panic(args ...interface{}) { - zl.sugar.Panic(args...) -} - -func (zl *zapRaftLogger) Panicf(format string, args ...interface{}) { - zl.sugar.Panicf(format, args...) -} diff --git a/vendor/go.etcd.io/etcd/pkg/systemd/doc.go b/vendor/go.etcd.io/etcd/pkg/systemd/doc.go deleted file mode 100644 index 30e77ce04..000000000 --- a/vendor/go.etcd.io/etcd/pkg/systemd/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package systemd provides utility functions for systemd. -package systemd diff --git a/vendor/go.etcd.io/etcd/pkg/v3/LICENSE b/vendor/go.etcd.io/etcd/pkg/v3/LICENSE new file mode 100644 index 000000000..d64569567 --- /dev/null +++ b/vendor/go.etcd.io/etcd/pkg/v3/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/go.etcd.io/etcd/pkg/crc/crc.go b/vendor/go.etcd.io/etcd/pkg/v3/crc/crc.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/crc/crc.go rename to vendor/go.etcd.io/etcd/pkg/v3/crc/crc.go diff --git a/vendor/go.etcd.io/etcd/pkg/httputil/httputil.go b/vendor/go.etcd.io/etcd/pkg/v3/httputil/httputil.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/httputil/httputil.go rename to vendor/go.etcd.io/etcd/pkg/v3/httputil/httputil.go diff --git a/vendor/go.etcd.io/etcd/pkg/ioutil/pagewriter.go b/vendor/go.etcd.io/etcd/pkg/v3/ioutil/pagewriter.go similarity index 96% rename from vendor/go.etcd.io/etcd/pkg/ioutil/pagewriter.go rename to vendor/go.etcd.io/etcd/pkg/v3/ioutil/pagewriter.go index cf9a8dc66..62eb5cd43 100644 --- a/vendor/go.etcd.io/etcd/pkg/ioutil/pagewriter.go +++ b/vendor/go.etcd.io/etcd/pkg/v3/ioutil/pagewriter.go @@ -15,6 +15,7 @@ package ioutil import ( + "fmt" "io" ) @@ -41,6 +42,9 @@ type PageWriter struct { // NewPageWriter creates a new PageWriter. pageBytes is the number of bytes // to write per page. pageOffset is the starting offset of io.Writer. func NewPageWriter(w io.Writer, pageBytes, pageOffset int) *PageWriter { + if pageBytes <= 0 { + panic(fmt.Sprintf("assertion failed: invalid pageBytes (%d) value, it must be greater than 0", pageBytes)) + } return &PageWriter{ w: w, pageOffset: pageOffset, diff --git a/vendor/go.etcd.io/etcd/pkg/ioutil/readcloser.go b/vendor/go.etcd.io/etcd/pkg/v3/ioutil/readcloser.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/ioutil/readcloser.go rename to vendor/go.etcd.io/etcd/pkg/v3/ioutil/readcloser.go diff --git a/vendor/go.etcd.io/etcd/pkg/ioutil/reader.go b/vendor/go.etcd.io/etcd/pkg/v3/ioutil/reader.go similarity index 100% rename from vendor/go.etcd.io/etcd/pkg/ioutil/reader.go rename to vendor/go.etcd.io/etcd/pkg/v3/ioutil/reader.go diff --git a/vendor/go.etcd.io/etcd/pkg/ioutil/util.go b/vendor/go.etcd.io/etcd/pkg/v3/ioutil/util.go similarity index 96% rename from vendor/go.etcd.io/etcd/pkg/ioutil/util.go rename to vendor/go.etcd.io/etcd/pkg/v3/ioutil/util.go index 6a6746e0b..dc36e183c 100644 --- a/vendor/go.etcd.io/etcd/pkg/ioutil/util.go +++ b/vendor/go.etcd.io/etcd/pkg/v3/ioutil/util.go @@ -18,7 +18,7 @@ import ( "io" "os" - "go.etcd.io/etcd/pkg/fileutil" + "go.etcd.io/etcd/client/pkg/v3/fileutil" ) // WriteAndSyncFile behaves just like ioutil.WriteFile in the standard library, diff --git a/vendor/go.etcd.io/etcd/pkg/pbutil/pbutil.go b/vendor/go.etcd.io/etcd/pkg/v3/pbutil/pbutil.go similarity index 85% rename from vendor/go.etcd.io/etcd/pkg/pbutil/pbutil.go rename to vendor/go.etcd.io/etcd/pkg/v3/pbutil/pbutil.go index 53167ffa5..821f59703 100644 --- a/vendor/go.etcd.io/etcd/pkg/pbutil/pbutil.go +++ b/vendor/go.etcd.io/etcd/pkg/v3/pbutil/pbutil.go @@ -15,11 +15,7 @@ // Package pbutil defines interfaces for handling Protocol Buffer objects. package pbutil -import "github.com/coreos/pkg/capnslog" - -var ( - plog = capnslog.NewPackageLogger("go.etcd.io/etcd", "pkg/pbutil") -) +import "fmt" type Marshaler interface { Marshal() (data []byte, err error) @@ -32,14 +28,14 @@ type Unmarshaler interface { func MustMarshal(m Marshaler) []byte { d, err := m.Marshal() if err != nil { - plog.Panicf("marshal should never fail (%v)", err) + panic(fmt.Sprintf("marshal should never fail (%v)", err)) } return d } func MustUnmarshal(um Unmarshaler, data []byte) { if err := um.Unmarshal(data); err != nil { - plog.Panicf("unmarshal should never fail (%v)", err) + panic(fmt.Sprintf("unmarshal should never fail (%v)", err)) } } diff --git a/vendor/go.etcd.io/etcd/raft/v3/LICENSE b/vendor/go.etcd.io/etcd/raft/v3/LICENSE new file mode 100644 index 000000000..d64569567 --- /dev/null +++ b/vendor/go.etcd.io/etcd/raft/v3/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/go.etcd.io/etcd/raft/OWNERS b/vendor/go.etcd.io/etcd/raft/v3/OWNERS similarity index 100% rename from vendor/go.etcd.io/etcd/raft/OWNERS rename to vendor/go.etcd.io/etcd/raft/v3/OWNERS diff --git a/vendor/go.etcd.io/etcd/raft/README.md b/vendor/go.etcd.io/etcd/raft/v3/README.md similarity index 97% rename from vendor/go.etcd.io/etcd/raft/README.md rename to vendor/go.etcd.io/etcd/raft/v3/README.md index 83cf04035..fbd8b4d49 100644 --- a/vendor/go.etcd.io/etcd/raft/README.md +++ b/vendor/go.etcd.io/etcd/raft/v3/README.md @@ -5,7 +5,7 @@ The state machine is kept in sync through the use of a replicated log. For more details on Raft, see "In Search of an Understandable Consensus Algorithm" (https://raft.github.io/raft.pdf) by Diego Ongaro and John Ousterhout. -This Raft library is stable and feature complete. As of 2016, it is **the most widely used** Raft library in production, serving tens of thousands clusters each day. It powers distributed systems such as etcd, Kubernetes, Docker Swarm, Cloud Foundry Diego, CockroachDB, TiDB, Project Calico, Flannel, and more. +This Raft library is stable and feature complete. As of 2016, it is **the most widely used** Raft library in production, serving tens of thousands clusters each day. It powers distributed systems such as etcd, Kubernetes, Docker Swarm, Cloud Foundry Diego, CockroachDB, TiDB, Project Calico, Flannel, Hyperledger and more. Most Raft implementations have a monolithic design, including storage handling, messaging serialization, and network transport. This library instead follows a minimalistic design philosophy by only implementing the core raft algorithm. This minimalism buys flexibility, determinism, and performance. @@ -13,7 +13,7 @@ To keep the codebase small as well as provide flexibility, the library only impl In order to easily test the Raft library, its behavior should be deterministic. To achieve this determinism, the library models Raft as a state machine. The state machine takes a `Message` as input. A message can either be a local timer update or a network message sent from a remote peer. The state machine's output is a 3-tuple `{[]Messages, []LogEntries, NextState}` consisting of an array of `Messages`, `log entries`, and `Raft state changes`. For state machines with the same state, the same state machine input should always generate the same state machine output. -A simple example application, _raftexample_, is also available to help illustrate how to use this package in practice: https://github.com/etcd-io/etcd/tree/master/contrib/raftexample +A simple example application, _raftexample_, is also available to help illustrate how to use this package in practice: https://github.com/etcd-io/etcd/tree/main/contrib/raftexample # Features @@ -59,7 +59,7 @@ The primary object in raft is a Node. Either start a Node from scratch using raf To start a three-node cluster ```go storage := raft.NewMemoryStorage() - c := &Config{ + c := &raft.Config{ ID: 0x01, ElectionTick: 10, HeartbeatTick: 1, @@ -95,7 +95,7 @@ To restart a node from previous state: storage.SetHardState(state) storage.Append(entries) - c := &Config{ + c := &raft.Config{ ID: 0x01, ElectionTick: 10, HeartbeatTick: 1, @@ -195,3 +195,7 @@ This implementation is up to date with the final Raft thesis (https://github.com To ensure there is no attempt to commit two membership changes at once by matching log positions (which would be unsafe since they should have different quorum requirements), any proposed membership change is simply disallowed while any uncommitted change appears in the leader's log. This approach introduces a problem when removing a member from a two-member cluster: If one of the members dies before the other one receives the commit of the confchange entry, then the member cannot be removed any more since the cluster cannot make progress. For this reason it is highly recommended to use three or more nodes in every cluster. + +## Go docs + +More detailed development documentation can be found in go docs: https://pkg.go.dev/go.etcd.io/etcd/raft/v3. \ No newline at end of file diff --git a/vendor/go.etcd.io/etcd/raft/bootstrap.go b/vendor/go.etcd.io/etcd/raft/v3/bootstrap.go similarity index 98% rename from vendor/go.etcd.io/etcd/raft/bootstrap.go rename to vendor/go.etcd.io/etcd/raft/v3/bootstrap.go index bd82b2041..824bd5f51 100644 --- a/vendor/go.etcd.io/etcd/raft/bootstrap.go +++ b/vendor/go.etcd.io/etcd/raft/v3/bootstrap.go @@ -17,7 +17,7 @@ package raft import ( "errors" - pb "go.etcd.io/etcd/raft/raftpb" + pb "go.etcd.io/etcd/raft/v3/raftpb" ) // Bootstrap initializes the RawNode for first use by appending configuration diff --git a/vendor/go.etcd.io/etcd/raft/confchange/confchange.go b/vendor/go.etcd.io/etcd/raft/v3/confchange/confchange.go similarity index 97% rename from vendor/go.etcd.io/etcd/raft/confchange/confchange.go rename to vendor/go.etcd.io/etcd/raft/v3/confchange/confchange.go index d8a878780..dddbcc9d9 100644 --- a/vendor/go.etcd.io/etcd/raft/confchange/confchange.go +++ b/vendor/go.etcd.io/etcd/raft/v3/confchange/confchange.go @@ -19,9 +19,9 @@ import ( "fmt" "strings" - "go.etcd.io/etcd/raft/quorum" - pb "go.etcd.io/etcd/raft/raftpb" - "go.etcd.io/etcd/raft/tracker" + "go.etcd.io/etcd/raft/v3/quorum" + pb "go.etcd.io/etcd/raft/v3/raftpb" + "go.etcd.io/etcd/raft/v3/tracker" ) // Changer facilitates configuration changes. It exposes methods to handle @@ -144,9 +144,6 @@ func (c Changer) Simple(ccs ...pb.ConfChangeSingle) (tracker.Config, tracker.Pro if n := symdiff(incoming(c.Tracker.Voters), incoming(cfg.Voters)); n > 1 { return tracker.Config{}, nil, errors.New("more than one voter changed without entering joint config") } - if err := checkInvariants(cfg, prs); err != nil { - return tracker.Config{}, tracker.ProgressMap{}, nil - } return checkAndReturn(cfg, prs) } @@ -193,7 +190,6 @@ func (c Changer) makeVoter(cfg *tracker.Config, prs tracker.ProgressMap, id uint nilAwareDelete(&cfg.Learners, id) nilAwareDelete(&cfg.LearnersNext, id) incoming(cfg.Voters)[id] = struct{}{} - return } // makeLearner makes the given ID a learner or stages it to be a learner once @@ -326,10 +322,10 @@ func checkInvariants(cfg tracker.Config, prs tracker.ProgressMap) error { if !joint(cfg) { // We enforce that empty maps are nil instead of zero. if outgoing(cfg.Voters) != nil { - return fmt.Errorf("Voters[1] must be nil when not joint") + return fmt.Errorf("cfg.Voters[1] must be nil when not joint") } if cfg.LearnersNext != nil { - return fmt.Errorf("LearnersNext must be nil when not joint") + return fmt.Errorf("cfg.LearnersNext must be nil when not joint") } if cfg.AutoLeave { return fmt.Errorf("AutoLeave must be false when not joint") diff --git a/vendor/go.etcd.io/etcd/raft/confchange/restore.go b/vendor/go.etcd.io/etcd/raft/v3/confchange/restore.go similarity index 97% rename from vendor/go.etcd.io/etcd/raft/confchange/restore.go rename to vendor/go.etcd.io/etcd/raft/v3/confchange/restore.go index 724068da0..ea317fc28 100644 --- a/vendor/go.etcd.io/etcd/raft/confchange/restore.go +++ b/vendor/go.etcd.io/etcd/raft/v3/confchange/restore.go @@ -15,8 +15,8 @@ package confchange import ( - pb "go.etcd.io/etcd/raft/raftpb" - "go.etcd.io/etcd/raft/tracker" + pb "go.etcd.io/etcd/raft/v3/raftpb" + "go.etcd.io/etcd/raft/v3/tracker" ) // toConfChangeSingle translates a conf state into 1) a slice of operations creating @@ -28,7 +28,7 @@ func toConfChangeSingle(cs pb.ConfState) (out []pb.ConfChangeSingle, in []pb.Con // voters=(1 2 3) learners=(5) outgoing=(1 2 4 6) learners_next=(4) // // This means that before entering the joint config, the configuration - // had voters (1 2 4) and perhaps some learners that are already gone. + // had voters (1 2 4 6) and perhaps some learners that are already gone. // The new set of voters is (1 2 3), i.e. (1 2) were kept around, and (4 6) // are no longer voters; however 4 is poised to become a learner upon leaving // the joint state. diff --git a/vendor/go.etcd.io/etcd/raft/design.md b/vendor/go.etcd.io/etcd/raft/v3/design.md similarity index 100% rename from vendor/go.etcd.io/etcd/raft/design.md rename to vendor/go.etcd.io/etcd/raft/v3/design.md diff --git a/vendor/go.etcd.io/etcd/raft/doc.go b/vendor/go.etcd.io/etcd/raft/v3/doc.go similarity index 99% rename from vendor/go.etcd.io/etcd/raft/doc.go rename to vendor/go.etcd.io/etcd/raft/v3/doc.go index f58703105..4febfe608 100644 --- a/vendor/go.etcd.io/etcd/raft/doc.go +++ b/vendor/go.etcd.io/etcd/raft/v3/doc.go @@ -23,7 +23,7 @@ For more details on Raft, see "In Search of an Understandable Consensus Algorith A simple example application, _raftexample_, is also available to help illustrate how to use this package in practice: -https://github.com/etcd-io/etcd/tree/master/contrib/raftexample +https://github.com/etcd-io/etcd/tree/main/contrib/raftexample # Usage diff --git a/vendor/go.etcd.io/etcd/raft/log.go b/vendor/go.etcd.io/etcd/raft/v3/log.go similarity index 88% rename from vendor/go.etcd.io/etcd/raft/log.go rename to vendor/go.etcd.io/etcd/raft/v3/log.go index 77eedfccb..c94c41f77 100644 --- a/vendor/go.etcd.io/etcd/raft/log.go +++ b/vendor/go.etcd.io/etcd/raft/v3/log.go @@ -18,7 +18,7 @@ import ( "fmt" "log" - pb "go.etcd.io/etcd/raft/raftpb" + pb "go.etcd.io/etcd/raft/v3/raftpb" ) type raftLog struct { @@ -123,7 +123,6 @@ func (l *raftLog) append(ents ...pb.Entry) uint64 { // entries, the index of the first new entry will be returned. // An entry is considered to be conflicting if it has the same index but // a different term. -// The first entry MUST have an index equal to the argument 'from'. // The index of the given entries MUST be continuously increasing. func (l *raftLog) findConflict(ents []pb.Entry) uint64 { for _, ne := range ents { @@ -138,6 +137,36 @@ func (l *raftLog) findConflict(ents []pb.Entry) uint64 { return 0 } +// findConflictByTerm takes an (index, term) pair (indicating a conflicting log +// entry on a leader/follower during an append) and finds the largest index in +// log l with a term <= `term` and an index <= `index`. If no such index exists +// in the log, the log's first index is returned. +// +// The index provided MUST be equal to or less than l.lastIndex(). Invalid +// inputs log a warning and the input index is returned. +func (l *raftLog) findConflictByTerm(index uint64, term uint64) uint64 { + if li := l.lastIndex(); index > li { + // NB: such calls should not exist, but since there is a straightfoward + // way to recover, do it. + // + // It is tempting to also check something about the first index, but + // there is odd behavior with peers that have no log, in which case + // lastIndex will return zero and firstIndex will return one, which + // leads to calls with an index of zero into this method. + l.logger.Warningf("index(%d) is out of range [0, lastIndex(%d)] in findConflictByTerm", + index, li) + return index + } + for { + logTerm, err := l.term(index) + if logTerm <= term || err != nil { + break + } + index-- + } + return index +} + func (l *raftLog) unstableEntries() []pb.Entry { if len(l.unstable.entries) == 0 { return nil @@ -167,6 +196,11 @@ func (l *raftLog) hasNextEnts() bool { return l.committed+1 > off } +// hasPendingSnapshot returns if there is pending snapshot waiting for applying. +func (l *raftLog) hasPendingSnapshot() bool { + return l.unstable.snapshot != nil && !IsEmptySnap(*l.unstable.snapshot) +} + func (l *raftLog) snapshot() (pb.Snapshot, error) { if l.unstable.snapshot != nil { return *l.unstable.snapshot, nil @@ -354,7 +388,7 @@ func (l *raftLog) mustCheckOutOfBounds(lo, hi uint64) error { } length := l.lastIndex() + 1 - fi - if lo < fi || hi > fi+length { + if hi > fi+length { l.logger.Panicf("slice[%d,%d) out of bound [%d,%d]", lo, hi, fi, l.lastIndex()) } return nil diff --git a/vendor/go.etcd.io/etcd/raft/log_unstable.go b/vendor/go.etcd.io/etcd/raft/v3/log_unstable.go similarity index 99% rename from vendor/go.etcd.io/etcd/raft/log_unstable.go rename to vendor/go.etcd.io/etcd/raft/v3/log_unstable.go index 1bff5a7bd..230fd21f9 100644 --- a/vendor/go.etcd.io/etcd/raft/log_unstable.go +++ b/vendor/go.etcd.io/etcd/raft/v3/log_unstable.go @@ -14,7 +14,7 @@ package raft -import pb "go.etcd.io/etcd/raft/raftpb" +import pb "go.etcd.io/etcd/raft/v3/raftpb" // unstable.entries[i] has raft log position i+unstable.offset. // Note that unstable.offset may be less than the highest log diff --git a/vendor/go.etcd.io/etcd/raft/logger.go b/vendor/go.etcd.io/etcd/raft/v3/logger.go similarity index 95% rename from vendor/go.etcd.io/etcd/raft/logger.go rename to vendor/go.etcd.io/etcd/raft/v3/logger.go index 6d8962965..dc73b1f21 100644 --- a/vendor/go.etcd.io/etcd/raft/logger.go +++ b/vendor/go.etcd.io/etcd/raft/v3/logger.go @@ -48,6 +48,16 @@ func SetLogger(l Logger) { raftLoggerMu.Unlock() } +func ResetDefaultLogger() { + SetLogger(defaultLogger) +} + +func getLogger() Logger { + raftLoggerMu.Lock() + defer raftLoggerMu.Unlock() + return raftLogger +} + var ( defaultLogger = &DefaultLogger{Logger: log.New(os.Stderr, "raft", log.LstdFlags)} discardLogger = &DefaultLogger{Logger: log.New(ioutil.Discard, "", 0)} diff --git a/vendor/go.etcd.io/etcd/raft/node.go b/vendor/go.etcd.io/etcd/raft/v3/node.go similarity index 98% rename from vendor/go.etcd.io/etcd/raft/node.go rename to vendor/go.etcd.io/etcd/raft/v3/node.go index 8832d74c8..dca5954f7 100644 --- a/vendor/go.etcd.io/etcd/raft/node.go +++ b/vendor/go.etcd.io/etcd/raft/v3/node.go @@ -18,7 +18,7 @@ import ( "context" "errors" - pb "go.etcd.io/etcd/raft/raftpb" + pb "go.etcd.io/etcd/raft/v3/raftpb" ) type SnapshotStatus int @@ -168,7 +168,9 @@ type Node interface { Advance() // ApplyConfChange applies a config change (previously passed to // ProposeConfChange) to the node. This must be called whenever a config - // change is observed in Ready.CommittedEntries. + // change is observed in Ready.CommittedEntries, except when the app decides + // to reject the configuration change (i.e. treats it as a noop instead), in + // which case it must not be called. // // Returns an opaque non-nil ConfState protobuf which must be recorded in // snapshots. @@ -367,10 +369,12 @@ func (n *node) run() { // very sound and likely has bugs. if _, okAfter := r.prs.Progress[r.id]; okBefore && !okAfter { var found bool + outer: for _, sl := range [][]uint64{cs.Voters, cs.VotersOutgoing} { for _, id := range sl { if id == r.id { found = true + break outer } } } @@ -407,7 +411,7 @@ func (n *node) Tick() { case n.tickc <- struct{}{}: case <-n.done: default: - n.rn.raft.logger.Warningf("%x (leader %v) A tick missed to fire. Node blocks too long!", n.rn.raft.id, n.rn.raft.id == n.rn.raft.lead) + n.rn.raft.logger.Warningf("%x A tick missed to fire. Node blocks too long!", n.rn.raft.id) } } diff --git a/vendor/go.etcd.io/etcd/raft/quorum/joint.go b/vendor/go.etcd.io/etcd/raft/v3/quorum/joint.go similarity index 100% rename from vendor/go.etcd.io/etcd/raft/quorum/joint.go rename to vendor/go.etcd.io/etcd/raft/v3/quorum/joint.go diff --git a/vendor/go.etcd.io/etcd/raft/quorum/majority.go b/vendor/go.etcd.io/etcd/raft/v3/quorum/majority.go similarity index 100% rename from vendor/go.etcd.io/etcd/raft/quorum/majority.go rename to vendor/go.etcd.io/etcd/raft/v3/quorum/majority.go diff --git a/vendor/go.etcd.io/etcd/raft/quorum/quorum.go b/vendor/go.etcd.io/etcd/raft/v3/quorum/quorum.go similarity index 100% rename from vendor/go.etcd.io/etcd/raft/quorum/quorum.go rename to vendor/go.etcd.io/etcd/raft/v3/quorum/quorum.go diff --git a/vendor/go.etcd.io/etcd/raft/quorum/voteresult_string.go b/vendor/go.etcd.io/etcd/raft/v3/quorum/voteresult_string.go similarity index 100% rename from vendor/go.etcd.io/etcd/raft/quorum/voteresult_string.go rename to vendor/go.etcd.io/etcd/raft/v3/quorum/voteresult_string.go diff --git a/vendor/go.etcd.io/etcd/raft/raft.go b/vendor/go.etcd.io/etcd/raft/v3/raft.go similarity index 84% rename from vendor/go.etcd.io/etcd/raft/raft.go rename to vendor/go.etcd.io/etcd/raft/v3/raft.go index 199dd829d..c80262eba 100644 --- a/vendor/go.etcd.io/etcd/raft/raft.go +++ b/vendor/go.etcd.io/etcd/raft/v3/raft.go @@ -25,10 +25,10 @@ import ( "sync" "time" - "go.etcd.io/etcd/raft/confchange" - "go.etcd.io/etcd/raft/quorum" - pb "go.etcd.io/etcd/raft/raftpb" - "go.etcd.io/etcd/raft/tracker" + "go.etcd.io/etcd/raft/v3/confchange" + "go.etcd.io/etcd/raft/v3/quorum" + pb "go.etcd.io/etcd/raft/v3/raftpb" + "go.etcd.io/etcd/raft/v3/tracker" ) // None is a placeholder node ID used when there is no leader. @@ -117,17 +117,6 @@ type Config struct { // ID is the identity of the local raft. ID cannot be 0. ID uint64 - // peers contains the IDs of all nodes (including self) in the raft cluster. It - // should only be set when starting a new raft cluster. Restarting raft from - // previous configuration will panic if peers is set. peer is private and only - // used for testing right now. - peers []uint64 - - // learners contains the IDs of all learner nodes (including self if the - // local node is a learner) in the raft cluster. learners only receives - // entries from the leader node. It does not vote or promote itself. - learners []uint64 - // ElectionTick is the number of Node.Tick invocations that must pass between // elections. That is, if a follower does not receive any message from the // leader of current term before ElectionTick has elapsed, it will become @@ -241,7 +230,7 @@ func (c *Config) validate() error { } if c.Logger == nil { - c.Logger = raftLogger + c.Logger = getLogger() } if c.ReadOnlyOption == ReadOnlyLeaseBased && !c.CheckQuorum { @@ -336,17 +325,6 @@ func newRaft(c *Config) *raft { panic(err) // TODO(bdarnell) } - if len(c.peers) > 0 || len(c.learners) > 0 { - if len(cs.Voters) > 0 || len(cs.Learners) > 0 { - // TODO(bdarnell): the peers argument is always nil except in - // tests; the argument should be removed and these tests should be - // updated to specify their nodes through a snapshot. - panic("cannot specify both newRaft(peers, learners) and ConfState.(Voters, Learners)") - } - cs.Voters = c.peers - cs.Learners = c.learners - } - r := &raft{ id: c.ID, lead: None, @@ -403,9 +381,12 @@ func (r *raft) hardState() pb.HardState { } } -// send persists state to stable storage and then sends to its mailbox. +// send schedules persisting state to a stable storage and AFTER that +// sending the message (as part of next Ready message processing). func (r *raft) send(m pb.Message) { - m.From = r.id + if m.From == None { + m.From = r.id + } if m.Type == pb.MsgVote || m.Type == pb.MsgVoteResp || m.Type == pb.MsgPreVote || m.Type == pb.MsgPreVoteResp { if m.Term == 0 { // All {pre-,}campaign messages need to have the term set when @@ -560,35 +541,34 @@ func (r *raft) bcastHeartbeatWithCtx(ctx []byte) { } func (r *raft) advance(rd Ready) { + r.reduceUncommittedSize(rd.CommittedEntries) + // If entries were applied (or a snapshot), update our cursor for // the next Ready. Note that if the current HardState contains a // new Commit index, this does not mean that we're also applying // all of the new entries due to commit pagination by size. - if index := rd.appliedCursor(); index > 0 { - r.raftLog.appliedTo(index) - if r.prs.Config.AutoLeave && index >= r.pendingConfIndex && r.state == StateLeader { + if newApplied := rd.appliedCursor(); newApplied > 0 { + oldApplied := r.raftLog.applied + r.raftLog.appliedTo(newApplied) + + if r.prs.Config.AutoLeave && oldApplied <= r.pendingConfIndex && newApplied >= r.pendingConfIndex && r.state == StateLeader { // If the current (and most recent, at least for this leader's term) - // configuration should be auto-left, initiate that now. - ccdata, err := (&pb.ConfChangeV2{}).Marshal() - if err != nil { - panic(err) - } + // configuration should be auto-left, initiate that now. We use a + // nil Data which unmarshals into an empty ConfChangeV2 and has the + // benefit that appendEntry can never refuse it based on its size + // (which registers as zero). ent := pb.Entry{ Type: pb.EntryConfChangeV2, - Data: ccdata, + Data: nil, } + // There's no way in which this proposal should be able to be rejected. if !r.appendEntry(ent) { - // If we could not append the entry, bump the pending conf index - // so that we'll try again later. - // - // TODO(tbg): test this case. - r.pendingConfIndex = r.raftLog.lastIndex() - } else { - r.logger.Infof("initiating automatic transition out of joint configuration %s", r.prs.Config) + panic("refused un-refusable auto-leaving ConfChangeV2") } + r.pendingConfIndex = r.raftLog.lastIndex() + r.logger.Infof("initiating automatic transition out of joint configuration %s", r.prs.Config) } } - r.reduceUncommittedSize(rd.CommittedEntries) if len(rd.Entries) > 0 { e := rd.Entries[len(rd.Entries)-1] @@ -771,6 +751,29 @@ func (r *raft) becomeLeader() { r.logger.Infof("%x became leader at term %d", r.id, r.Term) } +func (r *raft) hup(t CampaignType) { + if r.state == StateLeader { + r.logger.Debugf("%x ignoring MsgHup because already leader", r.id) + return + } + + if !r.promotable() { + r.logger.Warningf("%x is unpromotable and can not campaign", r.id) + return + } + ents, err := r.raftLog.slice(r.raftLog.applied+1, r.raftLog.committed+1, noLimit) + if err != nil { + r.logger.Panicf("unexpected error getting unapplied entries (%v)", err) + } + if n := numOfPendingConf(ents); n != 0 && r.raftLog.committed > r.raftLog.applied { + r.logger.Warningf("%x cannot campaign at term %d since there are still %d pending configuration changes to apply", r.id, r.Term, n) + return + } + + r.logger.Infof("%x is starting a new election at term %d", r.id, r.Term) + r.campaign(t) +} + // campaign transitions the raft instance to candidate state. This must only be // called after verifying that this is a legitimate transition. func (r *raft) campaign(t CampaignType) { @@ -912,28 +915,10 @@ func (r *raft) Step(m pb.Message) error { switch m.Type { case pb.MsgHup: - if r.state != StateLeader { - if !r.promotable() { - r.logger.Warningf("%x is unpromotable and can not campaign; ignoring MsgHup", r.id) - return nil - } - ents, err := r.raftLog.slice(r.raftLog.applied+1, r.raftLog.committed+1, noLimit) - if err != nil { - r.logger.Panicf("unexpected error getting unapplied entries (%v)", err) - } - if n := numOfPendingConf(ents); n != 0 && r.raftLog.committed > r.raftLog.applied { - r.logger.Warningf("%x cannot campaign at term %d since there are still %d pending configuration changes to apply", r.id, r.Term, n) - return nil - } - - r.logger.Infof("%x is starting a new election at term %d", r.id, r.Term) - if r.preVote { - r.campaign(campaignPreElection) - } else { - r.campaign(campaignElection) - } + if r.preVote { + r.hup(campaignPreElection) } else { - r.logger.Debugf("%x ignoring MsgHup because already leader", r.id) + r.hup(campaignElection) } case pb.MsgVote, pb.MsgPreVote: @@ -1116,9 +1101,127 @@ func stepLeader(r *raft, m pb.Message) error { pr.RecentActive = true if m.Reject { - r.logger.Debugf("%x received MsgAppResp(MsgApp was rejected, lastindex: %d) from %x for index %d", - r.id, m.RejectHint, m.From, m.Index) - if pr.MaybeDecrTo(m.Index, m.RejectHint) { + // RejectHint is the suggested next base entry for appending (i.e. + // we try to append entry RejectHint+1 next), and LogTerm is the + // term that the follower has at index RejectHint. Older versions + // of this library did not populate LogTerm for rejections and it + // is zero for followers with an empty log. + // + // Under normal circumstances, the leader's log is longer than the + // follower's and the follower's log is a prefix of the leader's + // (i.e. there is no divergent uncommitted suffix of the log on the + // follower). In that case, the first probe reveals where the + // follower's log ends (RejectHint=follower's last index) and the + // subsequent probe succeeds. + // + // However, when networks are partitioned or systems overloaded, + // large divergent log tails can occur. The naive attempt, probing + // entry by entry in decreasing order, will be the product of the + // length of the diverging tails and the network round-trip latency, + // which can easily result in hours of time spent probing and can + // even cause outright outages. The probes are thus optimized as + // described below. + r.logger.Debugf("%x received MsgAppResp(rejected, hint: (index %d, term %d)) from %x for index %d", + r.id, m.RejectHint, m.LogTerm, m.From, m.Index) + nextProbeIdx := m.RejectHint + if m.LogTerm > 0 { + // If the follower has an uncommitted log tail, we would end up + // probing one by one until we hit the common prefix. + // + // For example, if the leader has: + // + // idx 1 2 3 4 5 6 7 8 9 + // ----------------- + // term (L) 1 3 3 3 5 5 5 5 5 + // term (F) 1 1 1 1 2 2 + // + // Then, after sending an append anchored at (idx=9,term=5) we + // would receive a RejectHint of 6 and LogTerm of 2. Without the + // code below, we would try an append at index 6, which would + // fail again. + // + // However, looking only at what the leader knows about its own + // log and the rejection hint, it is clear that a probe at index + // 6, 5, 4, 3, and 2 must fail as well: + // + // For all of these indexes, the leader's log term is larger than + // the rejection's log term. If a probe at one of these indexes + // succeeded, its log term at that index would match the leader's, + // i.e. 3 or 5 in this example. But the follower already told the + // leader that it is still at term 2 at index 9, and since the + // log term only ever goes up (within a log), this is a contradiction. + // + // At index 1, however, the leader can draw no such conclusion, + // as its term 1 is not larger than the term 2 from the + // follower's rejection. We thus probe at 1, which will succeed + // in this example. In general, with this approach we probe at + // most once per term found in the leader's log. + // + // There is a similar mechanism on the follower (implemented in + // handleAppendEntries via a call to findConflictByTerm) that is + // useful if the follower has a large divergent uncommitted log + // tail[1], as in this example: + // + // idx 1 2 3 4 5 6 7 8 9 + // ----------------- + // term (L) 1 3 3 3 3 3 3 3 7 + // term (F) 1 3 3 4 4 5 5 5 6 + // + // Naively, the leader would probe at idx=9, receive a rejection + // revealing the log term of 6 at the follower. Since the leader's + // term at the previous index is already smaller than 6, the leader- + // side optimization discussed above is ineffective. The leader thus + // probes at index 8 and, naively, receives a rejection for the same + // index and log term 5. Again, the leader optimization does not improve + // over linear probing as term 5 is above the leader's term 3 for that + // and many preceding indexes; the leader would have to probe linearly + // until it would finally hit index 3, where the probe would succeed. + // + // Instead, we apply a similar optimization on the follower. When the + // follower receives the probe at index 8 (log term 3), it concludes + // that all of the leader's log preceding that index has log terms of + // 3 or below. The largest index in the follower's log with a log term + // of 3 or below is index 3. The follower will thus return a rejection + // for index=3, log term=3 instead. The leader's next probe will then + // succeed at that index. + // + // [1]: more precisely, if the log terms in the large uncommitted + // tail on the follower are larger than the leader's. At first, + // it may seem unintuitive that a follower could even have such + // a large tail, but it can happen: + // + // 1. Leader appends (but does not commit) entries 2 and 3, crashes. + // idx 1 2 3 4 5 6 7 8 9 + // ----------------- + // term (L) 1 2 2 [crashes] + // term (F) 1 + // term (F) 1 + // + // 2. a follower becomes leader and appends entries at term 3. + // ----------------- + // term (x) 1 2 2 [down] + // term (F) 1 3 3 3 3 + // term (F) 1 + // + // 3. term 3 leader goes down, term 2 leader returns as term 4 + // leader. It commits the log & entries at term 4. + // + // ----------------- + // term (L) 1 2 2 2 + // term (x) 1 3 3 3 3 [down] + // term (F) 1 + // ----------------- + // term (L) 1 2 2 2 4 4 4 + // term (F) 1 3 3 3 3 [gets probed] + // term (F) 1 2 2 2 4 4 4 + // + // 4. the leader will now probe the returning follower at index + // 7, the rejection points it at the end of the follower's log + // which is at a higher log term than the actually committed + // log. + nextProbeIdx = r.raftLog.findConflictByTerm(m.RejectHint, m.LogTerm) + } + if pr.MaybeDecrTo(m.Index, nextProbeIdx) { r.logger.Debugf("%x decreased progress of %x to [%s]", r.id, m.From, pr) if pr.State == tracker.StateReplicate { pr.BecomeProbe() @@ -1194,11 +1297,8 @@ func stepLeader(r *raft, m pb.Message) error { rss := r.readOnly.advance(m) for _, rs := range rss { - req := rs.req - if req.From == None || req.From == r.id { // from local member - r.readStates = append(r.readStates, ReadState{Index: rs.index, RequestCtx: req.Entries[0].Data}) - } else { - r.send(pb.Message{To: req.From, Type: pb.MsgReadIndexResp, Index: rs.index, Entries: req.Entries}) + if resp := r.responseToReadIndexReq(rs.req, rs.index); resp.To != None { + r.send(resp) } } case pb.MsgSnapStatus: @@ -1344,15 +1444,11 @@ func stepFollower(r *raft, m pb.Message) error { m.To = r.lead r.send(m) case pb.MsgTimeoutNow: - if r.promotable() { - r.logger.Infof("%x [term %d] received MsgTimeoutNow from %x and starts an election to get leadership.", r.id, r.Term, m.From) - // Leadership transfers never use pre-vote even if r.preVote is true; we - // know we are not recovering from a partition so there is no need for the - // extra round trip. - r.campaign(campaignTransfer) - } else { - r.logger.Infof("%x received MsgTimeoutNow from %x but is not promotable", r.id, m.From) - } + r.logger.Infof("%x [term %d] received MsgTimeoutNow from %x and starts an election to get leadership.", r.id, r.Term, m.From) + // Leadership transfers never use pre-vote even if r.preVote is true; we + // know we are not recovering from a partition so there is no need for the + // extra round trip. + r.hup(campaignTransfer) case pb.MsgReadIndex: if r.lead == None { r.logger.Infof("%x no leader at term %d; dropping index reading msg", r.id, r.Term) @@ -1381,7 +1477,30 @@ func (r *raft) handleAppendEntries(m pb.Message) { } else { r.logger.Debugf("%x [logterm: %d, index: %d] rejected MsgApp [logterm: %d, index: %d] from %x", r.id, r.raftLog.zeroTermOnErrCompacted(r.raftLog.term(m.Index)), m.Index, m.LogTerm, m.Index, m.From) - r.send(pb.Message{To: m.From, Type: pb.MsgAppResp, Index: m.Index, Reject: true, RejectHint: r.raftLog.lastIndex()}) + + // Return a hint to the leader about the maximum index and term that the + // two logs could be divergent at. Do this by searching through the + // follower's log for the maximum (index, term) pair with a term <= the + // MsgApp's LogTerm and an index <= the MsgApp's Index. This can help + // skip all indexes in the follower's uncommitted tail with terms + // greater than the MsgApp's LogTerm. + // + // See the other caller for findConflictByTerm (in stepLeader) for a much + // more detailed explanation of this mechanism. + hintIndex := min(m.Index, r.raftLog.lastIndex()) + hintIndex = r.raftLog.findConflictByTerm(hintIndex, m.LogTerm) + hintTerm, err := r.raftLog.term(hintIndex) + if err != nil { + panic(fmt.Sprintf("term(%d) must be valid, but got %v", hintIndex, err)) + } + r.send(pb.Message{ + To: m.From, + Type: pb.MsgAppResp, + Index: m.Index, + Reject: true, + RejectHint: hintIndex, + LogTerm: hintTerm, + }) } } @@ -1424,13 +1543,17 @@ func (r *raft) restore(s pb.Snapshot) bool { } // More defense-in-depth: throw away snapshot if recipient is not in the - // config. This shouuldn't ever happen (at the time of writing) but lots of + // config. This shouldn't ever happen (at the time of writing) but lots of // code here and there assumes that r.id is in the progress tracker. found := false cs := s.Metadata.ConfState + for _, set := range [][]uint64{ cs.Voters, cs.Learners, + cs.VotersOutgoing, + // `LearnersNext` doesn't need to be checked. According to the rules, if a peer in + // `LearnersNext`, it has to be in `VotersOutgoing`. } { for _, id := range set { if id == r.id { @@ -1438,6 +1561,9 @@ func (r *raft) restore(s pb.Snapshot) bool { break } } + if found { + break + } } if !found { r.logger.Warningf( @@ -1485,7 +1611,7 @@ func (r *raft) restore(s pb.Snapshot) bool { // which is true when its own id is in progress list. func (r *raft) promotable() bool { pr := r.prs.Progress[r.id] - return pr != nil && !pr.IsLearner + return pr != nil && !pr.IsLearner && !r.raftLog.hasPendingSnapshot() } func (r *raft) applyConfChange(cc pb.ConfChangeV2) pb.ConfState { @@ -1559,8 +1685,8 @@ func (r *raft) switchToConfig(cfg tracker.Config, prs tracker.ProgressMap) pb.Co r.maybeSendAppend(id, false /* sendIfEmpty */) }) } - // If the the leadTransferee was removed, abort the leadership transfer. - if _, tOK := r.prs.Progress[r.leadTransferee]; !tOK && r.leadTransferee != 0 { + // If the the leadTransferee was removed or demoted, abort the leadership transfer. + if _, tOK := r.prs.Config.Voters.IDs()[r.leadTransferee]; !tOK && r.leadTransferee != 0 { r.abortLeaderTransfer() } @@ -1623,16 +1749,23 @@ func (r *raft) responseToReadIndexReq(req pb.Message, readIndex uint64) pb.Messa // If the new entries would exceed the limit, the method returns false. If not, // the increase in uncommitted entry size is recorded and the method returns // true. +// +// Empty payloads are never refused. This is used both for appending an empty +// entry at a new leader's term, as well as leaving a joint configuration. func (r *raft) increaseUncommittedSize(ents []pb.Entry) bool { var s uint64 for _, e := range ents { s += uint64(PayloadSize(e)) } - if r.uncommittedSize > 0 && r.uncommittedSize+s > r.maxUncommittedSize { + if r.uncommittedSize > 0 && s > 0 && r.uncommittedSize+s > r.maxUncommittedSize { // If the uncommitted tail of the Raft log is empty, allow any size // proposal. Otherwise, limit the size of the uncommitted tail of the // log and drop any proposal that would push the size over the limit. + // Note the added requirement s>0 which is used to make sure that + // appending single empty entries to the log always succeeds, used both + // for replicating a new leader's initial empty entry, and for + // auto-leaving joint configurations. return false } r.uncommittedSize += s @@ -1664,7 +1797,7 @@ func (r *raft) reduceUncommittedSize(ents []pb.Entry) { func numOfPendingConf(ents []pb.Entry) int { n := 0 for i := range ents { - if ents[i].Type == pb.EntryConfChange { + if ents[i].Type == pb.EntryConfChange || ents[i].Type == pb.EntryConfChangeV2 { n++ } } diff --git a/vendor/go.etcd.io/etcd/raft/raftpb/confchange.go b/vendor/go.etcd.io/etcd/raft/v3/raftpb/confchange.go similarity index 96% rename from vendor/go.etcd.io/etcd/raft/raftpb/confchange.go rename to vendor/go.etcd.io/etcd/raft/v3/raftpb/confchange.go index 46a7a7021..47fae65df 100644 --- a/vendor/go.etcd.io/etcd/raft/raftpb/confchange.go +++ b/vendor/go.etcd.io/etcd/raft/v3/raftpb/confchange.go @@ -73,7 +73,7 @@ func (c ConfChangeV2) AsV1() (ConfChange, bool) { return ConfChange{}, false } // than one change or if the use of Joint Consensus was requested explicitly. // The first bool can only be true if second one is, and indicates whether the // Joint State will be left automatically. -func (c *ConfChangeV2) EnterJoint() (autoLeave bool, ok bool) { +func (c ConfChangeV2) EnterJoint() (autoLeave bool, ok bool) { // NB: in theory, more config changes could qualify for the "simple" // protocol but it depends on the config on top of which the changes apply. // For example, adding two learners is not OK if both nodes are part of the @@ -100,10 +100,10 @@ func (c *ConfChangeV2) EnterJoint() (autoLeave bool, ok bool) { // LeaveJoint is true if the configuration change leaves a joint configuration. // This is the case if the ConfChangeV2 is zero, with the possible exception of // the Context field. -func (c *ConfChangeV2) LeaveJoint() bool { - cpy := *c - cpy.Context = nil - return proto.Equal(&cpy, &ConfChangeV2{}) +func (c ConfChangeV2) LeaveJoint() bool { + // NB: c is already a copy. + c.Context = nil + return proto.Equal(&c, &ConfChangeV2{}) } // ConfChangesFromString parses a Space-delimited sequence of operations into a diff --git a/vendor/go.etcd.io/etcd/raft/raftpb/confstate.go b/vendor/go.etcd.io/etcd/raft/v3/raftpb/confstate.go similarity index 97% rename from vendor/go.etcd.io/etcd/raft/raftpb/confstate.go rename to vendor/go.etcd.io/etcd/raft/v3/raftpb/confstate.go index 4bda93214..39b9dd700 100644 --- a/vendor/go.etcd.io/etcd/raft/raftpb/confstate.go +++ b/vendor/go.etcd.io/etcd/raft/v3/raftpb/confstate.go @@ -35,7 +35,6 @@ func (cs ConfState) Equivalent(cs2 ConfState) error { s(&cs.Learners) s(&cs.VotersOutgoing) s(&cs.LearnersNext) - cs.XXX_unrecognized = nil } if !reflect.DeepEqual(cs1, cs2) { diff --git a/vendor/go.etcd.io/etcd/raft/raftpb/raft.pb.go b/vendor/go.etcd.io/etcd/raft/v3/raftpb/raft.pb.go similarity index 64% rename from vendor/go.etcd.io/etcd/raft/raftpb/raft.pb.go rename to vendor/go.etcd.io/etcd/raft/v3/raftpb/raft.pb.go index 071815198..1ee77a9a4 100644 --- a/vendor/go.etcd.io/etcd/raft/raftpb/raft.pb.go +++ b/vendor/go.etcd.io/etcd/raft/v3/raftpb/raft.pb.go @@ -1,37 +1,16 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: raft.proto -/* -Package raftpb is a generated protocol buffer package. - -It is generated from these files: - - raft.proto - -It has these top-level messages: - - Entry - SnapshotMetadata - Snapshot - Message - HardState - ConfState - ConfChange - ConfChangeSingle - ConfChangeV2 -*/ package raftpb import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - + fmt "fmt" + io "io" math "math" + math_bits "math/bits" _ "github.com/gogo/protobuf/gogoproto" - - io "io" + proto "github.com/golang/protobuf/proto" ) // Reference imports to suppress errors if they are not otherwise used. @@ -43,7 +22,7 @@ var _ = math.Inf // is compatible with the proto package it is being compiled against. // A compilation error at this line likely means your copy of the // proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package type EntryType int32 @@ -58,6 +37,7 @@ var EntryType_name = map[int32]string{ 1: "EntryConfChange", 2: "EntryConfChangeV2", } + var EntryType_value = map[string]int32{ "EntryNormal": 0, "EntryConfChange": 1, @@ -69,9 +49,11 @@ func (x EntryType) Enum() *EntryType { *p = x return p } + func (x EntryType) String() string { return proto.EnumName(EntryType_name, int32(x)) } + func (x *EntryType) UnmarshalJSON(data []byte) error { value, err := proto.UnmarshalJSONEnum(EntryType_value, data, "EntryType") if err != nil { @@ -80,8 +62,13 @@ func (x *EntryType) UnmarshalJSON(data []byte) error { *x = EntryType(value) return nil } -func (EntryType) EnumDescriptor() ([]byte, []int) { return fileDescriptorRaft, []int{0} } +func (EntryType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_b042552c306ae59b, []int{0} +} + +// For description of different message types, see: +// https://pkg.go.dev/go.etcd.io/etcd/raft/v3#hdr-MessageType type MessageType int32 const ( @@ -127,6 +114,7 @@ var MessageType_name = map[int32]string{ 17: "MsgPreVote", 18: "MsgPreVoteResp", } + var MessageType_value = map[string]int32{ "MsgHup": 0, "MsgBeat": 1, @@ -154,9 +142,11 @@ func (x MessageType) Enum() *MessageType { *p = x return p } + func (x MessageType) String() string { return proto.EnumName(MessageType_name, int32(x)) } + func (x *MessageType) UnmarshalJSON(data []byte) error { value, err := proto.UnmarshalJSONEnum(MessageType_value, data, "MessageType") if err != nil { @@ -165,7 +155,10 @@ func (x *MessageType) UnmarshalJSON(data []byte) error { *x = MessageType(value) return nil } -func (MessageType) EnumDescriptor() ([]byte, []int) { return fileDescriptorRaft, []int{1} } + +func (MessageType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_b042552c306ae59b, []int{1} +} // ConfChangeTransition specifies the behavior of a configuration change with // respect to joint consensus. @@ -194,6 +187,7 @@ var ConfChangeTransition_name = map[int32]string{ 1: "ConfChangeTransitionJointImplicit", 2: "ConfChangeTransitionJointExplicit", } + var ConfChangeTransition_value = map[string]int32{ "ConfChangeTransitionAuto": 0, "ConfChangeTransitionJointImplicit": 1, @@ -205,9 +199,11 @@ func (x ConfChangeTransition) Enum() *ConfChangeTransition { *p = x return p } + func (x ConfChangeTransition) String() string { return proto.EnumName(ConfChangeTransition_name, int32(x)) } + func (x *ConfChangeTransition) UnmarshalJSON(data []byte) error { value, err := proto.UnmarshalJSONEnum(ConfChangeTransition_value, data, "ConfChangeTransition") if err != nil { @@ -216,7 +212,10 @@ func (x *ConfChangeTransition) UnmarshalJSON(data []byte) error { *x = ConfChangeTransition(value) return nil } -func (ConfChangeTransition) EnumDescriptor() ([]byte, []int) { return fileDescriptorRaft, []int{2} } + +func (ConfChangeTransition) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_b042552c306ae59b, []int{2} +} type ConfChangeType int32 @@ -233,6 +232,7 @@ var ConfChangeType_name = map[int32]string{ 2: "ConfChangeUpdateNode", 3: "ConfChangeAddLearnerNode", } + var ConfChangeType_value = map[string]int32{ "ConfChangeAddNode": 0, "ConfChangeRemoveNode": 1, @@ -245,9 +245,11 @@ func (x ConfChangeType) Enum() *ConfChangeType { *p = x return p } + func (x ConfChangeType) String() string { return proto.EnumName(ConfChangeType_name, int32(x)) } + func (x *ConfChangeType) UnmarshalJSON(data []byte) error { value, err := proto.UnmarshalJSONEnum(ConfChangeType_value, data, "ConfChangeType") if err != nil { @@ -256,76 +258,219 @@ func (x *ConfChangeType) UnmarshalJSON(data []byte) error { *x = ConfChangeType(value) return nil } -func (ConfChangeType) EnumDescriptor() ([]byte, []int) { return fileDescriptorRaft, []int{3} } + +func (ConfChangeType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_b042552c306ae59b, []int{3} +} type Entry struct { - Term uint64 `protobuf:"varint,2,opt,name=Term" json:"Term"` - Index uint64 `protobuf:"varint,3,opt,name=Index" json:"Index"` - Type EntryType `protobuf:"varint,1,opt,name=Type,enum=raftpb.EntryType" json:"Type"` - Data []byte `protobuf:"bytes,4,opt,name=Data" json:"Data,omitempty"` - XXX_unrecognized []byte `json:"-"` + Term uint64 `protobuf:"varint,2,opt,name=Term" json:"Term"` + Index uint64 `protobuf:"varint,3,opt,name=Index" json:"Index"` + Type EntryType `protobuf:"varint,1,opt,name=Type,enum=raftpb.EntryType" json:"Type"` + Data []byte `protobuf:"bytes,4,opt,name=Data" json:"Data,omitempty"` +} + +func (m *Entry) Reset() { *m = Entry{} } +func (m *Entry) String() string { return proto.CompactTextString(m) } +func (*Entry) ProtoMessage() {} +func (*Entry) Descriptor() ([]byte, []int) { + return fileDescriptor_b042552c306ae59b, []int{0} +} +func (m *Entry) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Entry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Entry.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Entry) XXX_Merge(src proto.Message) { + xxx_messageInfo_Entry.Merge(m, src) +} +func (m *Entry) XXX_Size() int { + return m.Size() +} +func (m *Entry) XXX_DiscardUnknown() { + xxx_messageInfo_Entry.DiscardUnknown(m) } -func (m *Entry) Reset() { *m = Entry{} } -func (m *Entry) String() string { return proto.CompactTextString(m) } -func (*Entry) ProtoMessage() {} -func (*Entry) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{0} } +var xxx_messageInfo_Entry proto.InternalMessageInfo type SnapshotMetadata struct { - ConfState ConfState `protobuf:"bytes,1,opt,name=conf_state,json=confState" json:"conf_state"` - Index uint64 `protobuf:"varint,2,opt,name=index" json:"index"` - Term uint64 `protobuf:"varint,3,opt,name=term" json:"term"` - XXX_unrecognized []byte `json:"-"` + ConfState ConfState `protobuf:"bytes,1,opt,name=conf_state,json=confState" json:"conf_state"` + Index uint64 `protobuf:"varint,2,opt,name=index" json:"index"` + Term uint64 `protobuf:"varint,3,opt,name=term" json:"term"` } -func (m *SnapshotMetadata) Reset() { *m = SnapshotMetadata{} } -func (m *SnapshotMetadata) String() string { return proto.CompactTextString(m) } -func (*SnapshotMetadata) ProtoMessage() {} -func (*SnapshotMetadata) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{1} } +func (m *SnapshotMetadata) Reset() { *m = SnapshotMetadata{} } +func (m *SnapshotMetadata) String() string { return proto.CompactTextString(m) } +func (*SnapshotMetadata) ProtoMessage() {} +func (*SnapshotMetadata) Descriptor() ([]byte, []int) { + return fileDescriptor_b042552c306ae59b, []int{1} +} +func (m *SnapshotMetadata) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SnapshotMetadata) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SnapshotMetadata.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SnapshotMetadata) XXX_Merge(src proto.Message) { + xxx_messageInfo_SnapshotMetadata.Merge(m, src) +} +func (m *SnapshotMetadata) XXX_Size() int { + return m.Size() +} +func (m *SnapshotMetadata) XXX_DiscardUnknown() { + xxx_messageInfo_SnapshotMetadata.DiscardUnknown(m) +} + +var xxx_messageInfo_SnapshotMetadata proto.InternalMessageInfo type Snapshot struct { - Data []byte `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"` - Metadata SnapshotMetadata `protobuf:"bytes,2,opt,name=metadata" json:"metadata"` - XXX_unrecognized []byte `json:"-"` + Data []byte `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"` + Metadata SnapshotMetadata `protobuf:"bytes,2,opt,name=metadata" json:"metadata"` } -func (m *Snapshot) Reset() { *m = Snapshot{} } -func (m *Snapshot) String() string { return proto.CompactTextString(m) } -func (*Snapshot) ProtoMessage() {} -func (*Snapshot) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{2} } +func (m *Snapshot) Reset() { *m = Snapshot{} } +func (m *Snapshot) String() string { return proto.CompactTextString(m) } +func (*Snapshot) ProtoMessage() {} +func (*Snapshot) Descriptor() ([]byte, []int) { + return fileDescriptor_b042552c306ae59b, []int{2} +} +func (m *Snapshot) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Snapshot) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Snapshot.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Snapshot) XXX_Merge(src proto.Message) { + xxx_messageInfo_Snapshot.Merge(m, src) +} +func (m *Snapshot) XXX_Size() int { + return m.Size() +} +func (m *Snapshot) XXX_DiscardUnknown() { + xxx_messageInfo_Snapshot.DiscardUnknown(m) +} + +var xxx_messageInfo_Snapshot proto.InternalMessageInfo type Message struct { - Type MessageType `protobuf:"varint,1,opt,name=type,enum=raftpb.MessageType" json:"type"` - To uint64 `protobuf:"varint,2,opt,name=to" json:"to"` - From uint64 `protobuf:"varint,3,opt,name=from" json:"from"` - Term uint64 `protobuf:"varint,4,opt,name=term" json:"term"` - LogTerm uint64 `protobuf:"varint,5,opt,name=logTerm" json:"logTerm"` - Index uint64 `protobuf:"varint,6,opt,name=index" json:"index"` - Entries []Entry `protobuf:"bytes,7,rep,name=entries" json:"entries"` - Commit uint64 `protobuf:"varint,8,opt,name=commit" json:"commit"` - Snapshot Snapshot `protobuf:"bytes,9,opt,name=snapshot" json:"snapshot"` - Reject bool `protobuf:"varint,10,opt,name=reject" json:"reject"` - RejectHint uint64 `protobuf:"varint,11,opt,name=rejectHint" json:"rejectHint"` - Context []byte `protobuf:"bytes,12,opt,name=context" json:"context,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Message) Reset() { *m = Message{} } -func (m *Message) String() string { return proto.CompactTextString(m) } -func (*Message) ProtoMessage() {} -func (*Message) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{3} } + Type MessageType `protobuf:"varint,1,opt,name=type,enum=raftpb.MessageType" json:"type"` + To uint64 `protobuf:"varint,2,opt,name=to" json:"to"` + From uint64 `protobuf:"varint,3,opt,name=from" json:"from"` + Term uint64 `protobuf:"varint,4,opt,name=term" json:"term"` + // logTerm is generally used for appending Raft logs to followers. For example, + // (type=MsgApp,index=100,logTerm=5) means leader appends entries starting at + // index=101, and the term of entry at index 100 is 5. + // (type=MsgAppResp,reject=true,index=100,logTerm=5) means follower rejects some + // entries from its leader as it already has an entry with term 5 at index 100. + LogTerm uint64 `protobuf:"varint,5,opt,name=logTerm" json:"logTerm"` + Index uint64 `protobuf:"varint,6,opt,name=index" json:"index"` + Entries []Entry `protobuf:"bytes,7,rep,name=entries" json:"entries"` + Commit uint64 `protobuf:"varint,8,opt,name=commit" json:"commit"` + Snapshot Snapshot `protobuf:"bytes,9,opt,name=snapshot" json:"snapshot"` + Reject bool `protobuf:"varint,10,opt,name=reject" json:"reject"` + RejectHint uint64 `protobuf:"varint,11,opt,name=rejectHint" json:"rejectHint"` + Context []byte `protobuf:"bytes,12,opt,name=context" json:"context,omitempty"` +} + +func (m *Message) Reset() { *m = Message{} } +func (m *Message) String() string { return proto.CompactTextString(m) } +func (*Message) ProtoMessage() {} +func (*Message) Descriptor() ([]byte, []int) { + return fileDescriptor_b042552c306ae59b, []int{3} +} +func (m *Message) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Message) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Message.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Message) XXX_Merge(src proto.Message) { + xxx_messageInfo_Message.Merge(m, src) +} +func (m *Message) XXX_Size() int { + return m.Size() +} +func (m *Message) XXX_DiscardUnknown() { + xxx_messageInfo_Message.DiscardUnknown(m) +} + +var xxx_messageInfo_Message proto.InternalMessageInfo type HardState struct { - Term uint64 `protobuf:"varint,1,opt,name=term" json:"term"` - Vote uint64 `protobuf:"varint,2,opt,name=vote" json:"vote"` - Commit uint64 `protobuf:"varint,3,opt,name=commit" json:"commit"` - XXX_unrecognized []byte `json:"-"` + Term uint64 `protobuf:"varint,1,opt,name=term" json:"term"` + Vote uint64 `protobuf:"varint,2,opt,name=vote" json:"vote"` + Commit uint64 `protobuf:"varint,3,opt,name=commit" json:"commit"` } -func (m *HardState) Reset() { *m = HardState{} } -func (m *HardState) String() string { return proto.CompactTextString(m) } -func (*HardState) ProtoMessage() {} -func (*HardState) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{4} } +func (m *HardState) Reset() { *m = HardState{} } +func (m *HardState) String() string { return proto.CompactTextString(m) } +func (*HardState) ProtoMessage() {} +func (*HardState) Descriptor() ([]byte, []int) { + return fileDescriptor_b042552c306ae59b, []int{4} +} +func (m *HardState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *HardState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_HardState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *HardState) XXX_Merge(src proto.Message) { + xxx_messageInfo_HardState.Merge(m, src) +} +func (m *HardState) XXX_Size() int { + return m.Size() +} +func (m *HardState) XXX_DiscardUnknown() { + xxx_messageInfo_HardState.DiscardUnknown(m) +} + +var xxx_messageInfo_HardState proto.InternalMessageInfo type ConfState struct { // The voters in the incoming config. (If the configuration is not joint, @@ -341,14 +486,41 @@ type ConfState struct { LearnersNext []uint64 `protobuf:"varint,4,rep,name=learners_next,json=learnersNext" json:"learners_next,omitempty"` // If set, the config is joint and Raft will automatically transition into // the final config (i.e. remove the outgoing config) when this is safe. - AutoLeave bool `protobuf:"varint,5,opt,name=auto_leave,json=autoLeave" json:"auto_leave"` - XXX_unrecognized []byte `json:"-"` + AutoLeave bool `protobuf:"varint,5,opt,name=auto_leave,json=autoLeave" json:"auto_leave"` } -func (m *ConfState) Reset() { *m = ConfState{} } -func (m *ConfState) String() string { return proto.CompactTextString(m) } -func (*ConfState) ProtoMessage() {} -func (*ConfState) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{5} } +func (m *ConfState) Reset() { *m = ConfState{} } +func (m *ConfState) String() string { return proto.CompactTextString(m) } +func (*ConfState) ProtoMessage() {} +func (*ConfState) Descriptor() ([]byte, []int) { + return fileDescriptor_b042552c306ae59b, []int{5} +} +func (m *ConfState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ConfState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ConfState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ConfState) XXX_Merge(src proto.Message) { + xxx_messageInfo_ConfState.Merge(m, src) +} +func (m *ConfState) XXX_Size() int { + return m.Size() +} +func (m *ConfState) XXX_DiscardUnknown() { + xxx_messageInfo_ConfState.DiscardUnknown(m) +} + +var xxx_messageInfo_ConfState proto.InternalMessageInfo type ConfChange struct { Type ConfChangeType `protobuf:"varint,2,opt,name=type,enum=raftpb.ConfChangeType" json:"type"` @@ -357,27 +529,81 @@ type ConfChange struct { // NB: this is used only by etcd to thread through a unique identifier. // Ideally it should really use the Context instead. No counterpart to // this field exists in ConfChangeV2. - ID uint64 `protobuf:"varint,1,opt,name=id" json:"id"` - XXX_unrecognized []byte `json:"-"` + ID uint64 `protobuf:"varint,1,opt,name=id" json:"id"` +} + +func (m *ConfChange) Reset() { *m = ConfChange{} } +func (m *ConfChange) String() string { return proto.CompactTextString(m) } +func (*ConfChange) ProtoMessage() {} +func (*ConfChange) Descriptor() ([]byte, []int) { + return fileDescriptor_b042552c306ae59b, []int{6} +} +func (m *ConfChange) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ConfChange) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ConfChange.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ConfChange) XXX_Merge(src proto.Message) { + xxx_messageInfo_ConfChange.Merge(m, src) +} +func (m *ConfChange) XXX_Size() int { + return m.Size() +} +func (m *ConfChange) XXX_DiscardUnknown() { + xxx_messageInfo_ConfChange.DiscardUnknown(m) } -func (m *ConfChange) Reset() { *m = ConfChange{} } -func (m *ConfChange) String() string { return proto.CompactTextString(m) } -func (*ConfChange) ProtoMessage() {} -func (*ConfChange) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{6} } +var xxx_messageInfo_ConfChange proto.InternalMessageInfo // ConfChangeSingle is an individual configuration change operation. Multiple // such operations can be carried out atomically via a ConfChangeV2. type ConfChangeSingle struct { - Type ConfChangeType `protobuf:"varint,1,opt,name=type,enum=raftpb.ConfChangeType" json:"type"` - NodeID uint64 `protobuf:"varint,2,opt,name=node_id,json=nodeId" json:"node_id"` - XXX_unrecognized []byte `json:"-"` + Type ConfChangeType `protobuf:"varint,1,opt,name=type,enum=raftpb.ConfChangeType" json:"type"` + NodeID uint64 `protobuf:"varint,2,opt,name=node_id,json=nodeId" json:"node_id"` +} + +func (m *ConfChangeSingle) Reset() { *m = ConfChangeSingle{} } +func (m *ConfChangeSingle) String() string { return proto.CompactTextString(m) } +func (*ConfChangeSingle) ProtoMessage() {} +func (*ConfChangeSingle) Descriptor() ([]byte, []int) { + return fileDescriptor_b042552c306ae59b, []int{7} +} +func (m *ConfChangeSingle) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ConfChangeSingle) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ConfChangeSingle.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ConfChangeSingle) XXX_Merge(src proto.Message) { + xxx_messageInfo_ConfChangeSingle.Merge(m, src) +} +func (m *ConfChangeSingle) XXX_Size() int { + return m.Size() +} +func (m *ConfChangeSingle) XXX_DiscardUnknown() { + xxx_messageInfo_ConfChangeSingle.DiscardUnknown(m) } -func (m *ConfChangeSingle) Reset() { *m = ConfChangeSingle{} } -func (m *ConfChangeSingle) String() string { return proto.CompactTextString(m) } -func (*ConfChangeSingle) ProtoMessage() {} -func (*ConfChangeSingle) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{7} } +var xxx_messageInfo_ConfChangeSingle proto.InternalMessageInfo // ConfChangeV2 messages initiate configuration changes. They support both the // simple "one at a time" membership change protocol and full Joint Consensus @@ -412,18 +638,49 @@ func (*ConfChangeSingle) Descriptor() ([]byte, []int) { return fileDescriptorRaf // // [1]: https://github.com/ongardie/dissertation/blob/master/online-trim.pdf type ConfChangeV2 struct { - Transition ConfChangeTransition `protobuf:"varint,1,opt,name=transition,enum=raftpb.ConfChangeTransition" json:"transition"` - Changes []ConfChangeSingle `protobuf:"bytes,2,rep,name=changes" json:"changes"` - Context []byte `protobuf:"bytes,3,opt,name=context" json:"context,omitempty"` - XXX_unrecognized []byte `json:"-"` + Transition ConfChangeTransition `protobuf:"varint,1,opt,name=transition,enum=raftpb.ConfChangeTransition" json:"transition"` + Changes []ConfChangeSingle `protobuf:"bytes,2,rep,name=changes" json:"changes"` + Context []byte `protobuf:"bytes,3,opt,name=context" json:"context,omitempty"` +} + +func (m *ConfChangeV2) Reset() { *m = ConfChangeV2{} } +func (m *ConfChangeV2) String() string { return proto.CompactTextString(m) } +func (*ConfChangeV2) ProtoMessage() {} +func (*ConfChangeV2) Descriptor() ([]byte, []int) { + return fileDescriptor_b042552c306ae59b, []int{8} +} +func (m *ConfChangeV2) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ConfChangeV2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ConfChangeV2.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ConfChangeV2) XXX_Merge(src proto.Message) { + xxx_messageInfo_ConfChangeV2.Merge(m, src) +} +func (m *ConfChangeV2) XXX_Size() int { + return m.Size() +} +func (m *ConfChangeV2) XXX_DiscardUnknown() { + xxx_messageInfo_ConfChangeV2.DiscardUnknown(m) } -func (m *ConfChangeV2) Reset() { *m = ConfChangeV2{} } -func (m *ConfChangeV2) String() string { return proto.CompactTextString(m) } -func (*ConfChangeV2) ProtoMessage() {} -func (*ConfChangeV2) Descriptor() ([]byte, []int) { return fileDescriptorRaft, []int{8} } +var xxx_messageInfo_ConfChangeV2 proto.InternalMessageInfo func init() { + proto.RegisterEnum("raftpb.EntryType", EntryType_name, EntryType_value) + proto.RegisterEnum("raftpb.MessageType", MessageType_name, MessageType_value) + proto.RegisterEnum("raftpb.ConfChangeTransition", ConfChangeTransition_name, ConfChangeTransition_value) + proto.RegisterEnum("raftpb.ConfChangeType", ConfChangeType_name, ConfChangeType_value) proto.RegisterType((*Entry)(nil), "raftpb.Entry") proto.RegisterType((*SnapshotMetadata)(nil), "raftpb.SnapshotMetadata") proto.RegisterType((*Snapshot)(nil), "raftpb.Snapshot") @@ -433,15 +690,83 @@ func init() { proto.RegisterType((*ConfChange)(nil), "raftpb.ConfChange") proto.RegisterType((*ConfChangeSingle)(nil), "raftpb.ConfChangeSingle") proto.RegisterType((*ConfChangeV2)(nil), "raftpb.ConfChangeV2") - proto.RegisterEnum("raftpb.EntryType", EntryType_name, EntryType_value) - proto.RegisterEnum("raftpb.MessageType", MessageType_name, MessageType_value) - proto.RegisterEnum("raftpb.ConfChangeTransition", ConfChangeTransition_name, ConfChangeTransition_value) - proto.RegisterEnum("raftpb.ConfChangeType", ConfChangeType_name, ConfChangeType_value) } + +func init() { proto.RegisterFile("raft.proto", fileDescriptor_b042552c306ae59b) } + +var fileDescriptor_b042552c306ae59b = []byte{ + // 1026 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xcd, 0x6e, 0xdb, 0x46, + 0x17, 0x25, 0x29, 0x5a, 0x3f, 0x57, 0xb2, 0x3c, 0xbe, 0xf1, 0x17, 0x10, 0x86, 0xc1, 0xe8, 0x53, + 0x52, 0x44, 0x70, 0x11, 0xb7, 0xd0, 0xa2, 0x28, 0xba, 0xf3, 0x4f, 0x00, 0xab, 0xb0, 0xdc, 0x54, + 0x76, 0xbc, 0x28, 0x50, 0x08, 0x63, 0x71, 0x44, 0xb3, 0x15, 0x39, 0x04, 0x39, 0x72, 0xed, 0x4d, + 0x51, 0xf4, 0x09, 0xba, 0xec, 0x26, 0xdb, 0x3e, 0x40, 0x9f, 0xc2, 0x4b, 0x03, 0xdd, 0x74, 0x15, + 0x34, 0xf6, 0x8b, 0x14, 0x33, 0x1c, 0x4a, 0x94, 0x6c, 0x64, 0xd1, 0xdd, 0xcc, 0xb9, 0x67, 0xee, + 0x9c, 0x73, 0xef, 0xe5, 0x10, 0x20, 0xa1, 0x63, 0xb1, 0x13, 0x27, 0x5c, 0x70, 0x2c, 0xcb, 0x75, + 0x7c, 0xbe, 0xb9, 0xe1, 0x73, 0x9f, 0x2b, 0xe8, 0x33, 0xb9, 0xca, 0xa2, 0xed, 0x9f, 0x61, 0xe5, + 0x75, 0x24, 0x92, 0x6b, 0x74, 0xc0, 0x3e, 0x65, 0x49, 0xe8, 0x58, 0x2d, 0xb3, 0x63, 0xef, 0xd9, + 0x37, 0xef, 0x9f, 0x19, 0x03, 0x85, 0xe0, 0x26, 0xac, 0xf4, 0x22, 0x8f, 0x5d, 0x39, 0xa5, 0x42, + 0x28, 0x83, 0xf0, 0x53, 0xb0, 0x4f, 0xaf, 0x63, 0xe6, 0x98, 0x2d, 0xb3, 0xd3, 0xec, 0xae, 0xef, + 0x64, 0x77, 0xed, 0xa8, 0x94, 0x32, 0x30, 0x4b, 0x74, 0x1d, 0x33, 0x44, 0xb0, 0x0f, 0xa8, 0xa0, + 0x8e, 0xdd, 0x32, 0x3b, 0x8d, 0x81, 0x5a, 0xb7, 0x7f, 0x31, 0x81, 0x9c, 0x44, 0x34, 0x4e, 0x2f, + 0xb8, 0xe8, 0x33, 0x41, 0x3d, 0x2a, 0x28, 0x7e, 0x01, 0x30, 0xe2, 0xd1, 0x78, 0x98, 0x0a, 0x2a, + 0xb2, 0xdc, 0xf5, 0x79, 0xee, 0x7d, 0x1e, 0x8d, 0x4f, 0x64, 0x40, 0xe7, 0xae, 0x8d, 0x72, 0x40, + 0x2a, 0x0d, 0x94, 0xd2, 0xa2, 0x89, 0x0c, 0x92, 0xfe, 0x84, 0xf4, 0x57, 0x34, 0xa1, 0x90, 0xf6, + 0x77, 0x50, 0xcd, 0x15, 0x48, 0x89, 0x52, 0x81, 0xba, 0xb3, 0x31, 0x50, 0x6b, 0xfc, 0x0a, 0xaa, + 0xa1, 0x56, 0xa6, 0x12, 0xd7, 0xbb, 0x4e, 0xae, 0x65, 0x59, 0xb9, 0xce, 0x3b, 0xe3, 0xb7, 0xdf, + 0x95, 0xa0, 0xd2, 0x67, 0x69, 0x4a, 0x7d, 0x86, 0xaf, 0xc0, 0x16, 0xf3, 0x5a, 0x3d, 0xc9, 0x73, + 0xe8, 0x70, 0xb1, 0x5a, 0x92, 0x86, 0x1b, 0x60, 0x09, 0xbe, 0xe0, 0xc4, 0x12, 0x5c, 0xda, 0x18, + 0x27, 0x7c, 0xc9, 0x86, 0x44, 0x66, 0x06, 0xed, 0x65, 0x83, 0xe8, 0x42, 0x65, 0xc2, 0x7d, 0xd5, + 0xdd, 0x95, 0x42, 0x30, 0x07, 0xe7, 0x65, 0x2b, 0x3f, 0x2c, 0xdb, 0x2b, 0xa8, 0xb0, 0x48, 0x24, + 0x01, 0x4b, 0x9d, 0x4a, 0xab, 0xd4, 0xa9, 0x77, 0x57, 0x17, 0x7a, 0x9c, 0xa7, 0xd2, 0x1c, 0xdc, + 0x82, 0xf2, 0x88, 0x87, 0x61, 0x20, 0x9c, 0x6a, 0x21, 0x97, 0xc6, 0xb0, 0x0b, 0xd5, 0x54, 0x57, + 0xcc, 0xa9, 0xa9, 0x4a, 0x92, 0xe5, 0x4a, 0xe6, 0x15, 0xcc, 0x79, 0x32, 0x63, 0xc2, 0x7e, 0x60, + 0x23, 0xe1, 0x40, 0xcb, 0xec, 0x54, 0xf3, 0x8c, 0x19, 0x86, 0x2f, 0x00, 0xb2, 0xd5, 0x61, 0x10, + 0x09, 0xa7, 0x5e, 0xb8, 0xb3, 0x80, 0xa3, 0x03, 0x95, 0x11, 0x8f, 0x04, 0xbb, 0x12, 0x4e, 0x43, + 0x35, 0x36, 0xdf, 0xb6, 0xbf, 0x87, 0xda, 0x21, 0x4d, 0xbc, 0x6c, 0x7c, 0xf2, 0x0a, 0x9a, 0x0f, + 0x2a, 0xe8, 0x80, 0x7d, 0xc9, 0x05, 0x5b, 0xfc, 0x38, 0x24, 0x52, 0x30, 0x5c, 0x7a, 0x68, 0xb8, + 0xfd, 0xa7, 0x09, 0xb5, 0xd9, 0xbc, 0xe2, 0x53, 0x28, 0xcb, 0x33, 0x49, 0xea, 0x98, 0xad, 0x52, + 0xc7, 0x1e, 0xe8, 0x1d, 0x6e, 0x42, 0x75, 0xc2, 0x68, 0x12, 0xc9, 0x88, 0xa5, 0x22, 0xb3, 0x3d, + 0xbe, 0x84, 0xb5, 0x8c, 0x35, 0xe4, 0x53, 0xe1, 0xf3, 0x20, 0xf2, 0x9d, 0x92, 0xa2, 0x34, 0x33, + 0xf8, 0x1b, 0x8d, 0xe2, 0x73, 0x58, 0xcd, 0x0f, 0x0d, 0x23, 0xe9, 0xd4, 0x56, 0xb4, 0x46, 0x0e, + 0x1e, 0xb3, 0x2b, 0x81, 0xcf, 0x01, 0xe8, 0x54, 0xf0, 0xe1, 0x84, 0xd1, 0x4b, 0xa6, 0x86, 0x21, + 0x2f, 0x68, 0x4d, 0xe2, 0x47, 0x12, 0x6e, 0xbf, 0x33, 0x01, 0xa4, 0xe8, 0xfd, 0x0b, 0x1a, 0xf9, + 0x0c, 0x3f, 0xd7, 0x63, 0x6b, 0xa9, 0xb1, 0x7d, 0x5a, 0xfc, 0x0c, 0x33, 0xc6, 0x83, 0xc9, 0x7d, + 0x09, 0x95, 0x88, 0x7b, 0x6c, 0x18, 0x78, 0xba, 0x28, 0x4d, 0x19, 0xbc, 0x7b, 0xff, 0xac, 0x7c, + 0xcc, 0x3d, 0xd6, 0x3b, 0x18, 0x94, 0x65, 0xb8, 0xe7, 0x15, 0xfb, 0x62, 0x2f, 0xf4, 0x05, 0x37, + 0xc1, 0x0a, 0x3c, 0xdd, 0x08, 0xd0, 0xa7, 0xad, 0xde, 0xc1, 0xc0, 0x0a, 0xbc, 0x76, 0x08, 0x64, + 0x7e, 0xf9, 0x49, 0x10, 0xf9, 0x93, 0xb9, 0x48, 0xf3, 0xbf, 0x88, 0xb4, 0x3e, 0x26, 0xb2, 0xfd, + 0x87, 0x09, 0x8d, 0x79, 0x9e, 0xb3, 0x2e, 0xee, 0x01, 0x88, 0x84, 0x46, 0x69, 0x20, 0x02, 0x1e, + 0xe9, 0x1b, 0xb7, 0x1e, 0xb9, 0x71, 0xc6, 0xc9, 0x27, 0x72, 0x7e, 0x0a, 0xbf, 0x84, 0xca, 0x48, + 0xb1, 0xb2, 0x8e, 0x17, 0x9e, 0x94, 0x65, 0x6b, 0xf9, 0x17, 0xa6, 0xe9, 0xc5, 0x9a, 0x95, 0x16, + 0x6a, 0xb6, 0x7d, 0x08, 0xb5, 0xd9, 0xbb, 0x8b, 0x6b, 0x50, 0x57, 0x9b, 0x63, 0x9e, 0x84, 0x74, + 0x42, 0x0c, 0x7c, 0x02, 0x6b, 0x0a, 0x98, 0xe7, 0x27, 0x26, 0xfe, 0x0f, 0xd6, 0x97, 0xc0, 0xb3, + 0x2e, 0xb1, 0xb6, 0xff, 0xb2, 0xa0, 0x5e, 0x78, 0x96, 0x10, 0xa0, 0xdc, 0x4f, 0xfd, 0xc3, 0x69, + 0x4c, 0x0c, 0xac, 0x43, 0xa5, 0x9f, 0xfa, 0x7b, 0x8c, 0x0a, 0x62, 0xea, 0xcd, 0x9b, 0x84, 0xc7, + 0xc4, 0xd2, 0xac, 0xdd, 0x38, 0x26, 0x25, 0x6c, 0x02, 0x64, 0xeb, 0x01, 0x4b, 0x63, 0x62, 0x6b, + 0xe2, 0x19, 0x17, 0x8c, 0xac, 0x48, 0x6d, 0x7a, 0xa3, 0xa2, 0x65, 0x1d, 0x95, 0x4f, 0x00, 0xa9, + 0x20, 0x81, 0x86, 0xbc, 0x8c, 0xd1, 0x44, 0x9c, 0xcb, 0x5b, 0xaa, 0xb8, 0x01, 0xa4, 0x88, 0xa8, + 0x43, 0x35, 0x44, 0x68, 0xf6, 0x53, 0xff, 0x6d, 0x94, 0x30, 0x3a, 0xba, 0xa0, 0xe7, 0x13, 0x46, + 0x00, 0xd7, 0x61, 0x55, 0x27, 0x92, 0x5f, 0xdc, 0x34, 0x25, 0x75, 0x4d, 0xdb, 0xbf, 0x60, 0xa3, + 0x1f, 0xbf, 0x9d, 0xf2, 0x64, 0x1a, 0x92, 0x86, 0xb4, 0xdd, 0x4f, 0x7d, 0xd5, 0xa0, 0x31, 0x4b, + 0x8e, 0x18, 0xf5, 0x58, 0x42, 0x56, 0xf5, 0xe9, 0xd3, 0x20, 0x64, 0x7c, 0x2a, 0x8e, 0xf9, 0x4f, + 0xa4, 0xa9, 0xc5, 0x0c, 0x18, 0xf5, 0xd4, 0xff, 0x8e, 0xac, 0x69, 0x31, 0x33, 0x44, 0x89, 0x21, + 0xda, 0xef, 0x9b, 0x84, 0x29, 0x8b, 0xeb, 0xfa, 0x56, 0xbd, 0x57, 0x1c, 0xdc, 0xfe, 0xd5, 0x84, + 0x8d, 0xc7, 0xc6, 0x03, 0xb7, 0xc0, 0x79, 0x0c, 0xdf, 0x9d, 0x0a, 0x4e, 0x0c, 0xfc, 0x04, 0xfe, + 0xff, 0x58, 0xf4, 0x6b, 0x1e, 0x44, 0xa2, 0x17, 0xc6, 0x93, 0x60, 0x14, 0xc8, 0x56, 0x7c, 0x8c, + 0xf6, 0xfa, 0x4a, 0xd3, 0xac, 0xed, 0x6b, 0x68, 0x2e, 0x7e, 0x14, 0xb2, 0x18, 0x73, 0x64, 0xd7, + 0xf3, 0xe4, 0xf8, 0x13, 0x03, 0x9d, 0xa2, 0xd8, 0x01, 0x0b, 0xf9, 0x25, 0x53, 0x11, 0x73, 0x31, + 0xf2, 0x36, 0xf6, 0xa8, 0xc8, 0x22, 0xd6, 0xa2, 0x91, 0x5d, 0xcf, 0x3b, 0xca, 0xde, 0x1e, 0x15, + 0x2d, 0xed, 0xbd, 0xb8, 0xf9, 0xe0, 0x1a, 0xb7, 0x1f, 0x5c, 0xe3, 0xe6, 0xce, 0x35, 0x6f, 0xef, + 0x5c, 0xf3, 0x9f, 0x3b, 0xd7, 0xfc, 0xed, 0xde, 0x35, 0x7e, 0xbf, 0x77, 0x8d, 0xdb, 0x7b, 0xd7, + 0xf8, 0xfb, 0xde, 0x35, 0xfe, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xee, 0xe3, 0x39, 0x8b, 0xbb, 0x08, + 0x00, 0x00, +} + func (m *Entry) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -449,35 +774,38 @@ func (m *Entry) Marshal() (dAtA []byte, err error) { } func (m *Entry) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Entry) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Type)) - dAtA[i] = 0x10 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Term)) - dAtA[i] = 0x18 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Index)) if m.Data != nil { - dAtA[i] = 0x22 - i++ + i -= len(m.Data) + copy(dAtA[i:], m.Data) i = encodeVarintRaft(dAtA, i, uint64(len(m.Data))) - i += copy(dAtA[i:], m.Data) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) + i-- + dAtA[i] = 0x22 } - return i, nil + i = encodeVarintRaft(dAtA, i, uint64(m.Index)) + i-- + dAtA[i] = 0x18 + i = encodeVarintRaft(dAtA, i, uint64(m.Term)) + i-- + dAtA[i] = 0x10 + i = encodeVarintRaft(dAtA, i, uint64(m.Type)) + i-- + dAtA[i] = 0x8 + return len(dAtA) - i, nil } func (m *SnapshotMetadata) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -485,34 +813,38 @@ func (m *SnapshotMetadata) Marshal() (dAtA []byte, err error) { } func (m *SnapshotMetadata) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SnapshotMetadata) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - dAtA[i] = 0xa - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.ConfState.Size())) - n1, err := m.ConfState.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - dAtA[i] = 0x10 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Index)) - dAtA[i] = 0x18 - i++ i = encodeVarintRaft(dAtA, i, uint64(m.Term)) - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) + i-- + dAtA[i] = 0x18 + i = encodeVarintRaft(dAtA, i, uint64(m.Index)) + i-- + dAtA[i] = 0x10 + { + size, err := m.ConfState.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintRaft(dAtA, i, uint64(size)) } - return i, nil + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil } func (m *Snapshot) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -520,34 +852,39 @@ func (m *Snapshot) Marshal() (dAtA []byte, err error) { } func (m *Snapshot) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Snapshot) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if m.Data != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintRaft(dAtA, i, uint64(len(m.Data))) - i += copy(dAtA[i:], m.Data) + { + size, err := m.Metadata.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintRaft(dAtA, i, uint64(size)) } + i-- dAtA[i] = 0x12 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Metadata.Size())) - n2, err := m.Metadata.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) + if m.Data != nil { + i -= len(m.Data) + copy(dAtA[i:], m.Data) + i = encodeVarintRaft(dAtA, i, uint64(len(m.Data))) + i-- + dAtA[i] = 0xa } - return i, nil + return len(dAtA) - i, nil } func (m *Message) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -555,78 +892,85 @@ func (m *Message) Marshal() (dAtA []byte, err error) { } func (m *Message) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Message) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Type)) - dAtA[i] = 0x10 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.To)) - dAtA[i] = 0x18 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.From)) - dAtA[i] = 0x20 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Term)) - dAtA[i] = 0x28 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.LogTerm)) - dAtA[i] = 0x30 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Index)) - if len(m.Entries) > 0 { - for _, msg := range m.Entries { - dAtA[i] = 0x3a - i++ - i = encodeVarintRaft(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } - dAtA[i] = 0x40 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Commit)) - dAtA[i] = 0x4a - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Snapshot.Size())) - n3, err := m.Snapshot.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err + if m.Context != nil { + i -= len(m.Context) + copy(dAtA[i:], m.Context) + i = encodeVarintRaft(dAtA, i, uint64(len(m.Context))) + i-- + dAtA[i] = 0x62 } - i += n3 - dAtA[i] = 0x50 - i++ + i = encodeVarintRaft(dAtA, i, uint64(m.RejectHint)) + i-- + dAtA[i] = 0x58 + i-- if m.Reject { dAtA[i] = 1 } else { dAtA[i] = 0 } - i++ - dAtA[i] = 0x58 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.RejectHint)) - if m.Context != nil { - dAtA[i] = 0x62 - i++ - i = encodeVarintRaft(dAtA, i, uint64(len(m.Context))) - i += copy(dAtA[i:], m.Context) + i-- + dAtA[i] = 0x50 + { + size, err := m.Snapshot.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintRaft(dAtA, i, uint64(size)) } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) + i-- + dAtA[i] = 0x4a + i = encodeVarintRaft(dAtA, i, uint64(m.Commit)) + i-- + dAtA[i] = 0x40 + if len(m.Entries) > 0 { + for iNdEx := len(m.Entries) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Entries[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintRaft(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + } } - return i, nil + i = encodeVarintRaft(dAtA, i, uint64(m.Index)) + i-- + dAtA[i] = 0x30 + i = encodeVarintRaft(dAtA, i, uint64(m.LogTerm)) + i-- + dAtA[i] = 0x28 + i = encodeVarintRaft(dAtA, i, uint64(m.Term)) + i-- + dAtA[i] = 0x20 + i = encodeVarintRaft(dAtA, i, uint64(m.From)) + i-- + dAtA[i] = 0x18 + i = encodeVarintRaft(dAtA, i, uint64(m.To)) + i-- + dAtA[i] = 0x10 + i = encodeVarintRaft(dAtA, i, uint64(m.Type)) + i-- + dAtA[i] = 0x8 + return len(dAtA) - i, nil } func (m *HardState) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -634,29 +978,31 @@ func (m *HardState) Marshal() (dAtA []byte, err error) { } func (m *HardState) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *HardState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Term)) - dAtA[i] = 0x10 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Vote)) - dAtA[i] = 0x18 - i++ i = encodeVarintRaft(dAtA, i, uint64(m.Commit)) - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil + i-- + dAtA[i] = 0x18 + i = encodeVarintRaft(dAtA, i, uint64(m.Vote)) + i-- + dAtA[i] = 0x10 + i = encodeVarintRaft(dAtA, i, uint64(m.Term)) + i-- + dAtA[i] = 0x8 + return len(dAtA) - i, nil } func (m *ConfState) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -664,56 +1010,58 @@ func (m *ConfState) Marshal() (dAtA []byte, err error) { } func (m *ConfState) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ConfState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - if len(m.Voters) > 0 { - for _, num := range m.Voters { - dAtA[i] = 0x8 - i++ - i = encodeVarintRaft(dAtA, i, uint64(num)) - } + i-- + if m.AutoLeave { + dAtA[i] = 1 + } else { + dAtA[i] = 0 } - if len(m.Learners) > 0 { - for _, num := range m.Learners { - dAtA[i] = 0x10 - i++ - i = encodeVarintRaft(dAtA, i, uint64(num)) + i-- + dAtA[i] = 0x28 + if len(m.LearnersNext) > 0 { + for iNdEx := len(m.LearnersNext) - 1; iNdEx >= 0; iNdEx-- { + i = encodeVarintRaft(dAtA, i, uint64(m.LearnersNext[iNdEx])) + i-- + dAtA[i] = 0x20 } } if len(m.VotersOutgoing) > 0 { - for _, num := range m.VotersOutgoing { + for iNdEx := len(m.VotersOutgoing) - 1; iNdEx >= 0; iNdEx-- { + i = encodeVarintRaft(dAtA, i, uint64(m.VotersOutgoing[iNdEx])) + i-- dAtA[i] = 0x18 - i++ - i = encodeVarintRaft(dAtA, i, uint64(num)) } } - if len(m.LearnersNext) > 0 { - for _, num := range m.LearnersNext { - dAtA[i] = 0x20 - i++ - i = encodeVarintRaft(dAtA, i, uint64(num)) + if len(m.Learners) > 0 { + for iNdEx := len(m.Learners) - 1; iNdEx >= 0; iNdEx-- { + i = encodeVarintRaft(dAtA, i, uint64(m.Learners[iNdEx])) + i-- + dAtA[i] = 0x10 } } - dAtA[i] = 0x28 - i++ - if m.AutoLeave { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) + if len(m.Voters) > 0 { + for iNdEx := len(m.Voters) - 1; iNdEx >= 0; iNdEx-- { + i = encodeVarintRaft(dAtA, i, uint64(m.Voters[iNdEx])) + i-- + dAtA[i] = 0x8 + } } - return i, nil + return len(dAtA) - i, nil } func (m *ConfChange) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -721,35 +1069,38 @@ func (m *ConfChange) Marshal() (dAtA []byte, err error) { } func (m *ConfChange) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ConfChange) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.ID)) - dAtA[i] = 0x10 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Type)) - dAtA[i] = 0x18 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.NodeID)) if m.Context != nil { - dAtA[i] = 0x22 - i++ + i -= len(m.Context) + copy(dAtA[i:], m.Context) i = encodeVarintRaft(dAtA, i, uint64(len(m.Context))) - i += copy(dAtA[i:], m.Context) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) + i-- + dAtA[i] = 0x22 } - return i, nil + i = encodeVarintRaft(dAtA, i, uint64(m.NodeID)) + i-- + dAtA[i] = 0x18 + i = encodeVarintRaft(dAtA, i, uint64(m.Type)) + i-- + dAtA[i] = 0x10 + i = encodeVarintRaft(dAtA, i, uint64(m.ID)) + i-- + dAtA[i] = 0x8 + return len(dAtA) - i, nil } func (m *ConfChangeSingle) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -757,26 +1108,28 @@ func (m *ConfChangeSingle) Marshal() (dAtA []byte, err error) { } func (m *ConfChangeSingle) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ConfChangeSingle) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Type)) - dAtA[i] = 0x10 - i++ i = encodeVarintRaft(dAtA, i, uint64(m.NodeID)) - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil + i-- + dAtA[i] = 0x10 + i = encodeVarintRaft(dAtA, i, uint64(m.Type)) + i-- + dAtA[i] = 0x8 + return len(dAtA) - i, nil } func (m *ConfChangeV2) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -784,47 +1137,57 @@ func (m *ConfChangeV2) Marshal() (dAtA []byte, err error) { } func (m *ConfChangeV2) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ConfChangeV2) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRaft(dAtA, i, uint64(m.Transition)) - if len(m.Changes) > 0 { - for _, msg := range m.Changes { - dAtA[i] = 0x12 - i++ - i = encodeVarintRaft(dAtA, i, uint64(msg.Size())) - n, err := msg.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n - } - } if m.Context != nil { - dAtA[i] = 0x1a - i++ + i -= len(m.Context) + copy(dAtA[i:], m.Context) i = encodeVarintRaft(dAtA, i, uint64(len(m.Context))) - i += copy(dAtA[i:], m.Context) + i-- + dAtA[i] = 0x1a } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) + if len(m.Changes) > 0 { + for iNdEx := len(m.Changes) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Changes[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintRaft(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } } - return i, nil + i = encodeVarintRaft(dAtA, i, uint64(m.Transition)) + i-- + dAtA[i] = 0x8 + return len(dAtA) - i, nil } func encodeVarintRaft(dAtA []byte, offset int, v uint64) int { + offset -= sovRaft(v) + base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) v >>= 7 offset++ } dAtA[offset] = uint8(v) - return offset + 1 + return base } func (m *Entry) Size() (n int) { + if m == nil { + return 0 + } var l int _ = l n += 1 + sovRaft(uint64(m.Type)) @@ -834,26 +1197,26 @@ func (m *Entry) Size() (n int) { l = len(m.Data) n += 1 + l + sovRaft(uint64(l)) } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } return n } func (m *SnapshotMetadata) Size() (n int) { + if m == nil { + return 0 + } var l int _ = l l = m.ConfState.Size() n += 1 + l + sovRaft(uint64(l)) n += 1 + sovRaft(uint64(m.Index)) n += 1 + sovRaft(uint64(m.Term)) - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } return n } func (m *Snapshot) Size() (n int) { + if m == nil { + return 0 + } var l int _ = l if m.Data != nil { @@ -862,13 +1225,13 @@ func (m *Snapshot) Size() (n int) { } l = m.Metadata.Size() n += 1 + l + sovRaft(uint64(l)) - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } return n } func (m *Message) Size() (n int) { + if m == nil { + return 0 + } var l int _ = l n += 1 + sovRaft(uint64(m.Type)) @@ -892,25 +1255,25 @@ func (m *Message) Size() (n int) { l = len(m.Context) n += 1 + l + sovRaft(uint64(l)) } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } return n } func (m *HardState) Size() (n int) { + if m == nil { + return 0 + } var l int _ = l n += 1 + sovRaft(uint64(m.Term)) n += 1 + sovRaft(uint64(m.Vote)) n += 1 + sovRaft(uint64(m.Commit)) - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } return n } func (m *ConfState) Size() (n int) { + if m == nil { + return 0 + } var l int _ = l if len(m.Voters) > 0 { @@ -934,13 +1297,13 @@ func (m *ConfState) Size() (n int) { } } n += 2 - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } return n } func (m *ConfChange) Size() (n int) { + if m == nil { + return 0 + } var l int _ = l n += 1 + sovRaft(uint64(m.ID)) @@ -950,24 +1313,24 @@ func (m *ConfChange) Size() (n int) { l = len(m.Context) n += 1 + l + sovRaft(uint64(l)) } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } return n } func (m *ConfChangeSingle) Size() (n int) { + if m == nil { + return 0 + } var l int _ = l n += 1 + sovRaft(uint64(m.Type)) n += 1 + sovRaft(uint64(m.NodeID)) - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } return n } func (m *ConfChangeV2) Size() (n int) { + if m == nil { + return 0 + } var l int _ = l n += 1 + sovRaft(uint64(m.Transition)) @@ -981,21 +1344,11 @@ func (m *ConfChangeV2) Size() (n int) { l = len(m.Context) n += 1 + l + sovRaft(uint64(l)) } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } return n } func sovRaft(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n + return (math_bits.Len64(x|1) + 6) / 7 } func sozRaft(x uint64) (n int) { return sovRaft(uint64((x << 1) ^ uint64((int64(x) >> 63)))) @@ -1015,7 +1368,7 @@ func (m *Entry) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - wire |= (uint64(b) & 0x7F) << shift + wire |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1043,7 +1396,7 @@ func (m *Entry) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Type |= (EntryType(b) & 0x7F) << shift + m.Type |= EntryType(b&0x7F) << shift if b < 0x80 { break } @@ -1062,7 +1415,7 @@ func (m *Entry) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Term |= (uint64(b) & 0x7F) << shift + m.Term |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1081,7 +1434,7 @@ func (m *Entry) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Index |= (uint64(b) & 0x7F) << shift + m.Index |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1100,7 +1453,7 @@ func (m *Entry) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= (int(b) & 0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } @@ -1109,6 +1462,9 @@ func (m *Entry) Unmarshal(dAtA []byte) error { return ErrInvalidLengthRaft } postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthRaft + } if postIndex > l { return io.ErrUnexpectedEOF } @@ -1123,13 +1479,12 @@ func (m *Entry) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthRaft } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) iNdEx += skippy } } @@ -1154,7 +1509,7 @@ func (m *SnapshotMetadata) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - wire |= (uint64(b) & 0x7F) << shift + wire |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1182,7 +1537,7 @@ func (m *SnapshotMetadata) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= (int(b) & 0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } @@ -1191,6 +1546,9 @@ func (m *SnapshotMetadata) Unmarshal(dAtA []byte) error { return ErrInvalidLengthRaft } postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthRaft + } if postIndex > l { return io.ErrUnexpectedEOF } @@ -1212,7 +1570,7 @@ func (m *SnapshotMetadata) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Index |= (uint64(b) & 0x7F) << shift + m.Index |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1231,7 +1589,7 @@ func (m *SnapshotMetadata) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Term |= (uint64(b) & 0x7F) << shift + m.Term |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1242,13 +1600,12 @@ func (m *SnapshotMetadata) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthRaft } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) iNdEx += skippy } } @@ -1273,7 +1630,7 @@ func (m *Snapshot) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - wire |= (uint64(b) & 0x7F) << shift + wire |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1301,7 +1658,7 @@ func (m *Snapshot) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= (int(b) & 0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } @@ -1310,6 +1667,9 @@ func (m *Snapshot) Unmarshal(dAtA []byte) error { return ErrInvalidLengthRaft } postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthRaft + } if postIndex > l { return io.ErrUnexpectedEOF } @@ -1332,7 +1692,7 @@ func (m *Snapshot) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= (int(b) & 0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } @@ -1341,6 +1701,9 @@ func (m *Snapshot) Unmarshal(dAtA []byte) error { return ErrInvalidLengthRaft } postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthRaft + } if postIndex > l { return io.ErrUnexpectedEOF } @@ -1354,13 +1717,12 @@ func (m *Snapshot) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthRaft } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) iNdEx += skippy } } @@ -1385,7 +1747,7 @@ func (m *Message) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - wire |= (uint64(b) & 0x7F) << shift + wire |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1413,7 +1775,7 @@ func (m *Message) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Type |= (MessageType(b) & 0x7F) << shift + m.Type |= MessageType(b&0x7F) << shift if b < 0x80 { break } @@ -1432,7 +1794,7 @@ func (m *Message) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.To |= (uint64(b) & 0x7F) << shift + m.To |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1451,7 +1813,7 @@ func (m *Message) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.From |= (uint64(b) & 0x7F) << shift + m.From |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1470,7 +1832,7 @@ func (m *Message) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Term |= (uint64(b) & 0x7F) << shift + m.Term |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1489,7 +1851,7 @@ func (m *Message) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.LogTerm |= (uint64(b) & 0x7F) << shift + m.LogTerm |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1508,7 +1870,7 @@ func (m *Message) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Index |= (uint64(b) & 0x7F) << shift + m.Index |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1527,7 +1889,7 @@ func (m *Message) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= (int(b) & 0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } @@ -1536,6 +1898,9 @@ func (m *Message) Unmarshal(dAtA []byte) error { return ErrInvalidLengthRaft } postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthRaft + } if postIndex > l { return io.ErrUnexpectedEOF } @@ -1558,7 +1923,7 @@ func (m *Message) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Commit |= (uint64(b) & 0x7F) << shift + m.Commit |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1577,7 +1942,7 @@ func (m *Message) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= (int(b) & 0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } @@ -1586,6 +1951,9 @@ func (m *Message) Unmarshal(dAtA []byte) error { return ErrInvalidLengthRaft } postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthRaft + } if postIndex > l { return io.ErrUnexpectedEOF } @@ -1607,7 +1975,7 @@ func (m *Message) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= (int(b) & 0x7F) << shift + v |= int(b&0x7F) << shift if b < 0x80 { break } @@ -1627,7 +1995,7 @@ func (m *Message) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.RejectHint |= (uint64(b) & 0x7F) << shift + m.RejectHint |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1646,7 +2014,7 @@ func (m *Message) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= (int(b) & 0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } @@ -1655,6 +2023,9 @@ func (m *Message) Unmarshal(dAtA []byte) error { return ErrInvalidLengthRaft } postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthRaft + } if postIndex > l { return io.ErrUnexpectedEOF } @@ -1669,13 +2040,12 @@ func (m *Message) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthRaft } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) iNdEx += skippy } } @@ -1700,7 +2070,7 @@ func (m *HardState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - wire |= (uint64(b) & 0x7F) << shift + wire |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1728,7 +2098,7 @@ func (m *HardState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Term |= (uint64(b) & 0x7F) << shift + m.Term |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1747,7 +2117,7 @@ func (m *HardState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Vote |= (uint64(b) & 0x7F) << shift + m.Vote |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1766,7 +2136,7 @@ func (m *HardState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Commit |= (uint64(b) & 0x7F) << shift + m.Commit |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1777,13 +2147,12 @@ func (m *HardState) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthRaft } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) iNdEx += skippy } } @@ -1808,7 +2177,7 @@ func (m *ConfState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - wire |= (uint64(b) & 0x7F) << shift + wire |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1834,7 +2203,7 @@ func (m *ConfState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= (uint64(b) & 0x7F) << shift + v |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1851,7 +2220,7 @@ func (m *ConfState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - packedLen |= (int(b) & 0x7F) << shift + packedLen |= int(b&0x7F) << shift if b < 0x80 { break } @@ -1860,9 +2229,23 @@ func (m *ConfState) Unmarshal(dAtA []byte) error { return ErrInvalidLengthRaft } postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthRaft + } if postIndex > l { return io.ErrUnexpectedEOF } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(m.Voters) == 0 { + m.Voters = make([]uint64, 0, elementCount) + } for iNdEx < postIndex { var v uint64 for shift := uint(0); ; shift += 7 { @@ -1874,7 +2257,7 @@ func (m *ConfState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= (uint64(b) & 0x7F) << shift + v |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1896,7 +2279,7 @@ func (m *ConfState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= (uint64(b) & 0x7F) << shift + v |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1913,7 +2296,7 @@ func (m *ConfState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - packedLen |= (int(b) & 0x7F) << shift + packedLen |= int(b&0x7F) << shift if b < 0x80 { break } @@ -1922,9 +2305,23 @@ func (m *ConfState) Unmarshal(dAtA []byte) error { return ErrInvalidLengthRaft } postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthRaft + } if postIndex > l { return io.ErrUnexpectedEOF } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(m.Learners) == 0 { + m.Learners = make([]uint64, 0, elementCount) + } for iNdEx < postIndex { var v uint64 for shift := uint(0); ; shift += 7 { @@ -1936,7 +2333,7 @@ func (m *ConfState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= (uint64(b) & 0x7F) << shift + v |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1958,7 +2355,7 @@ func (m *ConfState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= (uint64(b) & 0x7F) << shift + v |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1975,7 +2372,7 @@ func (m *ConfState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - packedLen |= (int(b) & 0x7F) << shift + packedLen |= int(b&0x7F) << shift if b < 0x80 { break } @@ -1984,9 +2381,23 @@ func (m *ConfState) Unmarshal(dAtA []byte) error { return ErrInvalidLengthRaft } postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthRaft + } if postIndex > l { return io.ErrUnexpectedEOF } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(m.VotersOutgoing) == 0 { + m.VotersOutgoing = make([]uint64, 0, elementCount) + } for iNdEx < postIndex { var v uint64 for shift := uint(0); ; shift += 7 { @@ -1998,7 +2409,7 @@ func (m *ConfState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= (uint64(b) & 0x7F) << shift + v |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -2020,7 +2431,7 @@ func (m *ConfState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= (uint64(b) & 0x7F) << shift + v |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -2037,7 +2448,7 @@ func (m *ConfState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - packedLen |= (int(b) & 0x7F) << shift + packedLen |= int(b&0x7F) << shift if b < 0x80 { break } @@ -2046,9 +2457,23 @@ func (m *ConfState) Unmarshal(dAtA []byte) error { return ErrInvalidLengthRaft } postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthRaft + } if postIndex > l { return io.ErrUnexpectedEOF } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(m.LearnersNext) == 0 { + m.LearnersNext = make([]uint64, 0, elementCount) + } for iNdEx < postIndex { var v uint64 for shift := uint(0); ; shift += 7 { @@ -2060,7 +2485,7 @@ func (m *ConfState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= (uint64(b) & 0x7F) << shift + v |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -2084,7 +2509,7 @@ func (m *ConfState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= (int(b) & 0x7F) << shift + v |= int(b&0x7F) << shift if b < 0x80 { break } @@ -2096,13 +2521,12 @@ func (m *ConfState) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthRaft } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) iNdEx += skippy } } @@ -2127,7 +2551,7 @@ func (m *ConfChange) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - wire |= (uint64(b) & 0x7F) << shift + wire |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -2155,7 +2579,7 @@ func (m *ConfChange) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.ID |= (uint64(b) & 0x7F) << shift + m.ID |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -2174,7 +2598,7 @@ func (m *ConfChange) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Type |= (ConfChangeType(b) & 0x7F) << shift + m.Type |= ConfChangeType(b&0x7F) << shift if b < 0x80 { break } @@ -2193,7 +2617,7 @@ func (m *ConfChange) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.NodeID |= (uint64(b) & 0x7F) << shift + m.NodeID |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -2212,7 +2636,7 @@ func (m *ConfChange) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= (int(b) & 0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } @@ -2221,6 +2645,9 @@ func (m *ConfChange) Unmarshal(dAtA []byte) error { return ErrInvalidLengthRaft } postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthRaft + } if postIndex > l { return io.ErrUnexpectedEOF } @@ -2235,13 +2662,12 @@ func (m *ConfChange) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthRaft } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) iNdEx += skippy } } @@ -2266,7 +2692,7 @@ func (m *ConfChangeSingle) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - wire |= (uint64(b) & 0x7F) << shift + wire |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -2294,7 +2720,7 @@ func (m *ConfChangeSingle) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Type |= (ConfChangeType(b) & 0x7F) << shift + m.Type |= ConfChangeType(b&0x7F) << shift if b < 0x80 { break } @@ -2313,7 +2739,7 @@ func (m *ConfChangeSingle) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.NodeID |= (uint64(b) & 0x7F) << shift + m.NodeID |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -2324,13 +2750,12 @@ func (m *ConfChangeSingle) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthRaft } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) iNdEx += skippy } } @@ -2355,7 +2780,7 @@ func (m *ConfChangeV2) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - wire |= (uint64(b) & 0x7F) << shift + wire |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -2383,7 +2808,7 @@ func (m *ConfChangeV2) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Transition |= (ConfChangeTransition(b) & 0x7F) << shift + m.Transition |= ConfChangeTransition(b&0x7F) << shift if b < 0x80 { break } @@ -2402,7 +2827,7 @@ func (m *ConfChangeV2) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= (int(b) & 0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } @@ -2411,6 +2836,9 @@ func (m *ConfChangeV2) Unmarshal(dAtA []byte) error { return ErrInvalidLengthRaft } postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthRaft + } if postIndex > l { return io.ErrUnexpectedEOF } @@ -2433,7 +2861,7 @@ func (m *ConfChangeV2) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= (int(b) & 0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } @@ -2442,6 +2870,9 @@ func (m *ConfChangeV2) Unmarshal(dAtA []byte) error { return ErrInvalidLengthRaft } postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthRaft + } if postIndex > l { return io.ErrUnexpectedEOF } @@ -2456,13 +2887,12 @@ func (m *ConfChangeV2) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthRaft } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) iNdEx += skippy } } @@ -2475,6 +2905,7 @@ func (m *ConfChangeV2) Unmarshal(dAtA []byte) error { func skipRaft(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 + depth := 0 for iNdEx < l { var wire uint64 for shift := uint(0); ; shift += 7 { @@ -2506,10 +2937,8 @@ func skipRaft(dAtA []byte) (n int, err error) { break } } - return iNdEx, nil case 1: iNdEx += 8 - return iNdEx, nil case 2: var length int for shift := uint(0); ; shift += 7 { @@ -2526,123 +2955,34 @@ func skipRaft(dAtA []byte) (n int, err error) { break } } - iNdEx += length if length < 0 { return 0, ErrInvalidLengthRaft } - return iNdEx, nil + iNdEx += length case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaft - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipRaft(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil + depth++ case 4: - return iNdEx, nil + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupRaft + } + depth-- case 5: iNdEx += 4 - return iNdEx, nil default: return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } + if iNdEx < 0 { + return 0, ErrInvalidLengthRaft + } + if depth == 0 { + return iNdEx, nil + } } - panic("unreachable") + return 0, io.ErrUnexpectedEOF } var ( - ErrInvalidLengthRaft = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowRaft = fmt.Errorf("proto: integer overflow") + ErrInvalidLengthRaft = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowRaft = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupRaft = fmt.Errorf("proto: unexpected end of group") ) - -func init() { proto.RegisterFile("raft.proto", fileDescriptorRaft) } - -var fileDescriptorRaft = []byte{ - // 1009 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xcd, 0x6e, 0xe3, 0x36, - 0x17, 0xb5, 0x64, 0xc5, 0x3f, 0xd7, 0x8e, 0xc3, 0xdc, 0xc9, 0x37, 0x20, 0x82, 0xc0, 0xe3, 0xcf, - 0xd3, 0x62, 0x8c, 0x14, 0x93, 0x16, 0x5e, 0x14, 0x45, 0x77, 0xf9, 0x19, 0x20, 0x29, 0xe2, 0x74, - 0xea, 0x64, 0xb2, 0x28, 0x50, 0x04, 0x8c, 0x45, 0x2b, 0x6a, 0x2d, 0x51, 0xa0, 0xe8, 0x34, 0xd9, - 0x14, 0x45, 0x9f, 0xa2, 0x9b, 0xd9, 0xf6, 0x01, 0xfa, 0x14, 0x59, 0x0e, 0xd0, 0xfd, 0xa0, 0x93, - 0xbe, 0x48, 0x41, 0x8a, 0xb2, 0x65, 0x27, 0x98, 0x45, 0x77, 0xe4, 0x39, 0x87, 0xf7, 0x9e, 0x7b, - 0x79, 0x45, 0x01, 0x48, 0x36, 0x56, 0x3b, 0x89, 0x14, 0x4a, 0x60, 0x45, 0xaf, 0x93, 0xcb, 0xcd, - 0x8d, 0x40, 0x04, 0xc2, 0x40, 0x9f, 0xeb, 0x55, 0xc6, 0x76, 0x7f, 0x81, 0x95, 0x57, 0xb1, 0x92, - 0xb7, 0xf8, 0x19, 0x78, 0x67, 0xb7, 0x09, 0xa7, 0x4e, 0xc7, 0xe9, 0xb5, 0xfa, 0xeb, 0x3b, 0xd9, - 0xa9, 0x1d, 0x43, 0x6a, 0x62, 0xcf, 0xbb, 0x7b, 0xff, 0xac, 0x34, 0x34, 0x22, 0xa4, 0xe0, 0x9d, - 0x71, 0x19, 0x51, 0xb7, 0xe3, 0xf4, 0xbc, 0x19, 0xc3, 0x65, 0x84, 0x9b, 0xb0, 0x72, 0x14, 0xfb, - 0xfc, 0x86, 0x96, 0x0b, 0x54, 0x06, 0x21, 0x82, 0x77, 0xc0, 0x14, 0xa3, 0x5e, 0xc7, 0xe9, 0x35, - 0x87, 0x66, 0xdd, 0xfd, 0xd5, 0x01, 0x72, 0x1a, 0xb3, 0x24, 0xbd, 0x12, 0x6a, 0xc0, 0x15, 0xf3, - 0x99, 0x62, 0xf8, 0x25, 0xc0, 0x48, 0xc4, 0xe3, 0x8b, 0x54, 0x31, 0x95, 0x39, 0x6a, 0xcc, 0x1d, - 0xed, 0x8b, 0x78, 0x7c, 0xaa, 0x09, 0x1b, 0xbc, 0x3e, 0xca, 0x01, 0x9d, 0x3c, 0x34, 0xc9, 0x8b, - 0xbe, 0x32, 0x48, 0x5b, 0x56, 0xda, 0x72, 0xd1, 0x97, 0x41, 0xba, 0xdf, 0x43, 0x2d, 0x77, 0xa0, - 0x2d, 0x6a, 0x07, 0x26, 0x67, 0x73, 0x68, 0xd6, 0xf8, 0x35, 0xd4, 0x22, 0xeb, 0xcc, 0x04, 0x6e, - 0xf4, 0x69, 0xee, 0x65, 0xd9, 0xb9, 0x8d, 0x3b, 0xd3, 0x77, 0xdf, 0x96, 0xa1, 0x3a, 0xe0, 0x69, - 0xca, 0x02, 0x8e, 0x2f, 0xc1, 0x53, 0xf3, 0x0e, 0x3f, 0xc9, 0x63, 0x58, 0xba, 0xd8, 0x63, 0x2d, - 0xc3, 0x0d, 0x70, 0x95, 0x58, 0xa8, 0xc4, 0x55, 0x42, 0x97, 0x31, 0x96, 0x62, 0xa9, 0x0c, 0x8d, - 0xcc, 0x0a, 0xf4, 0x96, 0x0b, 0xc4, 0x36, 0x54, 0x27, 0x22, 0x30, 0x17, 0xb6, 0x52, 0x20, 0x73, - 0x70, 0xde, 0xb6, 0xca, 0xc3, 0xb6, 0xbd, 0x84, 0x2a, 0x8f, 0x95, 0x0c, 0x79, 0x4a, 0xab, 0x9d, - 0x72, 0xaf, 0xd1, 0x5f, 0x5d, 0x98, 0x8c, 0x3c, 0x94, 0xd5, 0xe0, 0x16, 0x54, 0x46, 0x22, 0x8a, - 0x42, 0x45, 0x6b, 0x85, 0x58, 0x16, 0xc3, 0x3e, 0xd4, 0x52, 0xdb, 0x31, 0x5a, 0x37, 0x9d, 0x24, - 0xcb, 0x9d, 0xcc, 0x3b, 0x98, 0xeb, 0x74, 0x44, 0xc9, 0x7f, 0xe4, 0x23, 0x45, 0xa1, 0xe3, 0xf4, - 0x6a, 0x79, 0xc4, 0x0c, 0xc3, 0x4f, 0x00, 0xb2, 0xd5, 0x61, 0x18, 0x2b, 0xda, 0x28, 0xe4, 0x2c, - 0xe0, 0x48, 0xa1, 0x3a, 0x12, 0xb1, 0xe2, 0x37, 0x8a, 0x36, 0xcd, 0xc5, 0xe6, 0xdb, 0xee, 0x0f, - 0x50, 0x3f, 0x64, 0xd2, 0xcf, 0xc6, 0x27, 0xef, 0xa0, 0xf3, 0xa0, 0x83, 0x14, 0xbc, 0x6b, 0xa1, - 0xf8, 0xe2, 0xbc, 0x6b, 0xa4, 0x50, 0x70, 0xf9, 0x61, 0xc1, 0xdd, 0x3f, 0x1d, 0xa8, 0xcf, 0xe6, - 0x15, 0x9f, 0x42, 0x45, 0x9f, 0x91, 0x29, 0x75, 0x3a, 0xe5, 0x9e, 0x37, 0xb4, 0x3b, 0xdc, 0x84, - 0xda, 0x84, 0x33, 0x19, 0x6b, 0xc6, 0x35, 0xcc, 0x6c, 0x8f, 0x2f, 0x60, 0x2d, 0x53, 0x5d, 0x88, - 0xa9, 0x0a, 0x44, 0x18, 0x07, 0xb4, 0x6c, 0x24, 0xad, 0x0c, 0xfe, 0xd6, 0xa2, 0xf8, 0x1c, 0x56, - 0xf3, 0x43, 0x17, 0xb1, 0xae, 0xd4, 0x33, 0xb2, 0x66, 0x0e, 0x9e, 0xf0, 0x1b, 0x85, 0xcf, 0x01, - 0xd8, 0x54, 0x89, 0x8b, 0x09, 0x67, 0xd7, 0xdc, 0x0c, 0x43, 0xde, 0xd0, 0xba, 0xc6, 0x8f, 0x35, - 0xdc, 0x7d, 0xeb, 0x00, 0x68, 0xd3, 0xfb, 0x57, 0x2c, 0x0e, 0xf4, 0x47, 0xe5, 0x86, 0xbe, 0xed, - 0x09, 0x68, 0xed, 0xfd, 0xfb, 0x67, 0xee, 0xd1, 0xc1, 0xd0, 0x0d, 0x7d, 0xfc, 0xc2, 0x8e, 0xb4, - 0x6b, 0x46, 0xfa, 0x69, 0xf1, 0x13, 0xcd, 0x4e, 0x3f, 0x98, 0xea, 0x17, 0x50, 0x8d, 0x85, 0xcf, - 0x2f, 0x42, 0xdf, 0x36, 0xac, 0x65, 0x43, 0x56, 0x4e, 0x84, 0xcf, 0x8f, 0x0e, 0x86, 0x15, 0x4d, - 0x1f, 0xf9, 0xc5, 0x3b, 0xf3, 0x16, 0xef, 0x2c, 0x02, 0x32, 0x4f, 0x70, 0x1a, 0xc6, 0xc1, 0x84, - 0xcf, 0x8c, 0x38, 0xff, 0xc5, 0x88, 0xfb, 0x31, 0x23, 0xdd, 0x3f, 0x1c, 0x68, 0xce, 0xe3, 0x9c, - 0xf7, 0x71, 0x0f, 0x40, 0x49, 0x16, 0xa7, 0xa1, 0x0a, 0x45, 0x6c, 0x33, 0x6e, 0x3d, 0x92, 0x71, - 0xa6, 0xc9, 0x27, 0x72, 0x7e, 0x0a, 0xbf, 0x82, 0xea, 0xc8, 0xa8, 0xb2, 0x1b, 0x2f, 0x3c, 0x29, - 0xcb, 0xa5, 0xe5, 0x5f, 0x98, 0x95, 0x17, 0xfb, 0x52, 0x5e, 0xe8, 0xcb, 0xf6, 0x21, 0xd4, 0x67, - 0xaf, 0x35, 0xae, 0x41, 0xc3, 0x6c, 0x4e, 0x84, 0x8c, 0xd8, 0x84, 0x94, 0xf0, 0x09, 0xac, 0x19, - 0x60, 0x1e, 0x9f, 0x38, 0xf8, 0x3f, 0x58, 0x5f, 0x02, 0xcf, 0xfb, 0xc4, 0xdd, 0xfe, 0xcb, 0x85, - 0x46, 0xe1, 0x59, 0x42, 0x80, 0xca, 0x20, 0x0d, 0x0e, 0xa7, 0x09, 0x29, 0x61, 0x03, 0xaa, 0x83, - 0x34, 0xd8, 0xe3, 0x4c, 0x11, 0xc7, 0x6e, 0x5e, 0x4b, 0x91, 0x10, 0xd7, 0xaa, 0x76, 0x93, 0x84, - 0x94, 0xb1, 0x05, 0x90, 0xad, 0x87, 0x3c, 0x4d, 0x88, 0x67, 0x85, 0xe7, 0x42, 0x71, 0xb2, 0xa2, - 0xbd, 0xd9, 0x8d, 0x61, 0x2b, 0x96, 0xd5, 0x4f, 0x00, 0xa9, 0x22, 0x81, 0xa6, 0x4e, 0xc6, 0x99, - 0x54, 0x97, 0x3a, 0x4b, 0x0d, 0x37, 0x80, 0x14, 0x11, 0x73, 0xa8, 0x8e, 0x08, 0xad, 0x41, 0x1a, - 0xbc, 0x89, 0x25, 0x67, 0xa3, 0x2b, 0x76, 0x39, 0xe1, 0x04, 0x70, 0x1d, 0x56, 0x6d, 0x20, 0xfd, - 0xc5, 0x4d, 0x53, 0xd2, 0xb0, 0xb2, 0xfd, 0x2b, 0x3e, 0xfa, 0xe9, 0xbb, 0xa9, 0x90, 0xd3, 0x88, - 0x34, 0x75, 0xd9, 0x83, 0x34, 0x30, 0x17, 0x34, 0xe6, 0xf2, 0x98, 0x33, 0x9f, 0x4b, 0xb2, 0x6a, - 0x4f, 0x9f, 0x85, 0x11, 0x17, 0x53, 0x75, 0x22, 0x7e, 0x26, 0x2d, 0x6b, 0x66, 0xc8, 0x99, 0x6f, - 0x7e, 0x61, 0x64, 0xcd, 0x9a, 0x99, 0x21, 0xc6, 0x0c, 0xb1, 0xf5, 0xbe, 0x96, 0xdc, 0x94, 0xb8, - 0x6e, 0xb3, 0xda, 0xbd, 0xd1, 0xe0, 0xf6, 0x6f, 0x0e, 0x6c, 0x3c, 0x36, 0x1e, 0xb8, 0x05, 0xf4, - 0x31, 0x7c, 0x77, 0xaa, 0x04, 0x29, 0xe1, 0xa7, 0xf0, 0xff, 0xc7, 0xd8, 0x6f, 0x44, 0x18, 0xab, - 0xa3, 0x28, 0x99, 0x84, 0xa3, 0x50, 0x5f, 0xc5, 0xc7, 0x64, 0xaf, 0x6e, 0xac, 0xcc, 0xdd, 0xbe, - 0x85, 0xd6, 0xe2, 0x47, 0xa1, 0x9b, 0x31, 0x47, 0x76, 0x7d, 0x5f, 0x8f, 0x3f, 0x29, 0x21, 0x2d, - 0x9a, 0x1d, 0xf2, 0x48, 0x5c, 0x73, 0xc3, 0x38, 0x8b, 0xcc, 0x9b, 0xc4, 0x67, 0x2a, 0x63, 0xdc, - 0xc5, 0x42, 0x76, 0x7d, 0xff, 0x38, 0x7b, 0x7b, 0x0c, 0x5b, 0xde, 0xa3, 0x77, 0x1f, 0xda, 0xa5, - 0x77, 0x1f, 0xda, 0xa5, 0xbb, 0xfb, 0xb6, 0xf3, 0xee, 0xbe, 0xed, 0xfc, 0x7d, 0xdf, 0x76, 0x7e, - 0xff, 0xa7, 0x5d, 0xfa, 0x37, 0x00, 0x00, 0xff, 0xff, 0x87, 0x11, 0x6d, 0xd6, 0xaf, 0x08, 0x00, - 0x00, -} diff --git a/vendor/go.etcd.io/etcd/raft/raftpb/raft.proto b/vendor/go.etcd.io/etcd/raft/v3/raftpb/raft.proto similarity index 92% rename from vendor/go.etcd.io/etcd/raft/raftpb/raft.proto rename to vendor/go.etcd.io/etcd/raft/v3/raftpb/raft.proto index 23d62ec2f..f46a54c94 100644 --- a/vendor/go.etcd.io/etcd/raft/raftpb/raft.proto +++ b/vendor/go.etcd.io/etcd/raft/v3/raftpb/raft.proto @@ -8,6 +8,9 @@ option (gogoproto.sizer_all) = true; option (gogoproto.unmarshaler_all) = true; option (gogoproto.goproto_getters_all) = false; option (gogoproto.goproto_enum_prefix_all) = false; +option (gogoproto.goproto_unkeyed_all) = false; +option (gogoproto.goproto_unrecognized_all) = false; +option (gogoproto.goproto_sizecache_all) = false; enum EntryType { EntryNormal = 0; @@ -33,6 +36,8 @@ message Snapshot { optional SnapshotMetadata metadata = 2 [(gogoproto.nullable) = false]; } +// For description of different message types, see: +// https://pkg.go.dev/go.etcd.io/etcd/raft/v3#hdr-MessageType enum MessageType { MsgHup = 0; MsgBeat = 1; @@ -60,6 +65,11 @@ message Message { optional uint64 to = 2 [(gogoproto.nullable) = false]; optional uint64 from = 3 [(gogoproto.nullable) = false]; optional uint64 term = 4 [(gogoproto.nullable) = false]; + // logTerm is generally used for appending Raft logs to followers. For example, + // (type=MsgApp,index=100,logTerm=5) means leader appends entries starting at + // index=101, and the term of entry at index 100 is 5. + // (type=MsgAppResp,reject=true,index=100,logTerm=5) means follower rejects some + // entries from its leader as it already has an entry with term 5 at index 100. optional uint64 logTerm = 5 [(gogoproto.nullable) = false]; optional uint64 index = 6 [(gogoproto.nullable) = false]; repeated Entry entries = 7 [(gogoproto.nullable) = false]; diff --git a/vendor/go.etcd.io/etcd/raft/rawnode.go b/vendor/go.etcd.io/etcd/raft/v3/rawnode.go similarity index 95% rename from vendor/go.etcd.io/etcd/raft/rawnode.go rename to vendor/go.etcd.io/etcd/raft/v3/rawnode.go index 90eb69493..4111d029d 100644 --- a/vendor/go.etcd.io/etcd/raft/rawnode.go +++ b/vendor/go.etcd.io/etcd/raft/v3/rawnode.go @@ -17,8 +17,8 @@ package raft import ( "errors" - pb "go.etcd.io/etcd/raft/raftpb" - "go.etcd.io/etcd/raft/tracker" + pb "go.etcd.io/etcd/raft/v3/raftpb" + "go.etcd.io/etcd/raft/v3/tracker" ) // ErrStepLocalMsg is returned when try to step a local raft message @@ -98,7 +98,9 @@ func (rn *RawNode) ProposeConfChange(cc pb.ConfChangeI) error { return rn.raft.Step(m) } -// ApplyConfChange applies a config change to the local node. +// ApplyConfChange applies a config change to the local node. The app must call +// this when it applies a configuration change, except when it decides to reject +// the configuration change, in which case no call must take place. func (rn *RawNode) ApplyConfChange(cc pb.ConfChangeI) *pb.ConfState { cs := rn.raft.applyConfChange(cc.AsV2()) return &cs @@ -155,7 +157,7 @@ func (rn *RawNode) HasReady() bool { if hardSt := r.hardState(); !IsEmptyHardState(hardSt) && !isHardStateEqual(hardSt, rn.prevHardSt) { return true } - if r.raftLog.unstable.snapshot != nil && !IsEmptySnap(*r.raftLog.unstable.snapshot) { + if r.raftLog.hasPendingSnapshot() { return true } if len(r.msgs) > 0 || len(r.raftLog.unstableEntries()) > 0 || r.raftLog.hasNextEnts() { diff --git a/vendor/go.etcd.io/etcd/raft/read_only.go b/vendor/go.etcd.io/etcd/raft/v3/read_only.go similarity index 97% rename from vendor/go.etcd.io/etcd/raft/read_only.go rename to vendor/go.etcd.io/etcd/raft/v3/read_only.go index 6987f1bd7..ad0688522 100644 --- a/vendor/go.etcd.io/etcd/raft/read_only.go +++ b/vendor/go.etcd.io/etcd/raft/v3/read_only.go @@ -14,7 +14,7 @@ package raft -import pb "go.etcd.io/etcd/raft/raftpb" +import pb "go.etcd.io/etcd/raft/v3/raftpb" // ReadState provides state for read only query. // It's caller's responsibility to call ReadIndex first before getting @@ -49,7 +49,7 @@ func newReadOnly(option ReadOnlyOption) *readOnly { } } -// addRequest adds a read only reuqest into readonly struct. +// addRequest adds a read only request into readonly struct. // `index` is the commit index of the raft state machine when it received // the read only request. // `m` is the original read only request message from the local or remote node. diff --git a/vendor/go.etcd.io/etcd/raft/status.go b/vendor/go.etcd.io/etcd/raft/v3/status.go similarity index 94% rename from vendor/go.etcd.io/etcd/raft/status.go rename to vendor/go.etcd.io/etcd/raft/v3/status.go index adc60486d..acfb56c39 100644 --- a/vendor/go.etcd.io/etcd/raft/status.go +++ b/vendor/go.etcd.io/etcd/raft/v3/status.go @@ -17,8 +17,8 @@ package raft import ( "fmt" - pb "go.etcd.io/etcd/raft/raftpb" - "go.etcd.io/etcd/raft/tracker" + pb "go.etcd.io/etcd/raft/v3/raftpb" + "go.etcd.io/etcd/raft/v3/tracker" ) // Status contains information about this Raft peer and its view of the system. @@ -44,8 +44,7 @@ type BasicStatus struct { func getProgressCopy(r *raft) map[uint64]tracker.Progress { m := make(map[uint64]tracker.Progress) r.prs.Visit(func(id uint64, pr *tracker.Progress) { - var p tracker.Progress - p = *pr + p := *pr p.Inflights = pr.Inflights.Clone() pr = nil @@ -100,7 +99,7 @@ func (s Status) MarshalJSON() ([]byte, error) { func (s Status) String() string { b, err := s.MarshalJSON() if err != nil { - raftLogger.Panicf("unexpected error: %v", err) + getLogger().Panicf("unexpected error: %v", err) } return string(b) } diff --git a/vendor/go.etcd.io/etcd/raft/storage.go b/vendor/go.etcd.io/etcd/raft/v3/storage.go similarity index 95% rename from vendor/go.etcd.io/etcd/raft/storage.go rename to vendor/go.etcd.io/etcd/raft/v3/storage.go index 6be574590..8b16d4fa2 100644 --- a/vendor/go.etcd.io/etcd/raft/storage.go +++ b/vendor/go.etcd.io/etcd/raft/v3/storage.go @@ -18,7 +18,7 @@ import ( "errors" "sync" - pb "go.etcd.io/etcd/raft/raftpb" + pb "go.etcd.io/etcd/raft/v3/raftpb" ) // ErrCompacted is returned by Storage.Entries/Compact when a requested @@ -115,7 +115,7 @@ func (ms *MemoryStorage) Entries(lo, hi, maxSize uint64) ([]pb.Entry, error) { return nil, ErrCompacted } if hi > ms.lastIndex()+1 { - raftLogger.Panicf("entries' hi(%d) is out of bound lastindex(%d)", hi, ms.lastIndex()) + getLogger().Panicf("entries' hi(%d) is out of bound lastindex(%d)", hi, ms.lastIndex()) } // only contains dummy entries. if len(ms.ents) == 1 { @@ -200,7 +200,7 @@ func (ms *MemoryStorage) CreateSnapshot(i uint64, cs *pb.ConfState, data []byte) offset := ms.ents[0].Index if i > ms.lastIndex() { - raftLogger.Panicf("snapshot %d is out of bound lastindex(%d)", i, ms.lastIndex()) + getLogger().Panicf("snapshot %d is out of bound lastindex(%d)", i, ms.lastIndex()) } ms.snapshot.Metadata.Index = i @@ -223,7 +223,7 @@ func (ms *MemoryStorage) Compact(compactIndex uint64) error { return ErrCompacted } if compactIndex > ms.lastIndex() { - raftLogger.Panicf("compact %d is out of bound lastindex(%d)", compactIndex, ms.lastIndex()) + getLogger().Panicf("compact %d is out of bound lastindex(%d)", compactIndex, ms.lastIndex()) } i := compactIndex - offset @@ -266,7 +266,7 @@ func (ms *MemoryStorage) Append(entries []pb.Entry) error { case uint64(len(ms.ents)) == offset: ms.ents = append(ms.ents, entries...) default: - raftLogger.Panicf("missing log entry [last: %d, append at: %d]", + getLogger().Panicf("missing log entry [last: %d, append at: %d]", ms.lastIndex(), entries[0].Index) } return nil diff --git a/vendor/go.etcd.io/etcd/raft/tracker/inflights.go b/vendor/go.etcd.io/etcd/raft/v3/tracker/inflights.go similarity index 100% rename from vendor/go.etcd.io/etcd/raft/tracker/inflights.go rename to vendor/go.etcd.io/etcd/raft/v3/tracker/inflights.go diff --git a/vendor/go.etcd.io/etcd/raft/tracker/progress.go b/vendor/go.etcd.io/etcd/raft/v3/tracker/progress.go similarity index 96% rename from vendor/go.etcd.io/etcd/raft/tracker/progress.go rename to vendor/go.etcd.io/etcd/raft/v3/tracker/progress.go index 62c81f45a..a36e5261a 100644 --- a/vendor/go.etcd.io/etcd/raft/tracker/progress.go +++ b/vendor/go.etcd.io/etcd/raft/v3/tracker/progress.go @@ -148,9 +148,7 @@ func (pr *Progress) MaybeUpdate(n uint64) bool { updated = true pr.ProbeAcked() } - if pr.Next < n+1 { - pr.Next = n + 1 - } + pr.Next = max(pr.Next, n+1) return updated } @@ -159,8 +157,8 @@ func (pr *Progress) MaybeUpdate(n uint64) bool { func (pr *Progress) OptimisticUpdate(n uint64) { pr.Next = n + 1 } // MaybeDecrTo adjusts the Progress to the receipt of a MsgApp rejection. The -// arguments are the index the follower rejected to append to its log, and its -// last index. +// arguments are the index of the append message rejected by the follower, and +// the hint that we want to decrease to. // // Rejections can happen spuriously as messages are sent out of order or // duplicated. In such cases, the rejection pertains to an index that the @@ -169,7 +167,7 @@ func (pr *Progress) OptimisticUpdate(n uint64) { pr.Next = n + 1 } // // If the rejection is genuine, Next is lowered sensibly, and the Progress is // cleared for sending log entries. -func (pr *Progress) MaybeDecrTo(rejected, last uint64) bool { +func (pr *Progress) MaybeDecrTo(rejected, matchHint uint64) bool { if pr.State == StateReplicate { // The rejection must be stale if the progress has matched and "rejected" // is smaller than "match". @@ -178,7 +176,7 @@ func (pr *Progress) MaybeDecrTo(rejected, last uint64) bool { } // Directly decrease next to match + 1. // - // TODO(tbg): why not use last if it's larger? + // TODO(tbg): why not use matchHint if it's larger? pr.Next = pr.Match + 1 return true } @@ -189,9 +187,7 @@ func (pr *Progress) MaybeDecrTo(rejected, last uint64) bool { return false } - if pr.Next = min(rejected, last+1); pr.Next < 1 { - pr.Next = 1 - } + pr.Next = max(min(rejected, matchHint+1), 1) pr.ProbeSent = false return true } diff --git a/vendor/go.etcd.io/etcd/raft/tracker/state.go b/vendor/go.etcd.io/etcd/raft/v3/tracker/state.go similarity index 100% rename from vendor/go.etcd.io/etcd/raft/tracker/state.go rename to vendor/go.etcd.io/etcd/raft/v3/tracker/state.go diff --git a/vendor/go.etcd.io/etcd/raft/tracker/tracker.go b/vendor/go.etcd.io/etcd/raft/v3/tracker/tracker.go similarity index 98% rename from vendor/go.etcd.io/etcd/raft/tracker/tracker.go rename to vendor/go.etcd.io/etcd/raft/v3/tracker/tracker.go index a4581143d..72dcc73b8 100644 --- a/vendor/go.etcd.io/etcd/raft/tracker/tracker.go +++ b/vendor/go.etcd.io/etcd/raft/v3/tracker/tracker.go @@ -19,8 +19,8 @@ import ( "sort" "strings" - "go.etcd.io/etcd/raft/quorum" - pb "go.etcd.io/etcd/raft/raftpb" + "go.etcd.io/etcd/raft/v3/quorum" + pb "go.etcd.io/etcd/raft/v3/raftpb" ) // Config reflects the configuration tracked in a ProgressTracker. @@ -194,7 +194,7 @@ func (p *ProgressTracker) Visit(f func(id uint64, pr *Progress)) { // The optimization here mirrors that in `(MajorityConfig).CommittedIndex`, // see there for details. var sl [7]uint64 - ids := sl[:] + var ids []uint64 if len(sl) >= n { ids = sl[:n] } else { diff --git a/vendor/go.etcd.io/etcd/raft/util.go b/vendor/go.etcd.io/etcd/raft/v3/util.go similarity index 99% rename from vendor/go.etcd.io/etcd/raft/util.go rename to vendor/go.etcd.io/etcd/raft/v3/util.go index 785cf735d..94ab368f6 100644 --- a/vendor/go.etcd.io/etcd/raft/util.go +++ b/vendor/go.etcd.io/etcd/raft/v3/util.go @@ -19,7 +19,7 @@ import ( "fmt" "strings" - pb "go.etcd.io/etcd/raft/raftpb" + pb "go.etcd.io/etcd/raft/v3/raftpb" ) func (st StateType) MarshalJSON() ([]byte, error) { diff --git a/vendor/go.etcd.io/etcd/server/v3/LICENSE b/vendor/go.etcd.io/etcd/server/v3/LICENSE new file mode 100644 index 000000000..d64569567 --- /dev/null +++ b/vendor/go.etcd.io/etcd/server/v3/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/coder.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/coder.go similarity index 95% rename from vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/coder.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/coder.go index 12c3e4424..cc2824969 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/coder.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/coder.go @@ -14,7 +14,7 @@ package rafthttp -import "go.etcd.io/etcd/raft/raftpb" +import "go.etcd.io/etcd/raft/v3/raftpb" type encoder interface { // encode encodes the given message to an output stream. diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/doc.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/doc.go similarity index 100% rename from vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/doc.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/doc.go diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/http.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/http.go similarity index 64% rename from vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/http.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/http.go index 0b05282c0..f60383f47 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/http.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/http.go @@ -24,11 +24,11 @@ import ( "strings" "time" - "go.etcd.io/etcd/etcdserver/api/snap" - pioutil "go.etcd.io/etcd/pkg/ioutil" - "go.etcd.io/etcd/pkg/types" - "go.etcd.io/etcd/raft/raftpb" - "go.etcd.io/etcd/version" + "go.etcd.io/etcd/api/v3/version" + "go.etcd.io/etcd/client/pkg/v3/types" + pioutil "go.etcd.io/etcd/pkg/v3/ioutil" + "go.etcd.io/etcd/raft/v3/raftpb" + "go.etcd.io/etcd/server/v3/etcdserver/api/snap" humanize "github.com/dustin/go-humanize" "go.uber.org/zap" @@ -42,6 +42,9 @@ const ( // throughput bottleneck as well as small enough // for not causing a read timeout. connReadLimitByte = 64 * 1024 + + // snapshotLimitByte limits the snapshot size to 1TB + snapshotLimitByte = 1 * 1024 * 1024 * 1024 * 1024 ) var ( @@ -51,7 +54,7 @@ var ( RaftSnapshotPrefix = path.Join(RaftPrefix, "snapshot") errIncompatibleVersion = errors.New("incompatible version") - errClusterIDMismatch = errors.New("cluster ID mismatch") + ErrClusterIDMismatch = errors.New("cluster ID mismatch") ) type peerGetter interface { @@ -76,13 +79,17 @@ type pipelineHandler struct { // The handler reads out the raft message from request body, // and forwards it to the given raft state machine for processing. func newPipelineHandler(t *Transport, r Raft, cid types.ID) http.Handler { - return &pipelineHandler{ + h := &pipelineHandler{ lg: t.Logger, localID: t.ID, tr: t, r: r, cid: cid, } + if h.lg == nil { + h.lg = zap.NewNop() + } + return h } func (h *pipelineHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { @@ -106,15 +113,11 @@ func (h *pipelineHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { limitedr := pioutil.NewLimitedBufferReader(r.Body, connReadLimitByte) b, err := ioutil.ReadAll(limitedr) if err != nil { - if h.lg != nil { - h.lg.Warn( - "failed to read Raft message", - zap.String("local-member-id", h.localID.String()), - zap.Error(err), - ) - } else { - plog.Errorf("failed to read raft message (%v)", err) - } + h.lg.Warn( + "failed to read Raft message", + zap.String("local-member-id", h.localID.String()), + zap.Error(err), + ) http.Error(w, "error reading raft message", http.StatusBadRequest) recvFailures.WithLabelValues(r.RemoteAddr).Inc() return @@ -122,15 +125,11 @@ func (h *pipelineHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { var m raftpb.Message if err := m.Unmarshal(b); err != nil { - if h.lg != nil { - h.lg.Warn( - "failed to unmarshal Raft message", - zap.String("local-member-id", h.localID.String()), - zap.Error(err), - ) - } else { - plog.Errorf("failed to unmarshal raft message (%v)", err) - } + h.lg.Warn( + "failed to unmarshal Raft message", + zap.String("local-member-id", h.localID.String()), + zap.Error(err), + ) http.Error(w, "error unmarshalling raft message", http.StatusBadRequest) recvFailures.WithLabelValues(r.RemoteAddr).Inc() return @@ -143,15 +142,11 @@ func (h *pipelineHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { case writerToResponse: v.WriteTo(w) default: - if h.lg != nil { - h.lg.Warn( - "failed to process Raft message", - zap.String("local-member-id", h.localID.String()), - zap.Error(err), - ) - } else { - plog.Warningf("failed to process raft message (%v)", err) - } + h.lg.Warn( + "failed to process Raft message", + zap.String("local-member-id", h.localID.String()), + zap.Error(err), + ) http.Error(w, "error processing raft message", http.StatusInternalServerError) w.(http.Flusher).Flush() // disconnect the http stream @@ -176,7 +171,7 @@ type snapshotHandler struct { } func newSnapshotHandler(t *Transport, r Raft, snapshotter *snap.Snapshotter, cid types.ID) http.Handler { - return &snapshotHandler{ + h := &snapshotHandler{ lg: t.Logger, tr: t, r: r, @@ -184,6 +179,10 @@ func newSnapshotHandler(t *Transport, r Raft, snapshotter *snap.Snapshotter, cid localID: t.ID, cid: cid, } + if h.lg == nil { + h.lg = zap.NewNop() + } + return h } const unknownSnapshotSender = "UNKNOWN_SNAPSHOT_SENDER" @@ -219,41 +218,32 @@ func (h *snapshotHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { dec := &messageDecoder{r: r.Body} // let snapshots be very large since they can exceed 512MB for large installations - m, err := dec.decodeLimit(uint64(1 << 63)) + m, err := dec.decodeLimit(snapshotLimitByte) from := types.ID(m.From).String() if err != nil { msg := fmt.Sprintf("failed to decode raft message (%v)", err) - if h.lg != nil { - h.lg.Warn( - "failed to decode Raft message", - zap.String("local-member-id", h.localID.String()), - zap.String("remote-snapshot-sender-id", from), - zap.Error(err), - ) - } else { - plog.Error(msg) - } + h.lg.Warn( + "failed to decode Raft message", + zap.String("local-member-id", h.localID.String()), + zap.String("remote-snapshot-sender-id", from), + zap.Error(err), + ) http.Error(w, msg, http.StatusBadRequest) recvFailures.WithLabelValues(r.RemoteAddr).Inc() snapshotReceiveFailures.WithLabelValues(from).Inc() return } - msgSizeVal := m.Size() - msgSize := humanize.Bytes(uint64(msgSizeVal)) - receivedBytes.WithLabelValues(from).Add(float64(msgSizeVal)) + msgSize := m.Size() + receivedBytes.WithLabelValues(from).Add(float64(msgSize)) if m.Type != raftpb.MsgSnap { - if h.lg != nil { - h.lg.Warn( - "unexpected Raft message type", - zap.String("local-member-id", h.localID.String()), - zap.String("remote-snapshot-sender-id", from), - zap.String("message-type", m.Type.String()), - ) - } else { - plog.Errorf("unexpected raft message type %s on snapshot path", m.Type) - } + h.lg.Warn( + "unexpected Raft message type", + zap.String("local-member-id", h.localID.String()), + zap.String("remote-snapshot-sender-id", from), + zap.String("message-type", m.Type.String()), + ) http.Error(w, "wrong raft message type", http.StatusBadRequest) snapshotReceiveFailures.WithLabelValues(from).Inc() return @@ -264,56 +254,44 @@ func (h *snapshotHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { snapshotReceiveInflights.WithLabelValues(from).Dec() }() - if h.lg != nil { - h.lg.Info( - "receiving database snapshot", - zap.String("local-member-id", h.localID.String()), - zap.String("remote-snapshot-sender-id", from), - zap.Uint64("incoming-snapshot-index", m.Snapshot.Metadata.Index), - zap.Int("incoming-snapshot-message-size-bytes", msgSizeVal), - zap.String("incoming-snapshot-message-size", msgSize), - ) - } else { - plog.Infof("receiving database snapshot [index: %d, from: %s, raft message size: %s]", m.Snapshot.Metadata.Index, types.ID(m.From), msgSize) - } + h.lg.Info( + "receiving database snapshot", + zap.String("local-member-id", h.localID.String()), + zap.String("remote-snapshot-sender-id", from), + zap.Uint64("incoming-snapshot-index", m.Snapshot.Metadata.Index), + zap.Int("incoming-snapshot-message-size-bytes", msgSize), + zap.String("incoming-snapshot-message-size", humanize.Bytes(uint64(msgSize))), + ) // save incoming database snapshot. + n, err := h.snapshotter.SaveDBFrom(r.Body, m.Snapshot.Metadata.Index) if err != nil { msg := fmt.Sprintf("failed to save KV snapshot (%v)", err) - if h.lg != nil { - h.lg.Warn( - "failed to save incoming database snapshot", - zap.String("local-member-id", h.localID.String()), - zap.String("remote-snapshot-sender-id", from), - zap.Uint64("incoming-snapshot-index", m.Snapshot.Metadata.Index), - zap.Error(err), - ) - } else { - plog.Error(msg) - } + h.lg.Warn( + "failed to save incoming database snapshot", + zap.String("local-member-id", h.localID.String()), + zap.String("remote-snapshot-sender-id", from), + zap.Uint64("incoming-snapshot-index", m.Snapshot.Metadata.Index), + zap.Error(err), + ) http.Error(w, msg, http.StatusInternalServerError) snapshotReceiveFailures.WithLabelValues(from).Inc() return } - dbSize := humanize.Bytes(uint64(n)) receivedBytes.WithLabelValues(from).Add(float64(n)) downloadTook := time.Since(start) - if h.lg != nil { - h.lg.Info( - "received and saved database snapshot", - zap.String("local-member-id", h.localID.String()), - zap.String("remote-snapshot-sender-id", from), - zap.Uint64("incoming-snapshot-index", m.Snapshot.Metadata.Index), - zap.Int64("incoming-snapshot-size-bytes", n), - zap.String("incoming-snapshot-size", dbSize), - zap.String("download-took", downloadTook.String()), - ) - } else { - plog.Infof("successfully received and saved database snapshot [index: %d, from: %s, raft message size: %s, db size: %s, took: %s]", m.Snapshot.Metadata.Index, types.ID(m.From), msgSize, dbSize, downloadTook.String()) - } + h.lg.Info( + "received and saved database snapshot", + zap.String("local-member-id", h.localID.String()), + zap.String("remote-snapshot-sender-id", from), + zap.Uint64("incoming-snapshot-index", m.Snapshot.Metadata.Index), + zap.Int64("incoming-snapshot-size-bytes", n), + zap.String("incoming-snapshot-size", humanize.Bytes(uint64(n))), + zap.String("download-took", downloadTook.String()), + ) if err := h.r.Process(context.TODO(), m); err != nil { switch v := err.(type) { @@ -323,16 +301,12 @@ func (h *snapshotHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { v.WriteTo(w) default: msg := fmt.Sprintf("failed to process raft message (%v)", err) - if h.lg != nil { - h.lg.Warn( - "failed to process Raft message", - zap.String("local-member-id", h.localID.String()), - zap.String("remote-snapshot-sender-id", from), - zap.Error(err), - ) - } else { - plog.Error(msg) - } + h.lg.Warn( + "failed to process Raft message", + zap.String("local-member-id", h.localID.String()), + zap.String("remote-snapshot-sender-id", from), + zap.Error(err), + ) http.Error(w, msg, http.StatusInternalServerError) snapshotReceiveFailures.WithLabelValues(from).Inc() } @@ -357,7 +331,7 @@ type streamHandler struct { } func newStreamHandler(t *Transport, pg peerGetter, r Raft, id, cid types.ID) http.Handler { - return &streamHandler{ + h := &streamHandler{ lg: t.Logger, tr: t, peerGetter: pg, @@ -365,6 +339,10 @@ func newStreamHandler(t *Transport, pg peerGetter, r Raft, id, cid types.ID) htt id: id, cid: cid, } + if h.lg == nil { + h.lg = zap.NewNop() + } + return h } func (h *streamHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { @@ -384,21 +362,17 @@ func (h *streamHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { var t streamType switch path.Dir(r.URL.Path) { - case streamTypeMsgAppV2.endpoint(): + case streamTypeMsgAppV2.endpoint(h.lg): t = streamTypeMsgAppV2 - case streamTypeMessage.endpoint(): + case streamTypeMessage.endpoint(h.lg): t = streamTypeMessage default: - if h.lg != nil { - h.lg.Debug( - "ignored unexpected streaming request path", - zap.String("local-member-id", h.tr.ID.String()), - zap.String("remote-peer-id-stream-handler", h.id.String()), - zap.String("path", r.URL.Path), - ) - } else { - plog.Debugf("ignored unexpected streaming request path %s", r.URL.Path) - } + h.lg.Debug( + "ignored unexpected streaming request path", + zap.String("local-member-id", h.tr.ID.String()), + zap.String("remote-peer-id-stream-handler", h.id.String()), + zap.String("path", r.URL.Path), + ) http.Error(w, "invalid path", http.StatusNotFound) return } @@ -406,31 +380,23 @@ func (h *streamHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { fromStr := path.Base(r.URL.Path) from, err := types.IDFromString(fromStr) if err != nil { - if h.lg != nil { - h.lg.Warn( - "failed to parse path into ID", - zap.String("local-member-id", h.tr.ID.String()), - zap.String("remote-peer-id-stream-handler", h.id.String()), - zap.String("path", fromStr), - zap.Error(err), - ) - } else { - plog.Errorf("failed to parse from %s into ID (%v)", fromStr, err) - } + h.lg.Warn( + "failed to parse path into ID", + zap.String("local-member-id", h.tr.ID.String()), + zap.String("remote-peer-id-stream-handler", h.id.String()), + zap.String("path", fromStr), + zap.Error(err), + ) http.Error(w, "invalid from", http.StatusNotFound) return } if h.r.IsIDRemoved(uint64(from)) { - if h.lg != nil { - h.lg.Warn( - "rejected stream from remote peer because it was removed", - zap.String("local-member-id", h.tr.ID.String()), - zap.String("remote-peer-id-stream-handler", h.id.String()), - zap.String("remote-peer-id-from", from.String()), - ) - } else { - plog.Warningf("rejected the stream from peer %s since it was removed", from) - } + h.lg.Warn( + "rejected stream from remote peer because it was removed", + zap.String("local-member-id", h.tr.ID.String()), + zap.String("remote-peer-id-stream-handler", h.id.String()), + zap.String("remote-peer-id-from", from.String()), + ) http.Error(w, "removed member", http.StatusGone) return } @@ -444,35 +410,27 @@ func (h *streamHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if urls := r.Header.Get("X-PeerURLs"); urls != "" { h.tr.AddRemote(from, strings.Split(urls, ",")) } - if h.lg != nil { - h.lg.Warn( - "failed to find remote peer in cluster", - zap.String("local-member-id", h.tr.ID.String()), - zap.String("remote-peer-id-stream-handler", h.id.String()), - zap.String("remote-peer-id-from", from.String()), - zap.String("cluster-id", h.cid.String()), - ) - } else { - plog.Errorf("failed to find member %s in cluster %s", from, h.cid) - } + h.lg.Warn( + "failed to find remote peer in cluster", + zap.String("local-member-id", h.tr.ID.String()), + zap.String("remote-peer-id-stream-handler", h.id.String()), + zap.String("remote-peer-id-from", from.String()), + zap.String("cluster-id", h.cid.String()), + ) http.Error(w, "error sender not found", http.StatusNotFound) return } wto := h.id.String() if gto := r.Header.Get("X-Raft-To"); gto != wto { - if h.lg != nil { - h.lg.Warn( - "ignored streaming request; ID mismatch", - zap.String("local-member-id", h.tr.ID.String()), - zap.String("remote-peer-id-stream-handler", h.id.String()), - zap.String("remote-peer-id-header", gto), - zap.String("remote-peer-id-from", from.String()), - zap.String("cluster-id", h.cid.String()), - ) - } else { - plog.Errorf("streaming request ignored (ID mismatch got %s want %s)", gto, wto) - } + h.lg.Warn( + "ignored streaming request; ID mismatch", + zap.String("local-member-id", h.tr.ID.String()), + zap.String("remote-peer-id-stream-handler", h.id.String()), + zap.String("remote-peer-id-header", gto), + zap.String("remote-peer-id-from", from.String()), + zap.String("cluster-id", h.cid.String()), + ) http.Error(w, "to field mismatch", http.StatusPreconditionFailed) return } @@ -487,7 +445,7 @@ func (h *streamHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { Flusher: w.(http.Flusher), Closer: c, localID: h.tr.ID, - peerID: h.id, + peerID: from, } p.attachOutgoingConn(conn) <-c.closeNotify() @@ -525,40 +483,32 @@ func checkClusterCompatibilityFromHeader(lg *zap.Logger, localID types.ID, heade } if err != nil { - if lg != nil { - lg.Warn( - "failed to check version compatibility", - zap.String("local-member-id", localID.String()), - zap.String("local-member-cluster-id", cid.String()), - zap.String("local-member-server-version", localVs), - zap.String("local-member-server-minimum-cluster-version", localMinClusterVs), - zap.String("remote-peer-server-name", remoteName), - zap.String("remote-peer-server-version", remoteVs), - zap.String("remote-peer-server-minimum-cluster-version", remoteMinClusterVs), - zap.Error(err), - ) - } else { - plog.Errorf("request version incompatibility (%v)", err) - } + lg.Warn( + "failed to check version compatibility", + zap.String("local-member-id", localID.String()), + zap.String("local-member-cluster-id", cid.String()), + zap.String("local-member-server-version", localVs), + zap.String("local-member-server-minimum-cluster-version", localMinClusterVs), + zap.String("remote-peer-server-name", remoteName), + zap.String("remote-peer-server-version", remoteVs), + zap.String("remote-peer-server-minimum-cluster-version", remoteMinClusterVs), + zap.Error(err), + ) return errIncompatibleVersion } if gcid := header.Get("X-Etcd-Cluster-ID"); gcid != cid.String() { - if lg != nil { - lg.Warn( - "request cluster ID mismatch", - zap.String("local-member-id", localID.String()), - zap.String("local-member-cluster-id", cid.String()), - zap.String("local-member-server-version", localVs), - zap.String("local-member-server-minimum-cluster-version", localMinClusterVs), - zap.String("remote-peer-server-name", remoteName), - zap.String("remote-peer-server-version", remoteVs), - zap.String("remote-peer-server-minimum-cluster-version", remoteMinClusterVs), - zap.String("remote-peer-cluster-id", gcid), - ) - } else { - plog.Errorf("request cluster ID mismatch (got %s want %s)", gcid, cid) - } - return errClusterIDMismatch + lg.Warn( + "request cluster ID mismatch", + zap.String("local-member-id", localID.String()), + zap.String("local-member-cluster-id", cid.String()), + zap.String("local-member-server-version", localVs), + zap.String("local-member-server-minimum-cluster-version", localMinClusterVs), + zap.String("remote-peer-server-name", remoteName), + zap.String("remote-peer-server-version", remoteVs), + zap.String("remote-peer-server-minimum-cluster-version", remoteMinClusterVs), + zap.String("remote-peer-cluster-id", gcid), + ) + return ErrClusterIDMismatch } return nil } diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/metrics.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/metrics.go similarity index 100% rename from vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/metrics.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/metrics.go diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/msg_codec.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/msg_codec.go similarity index 96% rename from vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/msg_codec.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/msg_codec.go index 2417d222e..7db880baa 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/msg_codec.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/msg_codec.go @@ -19,8 +19,8 @@ import ( "errors" "io" - "go.etcd.io/etcd/pkg/pbutil" - "go.etcd.io/etcd/raft/raftpb" + "go.etcd.io/etcd/pkg/v3/pbutil" + "go.etcd.io/etcd/raft/v3/raftpb" ) // messageEncoder is a encoder that can encode all kinds of messages. diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/msgappv2_codec.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/msgappv2_codec.go similarity index 97% rename from vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/msgappv2_codec.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/msgappv2_codec.go index 1fa36deb3..9a7f4a177 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/msgappv2_codec.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/msgappv2_codec.go @@ -20,10 +20,10 @@ import ( "io" "time" - stats "go.etcd.io/etcd/etcdserver/api/v2stats" - "go.etcd.io/etcd/pkg/pbutil" - "go.etcd.io/etcd/pkg/types" - "go.etcd.io/etcd/raft/raftpb" + "go.etcd.io/etcd/client/pkg/v3/types" + "go.etcd.io/etcd/pkg/v3/pbutil" + "go.etcd.io/etcd/raft/v3/raftpb" + stats "go.etcd.io/etcd/server/v3/etcdserver/api/v2stats" ) const ( diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/peer.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/peer.go similarity index 91% rename from vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/peer.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/peer.go index 8130c4a96..444d6bde9 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/peer.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/peer.go @@ -19,11 +19,11 @@ import ( "sync" "time" - "go.etcd.io/etcd/etcdserver/api/snap" - stats "go.etcd.io/etcd/etcdserver/api/v2stats" - "go.etcd.io/etcd/pkg/types" - "go.etcd.io/etcd/raft" - "go.etcd.io/etcd/raft/raftpb" + "go.etcd.io/etcd/client/pkg/v3/types" + "go.etcd.io/etcd/raft/v3" + "go.etcd.io/etcd/raft/v3/raftpb" + "go.etcd.io/etcd/server/v3/etcdserver/api/snap" + stats "go.etcd.io/etcd/server/v3/etcdserver/api/v2stats" "go.uber.org/zap" "golang.org/x/time/rate" @@ -37,8 +37,8 @@ const ( // to keep the connection alive. // For short term pipeline connections, the connection MUST be killed to avoid it being // put back to http pkg connection pool. - ConnReadTimeout = 5 * time.Second - ConnWriteTimeout = 5 * time.Second + DefaultConnReadTimeout = 5 * time.Second + DefaultConnWriteTimeout = 5 * time.Second recvBufSize = 4096 // maxPendingProposals holds the proposals during one leader election process. @@ -55,6 +55,11 @@ const ( sendSnap = "sendMsgSnap" ) +var ( + ConnReadTimeout = DefaultConnReadTimeout + ConnWriteTimeout = DefaultConnWriteTimeout +) + type Peer interface { // send sends the message to the remote peer. The function is non-blocking // and has no promise that the message will be received by the remote. @@ -126,14 +131,10 @@ type peer struct { func startPeer(t *Transport, urls types.URLs, peerID types.ID, fs *stats.FollowerStats) *peer { if t.Logger != nil { t.Logger.Info("starting remote peer", zap.String("remote-peer-id", peerID.String())) - } else { - plog.Infof("starting peer %s...", peerID) } defer func() { if t.Logger != nil { t.Logger.Info("started remote peer", zap.String("remote-peer-id", peerID.String())) - } else { - plog.Infof("started peer %s", peerID) } }() @@ -177,8 +178,6 @@ func startPeer(t *Transport, urls types.URLs, peerID types.ID, fs *stats.Followe if err := r.Process(ctx, mm); err != nil { if t.Logger != nil { t.Logger.Warn("failed to process Raft message", zap.Error(err)) - } else { - plog.Warningf("failed to process raft message (%v)", err) } } case <-p.stopc: @@ -195,7 +194,9 @@ func startPeer(t *Transport, urls types.URLs, peerID types.ID, fs *stats.Followe select { case mm := <-p.propc: if err := r.Process(ctx, mm); err != nil { - plog.Warningf("failed to process raft message (%v)", err) + if t.Logger != nil { + t.Logger.Warn("failed to process Raft message", zap.Error(err)) + } } case <-p.stopc: return @@ -257,10 +258,9 @@ func (p *peer) send(m raftpb.Message) { zap.String("local-member-id", p.localID.String()), zap.String("from", types.ID(m.From).String()), zap.String("remote-peer-id", p.id.String()), + zap.String("remote-peer-name", name), zap.Bool("remote-peer-active", p.status.isActive()), ) - } else { - plog.MergeWarningf("dropped internal raft message to %s since %s's sending buffer is full (bad/overloaded network)", p.id, name) } } else { if p.lg != nil { @@ -270,10 +270,9 @@ func (p *peer) send(m raftpb.Message) { zap.String("local-member-id", p.localID.String()), zap.String("from", types.ID(m.From).String()), zap.String("remote-peer-id", p.id.String()), + zap.String("remote-peer-name", name), zap.Bool("remote-peer-active", p.status.isActive()), ) - } else { - plog.Debugf("dropped %s to %s since %s's sending buffer is full", m.Type, p.id, name) } } sentFailures.WithLabelValues(types.ID(m.To).String()).Inc() @@ -298,8 +297,6 @@ func (p *peer) attachOutgoingConn(conn *outgoingConn) { default: if p.lg != nil { p.lg.Panic("unknown stream type", zap.String("type", conn.t.String())) - } else { - plog.Panicf("unhandled stream type %s", conn.t) } } if !ok { @@ -331,15 +328,11 @@ func (p *peer) Resume() { func (p *peer) stop() { if p.lg != nil { p.lg.Info("stopping remote peer", zap.String("remote-peer-id", p.id.String())) - } else { - plog.Infof("stopping peer %s...", p.id) } defer func() { if p.lg != nil { p.lg.Info("stopped remote peer", zap.String("remote-peer-id", p.id.String())) - } else { - plog.Infof("stopped peer %s", p.id) } }() diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/peer_status.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/peer_status.go similarity index 81% rename from vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/peer_status.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/peer_status.go index 66149ff67..cad19b2fb 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/peer_status.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/peer_status.go @@ -20,7 +20,7 @@ import ( "sync" "time" - "go.etcd.io/etcd/pkg/types" + "go.etcd.io/etcd/client/pkg/v3/types" "go.uber.org/zap" ) @@ -40,6 +40,9 @@ type peerStatus struct { } func newPeerStatus(lg *zap.Logger, local, id types.ID) *peerStatus { + if lg == nil { + lg = zap.NewNop() + } return &peerStatus{lg: lg, local: local, id: id} } @@ -47,11 +50,7 @@ func (s *peerStatus) activate() { s.mu.Lock() defer s.mu.Unlock() if !s.active { - if s.lg != nil { - s.lg.Info("peer became active", zap.String("peer-id", s.id.String())) - } else { - plog.Infof("peer %s became active", s.id) - } + s.lg.Info("peer became active", zap.String("peer-id", s.id.String())) s.active = true s.since = time.Now() @@ -64,12 +63,7 @@ func (s *peerStatus) deactivate(failure failureType, reason string) { defer s.mu.Unlock() msg := fmt.Sprintf("failed to %s %s on %s (%s)", failure.action, s.id, failure.source, reason) if s.active { - if s.lg != nil { - s.lg.Warn("peer became inactive (message send to peer failed)", zap.String("peer-id", s.id.String()), zap.Error(errors.New(msg))) - } else { - plog.Errorf(msg) - plog.Infof("peer %s became inactive (message send to peer failed)", s.id) - } + s.lg.Warn("peer became inactive (message send to peer failed)", zap.String("peer-id", s.id.String()), zap.Error(errors.New(msg))) s.active = false s.since = time.Time{} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/pipeline.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/pipeline.go similarity index 88% rename from vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/pipeline.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/pipeline.go index 70f92575d..de3b45911 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/pipeline.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/pipeline.go @@ -19,14 +19,15 @@ import ( "context" "errors" "io/ioutil" + "runtime" "sync" "time" - stats "go.etcd.io/etcd/etcdserver/api/v2stats" - "go.etcd.io/etcd/pkg/pbutil" - "go.etcd.io/etcd/pkg/types" - "go.etcd.io/etcd/raft" - "go.etcd.io/etcd/raft/raftpb" + "go.etcd.io/etcd/client/pkg/v3/types" + "go.etcd.io/etcd/pkg/v3/pbutil" + "go.etcd.io/etcd/raft/v3" + "go.etcd.io/etcd/raft/v3/raftpb" + stats "go.etcd.io/etcd/server/v3/etcdserver/api/v2stats" "go.uber.org/zap" ) @@ -73,8 +74,6 @@ func (p *pipeline) start() { zap.String("local-member-id", p.tr.ID.String()), zap.String("remote-peer-id", p.peerID.String()), ) - } else { - plog.Infof("started HTTP pipelining with peer %s", p.peerID) } } @@ -88,8 +87,6 @@ func (p *pipeline) stop() { zap.String("local-member-id", p.tr.ID.String()), zap.String("remote-peer-id", p.peerID.String()), ) - } else { - plog.Infof("stopped HTTP pipelining with peer %s", p.peerID) } } @@ -135,7 +132,7 @@ func (p *pipeline) handle() { // error on any failure. func (p *pipeline) post(data []byte) (err error) { u := p.picker.pick() - req := createPostRequest(u, RaftPrefix, bytes.NewBuffer(data), "application/protobuf", p.tr.URLs, p.tr.ID, p.tr.ClusterID) + req := createPostRequest(p.tr.Logger, u, RaftPrefix, bytes.NewBuffer(data), "application/protobuf", p.tr.URLs, p.tr.ID, p.tr.ClusterID) done := make(chan struct{}, 1) ctx, cancel := context.WithCancel(context.Background()) @@ -143,6 +140,7 @@ func (p *pipeline) post(data []byte) (err error) { go func() { select { case <-done: + cancel() case <-p.stopc: waitSchedule() cancel() @@ -162,7 +160,7 @@ func (p *pipeline) post(data []byte) (err error) { return err } - err = checkPostResponse(resp, b, req, p.peerID) + err = checkPostResponse(p.tr.Logger, resp, b, req, p.peerID) if err != nil { p.picker.unreachable(u) // errMemberRemoved is a critical error since a removed member should @@ -177,4 +175,4 @@ func (p *pipeline) post(data []byte) (err error) { } // waitSchedule waits other goroutines to be scheduled for a while -func waitSchedule() { time.Sleep(time.Millisecond) } +func waitSchedule() { runtime.Gosched() } diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/probing_status.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/probing_status.go similarity index 90% rename from vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/probing_status.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/probing_status.go index 474d9a0e4..672a579ce 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/probing_status.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/probing_status.go @@ -49,9 +49,7 @@ func addPeerToProber(lg *zap.Logger, p probing.Prober, id string, us []string, r s, err := p.Status(id) if err != nil { if lg != nil { - lg.Warn("failed to add peer into prober", zap.String("remote-peer-id", id)) - } else { - plog.Errorf("failed to add peer %s into prober", id) + lg.Warn("failed to add peer into prober", zap.String("remote-peer-id", id), zap.Error(err)) } return } @@ -74,8 +72,6 @@ func monitorProbingStatus(lg *zap.Logger, s probing.Status, id string, roundTrip zap.Duration("rtt", s.SRTT()), zap.Error(s.Err()), ) - } else { - plog.Warningf("health check for peer %s could not connect: %v", id, s.Err()) } interval = statusErrorInterval } else { @@ -91,8 +87,6 @@ func monitorProbingStatus(lg *zap.Logger, s probing.Status, id string, roundTrip zap.Duration("rtt", s.SRTT()), zap.Error(s.Err()), ) - } else { - plog.Warningf("the clock difference against peer %s is too high [%v > %v]", id, s.ClockDiff(), time.Second) } } rttSecProm.WithLabelValues(id).Observe(s.SRTT().Seconds()) diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/remote.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/remote.go similarity index 89% rename from vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/remote.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/remote.go index 1ef2493ed..eddb3f4da 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/remote.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/remote.go @@ -15,8 +15,8 @@ package rafthttp import ( - "go.etcd.io/etcd/pkg/types" - "go.etcd.io/etcd/raft/raftpb" + "go.etcd.io/etcd/client/pkg/v3/types" + "go.etcd.io/etcd/raft/v3/raftpb" "go.uber.org/zap" ) @@ -65,8 +65,6 @@ func (g *remote) send(m raftpb.Message) { zap.String("remote-peer-id", g.id.String()), zap.Bool("remote-peer-active", g.status.isActive()), ) - } else { - plog.MergeWarningf("dropped internal raft message to %s since sending buffer is full (bad/overloaded network)", g.id) } } else { if g.lg != nil { @@ -78,8 +76,6 @@ func (g *remote) send(m raftpb.Message) { zap.String("remote-peer-id", g.id.String()), zap.Bool("remote-peer-active", g.status.isActive()), ) - } else { - plog.Debugf("dropped %s to %s since sending buffer is full", m.Type, g.id) } } sentFailures.WithLabelValues(types.ID(m.To).String()).Inc() diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/snapshot_sender.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/snapshot_sender.go similarity index 80% rename from vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/snapshot_sender.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/snapshot_sender.go index 7105de188..84eb56bd0 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/snapshot_sender.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/snapshot_sender.go @@ -22,11 +22,11 @@ import ( "net/http" "time" - "go.etcd.io/etcd/etcdserver/api/snap" - "go.etcd.io/etcd/pkg/httputil" - pioutil "go.etcd.io/etcd/pkg/ioutil" - "go.etcd.io/etcd/pkg/types" - "go.etcd.io/etcd/raft" + "go.etcd.io/etcd/client/pkg/v3/types" + "go.etcd.io/etcd/pkg/v3/httputil" + pioutil "go.etcd.io/etcd/pkg/v3/ioutil" + "go.etcd.io/etcd/raft/v3" + "go.etcd.io/etcd/server/v3/etcdserver/api/snap" "github.com/dustin/go-humanize" "go.uber.org/zap" @@ -76,20 +76,18 @@ func (s *snapshotSender) send(merged snap.Message) { defer body.Close() u := s.picker.pick() - req := createPostRequest(u, RaftSnapshotPrefix, body, "application/octet-stream", s.tr.URLs, s.from, s.cid) + req := createPostRequest(s.tr.Logger, u, RaftSnapshotPrefix, body, "application/octet-stream", s.tr.URLs, s.from, s.cid) - snapshotTotalSizeVal := uint64(merged.TotalSize) - snapshotTotalSize := humanize.Bytes(snapshotTotalSizeVal) + snapshotSizeVal := uint64(merged.TotalSize) + snapshotSize := humanize.Bytes(snapshotSizeVal) if s.tr.Logger != nil { s.tr.Logger.Info( "sending database snapshot", zap.Uint64("snapshot-index", m.Snapshot.Metadata.Index), zap.String("remote-peer-id", to), - zap.Int64("bytes", merged.TotalSize), - zap.String("size", snapshotTotalSize), + zap.Uint64("bytes", snapshotSizeVal), + zap.String("size", snapshotSize), ) - } else { - plog.Infof("start to send database snapshot [index: %d, to %s, size %s]...", m.Snapshot.Metadata.Index, types.ID(m.To), snapshotTotalSize) } snapshotSendInflights.WithLabelValues(to).Inc() @@ -105,12 +103,10 @@ func (s *snapshotSender) send(merged snap.Message) { "failed to send database snapshot", zap.Uint64("snapshot-index", m.Snapshot.Metadata.Index), zap.String("remote-peer-id", to), - zap.Int64("bytes", merged.TotalSize), - zap.String("size", snapshotTotalSize), + zap.Uint64("bytes", snapshotSizeVal), + zap.String("size", snapshotSize), zap.Error(err), ) - } else { - plog.Warningf("database snapshot [index: %d, to: %s] failed to be sent out (%v)", m.Snapshot.Metadata.Index, types.ID(m.To), err) } // errMemberRemoved is a critical error since a removed member should @@ -138,11 +134,9 @@ func (s *snapshotSender) send(merged snap.Message) { "sent database snapshot", zap.Uint64("snapshot-index", m.Snapshot.Metadata.Index), zap.String("remote-peer-id", to), - zap.Int64("bytes", merged.TotalSize), - zap.String("size", snapshotTotalSize), + zap.Uint64("bytes", snapshotSizeVal), + zap.String("size", snapshotSize), ) - } else { - plog.Infof("database snapshot [index: %d, to: %s] sent out successfully", m.Snapshot.Metadata.Index, types.ID(m.To)) } sentBytes.WithLabelValues(to).Add(float64(merged.TotalSize)) @@ -186,7 +180,7 @@ func (s *snapshotSender) post(req *http.Request) (err error) { if r.err != nil { return r.err } - return checkPostResponse(r.resp, r.body, req, s.to) + return checkPostResponse(s.tr.Logger, r.resp, r.body, req, s.to) } } @@ -197,8 +191,6 @@ func createSnapBody(lg *zap.Logger, merged snap.Message) io.ReadCloser { if err := enc.encode(&merged.Message); err != nil { if lg != nil { lg.Panic("failed to encode message", zap.Error(err)) - } else { - plog.Panicf("encode message error (%v)", err) } } diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/stream.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/stream.go similarity index 87% rename from vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/stream.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/stream.go index cf7d8ccf6..1b180fca3 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/stream.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/stream.go @@ -25,12 +25,12 @@ import ( "sync" "time" - stats "go.etcd.io/etcd/etcdserver/api/v2stats" - "go.etcd.io/etcd/pkg/httputil" - "go.etcd.io/etcd/pkg/transport" - "go.etcd.io/etcd/pkg/types" - "go.etcd.io/etcd/raft/raftpb" - "go.etcd.io/etcd/version" + "go.etcd.io/etcd/api/v3/version" + "go.etcd.io/etcd/client/pkg/v3/transport" + "go.etcd.io/etcd/client/pkg/v3/types" + "go.etcd.io/etcd/pkg/v3/httputil" + "go.etcd.io/etcd/raft/v3/raftpb" + stats "go.etcd.io/etcd/server/v3/etcdserver/api/v2stats" "github.com/coreos/go-semver/semver" "go.uber.org/zap" @@ -58,19 +58,22 @@ var ( "3.2.0": {streamTypeMsgAppV2, streamTypeMessage}, "3.3.0": {streamTypeMsgAppV2, streamTypeMessage}, "3.4.0": {streamTypeMsgAppV2, streamTypeMessage}, + "3.5.0": {streamTypeMsgAppV2, streamTypeMessage}, } ) type streamType string -func (t streamType) endpoint() string { +func (t streamType) endpoint(lg *zap.Logger) string { switch t { case streamTypeMsgAppV2: return path.Join(RaftStreamPrefix, "msgapp") case streamTypeMessage: return path.Join(RaftStreamPrefix, "message") default: - plog.Panicf("unhandled stream type %v", t) + if lg != nil { + lg.Panic("unhandled stream type", zap.String("stream-type", t.String())) + } return "" } } @@ -168,8 +171,6 @@ func (cw *streamWriter) run() { zap.String("local-member-id", cw.localID.String()), zap.String("remote-peer-id", cw.peerID.String()), ) - } else { - plog.Infof("started streaming with peer %s (writer)", cw.peerID) } for { @@ -196,8 +197,6 @@ func (cw *streamWriter) run() { zap.String("local-member-id", cw.localID.String()), zap.String("remote-peer-id", cw.peerID.String()), ) - } else { - plog.Warningf("lost the TCP streaming connection with peer %s (%s writer)", cw.peerID, t) } heartbeatc, msgc = nil, nil @@ -227,8 +226,6 @@ func (cw *streamWriter) run() { zap.String("local-member-id", cw.localID.String()), zap.String("remote-peer-id", cw.peerID.String()), ) - } else { - plog.Warningf("lost the TCP streaming connection with peer %s (%s writer)", cw.peerID, t) } heartbeatc, msgc = nil, nil cw.r.ReportUnreachable(m.To) @@ -244,7 +241,9 @@ func (cw *streamWriter) run() { case streamTypeMessage: enc = &messageEncoder{w: conn.Writer} default: - plog.Panicf("unhandled stream type %s", conn.t) + if cw.lg != nil { + cw.lg.Panic("unhandled stream type", zap.String("stream-type", t.String())) + } } if cw.lg != nil { cw.lg.Info( @@ -269,19 +268,15 @@ func (cw *streamWriter) run() { zap.String("local-member-id", cw.localID.String()), zap.String("remote-peer-id", cw.peerID.String()), ) - } else { - plog.Warningf("closed an existing TCP streaming connection with peer %s (%s writer)", cw.peerID, t) } } if cw.lg != nil { - cw.lg.Warn( + cw.lg.Info( "established TCP streaming connection with remote peer", zap.String("stream-writer-type", t.String()), zap.String("local-member-id", cw.localID.String()), zap.String("remote-peer-id", cw.peerID.String()), ) - } else { - plog.Infof("established a TCP streaming connection with peer %s (%s writer)", cw.peerID, t) } heartbeatc, msgc = tickc.C, cw.msgc @@ -293,18 +288,14 @@ func (cw *streamWriter) run() { zap.String("stream-writer-type", t.String()), zap.String("remote-peer-id", cw.peerID.String()), ) - } else { - plog.Infof("closed the TCP streaming connection with peer %s (%s writer)", cw.peerID, t) } } if cw.lg != nil { - cw.lg.Warn( + cw.lg.Info( "stopped TCP streaming connection with remote peer", zap.String("stream-writer-type", t.String()), zap.String("remote-peer-id", cw.peerID.String()), ) - } else { - plog.Infof("stopped streaming with peer %s (writer)", cw.peerID) } close(cw.done) return @@ -335,8 +326,6 @@ func (cw *streamWriter) closeUnlocked() bool { zap.String("remote-peer-id", cw.peerID.String()), zap.Error(err), ) - } else { - plog.Errorf("peer %s (writer) connection close error: %v", cw.peerID, err) } } if len(cw.msgc) > 0 { @@ -409,8 +398,6 @@ func (cr *streamReader) run() { zap.String("local-member-id", cr.tr.ID.String()), zap.String("remote-peer-id", cr.peerID.String()), ) - } else { - plog.Infof("started streaming with peer %s (%s reader)", cr.peerID, t) } for { @@ -428,8 +415,6 @@ func (cr *streamReader) run() { zap.String("local-member-id", cr.tr.ID.String()), zap.String("remote-peer-id", cr.peerID.String()), ) - } else { - plog.Infof("established a TCP streaming connection with peer %s (%s reader)", cr.peerID, cr.typ) } err = cr.decodeLoop(rc, t) if cr.lg != nil { @@ -440,8 +425,6 @@ func (cr *streamReader) run() { zap.String("remote-peer-id", cr.peerID.String()), zap.Error(err), ) - } else { - plog.Warningf("lost the TCP streaming connection with peer %s (%s reader)", cr.peerID, cr.typ) } switch { // all data is read out @@ -462,8 +445,6 @@ func (cr *streamReader) run() { zap.String("local-member-id", cr.tr.ID.String()), zap.String("remote-peer-id", cr.peerID.String()), ) - } else { - plog.Infof("stopped streaming with peer %s (%s reader)", cr.peerID, t) } close(cr.done) return @@ -477,8 +458,6 @@ func (cr *streamReader) run() { zap.String("remote-peer-id", cr.peerID.String()), zap.Error(err), ) - } else { - plog.Errorf("streaming with peer %s (%s reader) rate limiter error: %v", cr.peerID, t, err) } } } @@ -495,8 +474,6 @@ func (cr *streamReader) decodeLoop(rc io.ReadCloser, t streamType) error { default: if cr.lg != nil { cr.lg.Panic("unknown stream type", zap.String("type", t.String())) - } else { - plog.Panicf("unhandled stream type %s", t) } } select { @@ -558,8 +535,6 @@ func (cr *streamReader) decodeLoop(rc io.ReadCloser, t streamType) error { zap.String("remote-peer-id", types.ID(m.To).String()), zap.Bool("remote-peer-active", cr.status.isActive()), ) - } else { - plog.MergeWarningf("dropped internal raft message from %s since receiving buffer is full (overloaded network)", types.ID(m.From)) } } else { if cr.lg != nil { @@ -571,8 +546,6 @@ func (cr *streamReader) decodeLoop(rc io.ReadCloser, t streamType) error { zap.String("remote-peer-id", types.ID(m.To).String()), zap.Bool("remote-peer-active", cr.status.isActive()), ) - } else { - plog.Debugf("dropped %s from %s since receiving buffer is full", m.Type, types.ID(m.From)) } } recvFailures.WithLabelValues(types.ID(m.From).String()).Inc() @@ -591,7 +564,7 @@ func (cr *streamReader) stop() { func (cr *streamReader) dial(t streamType) (io.ReadCloser, error) { u := cr.picker.pick() uu := u - uu.Path = path.Join(t.endpoint(), cr.tr.ID.String()) + uu.Path = path.Join(t.endpoint(cr.lg), cr.tr.ID.String()) if cr.lg != nil { cr.lg.Debug( @@ -672,12 +645,10 @@ func (cr *streamReader) dial(t streamType) (io.ReadCloser, error) { zap.String("remote-peer-id", cr.peerID.String()), zap.Error(errIncompatibleVersion), ) - } else { - plog.Errorf("request sent was ignored by peer %s (server version incompatible)", cr.peerID) } return nil, errIncompatibleVersion - case errClusterIDMismatch.Error(): + case ErrClusterIDMismatch.Error(): if cr.lg != nil { cr.lg.Warn( "request sent was ignored by remote peer due to cluster ID mismatch", @@ -685,13 +656,10 @@ func (cr *streamReader) dial(t streamType) (io.ReadCloser, error) { zap.String("remote-peer-cluster-id", resp.Header.Get("X-Etcd-Cluster-ID")), zap.String("local-member-id", cr.tr.ID.String()), zap.String("local-member-cluster-id", cr.tr.ClusterID.String()), - zap.Error(errClusterIDMismatch), + zap.Error(ErrClusterIDMismatch), ) - } else { - plog.Errorf("request sent was ignored (cluster ID mismatch: peer[%s]=%s, local=%s)", - cr.peerID, resp.Header.Get("X-Etcd-Cluster-ID"), cr.tr.ClusterID) } - return nil, errClusterIDMismatch + return nil, ErrClusterIDMismatch default: return nil, fmt.Errorf("unhandled error %q when precondition failed", string(b)) @@ -714,8 +682,6 @@ func (cr *streamReader) close() { zap.String("remote-peer-id", cr.peerID.String()), zap.Error(err), ) - } else { - plog.Errorf("peer %s (reader) connection close error: %v", cr.peerID, err) } } } diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/transport.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/transport.go similarity index 92% rename from vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/transport.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/transport.go index 7191c3d60..a1969549a 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/transport.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/transport.go @@ -20,22 +20,18 @@ import ( "sync" "time" - "go.etcd.io/etcd/etcdserver/api/snap" - stats "go.etcd.io/etcd/etcdserver/api/v2stats" - "go.etcd.io/etcd/pkg/logutil" - "go.etcd.io/etcd/pkg/transport" - "go.etcd.io/etcd/pkg/types" - "go.etcd.io/etcd/raft" - "go.etcd.io/etcd/raft/raftpb" - - "github.com/coreos/pkg/capnslog" + "go.etcd.io/etcd/client/pkg/v3/transport" + "go.etcd.io/etcd/client/pkg/v3/types" + "go.etcd.io/etcd/raft/v3" + "go.etcd.io/etcd/raft/v3/raftpb" + "go.etcd.io/etcd/server/v3/etcdserver/api/snap" + stats "go.etcd.io/etcd/server/v3/etcdserver/api/v2stats" + "github.com/xiang90/probing" "go.uber.org/zap" "golang.org/x/time/rate" ) -var plog = logutil.NewMergeLogger(capnslog.NewPackageLogger("go.etcd.io/etcd", "rafthttp")) - type Raft interface { Process(ctx context.Context, m raftpb.Message) error IsIDRemoved(id uint64) bool @@ -114,7 +110,7 @@ type Transport struct { Raft Raft // raft state machine, to which the Transport forwards received messages and reports status Snapshotter *snap.Snapshotter ServerStats *stats.ServerStats // used to record general transportation statistics - // used to record transportation statistics with followers when + // LeaderStats is used to record transportation statistics with followers when // performing as leader in raft protocol LeaderStats *stats.LeaderStats // ErrorC is used to report detected critical errors, e.g., @@ -208,8 +204,6 @@ func (t *Transport) Send(msgs []raftpb.Message) { zap.String("type", m.Type.String()), zap.String("unknown-target-peer-id", to.String()), ) - } else { - plog.Debugf("ignored message %s (sent to unknown peer %s)", m.Type, to) } } } @@ -284,8 +278,6 @@ func (t *Transport) AddRemote(id types.ID, us []string) { if err != nil { if t.Logger != nil { t.Logger.Panic("failed NewURLs", zap.Strings("urls", us), zap.Error(err)) - } else { - plog.Panicf("newURLs %+v should never fail: %+v", us, err) } } t.remotes[id] = startRemote(t, urls, id) @@ -314,8 +306,6 @@ func (t *Transport) AddPeer(id types.ID, us []string) { if err != nil { if t.Logger != nil { t.Logger.Panic("failed NewURLs", zap.Strings("urls", us), zap.Error(err)) - } else { - plog.Panicf("newURLs %+v should never fail: %+v", us, err) } } fs := t.LeaderStats.Follower(id.String()) @@ -330,8 +320,6 @@ func (t *Transport) AddPeer(id types.ID, us []string) { zap.String("remote-peer-id", id.String()), zap.Strings("remote-peer-urls", us), ) - } else { - plog.Infof("added peer %s", id) } } @@ -356,8 +344,6 @@ func (t *Transport) removePeer(id types.ID) { } else { if t.Logger != nil { t.Logger.Panic("unexpected removal of unknown remote peer", zap.String("remote-peer-id", id.String())) - } else { - plog.Panicf("unexpected removal of unknown peer '%d'", id) } } delete(t.peers, id) @@ -371,8 +357,6 @@ func (t *Transport) removePeer(id types.ID) { zap.String("local-member-id", t.ID.String()), zap.String("removed-remote-peer-id", id.String()), ) - } else { - plog.Infof("removed peer %s", id) } } @@ -387,8 +371,6 @@ func (t *Transport) UpdatePeer(id types.ID, us []string) { if err != nil { if t.Logger != nil { t.Logger.Panic("failed NewURLs", zap.Strings("urls", us), zap.Error(err)) - } else { - plog.Panicf("newURLs %+v should never fail: %+v", us, err) } } t.peers[id].update(urls) @@ -405,8 +387,6 @@ func (t *Transport) UpdatePeer(id types.ID, us []string) { zap.String("updated-remote-peer-id", id.String()), zap.Strings("updated-remote-peer-urls", us), ) - } else { - plog.Infof("updated peer %s", id) } } diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/urlpick.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/urlpick.go similarity index 97% rename from vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/urlpick.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/urlpick.go index 61ef46864..fc6054a78 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/urlpick.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/urlpick.go @@ -18,7 +18,7 @@ import ( "net/url" "sync" - "go.etcd.io/etcd/pkg/types" + "go.etcd.io/etcd/client/pkg/v3/types" ) type urlPicker struct { diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/util.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/util.go similarity index 84% rename from vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/util.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/util.go index 20938647c..6d0e6bdd6 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/rafthttp/util.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/util.go @@ -23,11 +23,12 @@ import ( "strings" "time" - "go.etcd.io/etcd/pkg/transport" - "go.etcd.io/etcd/pkg/types" - "go.etcd.io/etcd/version" + "go.etcd.io/etcd/api/v3/version" + "go.etcd.io/etcd/client/pkg/v3/transport" + "go.etcd.io/etcd/client/pkg/v3/types" "github.com/coreos/go-semver/semver" + "go.uber.org/zap" ) var ( @@ -38,7 +39,7 @@ var ( // NewListener returns a listener for raft message transfer between peers. // It uses timeout listener to identify broken streams promptly. func NewListener(u url.URL, tlsinfo *transport.TLSInfo) (net.Listener, error) { - return transport.NewTimeoutListener(u.Host, u.Scheme, tlsinfo, ConnReadTimeout, ConnWriteTimeout) + return transport.NewListenerWithOpts(u.Host, u.Scheme, transport.WithTLSInfo(tlsinfo), transport.WithTimeout(ConnReadTimeout, ConnWriteTimeout)) } // NewRoundTripper returns a roundTripper used to send requests @@ -60,12 +61,14 @@ func newStreamRoundTripper(tlsInfo transport.TLSInfo, dialTimeout time.Duration) } // createPostRequest creates a HTTP POST request that sends raft message. -func createPostRequest(u url.URL, path string, body io.Reader, ct string, urls types.URLs, from, cid types.ID) *http.Request { +func createPostRequest(lg *zap.Logger, u url.URL, path string, body io.Reader, ct string, urls types.URLs, from, cid types.ID) *http.Request { uu := u uu.Path = path req, err := http.NewRequest("POST", uu.String(), body) if err != nil { - plog.Panicf("unexpected new request error (%v)", err) + if lg != nil { + lg.Panic("unexpected new request error", zap.Error(err)) + } } req.Header.Set("Content-Type", ct) req.Header.Set("X-Server-From", from.String()) @@ -79,17 +82,28 @@ func createPostRequest(u url.URL, path string, body io.Reader, ct string, urls t // checkPostResponse checks the response of the HTTP POST request that sends // raft message. -func checkPostResponse(resp *http.Response, body []byte, req *http.Request, to types.ID) error { +func checkPostResponse(lg *zap.Logger, resp *http.Response, body []byte, req *http.Request, to types.ID) error { switch resp.StatusCode { case http.StatusPreconditionFailed: switch strings.TrimSuffix(string(body), "\n") { case errIncompatibleVersion.Error(): - plog.Errorf("request sent was ignored by peer %s (server version incompatible)", to) + if lg != nil { + lg.Error( + "request sent was ignored by peer", + zap.String("remote-peer-id", to.String()), + ) + } return errIncompatibleVersion - case errClusterIDMismatch.Error(): - plog.Errorf("request sent was ignored (cluster ID mismatch: remote[%s]=%s, local=%s)", - to, resp.Header.Get("X-Etcd-Cluster-ID"), req.Header.Get("X-Etcd-Cluster-ID")) - return errClusterIDMismatch + case ErrClusterIDMismatch.Error(): + if lg != nil { + lg.Error( + "request sent was ignored due to cluster ID mismatch", + zap.String("remote-peer-id", to.String()), + zap.String("remote-peer-cluster-id", resp.Header.Get("X-Etcd-Cluster-ID")), + zap.String("local-member-cluster-id", req.Header.Get("X-Etcd-Cluster-ID")), + ) + } + return ErrClusterIDMismatch default: return fmt.Errorf("unhandled error %q when precondition failed", string(body)) } diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/snap/db.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/db.go similarity index 88% rename from vendor/go.etcd.io/etcd/etcdserver/api/snap/db.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/db.go index 3002ccdcc..af653e1d5 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/snap/db.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/db.go @@ -23,7 +23,7 @@ import ( "path/filepath" "time" - "go.etcd.io/etcd/pkg/fileutil" + "go.etcd.io/etcd/client/pkg/v3/fileutil" humanize "github.com/dustin/go-humanize" "go.uber.org/zap" @@ -63,16 +63,12 @@ func (s *Snapshotter) SaveDBFrom(r io.Reader, id uint64) (int64, error) { return n, err } - if s.lg != nil { - s.lg.Info( - "saved database snapshot to disk", - zap.String("path", fn), - zap.Int64("bytes", n), - zap.String("size", humanize.Bytes(uint64(n))), - ) - } else { - plog.Infof("saved database snapshot to disk [total bytes: %d]", n) - } + s.lg.Info( + "saved database snapshot to disk", + zap.String("path", fn), + zap.Int64("bytes", n), + zap.String("size", humanize.Bytes(uint64(n))), + ) snapDBSaveSec.Observe(time.Since(start).Seconds()) return n, nil diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/snap/doc.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/doc.go similarity index 100% rename from vendor/go.etcd.io/etcd/etcdserver/api/snap/doc.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/doc.go diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/snap/message.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/message.go similarity index 96% rename from vendor/go.etcd.io/etcd/etcdserver/api/snap/message.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/message.go index c1151e27e..523b52b85 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/snap/message.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/message.go @@ -17,8 +17,8 @@ package snap import ( "io" - "go.etcd.io/etcd/pkg/ioutil" - "go.etcd.io/etcd/raft/raftpb" + "go.etcd.io/etcd/pkg/v3/ioutil" + "go.etcd.io/etcd/raft/v3/raftpb" ) // Message is a struct that contains a raft Message and a ReadCloser. The type diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/snap/metrics.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/metrics.go similarity index 100% rename from vendor/go.etcd.io/etcd/etcdserver/api/snap/metrics.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/metrics.go diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/snap/snappb/snap.pb.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snappb/snap.pb.go similarity index 69% rename from vendor/go.etcd.io/etcd/etcdserver/api/snap/snappb/snap.pb.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snappb/snap.pb.go index 51eba0114..6fd2b9c00 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/snap/snappb/snap.pb.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snappb/snap.pb.go @@ -1,29 +1,16 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: snap.proto -/* -Package snappb is a generated protocol buffer package. - -It is generated from these files: - - snap.proto - -It has these top-level messages: - - Snapshot -*/ package snappb import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - + fmt "fmt" + io "io" math "math" + math_bits "math/bits" _ "github.com/gogo/protobuf/gogoproto" - - io "io" + proto "github.com/golang/protobuf/proto" ) // Reference imports to suppress errors if they are not otherwise used. @@ -35,26 +22,71 @@ var _ = math.Inf // is compatible with the proto package it is being compiled against. // A compilation error at this line likely means your copy of the // proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package type Snapshot struct { - Crc uint32 `protobuf:"varint,1,opt,name=crc" json:"crc"` - Data []byte `protobuf:"bytes,2,opt,name=data" json:"data,omitempty"` - XXX_unrecognized []byte `json:"-"` + Crc uint32 `protobuf:"varint,1,opt,name=crc" json:"crc"` + Data []byte `protobuf:"bytes,2,opt,name=data" json:"data,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } -func (m *Snapshot) Reset() { *m = Snapshot{} } -func (m *Snapshot) String() string { return proto.CompactTextString(m) } -func (*Snapshot) ProtoMessage() {} -func (*Snapshot) Descriptor() ([]byte, []int) { return fileDescriptorSnap, []int{0} } +func (m *Snapshot) Reset() { *m = Snapshot{} } +func (m *Snapshot) String() string { return proto.CompactTextString(m) } +func (*Snapshot) ProtoMessage() {} +func (*Snapshot) Descriptor() ([]byte, []int) { + return fileDescriptor_f2e3c045ebf84d00, []int{0} +} +func (m *Snapshot) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Snapshot) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Snapshot.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Snapshot) XXX_Merge(src proto.Message) { + xxx_messageInfo_Snapshot.Merge(m, src) +} +func (m *Snapshot) XXX_Size() int { + return m.Size() +} +func (m *Snapshot) XXX_DiscardUnknown() { + xxx_messageInfo_Snapshot.DiscardUnknown(m) +} + +var xxx_messageInfo_Snapshot proto.InternalMessageInfo func init() { proto.RegisterType((*Snapshot)(nil), "snappb.snapshot") } + +func init() { proto.RegisterFile("snap.proto", fileDescriptor_f2e3c045ebf84d00) } + +var fileDescriptor_f2e3c045ebf84d00 = []byte{ + // 126 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2a, 0xce, 0x4b, 0x2c, + 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x03, 0xb1, 0x0b, 0x92, 0xa4, 0x44, 0xd2, 0xf3, + 0xd3, 0xf3, 0xc1, 0x42, 0xfa, 0x20, 0x16, 0x44, 0x56, 0xc9, 0x8c, 0x8b, 0x03, 0x24, 0x5f, 0x9c, + 0x91, 0x5f, 0x22, 0x24, 0xc6, 0xc5, 0x9c, 0x5c, 0x94, 0x2c, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0xeb, + 0xc4, 0x72, 0xe2, 0x9e, 0x3c, 0x43, 0x10, 0x48, 0x40, 0x48, 0x88, 0x8b, 0x25, 0x25, 0xb1, 0x24, + 0x51, 0x82, 0x49, 0x81, 0x51, 0x83, 0x27, 0x08, 0xcc, 0x76, 0x12, 0x39, 0xf1, 0x50, 0x8e, 0xe1, + 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf1, 0x58, 0x8e, + 0x01, 0x10, 0x00, 0x00, 0xff, 0xff, 0xd8, 0x0f, 0x32, 0xb2, 0x78, 0x00, 0x00, 0x00, +} + func (m *Snapshot) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -62,35 +94,47 @@ func (m *Snapshot) Marshal() (dAtA []byte, err error) { } func (m *Snapshot) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Snapshot) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintSnap(dAtA, i, uint64(m.Crc)) + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) + } if m.Data != nil { - dAtA[i] = 0x12 - i++ + i -= len(m.Data) + copy(dAtA[i:], m.Data) i = encodeVarintSnap(dAtA, i, uint64(len(m.Data))) - i += copy(dAtA[i:], m.Data) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) + i-- + dAtA[i] = 0x12 } - return i, nil + i = encodeVarintSnap(dAtA, i, uint64(m.Crc)) + i-- + dAtA[i] = 0x8 + return len(dAtA) - i, nil } func encodeVarintSnap(dAtA []byte, offset int, v uint64) int { + offset -= sovSnap(v) + base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) v >>= 7 offset++ } dAtA[offset] = uint8(v) - return offset + 1 + return base } func (m *Snapshot) Size() (n int) { + if m == nil { + return 0 + } var l int _ = l n += 1 + sovSnap(uint64(m.Crc)) @@ -105,14 +149,7 @@ func (m *Snapshot) Size() (n int) { } func sovSnap(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n + return (math_bits.Len64(x|1) + 6) / 7 } func sozSnap(x uint64) (n int) { return sovSnap(uint64((x << 1) ^ uint64((int64(x) >> 63)))) @@ -132,7 +169,7 @@ func (m *Snapshot) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - wire |= (uint64(b) & 0x7F) << shift + wire |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -160,7 +197,7 @@ func (m *Snapshot) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Crc |= (uint32(b) & 0x7F) << shift + m.Crc |= uint32(b&0x7F) << shift if b < 0x80 { break } @@ -179,7 +216,7 @@ func (m *Snapshot) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= (int(b) & 0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } @@ -188,6 +225,9 @@ func (m *Snapshot) Unmarshal(dAtA []byte) error { return ErrInvalidLengthSnap } postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthSnap + } if postIndex > l { return io.ErrUnexpectedEOF } @@ -202,7 +242,7 @@ func (m *Snapshot) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthSnap } if (iNdEx + skippy) > l { @@ -221,6 +261,7 @@ func (m *Snapshot) Unmarshal(dAtA []byte) error { func skipSnap(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 + depth := 0 for iNdEx < l { var wire uint64 for shift := uint(0); ; shift += 7 { @@ -252,10 +293,8 @@ func skipSnap(dAtA []byte) (n int, err error) { break } } - return iNdEx, nil case 1: iNdEx += 8 - return iNdEx, nil case 2: var length int for shift := uint(0); ; shift += 7 { @@ -272,67 +311,34 @@ func skipSnap(dAtA []byte) (n int, err error) { break } } - iNdEx += length if length < 0 { return 0, ErrInvalidLengthSnap } - return iNdEx, nil + iNdEx += length case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSnap - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipSnap(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil + depth++ case 4: - return iNdEx, nil + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupSnap + } + depth-- case 5: iNdEx += 4 - return iNdEx, nil default: return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } + if iNdEx < 0 { + return 0, ErrInvalidLengthSnap + } + if depth == 0 { + return iNdEx, nil + } } - panic("unreachable") + return 0, io.ErrUnexpectedEOF } var ( - ErrInvalidLengthSnap = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowSnap = fmt.Errorf("proto: integer overflow") + ErrInvalidLengthSnap = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowSnap = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupSnap = fmt.Errorf("proto: unexpected end of group") ) - -func init() { proto.RegisterFile("snap.proto", fileDescriptorSnap) } - -var fileDescriptorSnap = []byte{ - // 126 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2a, 0xce, 0x4b, 0x2c, - 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x03, 0xb1, 0x0b, 0x92, 0xa4, 0x44, 0xd2, 0xf3, - 0xd3, 0xf3, 0xc1, 0x42, 0xfa, 0x20, 0x16, 0x44, 0x56, 0xc9, 0x8c, 0x8b, 0x03, 0x24, 0x5f, 0x9c, - 0x91, 0x5f, 0x22, 0x24, 0xc6, 0xc5, 0x9c, 0x5c, 0x94, 0x2c, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0xeb, - 0xc4, 0x72, 0xe2, 0x9e, 0x3c, 0x43, 0x10, 0x48, 0x40, 0x48, 0x88, 0x8b, 0x25, 0x25, 0xb1, 0x24, - 0x51, 0x82, 0x49, 0x81, 0x51, 0x83, 0x27, 0x08, 0xcc, 0x76, 0x12, 0x39, 0xf1, 0x50, 0x8e, 0xe1, - 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf1, 0x58, 0x8e, - 0x01, 0x10, 0x00, 0x00, 0xff, 0xff, 0xd8, 0x0f, 0x32, 0xb2, 0x78, 0x00, 0x00, 0x00, -} diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/snap/snappb/snap.proto b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snappb/snap.proto similarity index 100% rename from vendor/go.etcd.io/etcd/etcdserver/api/snap/snappb/snap.proto rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snappb/snap.proto diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/snap/snapshotter.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snapshotter.go similarity index 76% rename from vendor/go.etcd.io/etcd/etcdserver/api/snap/snapshotter.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snapshotter.go index c5d6d6183..52cc0ae26 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/snap/snapshotter.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snapshotter.go @@ -26,21 +26,19 @@ import ( "strings" "time" - "github.com/coreos/pkg/capnslog" - "go.etcd.io/etcd/etcdserver/api/snap/snappb" - pioutil "go.etcd.io/etcd/pkg/ioutil" - "go.etcd.io/etcd/pkg/pbutil" - "go.etcd.io/etcd/raft" - "go.etcd.io/etcd/raft/raftpb" - "go.etcd.io/etcd/wal/walpb" + pioutil "go.etcd.io/etcd/pkg/v3/ioutil" + "go.etcd.io/etcd/pkg/v3/pbutil" + "go.etcd.io/etcd/raft/v3" + "go.etcd.io/etcd/raft/v3/raftpb" + "go.etcd.io/etcd/server/v3/etcdserver/api/snap/snappb" + "go.etcd.io/etcd/server/v3/wal/walpb" + "go.uber.org/zap" ) const snapSuffix = ".snap" var ( - plog = capnslog.NewPackageLogger("go.etcd.io/etcd/v3", "snap") - ErrNoSnapshot = errors.New("snap: no available snapshot") ErrEmptySnapshot = errors.New("snap: empty snapshot") ErrCRCMismatch = errors.New("snap: crc mismatch") @@ -58,6 +56,9 @@ type Snapshotter struct { } func New(lg *zap.Logger, dir string) *Snapshotter { + if lg == nil { + lg = zap.NewNop() + } return &Snapshotter{ lg: lg, dir: dir, @@ -91,16 +92,10 @@ func (s *Snapshotter) save(snapshot *raftpb.Snapshot) error { snapFsyncSec.Observe(time.Since(fsyncStart).Seconds()) if err != nil { - if s.lg != nil { - s.lg.Warn("failed to write a snap file", zap.String("path", spath), zap.Error(err)) - } + s.lg.Warn("failed to write a snap file", zap.String("path", spath), zap.Error(err)) rerr := os.Remove(spath) if rerr != nil { - if s.lg != nil { - s.lg.Warn("failed to remove a broken snap file", zap.String("path", spath), zap.Error(err)) - } else { - plog.Errorf("failed to remove broken snapshot file %s", spath) - } + s.lg.Warn("failed to remove a broken snap file", zap.String("path", spath), zap.Error(err)) } return err } @@ -153,8 +148,6 @@ func loadSnap(lg *zap.Logger, dir, name string) (*raftpb.Snapshot, error) { if rerr := os.Rename(fpath, brokenPath); rerr != nil { if lg != nil { lg.Warn("failed to rename a broken snap file", zap.String("path", fpath), zap.String("broken-path", brokenPath), zap.Error(rerr)) - } else { - plog.Warningf("cannot rename broken snapshot file %v to %v: %v", fpath, brokenPath, rerr) } } else { if lg != nil { @@ -171,8 +164,6 @@ func Read(lg *zap.Logger, snapname string) (*raftpb.Snapshot, error) { if err != nil { if lg != nil { lg.Warn("failed to read a snap file", zap.String("path", snapname), zap.Error(err)) - } else { - plog.Errorf("cannot read file %v: %v", snapname, err) } return nil, err } @@ -180,8 +171,6 @@ func Read(lg *zap.Logger, snapname string) (*raftpb.Snapshot, error) { if len(b) == 0 { if lg != nil { lg.Warn("failed to read empty snapshot file", zap.String("path", snapname)) - } else { - plog.Errorf("unexpected empty snapshot") } return nil, ErrEmptySnapshot } @@ -190,8 +179,6 @@ func Read(lg *zap.Logger, snapname string) (*raftpb.Snapshot, error) { if err = serializedSnap.Unmarshal(b); err != nil { if lg != nil { lg.Warn("failed to unmarshal snappb.Snapshot", zap.String("path", snapname), zap.Error(err)) - } else { - plog.Errorf("corrupted snapshot file %v: %v", snapname, err) } return nil, err } @@ -199,8 +186,6 @@ func Read(lg *zap.Logger, snapname string) (*raftpb.Snapshot, error) { if len(serializedSnap.Data) == 0 || serializedSnap.Crc == 0 { if lg != nil { lg.Warn("failed to read empty snapshot data", zap.String("path", snapname)) - } else { - plog.Errorf("unexpected empty snapshot") } return nil, ErrEmptySnapshot } @@ -213,8 +198,6 @@ func Read(lg *zap.Logger, snapname string) (*raftpb.Snapshot, error) { zap.Uint32("prev-crc", serializedSnap.Crc), zap.Uint32("new-crc", crc), ) - } else { - plog.Errorf("corrupted snapshot file %v: crc mismatch", snapname) } return nil, ErrCRCMismatch } @@ -223,8 +206,6 @@ func Read(lg *zap.Logger, snapname string) (*raftpb.Snapshot, error) { if err = snap.Unmarshal(serializedSnap.Data); err != nil { if lg != nil { lg.Warn("failed to unmarshal raftpb.Snapshot", zap.String("path", snapname), zap.Error(err)) - } else { - plog.Errorf("corrupted snapshot file %v: %v", snapname, err) } return nil, err } @@ -243,11 +224,11 @@ func (s *Snapshotter) snapNames() ([]string, error) { if err != nil { return nil, err } - names, err = s.cleanupSnapdir(names) + filenames, err := s.cleanupSnapdir(names) if err != nil { return nil, err } - snaps := checkSuffix(s.lg, names) + snaps := checkSuffix(s.lg, filenames) if len(snaps) == 0 { return nil, ErrNoSnapshot } @@ -266,8 +247,6 @@ func checkSuffix(lg *zap.Logger, names []string) []string { if _, ok := validFiles[names[i]]; !ok { if lg != nil { lg.Warn("found unexpected non-snap file; skipping", zap.String("path", names[i])) - } else { - plog.Warningf("skipped unexpected non snapshot file %v", names[i]) } } } @@ -278,19 +257,16 @@ func checkSuffix(lg *zap.Logger, names []string) []string { // cleanupSnapdir removes any files that should not be in the snapshot directory: // - db.tmp prefixed files that can be orphaned by defragmentation func (s *Snapshotter) cleanupSnapdir(filenames []string) (names []string, err error) { + names = make([]string, 0, len(filenames)) for _, filename := range filenames { if strings.HasPrefix(filename, "db.tmp") { - if s.lg != nil { - s.lg.Info("found orphaned defragmentation file; deleting", zap.String("path", filename)) - } else { - plog.Infof("found orphaned defragmentation file; deleting: %s", filename) - } + s.lg.Info("found orphaned defragmentation file; deleting", zap.String("path", filename)) if rmErr := os.Remove(filepath.Join(s.dir, filename)); rmErr != nil && !os.IsNotExist(rmErr) { - return nil, fmt.Errorf("failed to remove orphaned .snap.db file %s: %v", filename, rmErr) + return names, fmt.Errorf("failed to remove orphaned .snap.db file %s: %v", filename, rmErr) } - continue + } else { + names = append(names, filename) } - names = append(names, filename) } return names, nil } @@ -310,25 +286,13 @@ func (s *Snapshotter) ReleaseSnapDBs(snap raftpb.Snapshot) error { hexIndex := strings.TrimSuffix(filepath.Base(filename), ".snap.db") index, err := strconv.ParseUint(hexIndex, 16, 64) if err != nil { - if s.lg != nil { - s.lg.Warn("failed to parse index from filename", zap.String("path", filename), zap.String("error", err.Error())) - } else { - plog.Warningf("failed to parse index from filename: %s (%v)", filename, err) - } + s.lg.Error("failed to parse index from filename", zap.String("path", filename), zap.String("error", err.Error())) continue } if index < snap.Metadata.Index { - if s.lg != nil { - s.lg.Warn("found orphaned .snap.db file; deleting", zap.String("path", filename)) - } else { - plog.Warningf("found orphaned .snap.db file; deleting: %s", filename) - } + s.lg.Info("found orphaned .snap.db file; deleting", zap.String("path", filename)) if rmErr := os.Remove(filepath.Join(s.dir, filename)); rmErr != nil && !os.IsNotExist(rmErr) { - if s.lg != nil { - s.lg.Warn("failed to remove orphaned .snap.db file", zap.String("path", filename), zap.Error(rmErr)) - } else { - plog.Warningf("failed to remove orphaned .snap.db file: %s (%v)", filename, rmErr) - } + s.lg.Error("failed to remove orphaned .snap.db file", zap.String("path", filename), zap.String("error", rmErr.Error())) } } } diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v2stats/leader.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/leader.go similarity index 94% rename from vendor/go.etcd.io/etcd/etcdserver/api/v2stats/leader.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/leader.go index ca47f0f37..f17cecc2c 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v2stats/leader.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/leader.go @@ -19,11 +19,14 @@ import ( "math" "sync" "time" + + "go.uber.org/zap" ) // LeaderStats is used by the leader in an etcd cluster, and encapsulates // statistics about communication with its followers type LeaderStats struct { + lg *zap.Logger leaderStats sync.Mutex } @@ -36,8 +39,12 @@ type leaderStats struct { } // NewLeaderStats generates a new LeaderStats with the given id as leader -func NewLeaderStats(id string) *LeaderStats { +func NewLeaderStats(lg *zap.Logger, id string) *LeaderStats { + if lg == nil { + lg = zap.NewNop() + } return &LeaderStats{ + lg: lg, leaderStats: leaderStats{ Leader: id, Followers: make(map[string]*FollowerStats), @@ -52,7 +59,7 @@ func (ls *LeaderStats) JSON() []byte { b, err := json.Marshal(stats) // TODO(jonboulle): appropriate error handling? if err != nil { - plog.Errorf("error marshalling leader stats (%v)", err) + ls.lg.Error("failed to marshal leader stats", zap.Error(err)) } return b } diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v2stats/queue.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/queue.go similarity index 100% rename from vendor/go.etcd.io/etcd/etcdserver/api/v2stats/queue.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/queue.go diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v2stats/server.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/server.go similarity index 99% rename from vendor/go.etcd.io/etcd/etcdserver/api/v2stats/server.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/server.go index c4accc735..45effb1ed 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v2stats/server.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/server.go @@ -20,7 +20,7 @@ import ( "sync" "time" - "go.etcd.io/etcd/raft" + "go.etcd.io/etcd/raft/v3" ) // ServerStats encapsulates various statistics about an EtcdServer and its diff --git a/vendor/go.etcd.io/etcd/etcdserver/api/v2stats/stats.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/stats.go similarity index 89% rename from vendor/go.etcd.io/etcd/etcdserver/api/v2stats/stats.go rename to vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/stats.go index c50a20076..cbf60215a 100644 --- a/vendor/go.etcd.io/etcd/etcdserver/api/v2stats/stats.go +++ b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/stats.go @@ -15,10 +15,6 @@ // Package v2stats defines a standard interface for etcd cluster statistics. package v2stats -import "github.com/coreos/pkg/capnslog" - -var plog = capnslog.NewPackageLogger("go.etcd.io/etcd", "etcdserver/stats") - type Stats interface { // SelfStats returns the struct representing statistics of this server SelfStats() []byte diff --git a/vendor/go.etcd.io/etcd/wal/decoder.go b/vendor/go.etcd.io/etcd/server/v3/wal/decoder.go similarity index 80% rename from vendor/go.etcd.io/etcd/wal/decoder.go rename to vendor/go.etcd.io/etcd/server/v3/wal/decoder.go index d007fe1c7..b8c68bef6 100644 --- a/vendor/go.etcd.io/etcd/wal/decoder.go +++ b/vendor/go.etcd.io/etcd/server/v3/wal/decoder.go @@ -15,16 +15,17 @@ package wal import ( - "bufio" "encoding/binary" + "fmt" "hash" "io" "sync" - "go.etcd.io/etcd/pkg/crc" - "go.etcd.io/etcd/pkg/pbutil" - "go.etcd.io/etcd/raft/raftpb" - "go.etcd.io/etcd/wal/walpb" + "go.etcd.io/etcd/client/pkg/v3/fileutil" + "go.etcd.io/etcd/pkg/v3/crc" + "go.etcd.io/etcd/pkg/v3/pbutil" + "go.etcd.io/etcd/raft/v3/raftpb" + "go.etcd.io/etcd/server/v3/wal/walpb" ) const minSectorSize = 512 @@ -34,17 +35,17 @@ const frameSizeBytes = 8 type decoder struct { mu sync.Mutex - brs []*bufio.Reader + brs []*fileutil.FileBufReader // lastValidOff file offset following the last valid decoded record lastValidOff int64 crc hash.Hash32 } -func newDecoder(r ...io.Reader) *decoder { - readers := make([]*bufio.Reader, len(r)) +func newDecoder(r ...fileutil.FileReader) *decoder { + readers := make([]*fileutil.FileBufReader, len(r)) for i := range r { - readers[i] = bufio.NewReader(r[i]) + readers[i] = fileutil.NewFileBufReader(r[i]) } return &decoder{ brs: readers, @@ -59,17 +60,13 @@ func (d *decoder) decode(rec *walpb.Record) error { return d.decodeRecord(rec) } -// raft max message size is set to 1 MB in etcd server -// assume projects set reasonable message size limit, -// thus entry size should never exceed 10 MB -const maxWALEntrySizeLimit = int64(10 * 1024 * 1024) - func (d *decoder) decodeRecord(rec *walpb.Record) error { if len(d.brs) == 0 { return io.EOF } - l, err := readInt64(d.brs[0]) + fileBufReader := d.brs[0] + l, err := readInt64(fileBufReader) if err == io.EOF || (err == nil && l == 0) { // hit end of file or preallocated space d.brs = d.brs[1:] @@ -84,12 +81,15 @@ func (d *decoder) decodeRecord(rec *walpb.Record) error { } recBytes, padBytes := decodeFrameSize(l) - if recBytes >= maxWALEntrySizeLimit-padBytes { - return ErrMaxWALEntrySizeLimitExceeded + // The length of current WAL entry must be less than the remaining file size. + maxEntryLimit := fileBufReader.FileInfo().Size() - d.lastValidOff - padBytes + if recBytes > maxEntryLimit { + return fmt.Errorf("%w: [wal] max entry size limit exceeded when decoding %q, recBytes: %d, fileSize(%d) - offset(%d) - padBytes(%d) = entryLimit(%d)", + io.ErrUnexpectedEOF, fileBufReader.FileInfo().Name(), recBytes, fileBufReader.FileInfo().Size(), d.lastValidOff, padBytes, maxEntryLimit) } data := make([]byte, recBytes+padBytes) - if _, err = io.ReadFull(d.brs[0], data); err != nil { + if _, err = io.ReadFull(fileBufReader, data); err != nil { // ReadFull returns io.EOF only if no bytes were read // the decoder should treat this as an ErrUnexpectedEOF instead. if err == io.EOF { diff --git a/vendor/go.etcd.io/etcd/wal/doc.go b/vendor/go.etcd.io/etcd/server/v3/wal/doc.go similarity index 100% rename from vendor/go.etcd.io/etcd/wal/doc.go rename to vendor/go.etcd.io/etcd/server/v3/wal/doc.go diff --git a/vendor/go.etcd.io/etcd/wal/encoder.go b/vendor/go.etcd.io/etcd/server/v3/wal/encoder.go similarity index 96% rename from vendor/go.etcd.io/etcd/wal/encoder.go rename to vendor/go.etcd.io/etcd/server/v3/wal/encoder.go index 4de853b69..61b4c20ef 100644 --- a/vendor/go.etcd.io/etcd/wal/encoder.go +++ b/vendor/go.etcd.io/etcd/server/v3/wal/encoder.go @@ -21,9 +21,9 @@ import ( "os" "sync" - "go.etcd.io/etcd/pkg/crc" - "go.etcd.io/etcd/pkg/ioutil" - "go.etcd.io/etcd/wal/walpb" + "go.etcd.io/etcd/pkg/v3/crc" + "go.etcd.io/etcd/pkg/v3/ioutil" + "go.etcd.io/etcd/server/v3/wal/walpb" ) // walPageBytes is the alignment for flushing records to the backing Writer. diff --git a/vendor/go.etcd.io/etcd/wal/file_pipeline.go b/vendor/go.etcd.io/etcd/server/v3/wal/file_pipeline.go similarity index 91% rename from vendor/go.etcd.io/etcd/wal/file_pipeline.go rename to vendor/go.etcd.io/etcd/server/v3/wal/file_pipeline.go index e1e1c557b..c2feba6c1 100644 --- a/vendor/go.etcd.io/etcd/wal/file_pipeline.go +++ b/vendor/go.etcd.io/etcd/server/v3/wal/file_pipeline.go @@ -19,7 +19,7 @@ import ( "os" "path/filepath" - "go.etcd.io/etcd/pkg/fileutil" + "go.etcd.io/etcd/client/pkg/v3/fileutil" "go.uber.org/zap" ) @@ -41,6 +41,9 @@ type filePipeline struct { } func newFilePipeline(lg *zap.Logger, dir string, fileSize int64) *filePipeline { + if lg == nil { + lg = zap.NewNop() + } fp := &filePipeline{ lg: lg, dir: dir, @@ -75,11 +78,7 @@ func (fp *filePipeline) alloc() (f *fileutil.LockedFile, err error) { return nil, err } if err = fileutil.Preallocate(f.File, fp.size, true); err != nil { - if fp.lg != nil { - fp.lg.Warn("failed to preallocate space when creating a new WAL", zap.Int64("size", fp.size), zap.Error(err)) - } else { - plog.Errorf("failed to allocate space when creating new wal file (%v)", err) - } + fp.lg.Error("failed to preallocate space when creating a new WAL", zap.Int64("size", fp.size), zap.Error(err)) f.Close() return nil, err } diff --git a/vendor/go.etcd.io/etcd/wal/metrics.go b/vendor/go.etcd.io/etcd/server/v3/wal/metrics.go similarity index 100% rename from vendor/go.etcd.io/etcd/wal/metrics.go rename to vendor/go.etcd.io/etcd/server/v3/wal/metrics.go diff --git a/vendor/go.etcd.io/etcd/wal/repair.go b/vendor/go.etcd.io/etcd/server/v3/wal/repair.go similarity index 57% rename from vendor/go.etcd.io/etcd/wal/repair.go rename to vendor/go.etcd.io/etcd/server/v3/wal/repair.go index 5c7c5d175..dec2fa240 100644 --- a/vendor/go.etcd.io/etcd/wal/repair.go +++ b/vendor/go.etcd.io/etcd/server/v3/wal/repair.go @@ -15,38 +15,38 @@ package wal import ( + "errors" "io" "os" "path/filepath" "time" - "go.etcd.io/etcd/pkg/fileutil" - "go.etcd.io/etcd/wal/walpb" + "go.etcd.io/etcd/client/pkg/v3/fileutil" + "go.etcd.io/etcd/server/v3/wal/walpb" "go.uber.org/zap" ) // Repair tries to repair ErrUnexpectedEOF in the // last wal file by truncating. func Repair(lg *zap.Logger, dirpath string) bool { + if lg == nil { + lg = zap.NewNop() + } f, err := openLast(lg, dirpath) if err != nil { return false } defer f.Close() - if lg != nil { - lg.Info("repairing", zap.String("path", f.Name())) - } else { - plog.Noticef("repairing %v", f.Name()) - } + lg.Info("repairing", zap.String("path", f.Name())) rec := &walpb.Record{} - decoder := newDecoder(f) + decoder := newDecoder(fileutil.NewFileReader(f.File)) for { lastOffset := decoder.lastOffset() err := decoder.decode(rec) - switch err { - case nil: + switch { + case err == nil: // update crc of the decoder when necessary switch rec.Type { case crcType: @@ -60,73 +60,45 @@ func Repair(lg *zap.Logger, dirpath string) bool { } continue - case io.EOF: - if lg != nil { - lg.Info("repaired", zap.String("path", f.Name()), zap.Error(io.EOF)) - } + case errors.Is(err, io.EOF): + lg.Info("repaired", zap.String("path", f.Name()), zap.Error(io.EOF)) return true - case io.ErrUnexpectedEOF: + case errors.Is(err, io.ErrUnexpectedEOF): bf, bferr := os.Create(f.Name() + ".broken") if bferr != nil { - if lg != nil { - lg.Warn("failed to create backup file", zap.String("path", f.Name()+".broken"), zap.Error(bferr)) - } else { - plog.Errorf("could not repair %v, failed to create backup file", f.Name()) - } + lg.Warn("failed to create backup file", zap.String("path", f.Name()+".broken"), zap.Error(bferr)) return false } defer bf.Close() if _, err = f.Seek(0, io.SeekStart); err != nil { - if lg != nil { - lg.Warn("failed to read file", zap.String("path", f.Name()), zap.Error(err)) - } else { - plog.Errorf("could not repair %v, failed to read file", f.Name()) - } + lg.Warn("failed to read file", zap.String("path", f.Name()), zap.Error(err)) return false } if _, err = io.Copy(bf, f); err != nil { - if lg != nil { - lg.Warn("failed to copy", zap.String("from", f.Name()+".broken"), zap.String("to", f.Name()), zap.Error(err)) - } else { - plog.Errorf("could not repair %v, failed to copy file", f.Name()) - } + lg.Warn("failed to copy", zap.String("from", f.Name()+".broken"), zap.String("to", f.Name()), zap.Error(err)) return false } if err = f.Truncate(lastOffset); err != nil { - if lg != nil { - lg.Warn("failed to truncate", zap.String("path", f.Name()), zap.Error(err)) - } else { - plog.Errorf("could not repair %v, failed to truncate file", f.Name()) - } + lg.Warn("failed to truncate", zap.String("path", f.Name()), zap.Error(err)) return false } start := time.Now() if err = fileutil.Fsync(f.File); err != nil { - if lg != nil { - lg.Warn("failed to fsync", zap.String("path", f.Name()), zap.Error(err)) - } else { - plog.Errorf("could not repair %v, failed to sync file", f.Name()) - } + lg.Warn("failed to fsync", zap.String("path", f.Name()), zap.Error(err)) return false } walFsyncSec.Observe(time.Since(start).Seconds()) - if lg != nil { - lg.Info("repaired", zap.String("path", f.Name()), zap.Error(io.ErrUnexpectedEOF)) - } + lg.Info("repaired", zap.String("path", f.Name()), zap.Error(io.ErrUnexpectedEOF)) return true default: - if lg != nil { - lg.Warn("failed to repair", zap.String("path", f.Name()), zap.Error(err)) - } else { - plog.Errorf("could not repair error (%v)", err) - } + lg.Warn("failed to repair", zap.String("path", f.Name()), zap.Error(err)) return false } } diff --git a/vendor/go.etcd.io/etcd/wal/util.go b/vendor/go.etcd.io/etcd/server/v3/wal/util.go similarity index 81% rename from vendor/go.etcd.io/etcd/wal/util.go rename to vendor/go.etcd.io/etcd/server/v3/wal/util.go index a3f314bb1..4a21ae618 100644 --- a/vendor/go.etcd.io/etcd/wal/util.go +++ b/vendor/go.etcd.io/etcd/server/v3/wal/util.go @@ -19,7 +19,7 @@ import ( "fmt" "strings" - "go.etcd.io/etcd/pkg/fileutil" + "go.etcd.io/etcd/client/pkg/v3/fileutil" "go.uber.org/zap" ) @@ -43,11 +43,7 @@ func searchIndex(lg *zap.Logger, names []string, index uint64) (int, bool) { name := names[i] _, curIndex, err := parseWALName(name) if err != nil { - if lg != nil { - lg.Panic("failed to parse WAL file name", zap.String("path", name), zap.Error(err)) - } else { - plog.Panicf("parse correct name should never fail: %v", err) - } + lg.Panic("failed to parse WAL file name", zap.String("path", name), zap.Error(err)) } if index >= curIndex { return i, true @@ -63,11 +59,7 @@ func isValidSeq(lg *zap.Logger, names []string) bool { for _, name := range names { curSeq, _, err := parseWALName(name) if err != nil { - if lg != nil { - lg.Panic("failed to parse WAL file name", zap.String("path", name), zap.Error(err)) - } else { - plog.Panicf("parse correct name should never fail: %v", err) - } + lg.Panic("failed to parse WAL file name", zap.String("path", name), zap.Error(err)) } if lastSeq != 0 && lastSeq != curSeq-1 { return false @@ -95,14 +87,10 @@ func checkWalNames(lg *zap.Logger, names []string) []string { if _, _, err := parseWALName(name); err != nil { // don't complain about left over tmp files if !strings.HasSuffix(name, ".tmp") { - if lg != nil { - lg.Warn( - "ignored file in WAL directory", - zap.String("path", name), - ) - } else { - plog.Warningf("ignored file %v in wal", name) - } + lg.Warn( + "ignored file in WAL directory", + zap.String("path", name), + ) } continue } diff --git a/vendor/go.etcd.io/etcd/wal/wal.go b/vendor/go.etcd.io/etcd/server/v3/wal/wal.go similarity index 82% rename from vendor/go.etcd.io/etcd/wal/wal.go rename to vendor/go.etcd.io/etcd/server/v3/wal/wal.go index 072ef93fc..db9007877 100644 --- a/vendor/go.etcd.io/etcd/wal/wal.go +++ b/vendor/go.etcd.io/etcd/server/v3/wal/wal.go @@ -22,16 +22,16 @@ import ( "io" "os" "path/filepath" + "strings" "sync" "time" - "go.etcd.io/etcd/pkg/fileutil" - "go.etcd.io/etcd/pkg/pbutil" - "go.etcd.io/etcd/raft" - "go.etcd.io/etcd/raft/raftpb" - "go.etcd.io/etcd/wal/walpb" + "go.etcd.io/etcd/client/pkg/v3/fileutil" + "go.etcd.io/etcd/pkg/v3/pbutil" + "go.etcd.io/etcd/raft/v3" + "go.etcd.io/etcd/raft/v3/raftpb" + "go.etcd.io/etcd/server/v3/wal/walpb" - "github.com/coreos/pkg/capnslog" "go.uber.org/zap" ) @@ -54,17 +54,14 @@ var ( // so that tests can set a different segment size. SegmentSizeBytes int64 = 64 * 1000 * 1000 // 64MB - plog = capnslog.NewPackageLogger("go.etcd.io/etcd", "wal") - - ErrMetadataConflict = errors.New("wal: conflicting metadata found") - ErrFileNotFound = errors.New("wal: file not found") - ErrCRCMismatch = errors.New("wal: crc mismatch") - ErrSnapshotMismatch = errors.New("wal: snapshot mismatch") - ErrSnapshotNotFound = errors.New("wal: snapshot not found") - ErrSliceOutOfRange = errors.New("wal: slice bounds out of range") - ErrMaxWALEntrySizeLimitExceeded = errors.New("wal: max entry size limit exceeded") - ErrDecoderNotFound = errors.New("wal: decoder not found") - crcTable = crc32.MakeTable(crc32.Castagnoli) + ErrMetadataConflict = errors.New("wal: conflicting metadata found") + ErrFileNotFound = errors.New("wal: file not found") + ErrCRCMismatch = errors.New("wal: crc mismatch") + ErrSnapshotMismatch = errors.New("wal: snapshot mismatch") + ErrSnapshotNotFound = errors.New("wal: snapshot not found") + ErrSliceOutOfRange = errors.New("wal: slice bounds out of range") + ErrDecoderNotFound = errors.New("wal: decoder not found") + crcTable = crc32.MakeTable(crc32.Castagnoli) ) // WAL is a logical representation of the stable storage. @@ -105,6 +102,10 @@ func Create(lg *zap.Logger, dirpath string, metadata []byte) (*WAL, error) { return nil, os.ErrExist } + if lg == nil { + lg = zap.NewNop() + } + // keep temporary wal directory so WAL initialization appears atomic tmpdirpath := filepath.Clean(dirpath) + ".tmp" if fileutil.Exist(tmpdirpath) { @@ -112,49 +113,43 @@ func Create(lg *zap.Logger, dirpath string, metadata []byte) (*WAL, error) { return nil, err } } - if err := fileutil.CreateDirAll(tmpdirpath); err != nil { - if lg != nil { - lg.Warn( - "failed to create a temporary WAL directory", - zap.String("tmp-dir-path", tmpdirpath), - zap.String("dir-path", dirpath), - zap.Error(err), - ) - } + defer os.RemoveAll(tmpdirpath) + + if err := fileutil.CreateDirAll(lg, tmpdirpath); err != nil { + lg.Warn( + "failed to create a temporary WAL directory", + zap.String("tmp-dir-path", tmpdirpath), + zap.String("dir-path", dirpath), + zap.Error(err), + ) return nil, err } p := filepath.Join(tmpdirpath, walName(0, 0)) f, err := fileutil.LockFile(p, os.O_WRONLY|os.O_CREATE, fileutil.PrivateFileMode) if err != nil { - if lg != nil { - lg.Warn( - "failed to flock an initial WAL file", - zap.String("path", p), - zap.Error(err), - ) - } + lg.Warn( + "failed to flock an initial WAL file", + zap.String("path", p), + zap.Error(err), + ) return nil, err } if _, err = f.Seek(0, io.SeekEnd); err != nil { - if lg != nil { - lg.Warn( - "failed to seek an initial WAL file", - zap.String("path", p), - zap.Error(err), - ) - } + lg.Warn( + "failed to seek an initial WAL file", + zap.String("path", p), + zap.Error(err), + ) return nil, err } if err = fileutil.Preallocate(f.File, SegmentSizeBytes, true); err != nil { - if lg != nil { - lg.Warn( - "failed to preallocate an initial WAL file", - zap.String("path", p), - zap.Int64("segment-bytes", SegmentSizeBytes), - zap.Error(err), - ) - } + lg.Warn( + "failed to preallocate an initial WAL file", + zap.String("path", p), + zap.Int64("segment-bytes", SegmentSizeBytes), + zap.Error(err), + ) return nil, err } @@ -178,15 +173,14 @@ func Create(lg *zap.Logger, dirpath string, metadata []byte) (*WAL, error) { return nil, err } + logDirPath := w.dir if w, err = w.renameWAL(tmpdirpath); err != nil { - if lg != nil { - lg.Warn( - "failed to rename the temporary WAL directory", - zap.String("tmp-dir-path", tmpdirpath), - zap.String("dir-path", w.dir), - zap.Error(err), - ) - } + lg.Warn( + "failed to rename the temporary WAL directory", + zap.String("tmp-dir-path", tmpdirpath), + zap.String("dir-path", logDirPath), + zap.Error(err), + ) return nil, err } @@ -200,40 +194,40 @@ func Create(lg *zap.Logger, dirpath string, metadata []byte) (*WAL, error) { // directory was renamed; sync parent dir to persist rename pdir, perr := fileutil.OpenDir(filepath.Dir(w.dir)) if perr != nil { - if lg != nil { + lg.Warn( + "failed to open the parent data directory", + zap.String("parent-dir-path", filepath.Dir(w.dir)), + zap.String("dir-path", w.dir), + zap.Error(perr), + ) + return nil, perr + } + dirCloser := func() error { + if perr = pdir.Close(); perr != nil { lg.Warn( - "failed to open the parent data directory", + "failed to close the parent data directory file", zap.String("parent-dir-path", filepath.Dir(w.dir)), zap.String("dir-path", w.dir), zap.Error(perr), ) + return perr } - return nil, perr + return nil } start := time.Now() if perr = fileutil.Fsync(pdir); perr != nil { - if lg != nil { - lg.Warn( - "failed to fsync the parent data directory file", - zap.String("parent-dir-path", filepath.Dir(w.dir)), - zap.String("dir-path", w.dir), - zap.Error(perr), - ) - } + dirCloser() + lg.Warn( + "failed to fsync the parent data directory file", + zap.String("parent-dir-path", filepath.Dir(w.dir)), + zap.String("dir-path", w.dir), + zap.Error(perr), + ) return nil, perr } walFsyncSec.Observe(time.Since(start).Seconds()) - - if perr = pdir.Close(); perr != nil { - if lg != nil { - lg.Warn( - "failed to close the parent data directory file", - zap.String("parent-dir-path", filepath.Dir(w.dir)), - zap.String("dir-path", w.dir), - zap.Error(perr), - ) - } - return nil, perr + if err = dirCloser(); err != nil { + return nil, err } return w, nil @@ -246,24 +240,16 @@ func (w *WAL) SetUnsafeNoFsync() { func (w *WAL) cleanupWAL(lg *zap.Logger) { var err error if err = w.Close(); err != nil { - if lg != nil { - lg.Panic("failed to close WAL during cleanup", zap.Error(err)) - } else { - plog.Panicf("failed to close WAL during cleanup: %v", err) - } + lg.Panic("failed to close WAL during cleanup", zap.Error(err)) } brokenDirName := fmt.Sprintf("%s.broken.%v", w.dir, time.Now().Format("20060102.150405.999999")) if err = os.Rename(w.dir, brokenDirName); err != nil { - if lg != nil { - lg.Panic( - "failed to rename WAL during cleanup", - zap.Error(err), - zap.String("source-path", w.dir), - zap.String("rename-path", brokenDirName), - ) - } else { - plog.Panicf("failed to rename WAL during cleanup: %v", err) - } + lg.Panic( + "failed to rename WAL during cleanup", + zap.Error(err), + zap.String("source-path", w.dir), + zap.String("rename-path", brokenDirName), + ) } } @@ -292,15 +278,11 @@ func (w *WAL) renameWAL(tmpdirpath string) (*WAL, error) { func (w *WAL) renameWALUnlock(tmpdirpath string) (*WAL, error) { // rename of directory with locked files doesn't work on windows/cifs; // close the WAL to release the locks so the directory can be renamed. - if w.lg != nil { - w.lg.Info( - "closing WAL to release flock and retry directory renaming", - zap.String("from", tmpdirpath), - zap.String("to", w.dir), - ) - } else { - plog.Infof("releasing file lock to rename %q to %q", tmpdirpath, w.dir) - } + w.lg.Info( + "closing WAL to release flock and retry directory renaming", + zap.String("from", tmpdirpath), + zap.String("to", w.dir), + ) w.Close() if err := os.Rename(tmpdirpath, w.dir); err != nil { @@ -343,6 +325,9 @@ func OpenForRead(lg *zap.Logger, dirpath string, snap walpb.Snapshot) (*WAL, err } func openAtIndex(lg *zap.Logger, dirpath string, snap walpb.Snapshot, write bool) (*WAL, error) { + if lg == nil { + lg = zap.NewNop() + } names, nameIndex, err := selectWALFiles(lg, dirpath, snap) if err != nil { return nil, err @@ -392,33 +377,37 @@ func selectWALFiles(lg *zap.Logger, dirpath string, snap walpb.Snapshot) ([]stri return names, nameIndex, nil } -func openWALFiles(lg *zap.Logger, dirpath string, names []string, nameIndex int, write bool) ([]io.Reader, []*fileutil.LockedFile, func() error, error) { +func openWALFiles(lg *zap.Logger, dirpath string, names []string, nameIndex int, write bool) ([]fileutil.FileReader, []*fileutil.LockedFile, func() error, error) { rcs := make([]io.ReadCloser, 0) - rs := make([]io.Reader, 0) + rs := make([]fileutil.FileReader, 0) ls := make([]*fileutil.LockedFile, 0) for _, name := range names[nameIndex:] { p := filepath.Join(dirpath, name) + var f *os.File if write { l, err := fileutil.TryLockFile(p, os.O_RDWR, fileutil.PrivateFileMode) if err != nil { - closeAll(rcs...) + closeAll(lg, rcs...) return nil, nil, nil, err } ls = append(ls, l) rcs = append(rcs, l) + f = l.File } else { rf, err := os.OpenFile(p, os.O_RDONLY, fileutil.PrivateFileMode) if err != nil { - closeAll(rcs...) + closeAll(lg, rcs...) return nil, nil, nil, err } ls = append(ls, nil) rcs = append(rcs, rf) + f = rf } - rs = append(rs, rcs[len(rcs)-1]) + fileReader := fileutil.NewFileReader(f) + rs = append(rs, fileReader) } - closer := func() error { return closeAll(rcs...) } + closer := func() error { return closeAll(lg, rcs...) } return rs, ls, closer, nil } @@ -433,6 +422,13 @@ func openWALFiles(lg *zap.Logger, dirpath string, names []string, nameIndex int, // TODO: detect not-last-snap error. // TODO: maybe loose the checking of match. // After ReadAll, the WAL will be ready for appending new records. +// +// ReadAll suppresses WAL entries that got overridden (i.e. a newer entry with the same index +// exists in the log). Such a situation can happen in cases described in figure 7. of the +// RAFT paper (http://web.stanford.edu/~ouster/cgi-bin/papers/raft-atc14.pdf). +// +// ReadAll may return uncommitted yet entries, that are subject to be overriden. +// Do not apply entries that have index > state.commit, as they are subject to change. func (w *WAL) ReadAll() (metadata []byte, state raftpb.HardState, ents []raftpb.Entry, err error) { w.mu.Lock() defer w.mu.Unlock() @@ -457,6 +453,7 @@ func (w *WAL) ReadAll() (metadata []byte, state raftpb.HardState, ents []raftpb. // return error before append call causes runtime panic return nil, state, nil, ErrSliceOutOfRange } + // The line below is potentially overriding some 'uncommitted' entries. ents = append(ents[:up], e) } w.enti = e.Index @@ -503,13 +500,13 @@ func (w *WAL) ReadAll() (metadata []byte, state raftpb.HardState, ents []raftpb. // We do not have to read out all entries in read mode. // The last record maybe a partial written one, so // ErrunexpectedEOF might be returned. - if err != io.EOF && err != io.ErrUnexpectedEOF { + if !errors.Is(err, io.EOF) && !errors.Is(err, io.ErrUnexpectedEOF) { state.Reset() return nil, state, nil, err } default: - // We must read all of the entries if WAL is opened in write mode. - if err != io.EOF { + // We must read all the entries if WAL is opened in write mode. + if !errors.Is(err, io.EOF) { state.Reset() return nil, state, nil, err } @@ -601,7 +598,7 @@ func ValidSnapshotEntries(lg *zap.Logger, walDir string) ([]walpb.Snapshot, erro } // We do not have to read out all the WAL entries // as the decoder is opened in read mode. - if err != io.EOF && err != io.ErrUnexpectedEOF { + if !errors.Is(err, io.EOF) && !errors.Is(err, io.ErrUnexpectedEOF) { return nil, err } @@ -614,7 +611,6 @@ func ValidSnapshotEntries(lg *zap.Logger, walDir string) ([]walpb.Snapshot, erro } } snaps = snaps[:n:n] - return snaps, nil } @@ -625,24 +621,33 @@ func ValidSnapshotEntries(lg *zap.Logger, walDir string) ([]walpb.Snapshot, erro // If it cannot read out the expected snap, it will return ErrSnapshotNotFound. // If the loaded snap doesn't match with the expected one, it will // return error ErrSnapshotMismatch. -func Verify(lg *zap.Logger, walDir string, snap walpb.Snapshot) error { +func Verify(lg *zap.Logger, walDir string, snap walpb.Snapshot) (*raftpb.HardState, error) { var metadata []byte var err error var match bool + var state raftpb.HardState rec := &walpb.Record{} + if lg == nil { + lg = zap.NewNop() + } names, nameIndex, err := selectWALFiles(lg, walDir, snap) if err != nil { - return err + return nil, err } // open wal files in read mode, so that there is no conflict // when the same WAL is opened elsewhere in write mode rs, _, closer, err := openWALFiles(lg, walDir, names, nameIndex, false) if err != nil { - return err + return nil, err } + defer func() { + if closer != nil { + closer() + } + }() // create a new decoder from the readers on the WAL files decoder := newDecoder(rs...) @@ -651,7 +656,7 @@ func Verify(lg *zap.Logger, walDir string, snap walpb.Snapshot) error { switch rec.Type { case metadataType: if metadata != nil && !bytes.Equal(metadata, rec.Data) { - return ErrMetadataConflict + return nil, ErrMetadataConflict } metadata = rec.Data case crcType: @@ -659,7 +664,7 @@ func Verify(lg *zap.Logger, walDir string, snap walpb.Snapshot) error { // Current crc of decoder must match the crc of the record. // We need not match 0 crc, since the decoder is a new one at this point. if crc != 0 && rec.Validate(crc) != nil { - return ErrCRCMismatch + return nil, ErrCRCMismatch } decoder.updateCRC(rec.Crc) case snapshotType: @@ -667,7 +672,7 @@ func Verify(lg *zap.Logger, walDir string, snap walpb.Snapshot) error { pbutil.MustUnmarshal(&loadedSnap, rec.Data) if loadedSnap.Index == snap.Index { if loadedSnap.Term != snap.Term { - return ErrSnapshotMismatch + return nil, ErrSnapshotMismatch } match = true } @@ -675,26 +680,23 @@ func Verify(lg *zap.Logger, walDir string, snap walpb.Snapshot) error { // are not necessary for validating the WAL contents case entryType: case stateType: + pbutil.MustUnmarshal(&state, rec.Data) default: - return fmt.Errorf("unexpected block type %d", rec.Type) + return nil, fmt.Errorf("unexpected block type %d", rec.Type) } } - if closer != nil { - closer() - } - // We do not have to read out all the WAL entries // as the decoder is opened in read mode. - if err != io.EOF && err != io.ErrUnexpectedEOF { - return err + if !errors.Is(err, io.EOF) && !errors.Is(err, io.ErrUnexpectedEOF) { + return nil, err } if !match { - return ErrSnapshotNotFound + return nil, ErrSnapshotNotFound } - return nil + return &state, nil } // cut closes current file written and creates a new one ready to append. @@ -780,11 +782,7 @@ func (w *WAL) cut() error { return err } - if w.lg != nil { - w.lg.Info("created a new WAL segment", zap.String("path", fpath)) - } else { - plog.Infof("segmented wal file %v is created", fpath) - } + w.lg.Info("created a new WAL segment", zap.String("path", fpath)) return nil } @@ -804,15 +802,11 @@ func (w *WAL) sync() error { took := time.Since(start) if took > warnSyncDuration { - if w.lg != nil { - w.lg.Warn( - "slow fdatasync", - zap.Duration("took", took), - zap.Duration("expected-duration", warnSyncDuration), - ) - } else { - plog.Warningf("sync duration of %v, expected less than %v", took, warnSyncDuration) - } + w.lg.Warn( + "slow fdatasync", + zap.Duration("took", took), + zap.Duration("expected-duration", warnSyncDuration), + ) } walFsyncSec.Observe(took.Seconds()) @@ -890,11 +884,7 @@ func (w *WAL) Close() error { continue } if err := l.Close(); err != nil { - if w.lg != nil { - w.lg.Warn("failed to close WAL", zap.Error(err)) - } else { - plog.Errorf("failed to unlock during closing wal: %s", err) - } + w.lg.Error("failed to close WAL", zap.Error(err)) } } @@ -961,6 +951,10 @@ func (w *WAL) Save(st raftpb.HardState, ents []raftpb.Entry) error { } func (w *WAL) SaveSnapshot(e walpb.Snapshot) error { + if err := walpb.ValidateSnapshotForWrite(&e); err != nil { + return err + } + b := pbutil.MustMarshal(&e) w.mu.Lock() @@ -995,20 +989,21 @@ func (w *WAL) seq() uint64 { } seq, _, err := parseWALName(filepath.Base(t.Name())) if err != nil { - if w.lg != nil { - w.lg.Fatal("failed to parse WAL name", zap.String("name", t.Name()), zap.Error(err)) - } else { - plog.Fatalf("bad wal name %s (%v)", t.Name(), err) - } + w.lg.Fatal("failed to parse WAL name", zap.String("name", t.Name()), zap.Error(err)) } return seq } -func closeAll(rcs ...io.ReadCloser) error { +func closeAll(lg *zap.Logger, rcs ...io.ReadCloser) error { + stringArr := make([]string, 0) for _, f := range rcs { if err := f.Close(); err != nil { - return err + lg.Warn("failed to close: ", zap.Error(err)) + stringArr = append(stringArr, err.Error()) } } - return nil + if len(stringArr) == 0 { + return nil + } + return errors.New(strings.Join(stringArr, ", ")) } diff --git a/vendor/go.etcd.io/etcd/wal/walpb/record.go b/vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.go similarity index 66% rename from vendor/go.etcd.io/etcd/wal/walpb/record.go rename to vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.go index 30a05e0c1..e2070fbba 100644 --- a/vendor/go.etcd.io/etcd/wal/walpb/record.go +++ b/vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.go @@ -27,3 +27,15 @@ func (rec *Record) Validate(crc uint32) error { rec.Reset() return ErrCRCMismatch } + +// ValidateSnapshotForWrite ensures the Snapshot the newly written snapshot is valid. +// +// There might exist log-entries written by old etcd versions that does not conform +// to the requirements. +func ValidateSnapshotForWrite(e *Snapshot) error { + // Since etcd>=3.5.0 + if e.ConfState == nil && e.Index > 0 { + return errors.New("Saved (not-initial) snapshot is missing ConfState: " + e.String()) + } + return nil +} diff --git a/vendor/go.etcd.io/etcd/wal/walpb/record.pb.go b/vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.pb.go similarity index 52% rename from vendor/go.etcd.io/etcd/wal/walpb/record.pb.go rename to vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.pb.go index 394ccdc28..654d82636 100644 --- a/vendor/go.etcd.io/etcd/wal/walpb/record.pb.go +++ b/vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.pb.go @@ -1,30 +1,17 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: record.proto -/* -Package walpb is a generated protocol buffer package. - -It is generated from these files: - - record.proto - -It has these top-level messages: - - Record - Snapshot -*/ package walpb import ( - "fmt" - - proto "github.com/golang/protobuf/proto" - + fmt "fmt" + io "io" math "math" + math_bits "math/bits" _ "github.com/gogo/protobuf/gogoproto" - - io "io" + proto "github.com/golang/protobuf/proto" + raftpb "go.etcd.io/etcd/raft/v3/raftpb" ) // Reference imports to suppress errors if they are not otherwise used. @@ -36,39 +23,124 @@ var _ = math.Inf // is compatible with the proto package it is being compiled against. // A compilation error at this line likely means your copy of the // proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package type Record struct { - Type int64 `protobuf:"varint,1,opt,name=type" json:"type"` - Crc uint32 `protobuf:"varint,2,opt,name=crc" json:"crc"` - Data []byte `protobuf:"bytes,3,opt,name=data" json:"data,omitempty"` - XXX_unrecognized []byte `json:"-"` + Type int64 `protobuf:"varint,1,opt,name=type" json:"type"` + Crc uint32 `protobuf:"varint,2,opt,name=crc" json:"crc"` + Data []byte `protobuf:"bytes,3,opt,name=data" json:"data,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } -func (m *Record) Reset() { *m = Record{} } -func (m *Record) String() string { return proto.CompactTextString(m) } -func (*Record) ProtoMessage() {} -func (*Record) Descriptor() ([]byte, []int) { return fileDescriptorRecord, []int{0} } +func (m *Record) Reset() { *m = Record{} } +func (m *Record) String() string { return proto.CompactTextString(m) } +func (*Record) ProtoMessage() {} +func (*Record) Descriptor() ([]byte, []int) { + return fileDescriptor_bf94fd919e302a1d, []int{0} +} +func (m *Record) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Record) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Record.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Record) XXX_Merge(src proto.Message) { + xxx_messageInfo_Record.Merge(m, src) +} +func (m *Record) XXX_Size() int { + return m.Size() +} +func (m *Record) XXX_DiscardUnknown() { + xxx_messageInfo_Record.DiscardUnknown(m) +} + +var xxx_messageInfo_Record proto.InternalMessageInfo +// Keep in sync with raftpb.SnapshotMetadata. type Snapshot struct { - Index uint64 `protobuf:"varint,1,opt,name=index" json:"index"` - Term uint64 `protobuf:"varint,2,opt,name=term" json:"term"` - XXX_unrecognized []byte `json:"-"` + Index uint64 `protobuf:"varint,1,opt,name=index" json:"index"` + Term uint64 `protobuf:"varint,2,opt,name=term" json:"term"` + // Field populated since >=etcd-3.5.0. + ConfState *raftpb.ConfState `protobuf:"bytes,3,opt,name=conf_state,json=confState" json:"conf_state,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } -func (m *Snapshot) Reset() { *m = Snapshot{} } -func (m *Snapshot) String() string { return proto.CompactTextString(m) } -func (*Snapshot) ProtoMessage() {} -func (*Snapshot) Descriptor() ([]byte, []int) { return fileDescriptorRecord, []int{1} } +func (m *Snapshot) Reset() { *m = Snapshot{} } +func (m *Snapshot) String() string { return proto.CompactTextString(m) } +func (*Snapshot) ProtoMessage() {} +func (*Snapshot) Descriptor() ([]byte, []int) { + return fileDescriptor_bf94fd919e302a1d, []int{1} +} +func (m *Snapshot) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Snapshot) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Snapshot.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Snapshot) XXX_Merge(src proto.Message) { + xxx_messageInfo_Snapshot.Merge(m, src) +} +func (m *Snapshot) XXX_Size() int { + return m.Size() +} +func (m *Snapshot) XXX_DiscardUnknown() { + xxx_messageInfo_Snapshot.DiscardUnknown(m) +} + +var xxx_messageInfo_Snapshot proto.InternalMessageInfo func init() { proto.RegisterType((*Record)(nil), "walpb.Record") proto.RegisterType((*Snapshot)(nil), "walpb.Snapshot") } + +func init() { proto.RegisterFile("record.proto", fileDescriptor_bf94fd919e302a1d) } + +var fileDescriptor_bf94fd919e302a1d = []byte{ + // 234 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x3c, 0x8e, 0x41, 0x4e, 0xc3, 0x30, + 0x10, 0x45, 0x63, 0xe2, 0x22, 0x18, 0xca, 0x02, 0xab, 0xaa, 0xa2, 0x2c, 0x4c, 0xd4, 0x55, 0x56, + 0x29, 0xe2, 0x08, 0x65, 0xcf, 0x22, 0x3d, 0x00, 0x72, 0x1d, 0xa7, 0x20, 0xd1, 0x8c, 0x35, 0xb5, + 0x04, 0xdc, 0x84, 0x23, 0x65, 0xc9, 0x09, 0x10, 0x84, 0x8b, 0xa0, 0x8c, 0x03, 0x1b, 0xfb, 0xeb, + 0x7d, 0xf9, 0x7d, 0xc3, 0x9c, 0x9c, 0x45, 0x6a, 0x2a, 0x4f, 0x18, 0x50, 0xcd, 0x5e, 0xcc, 0xb3, + 0xdf, 0xe5, 0x8b, 0x3d, 0xee, 0x91, 0xc9, 0x7a, 0x4c, 0xb1, 0xcc, 0x97, 0x64, 0xda, 0xb0, 0x1e, + 0x0f, 0xbf, 0xe3, 0x2b, 0xf2, 0xd5, 0x3d, 0x9c, 0xd6, 0x2c, 0x51, 0x19, 0xc8, 0xf0, 0xe6, 0x5d, + 0x26, 0x0a, 0x51, 0xa6, 0x1b, 0xd9, 0x7f, 0x5e, 0x27, 0x35, 0x13, 0xb5, 0x84, 0xd4, 0x92, 0xcd, + 0x4e, 0x0a, 0x51, 0x5e, 0x4e, 0xc5, 0x08, 0x94, 0x02, 0xd9, 0x98, 0x60, 0xb2, 0xb4, 0x10, 0xe5, + 0xbc, 0xe6, 0xbc, 0x22, 0x38, 0xdb, 0x76, 0xc6, 0x1f, 0x1f, 0x31, 0xa8, 0x1c, 0x66, 0x4f, 0x5d, + 0xe3, 0x5e, 0x59, 0x29, 0xa7, 0x97, 0x11, 0xf1, 0x9a, 0xa3, 0x03, 0x4b, 0xe5, 0xff, 0x9a, 0xa3, + 0x83, 0xba, 0x01, 0xb0, 0xd8, 0xb5, 0x0f, 0xc7, 0x60, 0x82, 0x63, 0xf7, 0xc5, 0xed, 0x55, 0x15, + 0x7f, 0x5e, 0xdd, 0x61, 0xd7, 0x6e, 0xc7, 0xa2, 0x3e, 0xb7, 0x7f, 0x71, 0xb3, 0xe8, 0xbf, 0x75, + 0xd2, 0x0f, 0x5a, 0x7c, 0x0c, 0x5a, 0x7c, 0x0d, 0x5a, 0xbc, 0xff, 0xe8, 0xe4, 0x37, 0x00, 0x00, + 0xff, 0xff, 0xc3, 0x36, 0x0c, 0xad, 0x1d, 0x01, 0x00, 0x00, +} + func (m *Record) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -76,32 +148,39 @@ func (m *Record) Marshal() (dAtA []byte, err error) { } func (m *Record) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Record) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRecord(dAtA, i, uint64(m.Type)) - dAtA[i] = 0x10 - i++ - i = encodeVarintRecord(dAtA, i, uint64(m.Crc)) + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) + } if m.Data != nil { - dAtA[i] = 0x1a - i++ + i -= len(m.Data) + copy(dAtA[i:], m.Data) i = encodeVarintRecord(dAtA, i, uint64(len(m.Data))) - i += copy(dAtA[i:], m.Data) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) + i-- + dAtA[i] = 0x1a } - return i, nil + i = encodeVarintRecord(dAtA, i, uint64(m.Crc)) + i-- + dAtA[i] = 0x10 + i = encodeVarintRecord(dAtA, i, uint64(m.Type)) + i-- + dAtA[i] = 0x8 + return len(dAtA) - i, nil } func (m *Snapshot) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) if err != nil { return nil, err } @@ -109,32 +188,55 @@ func (m *Snapshot) Marshal() (dAtA []byte, err error) { } func (m *Snapshot) MarshalTo(dAtA []byte) (int, error) { - var i int + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Snapshot) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) _ = i var l int _ = l - dAtA[i] = 0x8 - i++ - i = encodeVarintRecord(dAtA, i, uint64(m.Index)) - dAtA[i] = 0x10 - i++ - i = encodeVarintRecord(dAtA, i, uint64(m.Term)) if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) + } + if m.ConfState != nil { + { + size, err := m.ConfState.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintRecord(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a } - return i, nil + i = encodeVarintRecord(dAtA, i, uint64(m.Term)) + i-- + dAtA[i] = 0x10 + i = encodeVarintRecord(dAtA, i, uint64(m.Index)) + i-- + dAtA[i] = 0x8 + return len(dAtA) - i, nil } func encodeVarintRecord(dAtA []byte, offset int, v uint64) int { + offset -= sovRecord(v) + base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) v >>= 7 offset++ } dAtA[offset] = uint8(v) - return offset + 1 + return base } func (m *Record) Size() (n int) { + if m == nil { + return 0 + } var l int _ = l n += 1 + sovRecord(uint64(m.Type)) @@ -150,10 +252,17 @@ func (m *Record) Size() (n int) { } func (m *Snapshot) Size() (n int) { + if m == nil { + return 0 + } var l int _ = l n += 1 + sovRecord(uint64(m.Index)) n += 1 + sovRecord(uint64(m.Term)) + if m.ConfState != nil { + l = m.ConfState.Size() + n += 1 + l + sovRecord(uint64(l)) + } if m.XXX_unrecognized != nil { n += len(m.XXX_unrecognized) } @@ -161,14 +270,7 @@ func (m *Snapshot) Size() (n int) { } func sovRecord(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n + return (math_bits.Len64(x|1) + 6) / 7 } func sozRecord(x uint64) (n int) { return sovRecord(uint64((x << 1) ^ uint64((int64(x) >> 63)))) @@ -188,7 +290,7 @@ func (m *Record) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - wire |= (uint64(b) & 0x7F) << shift + wire |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -216,7 +318,7 @@ func (m *Record) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Type |= (int64(b) & 0x7F) << shift + m.Type |= int64(b&0x7F) << shift if b < 0x80 { break } @@ -235,7 +337,7 @@ func (m *Record) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Crc |= (uint32(b) & 0x7F) << shift + m.Crc |= uint32(b&0x7F) << shift if b < 0x80 { break } @@ -254,7 +356,7 @@ func (m *Record) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= (int(b) & 0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } @@ -263,6 +365,9 @@ func (m *Record) Unmarshal(dAtA []byte) error { return ErrInvalidLengthRecord } postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthRecord + } if postIndex > l { return io.ErrUnexpectedEOF } @@ -277,7 +382,7 @@ func (m *Record) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthRecord } if (iNdEx + skippy) > l { @@ -308,7 +413,7 @@ func (m *Snapshot) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - wire |= (uint64(b) & 0x7F) << shift + wire |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -336,7 +441,7 @@ func (m *Snapshot) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Index |= (uint64(b) & 0x7F) << shift + m.Index |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -355,18 +460,54 @@ func (m *Snapshot) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Term |= (uint64(b) & 0x7F) << shift + m.Term |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConfState", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRecord + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } + if msglen < 0 { + return ErrInvalidLengthRecord + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthRecord + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.ConfState == nil { + m.ConfState = &raftpb.ConfState{} + } + if err := m.ConfState.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipRecord(dAtA[iNdEx:]) if err != nil { return err } - if skippy < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthRecord } if (iNdEx + skippy) > l { @@ -385,6 +526,7 @@ func (m *Snapshot) Unmarshal(dAtA []byte) error { func skipRecord(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 + depth := 0 for iNdEx < l { var wire uint64 for shift := uint(0); ; shift += 7 { @@ -416,10 +558,8 @@ func skipRecord(dAtA []byte) (n int, err error) { break } } - return iNdEx, nil case 1: iNdEx += 8 - return iNdEx, nil case 2: var length int for shift := uint(0); ; shift += 7 { @@ -436,71 +576,34 @@ func skipRecord(dAtA []byte) (n int, err error) { break } } - iNdEx += length if length < 0 { return 0, ErrInvalidLengthRecord } - return iNdEx, nil + iNdEx += length case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRecord - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipRecord(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil + depth++ case 4: - return iNdEx, nil + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupRecord + } + depth-- case 5: iNdEx += 4 - return iNdEx, nil default: return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } + if iNdEx < 0 { + return 0, ErrInvalidLengthRecord + } + if depth == 0 { + return iNdEx, nil + } } - panic("unreachable") + return 0, io.ErrUnexpectedEOF } var ( - ErrInvalidLengthRecord = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowRecord = fmt.Errorf("proto: integer overflow") + ErrInvalidLengthRecord = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowRecord = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupRecord = fmt.Errorf("proto: unexpected end of group") ) - -func init() { proto.RegisterFile("record.proto", fileDescriptorRecord) } - -var fileDescriptorRecord = []byte{ - // 186 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x29, 0x4a, 0x4d, 0xce, - 0x2f, 0x4a, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x2d, 0x4f, 0xcc, 0x29, 0x48, 0x92, - 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x8b, 0xe8, 0x83, 0x58, 0x10, 0x49, 0x25, 0x3f, 0x2e, 0xb6, - 0x20, 0xb0, 0x62, 0x21, 0x09, 0x2e, 0x96, 0x92, 0xca, 0x82, 0x54, 0x09, 0x46, 0x05, 0x46, 0x0d, - 0x66, 0x27, 0x96, 0x13, 0xf7, 0xe4, 0x19, 0x82, 0xc0, 0x22, 0x42, 0x62, 0x5c, 0xcc, 0xc9, 0x45, - 0xc9, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0xbc, 0x50, 0x09, 0x90, 0x80, 0x90, 0x10, 0x17, 0x4b, 0x4a, - 0x62, 0x49, 0xa2, 0x04, 0xb3, 0x02, 0xa3, 0x06, 0x4f, 0x10, 0x98, 0xad, 0xe4, 0xc0, 0xc5, 0x11, - 0x9c, 0x97, 0x58, 0x50, 0x9c, 0x91, 0x5f, 0x22, 0x24, 0xc5, 0xc5, 0x9a, 0x99, 0x97, 0x92, 0x5a, - 0x01, 0x36, 0x92, 0x05, 0xaa, 0x13, 0x22, 0x04, 0xb6, 0x2d, 0xb5, 0x28, 0x17, 0x6c, 0x28, 0x0b, - 0xdc, 0xb6, 0xd4, 0xa2, 0x5c, 0x27, 0x91, 0x13, 0x0f, 0xe5, 0x18, 0x4e, 0x3c, 0x92, 0x63, 0xbc, - 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x19, 0x8f, 0xe5, 0x18, 0x00, 0x01, 0x00, 0x00, - 0xff, 0xff, 0x7f, 0x5e, 0x5c, 0x46, 0xd3, 0x00, 0x00, 0x00, -} diff --git a/vendor/go.etcd.io/etcd/wal/walpb/record.proto b/vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.proto similarity index 76% rename from vendor/go.etcd.io/etcd/wal/walpb/record.proto rename to vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.proto index b694cb233..536fa6c19 100644 --- a/vendor/go.etcd.io/etcd/wal/walpb/record.proto +++ b/vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.proto @@ -2,6 +2,7 @@ syntax = "proto2"; package walpb; import "gogoproto/gogo.proto"; +import "raft/raftpb/raft.proto"; option (gogoproto.marshaler_all) = true; option (gogoproto.sizer_all) = true; @@ -14,7 +15,10 @@ message Record { optional bytes data = 3; } +// Keep in sync with raftpb.SnapshotMetadata. message Snapshot { optional uint64 index = 1 [(gogoproto.nullable) = false]; optional uint64 term = 2 [(gogoproto.nullable) = false]; + // Field populated since >=etcd-3.5.0. + optional raftpb.ConfState conf_state = 3; } diff --git a/vendor/modules.txt b/vendor/modules.txt index 8d86cbf7d..69abae150 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -84,15 +84,9 @@ github.com/cockroachdb/redact/internal/rfmt/fmtsort # github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 ## explicit; go 1.19 github.com/cockroachdb/tokenbucket -# github.com/coreos/go-semver v0.2.0 +# github.com/coreos/go-semver v0.3.0 ## explicit github.com/coreos/go-semver/semver -# github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7 -## explicit -github.com/coreos/go-systemd/journal -# github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf -## explicit -github.com/coreos/pkg/capnslog # github.com/cpuguy83/go-md2man/v2 v2.0.2 ## explicit; go 1.11 github.com/cpuguy83/go-md2man/v2/md2man @@ -332,30 +326,36 @@ github.com/xrash/smetrics # github.com/yusufpapurcu/wmi v1.2.3 ## explicit; go 1.16 github.com/yusufpapurcu/wmi -# go.etcd.io/etcd v0.5.0-alpha.5.0.20230414071934-94593e63d45c -## explicit; go 1.19 -go.etcd.io/etcd/etcdserver/api/rafthttp -go.etcd.io/etcd/etcdserver/api/snap -go.etcd.io/etcd/etcdserver/api/snap/snappb -go.etcd.io/etcd/etcdserver/api/v2stats -go.etcd.io/etcd/pkg/crc -go.etcd.io/etcd/pkg/fileutil -go.etcd.io/etcd/pkg/httputil -go.etcd.io/etcd/pkg/ioutil -go.etcd.io/etcd/pkg/logutil -go.etcd.io/etcd/pkg/pbutil -go.etcd.io/etcd/pkg/systemd -go.etcd.io/etcd/pkg/tlsutil -go.etcd.io/etcd/pkg/transport -go.etcd.io/etcd/pkg/types -go.etcd.io/etcd/raft -go.etcd.io/etcd/raft/confchange -go.etcd.io/etcd/raft/quorum -go.etcd.io/etcd/raft/raftpb -go.etcd.io/etcd/raft/tracker -go.etcd.io/etcd/version -go.etcd.io/etcd/wal -go.etcd.io/etcd/wal/walpb +# go.etcd.io/etcd/api/v3 v3.5.12 +## explicit; go 1.20 +go.etcd.io/etcd/api/v3/version +# go.etcd.io/etcd/client/pkg/v3 v3.5.12 +## explicit; go 1.20 +go.etcd.io/etcd/client/pkg/v3/fileutil +go.etcd.io/etcd/client/pkg/v3/tlsutil +go.etcd.io/etcd/client/pkg/v3/transport +go.etcd.io/etcd/client/pkg/v3/types +# go.etcd.io/etcd/pkg/v3 v3.5.12 +## explicit; go 1.20 +go.etcd.io/etcd/pkg/v3/crc +go.etcd.io/etcd/pkg/v3/httputil +go.etcd.io/etcd/pkg/v3/ioutil +go.etcd.io/etcd/pkg/v3/pbutil +# go.etcd.io/etcd/raft/v3 v3.5.12 +## explicit; go 1.20 +go.etcd.io/etcd/raft/v3 +go.etcd.io/etcd/raft/v3/confchange +go.etcd.io/etcd/raft/v3/quorum +go.etcd.io/etcd/raft/v3/raftpb +go.etcd.io/etcd/raft/v3/tracker +# go.etcd.io/etcd/server/v3 v3.5.12 +## explicit; go 1.20 +go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp +go.etcd.io/etcd/server/v3/etcdserver/api/snap +go.etcd.io/etcd/server/v3/etcdserver/api/snap/snappb +go.etcd.io/etcd/server/v3/etcdserver/api/v2stats +go.etcd.io/etcd/server/v3/wal +go.etcd.io/etcd/server/v3/wal/walpb # go.opentelemetry.io/contrib/instrumentation/host v0.49.0 ## explicit; go 1.20 go.opentelemetry.io/contrib/instrumentation/host