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

ISSUE-62: provide an interface to get raft members' offsets #63

Merged
merged 2 commits into from
Mar 25, 2022

Conversation

crystal-xu
Copy link
Collaborator

No description provided.

@jackyjia
Copy link
Contributor

jackyjia commented Feb 3, 2022

  • every commit must be signed
  • prefix each commit message with issue number
  • link this PR to the issue
  • give this PR an owner
  • mark this PR with proper labels (e.g., wip, ready for review)

@crystal-xu
Copy link
Collaborator Author

  • every commit must be signed
  • prefix each commit message with issue number
  • link this PR to the issue
  • give this PR an owner
  • mark this PR with proper labels (e.g., wip, ready for review)

Hi jj, it seems that I don't have the permission to assign assignees or request reviewers, would you please help?

mInSyncFollowers->push_back(peerLag);
}
std::sort(mInSyncFollowers->begin(), mInSyncFollowers->end(),
[](MemberOffsetInfo x, MemberOffsetInfo y) { return x.mId > y.mId; });
Copy link
Contributor

Choose a reason for hiding this comment

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

const &

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't sort at infra level

@@ -103,6 +112,7 @@ class RaftInterface {
virtual uint64_t getLastLogIndex() const = 0;
virtual std::optional<uint64_t> getLeaderHint() const = 0;
virtual std::vector<MemberInfo> getClusterMembers() const = 0;
virtual void getInSyncFollowers(const int64_t &, std::vector<MemberOffsetInfo> *) const = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

return leader offset and followers' offset

mInSyncFollowers->push_back(peerLag);
}
std::sort(mInSyncFollowers->begin(), mInSyncFollowers->end(),
[](MemberOffsetInfo x, MemberOffsetInfo y) { return x.mId > y.mId; });
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't sort at infra level

@crystal-xu crystal-xu force-pushed the issue/62 branch 2 times, most recently from cafe548 to 7a47e82 Compare March 24, 2022 13:34
@crystal-xu crystal-xu changed the title ISSUE-62: provide an interface to get in-sync followers ISSUE-62: provide an interface to get raft members' offsets Mar 24, 2022
mMemberOffsets->push_back(peerOffset);
}
/// put leader offset info at the back
mMemberOffsets->push_back({mSelfInfo.mId, mSelfInfo.mAddress, mMajorityIndex, true});
Copy link
Contributor

Choose a reason for hiding this comment

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

emplace_back

peerOffset.mAddress = peer.mAddress;
peerOffset.mOffset = peer.mMatchIndex;
peerOffset.mIsLeader = false;
mMemberOffsets->push_back(peerOffset);
Copy link
Contributor

Choose a reason for hiding this comment

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

emplace_back

@@ -297,6 +299,7 @@ class RaftCore : public RaftInterface {
uint64_t mBeginIndex = 1;

RaftRole mRaftRole = RaftRole::Follower;
std::atomic<uint64_t> mMajorityIndex = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

just use commited index

@crystal-xu
Copy link
Collaborator Author

Using commit index instead of majority index as leader offset is due to one edge case for getting in-sync replica (ISR).
Say we have a 5-member raft cluster, and use (majority index - match index) as each peer's lag for detecting slow followers. If two followers are in-sync for some time, and the other two are slow. Once the two in-sync followers crash, the majority index will be much smaller. In that case, the two slower followers will start serve read requests before they catch up with the leader.

huyumars
huyumars previously approved these changes Mar 25, 2022
@huyumars huyumars merged commit 8d15fe0 into eBay:master Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants