-
Notifications
You must be signed in to change notification settings - Fork 5.3k
upstream: add connpool map #5670
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
23 commits
Select commit
Hold shift + click to select a range
a5150d0
Add ConnPoolMap
klarose 8534755
Use ConnPoolMap in ClusterManagerImpl for http.
klarose 2b91fa5
Merge branch 'master' into conn_pool_map
klarose da8544b
Remove unnecessary todo
klarose d2da030
Various bits of cleanup
klarose 1863ff8
Fix clang errors
klarose b903bbf
Fix capture in UT
klarose 4807a5f
Do not clear out the pool until finished
klarose 11dbe57
Merge branch 'master' into conn_pool_map
klarose 85dcf41
Add a helpe class to fail on recursion
klarose 6743f7c
Various code review fixes
klarose aa18650
Code review fixes for cluster_manager_impl
klarose c3fc41a
Use flat_hash_map rather than map
klarose f74d8cf
Fix typo in comment
klarose e5216eb
Fix coverage expect death tests
klarose 1b50fd1
Code review fixes
klarose 1112b90
Rename recursion_checker to debug_recursion_checker
klarose 92afa73
Merge branch 'master' into conn_pool_map
klarose 25b58b2
Derive from TestBase
klarose 5ba7ae4
Don't run assert tests in debug
klarose 5d8536e
Merge branch 'master' into conn_pool_map
klarose 4b6e8ec
Nit fixes.
klarose 5887fec
Merge branch 'master' into conn_pool_map
klarose 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
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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #pragma once | ||
|
|
||
| #include "common/common/assert.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Common { | ||
| /** | ||
| * A helper class to assert that a call is not recursive. | ||
| */ | ||
| class DebugRecursionChecker { | ||
| public: | ||
| void enter() { | ||
| ASSERT(!entered_, "A resource should only be entered once"); | ||
| #if !defined(NDEBUG) | ||
| entered_ = true; | ||
| #endif // !defined(NDEBUG) | ||
| } | ||
|
|
||
| void exit() { | ||
| #if !defined(NDEBUG) | ||
| entered_ = false; | ||
| #endif // !defined(NDEBUG) | ||
| } | ||
|
|
||
| private: | ||
| bool entered_ = false; | ||
| }; | ||
|
|
||
| class AutoDebugRecursionChecker { | ||
| public: | ||
| explicit AutoDebugRecursionChecker(DebugRecursionChecker& checker) : checker_(checker) { | ||
| checker.enter(); | ||
| } | ||
|
|
||
| ~AutoDebugRecursionChecker() { checker_.exit(); } | ||
|
|
||
| private: | ||
| DebugRecursionChecker& checker_; | ||
| }; | ||
|
|
||
| } // namespace Common | ||
| } // namespace Envoy |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #pragma once | ||
|
|
||
| #include <vector> | ||
|
|
||
| #include "envoy/event/dispatcher.h" | ||
|
|
||
| #include "common/common/debug_recursion_checker.h" | ||
|
|
||
| #include "absl/container/flat_hash_map.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Upstream { | ||
| /** | ||
| * A class mapping keys to connection pools, with some recycling logic built in. | ||
| */ | ||
| template <typename KEY_TYPE, typename POOL_TYPE> class ConnPoolMap { | ||
| public: | ||
| using PoolFactory = std::function<std::unique_ptr<POOL_TYPE>()>; | ||
| using DrainedCb = std::function<void()>; | ||
|
|
||
| ConnPoolMap(Event::Dispatcher& dispatcher); | ||
| ~ConnPoolMap(); | ||
| /** | ||
| * Returns an existing pool for `key`, or creates a new one using `factory`. Note that it is | ||
| * possible for this to fail if a limit on the number of pools allowed is reached. | ||
| * @return The pool corresponding to `key`, or `absl::nullopt`. | ||
| */ | ||
| POOL_TYPE& getPool(KEY_TYPE key, const PoolFactory& factory); | ||
|
|
||
| /** | ||
| * @return the number of pools. | ||
| */ | ||
| size_t size() const; | ||
|
|
||
| /** | ||
| * Destroys all mapped pools. | ||
| */ | ||
| void clear(); | ||
|
|
||
| /** | ||
| * Adds a drain callback to all mapped pools. Any future mapped pools with have the callback | ||
| * automatically added. Be careful with the callback. If it itself calls into `this`, modifying | ||
klarose marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * the state of `this`, there is a good chance it will cause corruption due to the callback firing | ||
| * immediately. | ||
| */ | ||
| void addDrainedCallback(const DrainedCb& cb); | ||
|
|
||
| /** | ||
| * Instructs each connection pool to drain its connections. | ||
| */ | ||
| void drainConnections(); | ||
|
|
||
| private: | ||
| absl::flat_hash_map<KEY_TYPE, std::unique_ptr<POOL_TYPE>> active_pools_; | ||
| Event::Dispatcher& thread_local_dispatcher_; | ||
| std::vector<DrainedCb> cached_callbacks_; | ||
| Common::DebugRecursionChecker recursion_checker_; | ||
| }; | ||
|
|
||
| } // namespace Upstream | ||
| } // namespace Envoy | ||
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.