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

fix: Prevent proposal from being dropped accidentally #7741

Merged
merged 4 commits into from
Apr 26, 2021
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
1 change: 1 addition & 0 deletions worker/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,7 @@ func (n *node) retryUntilSuccess(fn func() error, pause time.Duration) {

// InitAndStartNode gets called after having at least one membership sync with the cluster.
func (n *node) InitAndStartNode() {
initProposalKey(n.Id)
_, restart, err := n.PastLife()
x.Check(err)

Expand Down
12 changes: 11 additions & 1 deletion worker/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/dgraph-io/dgraph/protos/pb"
"github.com/dgraph-io/dgraph/schema"
"github.com/dgraph-io/dgraph/x"
"github.com/dgraph-io/ristretto/z"

ostats "go.opencensus.io/stats"
"go.opencensus.io/tag"
Expand Down Expand Up @@ -108,9 +109,18 @@ func (rl *rateLimiter) decr(retry int) {
rl.c.Broadcast()
}

var proposalKey uint64

// {2 bytes Node ID} {4 bytes for random} {2 bytes zero}
func initProposalKey(id uint64) {
x.AssertTrue(id != 0)
proposalKey = uint64(groups().Node.Id)<<48 | uint64(z.FastRand())<<16
}

// uniqueKey is meant to be unique across all the replicas.
// initProposalKey should be called before calling uniqueKey.
func uniqueKey() uint64 {
return uint64(groups().Node.Id)<<32 | uint64(groups().Node.Rand.Uint32())
return atomic.AddUint64(&proposalKey, 1)
}

var errInternalRetry = errors.New("Retry Raft proposal internally")
Expand Down