-
-
Notifications
You must be signed in to change notification settings - Fork 90
State machine #135
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
State machine #135
Conversation
82a37e9 to
40625a3
Compare
1236d8f to
9b8e347
Compare
b44ab64 to
9afae59
Compare
9afae59 to
da88bf6
Compare
Sources/PostgresNIO/Connection/PostgresConnection+Database.swift
Outdated
Show resolved
Hide resolved
Sources/PostgresNIO/Connection/PostgresConnection+Database.swift
Outdated
Show resolved
Hide resolved
Sources/PostgresNIO/Connection/PostgresConnection+Database.swift
Outdated
Show resolved
Hide resolved
Sources/PostgresNIO/Connection/PostgresConnection+Database.swift
Outdated
Show resolved
Hide resolved
288a6cc to
f2c7a61
Compare
gwynne
left a comment
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.
Looking pretty great! Mostly just a bunch of silly little nits in strings, plus a few usage fixes.
Sources/PostgresNIO/New/Connection State Machine/AuthenticationStateMachine.swift
Outdated
Show resolved
Hide resolved
Sources/PostgresNIO/New/Connection State Machine/AuthenticationStateMachine.swift
Outdated
Show resolved
Hide resolved
Sources/PostgresNIO/New/Connection State Machine/AuthenticationStateMachine.swift
Show resolved
Hide resolved
Sources/PostgresNIO/New/Connection State Machine/AuthenticationStateMachine.swift
Outdated
Show resolved
Hide resolved
Sources/PostgresNIO/New/Connection State Machine/ConnectionStateMachine.swift
Outdated
Show resolved
Hide resolved
Sources/PostgresNIO/New/Connection State Machine/ConnectionStateMachine.swift
Outdated
Show resolved
Hide resolved
Sources/PostgresNIO/New/Connection State Machine/ConnectionStateMachine.swift
Outdated
Show resolved
Hide resolved
Sources/PostgresNIO/New/Connection State Machine/AuthenticationStateMachine.swift
Outdated
Show resolved
Hide resolved
…nStateMachine.swift Co-authored-by: Gwynne Raskind <gwynne@darkrainfall.org>
gwynne
left a comment
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.
Okay, I have no nits left to pick! Amazing work!!
| return prepared | ||
| let request = PrepareQueryRequest(query, as: name) | ||
| return self.send(PostgresCommands.prepareQuery(request: request), logger: self.logger).map { _ in | ||
| request.prepared! |
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.
Are there any cases where send() won't set prepared and should we be more defensive here rather than force unwrapping?
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.
There are none! :) I should add this as a code comment though. This is a workaround since the send only returns a EventLoopFuture<Void>. And we can't change the send method since it is part of the public PostgresDatabase protocol.
|
|
||
| /// Protocol to encapsulate a function call on the Postgres server | ||
| /// | ||
| /// This protocol is deprecated going forward. |
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.
Should we mark it with @deprecated?
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.
We don't want to mark anything deprecated in this pr to change as little as possible in the public API surface. However we should definitely change this with subsequent prs.
0xTim
left a comment
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.
Overall this is an awesome PR! Couple of minor queries that you can take or leave
|
These changes are now available in 1.5.0 |
1 similar comment
|
These changes are now available in 1.5.0 |
### Motivation In #135, I did some naming things just wrong. `PSQLRows` is a stupid name. We should name it `PSQLRowStream`. `PSQLRows.Row` is a stupid name for a single table row. We should name it `PSQLRow`. Transforming an incoming data row packet to a `[PSQLData]` array early is expensive and stupid. Let's not do this anymore. ### Changes - Extract `PSQLRows.Row` to `PSQLRows` (Got its own file). Stop the early `[PSQLData]` madness. - Rename `PSQLRows` to `PSQLRowStream` - Fix naming in integration tests to match `PSQLRowStream`
Motivation
Connection state changes can be modeled with state machines. This PR introduces a
ConnectionStateMachinethat models thePostgresConnection's state. This will improve the Unit-testability of this package.Changes
PostgresConnectionwith a newPSQLConnectionPSQLConnectionlive in the/NewfolderPSQLConnectionis mainly implemented using thesestructsandclasses:PSQLFrontendMessagea new enum modeling outgoing client messages to the serverPSQLBackendMessagea new enum modeling incoming server messages to the clientPSQLFrontendMessage.Encodera newMessageToByteEncoderPSQLBackendMessage.Decodera newByteToMessageEncoderConnectionStateMachinewith the sub state machines:AuthenticationStateMachineCloseStateMachineExtendedQueryStateMachinePrepareStatementStateMachinePSQLChannelHandleris the mainChannelDuplexHandlerfor thePSQLConnectionPSQLEventsHandleris a newChannelHandlerthat observes the channel events and closes the connection when appropriate.PSQLEncodableis a new protocol to convert Swift types to Postgres types.PSQLDecodableis a new protocol to convert Postgres types to Swift types.PSQLEncodableandPSQLDecodabledefer the encoding and decoding as much as possible, saving unnecessary allocations and conversions.Result
We get a better testable
PostgresConnection.