-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
Add RowStreamStateMachine #176
Add RowStreamStateMachine #176
Conversation
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.
LGTM , one style nit I didn't even handle correctly anyway 😅
case .waitingForRows(var buffer): | ||
self.state = .modifying | ||
buffer.append(newRow) | ||
self.state = .waitingForRows(buffer) | ||
|
||
// For all the following cases, please note: | ||
// Normally these code paths should never be hit. However there is one way to trigger | ||
// this: | ||
// | ||
// If the server decides to close a connection, NIO will forward all outstanding | ||
// `channelRead`s without waiting for a next `context.read` call. For this reason we might | ||
// receive new rows, when we don't expect them here. | ||
case .waitingForRead(var buffer): | ||
self.state = .modifying | ||
buffer.append(newRow) | ||
self.state = .waitingForRows(buffer) | ||
|
||
case .waitingForDemand(var buffer): | ||
self.state = .modifying | ||
buffer.append(newRow) | ||
self.state = .waitingForRows(buffer) | ||
|
||
case .waitingForReadOrDemand(var buffer): | ||
self.state = .modifying | ||
buffer.append(newRow) | ||
self.state = .waitingForRows(buffer) |
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.
Feel free to "tweak" my "code style" (generous to call it that, I agree) as you find apropos, I mostly just care about the code de-duplication.
case .waitingForRows(var buffer): | |
self.state = .modifying | |
buffer.append(newRow) | |
self.state = .waitingForRows(buffer) | |
// For all the following cases, please note: | |
// Normally these code paths should never be hit. However there is one way to trigger | |
// this: | |
// | |
// If the server decides to close a connection, NIO will forward all outstanding | |
// `channelRead`s without waiting for a next `context.read` call. For this reason we might | |
// receive new rows, when we don't expect them here. | |
case .waitingForRead(var buffer): | |
self.state = .modifying | |
buffer.append(newRow) | |
self.state = .waitingForRows(buffer) | |
case .waitingForDemand(var buffer): | |
self.state = .modifying | |
buffer.append(newRow) | |
self.state = .waitingForRows(buffer) | |
case .waitingForReadOrDemand(var buffer): | |
self.state = .modifying | |
buffer.append(newRow) | |
self.state = .waitingForRows(buffer) | |
case .waitingForRows(var buffer), | |
// For all the following cases, please note: | |
// Normally these code paths should never be hit. However there is one way to trigger | |
// this: | |
// | |
// If the server decides to close a connection, NIO will forward all outstanding | |
// `channelRead`s without waiting for a next `context.read` call. For this reason we might | |
// receive new rows, when we don't expect them here. | |
.waitingForRead(var buffer), | |
.waitingForDemand(var buffer), | |
.waitingForReadOrDemand(var buffer): | |
self.state = .modifying | |
buffer.append(newRow) | |
self.state = .waitingForRows(buffer |
} | ||
|
||
mutating func end() -> CircularBuffer<PSQLBackendMessage.DataRow> { | ||
switch self.state { |
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.
Yeah, like this! This is better than my suggestion above, do it this way there too!
0260b86
to
748ee70
Compare
Motivation
To best support back-pressure, we extract the necessary state machine into a dedicated substate machine.
Changes
Note
This pr does not include any tests and the new code will not be hit. We will add tests to the
ExtendedQueryStateMachine
that test the new functionality once we wire the new substate machine up.