ConnectionPool should support draining connections#638
ConnectionPool should support draining connections#638fabianfett merged 4 commits intovapor:mainfrom
Conversation
Fix weird states Test crash fix.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #638 +/- ##
==========================================
+ Coverage 76.39% 76.56% +0.17%
==========================================
Files 135 135
Lines 10239 10383 +144
==========================================
+ Hits 7822 7950 +128
- Misses 2417 2433 +16
🚀 New features to boost your workflow:
|
gwynne
left a comment
There was a problem hiding this comment.
Couple of minor remarks, nothing blocking.
|
|
||
| @inlinable | ||
| mutating func connectionWillClose(_ connectionID: Connection.ID) -> ConnectionWillCloseAction { | ||
| guard let index = self.connections.firstIndex(where: { $0.id == connectionID }) else { |
There was a problem hiding this comment.
General question: Why is self.connections an Array rather than a Dictionary or OrderedDictionary? I would assume it has something to do with speed on hotter paths than this particular line of code; I just cringe when I see "oh look, O(n) iteration of an ordered collection looking for an easily-hashed identifier".
There was a problem hiding this comment.
yeah, actually O(n) is smaller than calculating O(1) hashes :)
| let newUsedStreams = usedStreams - returnedStreams | ||
| if newUsedStreams == 0 { | ||
| self.state = .closing(connection) | ||
| return .drainingComplete(connection) | ||
| } else { | ||
| self.state = .draining(connection, usedStreams: newUsedStreams) |
There was a problem hiding this comment.
| let newUsedStreams = usedStreams - returnedStreams | |
| if newUsedStreams == 0 { | |
| self.state = .closing(connection) | |
| return .drainingComplete(connection) | |
| } else { | |
| self.state = .draining(connection, usedStreams: newUsedStreams) | |
| if usedStreams == returnedStreams { | |
| self.state = .closing(connection) | |
| return .drainingComplete(connection) | |
| } else { | |
| self.state = .draining(connection, usedStreams: usedStreams - returnedStreams) |
No description provided.