-
Notifications
You must be signed in to change notification settings - Fork 5.1k
thrift: refactor Thrift router to allow protocol upgrade #4286
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
thrift: refactor Thrift router to allow protocol upgrade #4286
Conversation
Modifies the Thrift router to allow protocols to upgrade on initial data from the downstream connection and upgrade an upstream connection before transmitting a request. As part of this work, Transport and Protocol objects are reused across downstream connections and for an upstream's request and response. *Risk Level*: low, upgrade path unused *Testing*: unit tests *Docs Changes*: n/a *Release Notes*: n/a Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
} | ||
|
||
/** | ||
* Check whether a given upstream connection can be upgraded and generates an upgrade request |
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.
[minor] Checks
for consistency with the other method comments
@@ -19,8 +19,8 @@ class ProtocolConverter : public virtual DecoderEventHandler { | |||
ProtocolConverter() {} | |||
virtual ~ProtocolConverter() {} | |||
|
|||
void initProtocolConverter(ProtocolPtr&& proto, Buffer::Instance& buffer) { | |||
proto_ = std::move(proto); | |||
void initProtocolConverter(Protocol* proto, Buffer::Instance& 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.
The change to a raw pointer here is dangerous.
@@ -350,8 +353,8 @@ ProtocolState DecoderStateMachine::run(Buffer::Instance& buffer) { | |||
return state_; | |||
} | |||
|
|||
Decoder::Decoder(TransportPtr&& transport, ProtocolPtr&& protocol, DecoderCallbacks& callbacks) | |||
: transport_(std::move(transport)), protocol_(std::move(protocol)), callbacks_(callbacks) {} | |||
Decoder::Decoder(Transport& transport, Protocol& protocol, DecoderCallbacks& callbacks) |
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.
With this change from TransportPtr&& transport
to Transport& transport
, what guarantees that the referenced transport
will remain valid for the full life of the Decoder
object?
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.
It's up to the constructor of the Decoder to make sure this is the case. ConnectionManager creates a TransportPtr, ProtocolPtr, and DecoderPtr when it's constructed. The TransportPtr and ProtocolPtr and never replaced so their lifecycle is the duration of the downstream connection.
Each Router has a TransportPtr and ProtocolPtr. A DecoderPtr is held indirectly via ThriftObjectPtr if protocol upgrade occurs for the upstream. Once upgrade is complete that ThriftObjectPtr and DecoderPtr are destroyed. If the request is terminated early the ThriftObjectPtr and DecoderPtr are destroyed before the TransportPtr or ProtocolPtr.
Finally the ConnectionManager::ActiveRpc holds a ResponseDecoder that has references to the Router's TransportPtr and ProtocolPtr. The destruction order there is ResponseDecoder before DecoderFilter so that's ok as well.
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.
Take my approval with a grain of salt because I'm still ramping up but looks reasonable.
Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
(prefer forward reference resolved in the same file to one resolved by a separate file) Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
@brian-pane can I get you refresh your review? (5fc9e3a is the only change from before). |
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.
Your "we wish Github supported our permissions model" approval, sir!
Modifies the Thrift router to allow protocols to upgrade on initial
data from the downstream connection and upgrade an upstream connection
before transmitting a request. As part of this work, Transport and
Protocol objects are reused across downstream connections and for
an upstream's request and response.
Risk Level: low, upgrade path unused
Testing: unit tests
Docs Changes: n/a
Release Notes: n/a
Signed-off-by: Stephan Zuercher stephan@turbinelabs.io