-
Notifications
You must be signed in to change notification settings - Fork 5.3k
stream_info: Add the concept of "life span" to StreamInfo::FilterState #9202
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
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
a95f443
Add "life span" concept to FilterState and use it for sharing
penguingao 6323439
Add test for FilterState::CopyInto
penguingao 33bc63d
Fix format and comment.
penguingao 4999df4
Fix comment and format.
penguingao 125cc54
Add default life_span value to FilterStateImpl as well since tests use
penguingao 4683ed5
Kick CI
penguingao ce7306c
data_ is a shared_ptr.
penguingao f76d532
Remove default parameter for life_span in FilterState::setData to let
penguingao 84ea166
Fix more test.
penguingao 08f1ed0
Revert to use default parameters
penguingao 793d942
Add LifeSpan::DownstreamConnection to StreamInfo::FilterState.
penguingao 7f2ee27
Merge remote-tracking branch 'upstream/master' into filter-state
penguingao 30ec74b
Merge branch 'filter-state' of github.com:penguingao/envoy into
penguingao 72ed2b9
Add default parameter back to FilterStateImpl::setData
penguingao 82931b4
Fix tests.
penguingao f83f449
Fix tests.
penguingao 10b6560
More test...
penguingao 80f45cb
filter_state_ needs to be always initialized in StreamInfoImpl.
penguingao 666e852
Resolve comments:
penguingao 72a5f8a
Resolve comment:
penguingao 4531b69
Resolve comment:
penguingao 022aa74
Fix format.
penguingao ed32ced
Fix build.
penguingao 25a79a2
Merge remote-tracking branch 'upstream/master' into filter-state
penguingao afcbaa7
Fix format.
penguingao 4c10770
Fix some comment and make filter_state_ in conn_manager_impl not created
penguingao 9282aea
Address comments:
penguingao 3a590a1
Kick CI
penguingao dd7cde5
Address comments:
penguingao 868ea9e
Merge remote-tracking branch 'upstream/master' into filter-state
penguingao 1987d25
Address comments:
penguingao 3f85eb7
Make tests also call FilterState::setData with correct LifeSpan for n…
penguingao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,13 +15,36 @@ namespace Envoy { | |
| namespace StreamInfo { | ||
|
|
||
| /** | ||
| * FilterState represents dynamically generated information regarding a | ||
| * stream (TCP or HTTP level) by various filters in Envoy. FilterState can | ||
| * be write-once or write-many. | ||
| * FilterState represents dynamically generated information regarding a stream (TCP or HTTP level) | ||
| * or a connection by various filters in Envoy. FilterState can be write-once or write-many. | ||
| */ | ||
| 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 | ||
| // share the same FilterStateImpl as parent, which may recursively share parent with other | ||
| // FilterStateImpl at the same life span. This interface is supposed to be accessed at the leaf | ||
| // level (FilterChain) for objects with any desired longer life span. | ||
| // | ||
| // - FilterChain has the shortest life span, which is as long as the filter chain lives. | ||
| // | ||
| // - DownstreamRequest is longer than FilterChain. When internal redirect is enabled, one | ||
| // downstream request may create multiple filter chains. DownstreamRequest allows an object to | ||
| // survive across filter chains for bookkeeping needs. | ||
| // | ||
| // - DownstreamConnection makes an object survive the entire duration of a downstream connection. | ||
| // Any stream within this connection can see the same object. | ||
| // | ||
| // Note that order matters in this enum because it's assumed that life span grows as enum number | ||
| // grows. | ||
| enum LifeSpan { | ||
| FilterChain, | ||
| DownstreamRequest, | ||
| DownstreamConnection, | ||
| TopSpan = DownstreamConnection | ||
| }; | ||
|
|
||
| class Object { | ||
| public: | ||
|
|
@@ -41,16 +64,18 @@ class FilterState { | |
| * @param data_name the name of the data being set. | ||
| * @param data an owning pointer to the data to be stored. | ||
| * @param state_type indicates whether the object is mutable or not. | ||
| * @param life_span indicates the life span of the object: bound to the filter chain, a | ||
| * downstream request, or a downstream connection. | ||
| * | ||
| * Note that it is an error to call setData() twice with the same | ||
| * data_name, if the existing object is immutable. Similarly, it is an | ||
| * error to call setData() with same data_name but different state_types | ||
| * (mutable and readOnly, or readOnly and mutable). This is to enforce a | ||
| * single authoritative source for each piece of immutable data stored in | ||
| * FilterState. | ||
| * (mutable and readOnly, or readOnly and mutable) or different life_span. | ||
| * This is to enforce a single authoritative source for each piece of | ||
| * data stored in FilterState. | ||
| */ | ||
| virtual void setData(absl::string_view data_name, std::unique_ptr<Object>&& data, | ||
| StateType state_type) PURE; | ||
| virtual void setData(absl::string_view data_name, std::shared_ptr<Object> data, | ||
| StateType state_type, LifeSpan life_span = LifeSpan::FilterChain) PURE; | ||
|
|
||
| /** | ||
| * @param data_name the name of the data being looked up (mutable/readonly). | ||
|
|
@@ -102,6 +127,24 @@ class FilterState { | |
| */ | ||
| virtual bool hasDataWithName(absl::string_view data_name) const PURE; | ||
|
|
||
| /** | ||
| * @param life_span the LifeSpan above which data existence is checked. | ||
| * @return whether data of any type exist with LifeSpan greater than life_span. | ||
| */ | ||
| virtual bool hasDataAtOrAboveLifeSpan(LifeSpan life_span) const PURE; | ||
|
|
||
| /** | ||
| * @return the LifeSpan of objects stored by this instance. Objects with | ||
| * LifeSpan longer than this are handled recursively. | ||
| */ | ||
| virtual LifeSpan lifeSpan() 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. |
||
| * @return the pointer of the parent FilterState that has longer life span. nullptr means this is | ||
| * either the top LifeSpan or the parent is not yet created. | ||
| */ | ||
| virtual std::shared_ptr<FilterState> parent() const PURE; | ||
|
|
||
| protected: | ||
| virtual const Object* getDataReadOnlyGeneric(absl::string_view data_name) const PURE; | ||
| virtual Object* getDataMutableGeneric(absl::string_view data_name) PURE; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,9 @@ class ConnectionManagerImpl : Logger::Loggable<Logger::Id::http>, | |
|
|
||
| TimeSource& timeSource() { return time_source_; } | ||
|
|
||
| // Return a reference to the shared_ptr so that it can be lazy created on demand. | ||
| std::shared_ptr<StreamInfo::FilterState>& filterState() { return filter_state_; } | ||
|
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. nit: can you add a small comment on why we return this by reference? |
||
|
|
||
| private: | ||
| struct ActiveStream; | ||
|
|
||
|
|
@@ -701,6 +704,7 @@ class ConnectionManagerImpl : Logger::Loggable<Logger::Id::http>, | |
| const Server::OverloadActionState& overload_stop_accepting_requests_ref_; | ||
| const Server::OverloadActionState& overload_disable_keepalive_ref_; | ||
| TimeSource& time_source_; | ||
| std::shared_ptr<StreamInfo::FilterState> filter_state_; | ||
| }; | ||
|
|
||
| } // namespace Http | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.