-
Notifications
You must be signed in to change notification settings - Fork 5.5k
filter state: add a mark for sharing with the upstream #21700
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
Changes from 11 commits
1c0cf91
52bd5c7
83a8469
03318e8
7a1b3ee
218f97d
eaca9db
0c3b11f
9e5a187
cd1f7c5
7ff0070
1948a0a
643e24b
a16242b
4566981
a1fd5df
30250ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -235,9 +235,10 @@ class TransportSocketOptions { | |
| virtual absl::optional<Network::ProxyProtocolData> proxyProtocolOptions() const PURE; | ||
|
|
||
| /** | ||
| * @return filter state from the downstream request or connection. | ||
| * @return filter state objects from the downstream request or connection | ||
| * that are marked as shared with the upstream connection. | ||
| */ | ||
| virtual const StreamInfo::FilterStateSharedPtr& filterState() const PURE; | ||
| virtual const StreamInfo::FilterState::Objects& filterStateObjects() const PURE; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this function name should be more descriptive, maybe something like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed. |
||
| }; | ||
|
|
||
| using TransportSocketOptionsConstSharedPtr = std::shared_ptr<const TransportSocketOptions>; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -27,6 +27,7 @@ using FilterStateSharedPtr = std::shared_ptr<FilterState>; | |||||
| class FilterState { | ||||||
| public: | ||||||
| enum class StateType { ReadOnly, Mutable }; | ||||||
|
|
||||||
| // Objects stored in the FilterState may have different life span. Life span is what controls | ||||||
| // how long an object stored in FilterState lives. Implementation of this interface actually | ||||||
| // stores objects in a (reverse) tree manner - multiple FilterStateImpl with shorter life span may | ||||||
|
|
@@ -45,8 +46,34 @@ class FilterState { | |||||
| // | ||||||
| // Note that order matters in this enum because it's assumed that life span grows as enum number | ||||||
| // grows. | ||||||
| // | ||||||
| // Note that for more accurate book-keeping it is recommended to subscribe to | ||||||
| // the stream callbacks instead of relying on the destruction of the filter | ||||||
| // state. | ||||||
| // | ||||||
| // As a special case, objects that are marked as shared with the upstream | ||||||
| // become bound to the upstream connection life span, regardless of the | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clarify: the object will live as long as either the downstream or upstream connection is open. The current wording implies that the lifetime is strictly tied to the upstream connection.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarified, LMK if it can be improved further. |
||||||
| // original life span. That means, for example, that a shared request span | ||||||
| // object may outlive the original request when it is shared, because it may | ||||||
| // be captured by an upstream connection for the original downstream request. | ||||||
| enum LifeSpan { FilterChain, Request, Connection, TopSpan = Connection }; | ||||||
|
|
||||||
| // Objects stored in the filter state can optionally be shared between the | ||||||
| // upstrean and downstream filter state. | ||||||
| enum class StreamSharing { | ||||||
| // None implies the object is exclusive to the stream. | ||||||
| None, | ||||||
|
|
||||||
| // Mark a filter state object as shared with the upstream connection. | ||||||
| // Shared filter state objects are copied by reference from the downstream | ||||||
| // requests and connections to the upstream connection filter state. When | ||||||
| // upstream connections are re-used between streams, the downstream objects | ||||||
| // are captured for the first, initiating stream. To force distinct | ||||||
| // upstream connections and prevent sharing, the shared filter state object | ||||||
| // must implement the hashing interface. | ||||||
| SharedWithUpstreamConnection, | ||||||
| }; | ||||||
|
|
||||||
| class Object { | ||||||
| public: | ||||||
| virtual ~Object() = default; | ||||||
|
|
@@ -66,6 +93,16 @@ class FilterState { | |||||
| virtual absl::optional<std::string> serializeAsString() const { return absl::nullopt; } | ||||||
| }; | ||||||
|
|
||||||
| struct FilterObject { | ||||||
| std::shared_ptr<Object> data_; | ||||||
| StateType state_type_; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
default initialize this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
| StreamSharing stream_sharing_{StreamSharing::None}; | ||||||
| std::string name_{""}; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The initialization can just be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
| }; | ||||||
|
|
||||||
| using Objects = std::vector<FilterObject>; | ||||||
| using ObjectsPtr = std::unique_ptr<Objects>; | ||||||
|
|
||||||
| virtual ~FilterState() = default; | ||||||
|
|
||||||
| /** | ||||||
|
|
@@ -83,7 +120,8 @@ class FilterState { | |||||
| * data stored in FilterState. | ||||||
| */ | ||||||
| virtual void setData(absl::string_view data_name, std::shared_ptr<Object> data, | ||||||
| StateType state_type, LifeSpan life_span = LifeSpan::FilterChain) PURE; | ||||||
| StateType state_type, LifeSpan life_span = LifeSpan::FilterChain, | ||||||
| StreamSharing stream_sharing = StreamSharing::None) PURE; | ||||||
|
|
||||||
| /** | ||||||
| * @param data_name the name of the data being looked up (mutable/readonly). | ||||||
|
|
@@ -156,6 +194,11 @@ class FilterState { | |||||
| * either the top LifeSpan or the parent is not yet created. | ||||||
| */ | ||||||
| virtual FilterStateSharedPtr parent() const PURE; | ||||||
|
|
||||||
| /** | ||||||
| * @return filter objects that are shared with the upstream connection. | ||||||
| **/ | ||||||
| virtual ObjectsPtr objectsSharedWithUpstreamConnection() const PURE; | ||||||
| }; | ||||||
|
|
||||||
| } // namespace StreamInfo | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.