-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
raft: refactor inflight #4931
Closed
Closed
raft: refactor inflight #4931
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,12 +64,17 @@ type Progress struct { | |
RecentActive bool | ||
|
||
// inflights is a sliding window for the inflight messages. | ||
// Each inflight message might contain more than one entries | ||
// and has a size limit defined in raft config as MaxSizePerMsg. | ||
// Thus inflight effectively limits both the number of inflight messages | ||
// and the bandwidth each Progress can use. | ||
// When inflights is full, no more message should be sent. | ||
// When a leader sends out a message, the index of the last | ||
// entry should be added to inflights. The index MUST be added | ||
// into inflights in order. | ||
// When a leader receives a reply, the previous inflights should | ||
// be freed by calling inflights.freeTo. | ||
// be freed by calling inflights.freeTo with the index of the last | ||
// received entry. | ||
ins *inflights | ||
} | ||
|
||
|
@@ -183,14 +188,13 @@ type inflights struct { | |
// number of inflights in the buffer | ||
count int | ||
|
||
// the size of the buffer | ||
size int | ||
// buffer contains the index of the last entry | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be better to word
|
||
// inside one message. | ||
buffer []uint64 | ||
} | ||
|
||
func newInflights(size int) *inflights { | ||
return &inflights{ | ||
size: size, | ||
buffer: make([]uint64, size), | ||
} | ||
} | ||
|
@@ -201,8 +205,9 @@ func (in *inflights) add(inflight uint64) { | |
panic("cannot add into a full inflights") | ||
} | ||
next := in.start + in.count | ||
if next >= in.size { | ||
next -= in.size | ||
size := in.size() | ||
if next >= size { | ||
next -= size | ||
} | ||
in.buffer[next] = inflight | ||
in.count++ | ||
|
@@ -220,10 +225,10 @@ func (in *inflights) freeTo(to uint64) { | |
if to < in.buffer[idx] { // found the first large inflight | ||
break | ||
} | ||
|
||
size := in.size() | ||
// increase index and maybe rotate | ||
if idx++; idx >= in.size { | ||
idx -= in.size | ||
if idx++; idx >= size { | ||
idx -= size | ||
} | ||
} | ||
// free i inflights and set new start index | ||
|
@@ -235,7 +240,11 @@ func (in *inflights) freeFirstOne() { in.freeTo(in.buffer[in.start]) } | |
|
||
// full returns true if the inflights is full. | ||
func (in *inflights) full() bool { | ||
return in.count == in.size | ||
return in.count == len(in.buffer) | ||
} | ||
|
||
func (in *inflights) size() int { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might as well inline this. |
||
return len(in.buffer) | ||
} | ||
|
||
// resets frees all inflights. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A size limit in number of bytes or number of entries? I'm again confused about the purpose of this whole thing. Are the number of bytes tracked anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry... So a message contains one or multiple raft entries. Each message has a max size.
Say leader sends 8 entries with 1MB per entries. For each message, the max size is 4MB. With flow control, two messages with entries [1,2,3,4] and [5,6,7,8] will be sent. We will have [4, 8] in inflights.
Once follower replies with index 8, then we clear 4 and 8 from inflights together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am considering to just make this a direct bytes based control. But it requires some changes from the upper level rafthttp, which now has a message based buffer (N number of messages).