-
Notifications
You must be signed in to change notification settings - Fork 227
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
Keep the list of free channels in sorted order #2151
Conversation
The operation of the list can be observed for testing by temporarily uncommenting the two calls to |
src/server.cpp
Outdated
{ | ||
int j = i++; | ||
vecChannelOrder[j] = vecChannelOrder[i]; | ||
} | ||
// put deleted channel at the end ready for re-use | ||
// put deleted channel in the correct position ready for re-use |
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.
This all now seems very cumbersome. If it's going to sit somewhere in vecChannelOrder
, why not just leave it where it was?
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.
Because the binary search relies on all the active channels being listed before all the free ones. All we are changing is how many IDs we shunt down the list when freeing, so that the freed ID is placed in order instead of just at the start of the free list. Doesn't seem cumbersome to me at all :)
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.
So you're saying it was (allocated | free):
1 2 3 4 5 ||
1 3 4 5 | 2 ||
1 3 4 | 5 2 ||
3 4 | 1 5 2 ||
and now it's
1 2 3 4 5 ||
1 3 4 5 | 2 ||
1 3 4 | 2 5 ||
3 4 | 1 2 5 ||
? I think the comment doesn't explain anything.
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.
Yes, exactly that. I'll change the comment to say "put deleted channel in the vacated position ready for re-use"
f632499
to
ff62760
Compare
ff62760
to
7bc861b
Compare
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.
Looks ok.
Short description of changes
Maintain the list of free channel IDs in sorted order, so that the lowest available channel ID will be used for a new client.
The fix has two parts, the first of which is not really necessary, but makes the output of
DumpChannels()
nicer:Context: Fixes an issue?
Fixes #2144
Does this change need documentation? What needs to be documented and how?
No documentation - internal enhancement only.
Status of this Pull Request
Tested and ready to merge.
What is missing until this pull request can be merged?
Nothing
Checklist