Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore: upgrade etcd/raft to v3 #7688

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions conn/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (

"github.com/golang/glog"
"github.com/pkg/errors"
"go.etcd.io/etcd/raft"
"go.etcd.io/etcd/raft/raftpb"
"go.etcd.io/etcd/raft/v3"
"go.etcd.io/etcd/raft/v3/raftpb"
otrace "go.opencensus.io/trace"

"github.com/dgraph-io/badger/v4/y"
Expand Down
4 changes: 2 additions & 2 deletions conn/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"time"

"github.com/stretchr/testify/require"
"go.etcd.io/etcd/raft"
"go.etcd.io/etcd/raft/raftpb"
"go.etcd.io/etcd/raft/v3"
"go.etcd.io/etcd/raft/v3/raftpb"

"github.com/dgraph-io/dgraph/protos/pb"
"github.com/dgraph-io/dgraph/raftwal"
Expand Down
4 changes: 2 additions & 2 deletions conn/raft_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

"github.com/golang/glog"
"github.com/pkg/errors"
"go.etcd.io/etcd/raft/raftpb"
"go.etcd.io/etcd/raft/v3/raftpb"
otrace "go.opencensus.io/trace"

"github.com/dgraph-io/dgo/v230/protos/api"
Expand Down Expand Up @@ -163,7 +163,7 @@ func (w *RaftServer) IsPeer(ctx context.Context, rc *pb.RaftContext) (
return &pb.PeerResponse{}, nil
}

for _, raftIdx := range confState.Nodes {
for _, raftIdx := range confState.Voters {
if rc.Id == raftIdx {
return &pb.PeerResponse{Status: true}, nil
}
Expand Down
4 changes: 2 additions & 2 deletions dgraph/cmd/debug/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"strings"

humanize "github.com/dustin/go-humanize"
"go.etcd.io/etcd/raft"
"go.etcd.io/etcd/raft/raftpb"
"go.etcd.io/etcd/raft/v3"
"go.etcd.io/etcd/raft/v3/raftpb"

"github.com/dgraph-io/dgraph/protos/pb"
"github.com/dgraph-io/dgraph/raftwal"
Expand Down
11 changes: 7 additions & 4 deletions dgraph/cmd/zero/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import (
"github.com/golang/glog"
"github.com/google/uuid"
"github.com/pkg/errors"
"go.etcd.io/etcd/raft"
"go.etcd.io/etcd/raft/raftpb"
"go.etcd.io/etcd/raft/v3"
"go.etcd.io/etcd/raft/v3/raftpb"
ostats "go.opencensus.io/stats"
"go.opencensus.io/tag"
otrace "go.opencensus.io/trace"
Expand Down Expand Up @@ -656,7 +656,7 @@ func (n *node) initAndStartNode() error {
var zs pb.ZeroSnapshot
x.Check(zs.Unmarshal(sp.Data))
n.server.SetMembershipState(zs.State)
for _, id := range sp.Metadata.ConfState.Nodes {
for _, id := range sp.Metadata.ConfState.Voters {
n.Connect(id, zs.State.Zeros[id].Addr)
}
}
Expand Down Expand Up @@ -700,7 +700,10 @@ func (n *node) initAndStartNode() error {
cancel()
}
glog.Infof("[%#x] Starting node\n", n.Id)
n.SetRaft(raft.StartNode(n.Cfg, nil))
// We call RestartNode here because nodes already exists in the cluster and
// we setup the state by calling c.JoinCluster above. We can't call StartNode
// here because we only have peer's IP addresses.
n.SetRaft(raft.RestartNode(n.Cfg))

default:
glog.Infof("Starting a brand new node")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ require (
github.com/stretchr/testify v1.8.4
github.com/twpayne/go-geom v1.0.5
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c
go.etcd.io/etcd v0.5.0-alpha.5.0.20190108173120-83c051b701d3
go.etcd.io/etcd/raft/v3 v3.5.9
go.opencensus.io v0.22.5
go.uber.org/zap v1.16.0
golang.org/x/crypto v0.9.0
Expand Down
40 changes: 4 additions & 36 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion raftwal/encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"go.etcd.io/etcd/raft/raftpb"
"go.etcd.io/etcd/raft/v3/raftpb"
)

func TestEntryReadWrite(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion raftwal/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

"github.com/golang/glog"
"github.com/pkg/errors"
"go.etcd.io/etcd/raft/raftpb"
"go.etcd.io/etcd/raft/v3/raftpb"

"github.com/dgraph-io/badger/v4"
"github.com/dgraph-io/badger/v4/pb"
Expand Down
4 changes: 2 additions & 2 deletions raftwal/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (

"github.com/golang/glog"
"github.com/pkg/errors"
"go.etcd.io/etcd/raft"
"go.etcd.io/etcd/raft/raftpb"
"go.etcd.io/etcd/raft/v3"
"go.etcd.io/etcd/raft/v3/raftpb"

"github.com/dgraph-io/dgraph/x"
"github.com/dgraph-io/ristretto/z"
Expand Down
4 changes: 2 additions & 2 deletions raftwal/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (

"github.com/golang/glog"
"github.com/pkg/errors"
"go.etcd.io/etcd/raft"
"go.etcd.io/etcd/raft/raftpb"
"go.etcd.io/etcd/raft/v3"
"go.etcd.io/etcd/raft/v3/raftpb"
"golang.org/x/net/trace"

"github.com/dgraph-io/dgraph/x"
Expand Down
6 changes: 3 additions & 3 deletions raftwal/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import (
"testing"

"github.com/stretchr/testify/require"
"go.etcd.io/etcd/raft"
"go.etcd.io/etcd/raft/raftpb"
"go.etcd.io/etcd/raft/v3"
"go.etcd.io/etcd/raft/v3/raftpb"

"github.com/dgraph-io/dgraph/x"
)
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestStorageCreateSnapshot(t *testing.T) {
ds := Init(dir)

ents := []raftpb.Entry{{Index: 3, Term: 3}, {Index: 4, Term: 4}, {Index: 5, Term: 5}}
cs := &raftpb.ConfState{Nodes: []uint64{1, 2, 3}}
cs := &raftpb.ConfState{Voters: []uint64{1, 2, 3}}
data := []byte("data")

tests := []struct {
Expand Down
4 changes: 2 additions & 2 deletions raftwal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (

"github.com/golang/glog"
"github.com/pkg/errors"
"go.etcd.io/etcd/raft"
"go.etcd.io/etcd/raft/raftpb"
"go.etcd.io/etcd/raft/v3"
"go.etcd.io/etcd/raft/v3/raftpb"

"github.com/dgraph-io/badger/v4/y"
"github.com/dgraph-io/dgraph/x"
Expand Down
2 changes: 1 addition & 1 deletion worker/cdc_ee.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

"github.com/golang/glog"
"github.com/pkg/errors"
"go.etcd.io/etcd/raft/raftpb"
"go.etcd.io/etcd/raft/v3/raftpb"

"github.com/dgraph-io/dgraph/posting"
"github.com/dgraph-io/dgraph/protos/pb"
Expand Down
14 changes: 10 additions & 4 deletions worker/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import (
"github.com/dustin/go-humanize"
"github.com/golang/glog"
"github.com/pkg/errors"
"go.etcd.io/etcd/raft"
"go.etcd.io/etcd/raft/raftpb"
"go.etcd.io/etcd/raft/v3"
"go.etcd.io/etcd/raft/v3/raftpb"
ostats "go.opencensus.io/stats"
"go.opencensus.io/tag"
otrace "go.opencensus.io/trace"
Expand Down Expand Up @@ -1221,6 +1221,9 @@ func (n *node) Run() {
n.Raft().Tick()

case rd := <-n.Raft().Ready():
// TODO(Aman): Based on the code here https://github.com/etcd-io/etcd/tree/raft/v3.5.9/raft,
// n.SaveToStorage should be called first before doing anything else.

timer.Start()
_, span := otrace.StartSpan(n.ctx, "Alpha.RunLoop",
otrace.WithSampler(otrace.ProbabilitySampler(0.001)))
Expand Down Expand Up @@ -1813,7 +1816,7 @@ func (n *node) InitAndStartNode() {

// TODO: Making connections here seems unnecessary, evaluate.
members := groups().members(n.gid)
for _, id := range sp.Metadata.ConfState.Nodes {
for _, id := range sp.Metadata.ConfState.Voters {
mangalaman93 marked this conversation as resolved.
Show resolved Hide resolved
m, ok := members[id]
if ok {
n.Connect(id, m.Addr)
Expand All @@ -1839,7 +1842,10 @@ func (n *node) InitAndStartNode() {
// snapshot as needed after joining the group, instead of us forcing one upfront.
glog.Infoln("Trying to join peers.")
n.retryUntilSuccess(n.joinPeers, time.Second)
n.SetRaft(raft.StartNode(n.Cfg, nil))
// We call RestartNode here because nodes already exists in the cluster and
// we setup the state by calling c.JoinCluster above. We can't call StartNode
// here because we only have peer's IP addresses.
n.SetRaft(raft.RestartNode(n.Cfg))
mangalaman93 marked this conversation as resolved.
Show resolved Hide resolved
} else {
peers := []raft.Peer{{ID: n.Id}}
n.SetRaft(raft.StartNode(n.Cfg, peers))
Expand Down
2 changes: 1 addition & 1 deletion worker/draft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"go.etcd.io/etcd/raft/raftpb"
"go.etcd.io/etcd/raft/v3/raftpb"

"github.com/dgraph-io/dgraph/posting"
"github.com/dgraph-io/dgraph/protos/pb"
Expand Down
2 changes: 1 addition & 1 deletion worker/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/dustin/go-humanize"
"github.com/golang/glog"
"github.com/pkg/errors"
"go.etcd.io/etcd/raft"
"go.etcd.io/etcd/raft/v3"

"github.com/dgraph-io/badger/v4"
"github.com/dgraph-io/dgraph/conn"
Expand Down