-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[router] Add SRDS configUpdate impl #7451
Changes from 9 commits
6a3f13b
cc806d7
bb55a44
8d7b4da
8bcddce
b1d0d5c
1007ee0
184ff2f
fe6b643
fc98e56
951bd28
75718d9
d84839d
27ff0a3
36a6e72
46e23f2
74038f4
ff7ccdb
06bd690
cf38720
5cad3ee
50e8fb5
ac65ba2
cb5324f
5c8a546
4a1fb01
fdd0a74
467a6a1
7dea1a0
c354a1e
2b5f572
9dd4214
5d2f8a2
86c455e
60dd433
6c1a672
c31de28
abfe558
69df754
5f357bd
dd3b97d
ee09a5b
46ad9af
47a417d
9c1f616
ae2ac31
b1acd70
d08bdb2
eb65b89
07bdfee
40b214e
4e57308
710c7e8
53081b2
2593bfa
2dd6714
cef747d
bb0cdb8
fa6ecb1
efaa891
bf4dc23
e329f49
c4719d8
56e2876
d26d9b7
4ab7005
bf703fc
2b375d4
c7a241c
c2ff015
eb5af9c
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 |
---|---|---|
|
@@ -66,8 +66,11 @@ class ScopeKey { | |
private: | ||
// Update the key's hash with the new fragment hash. | ||
void updateHash(const ScopeKeyFragmentBase& fragment) { | ||
absl::uint128 buffer = absl::MakeUint128(hash_, fragment.hash()); | ||
hash_ = HashUtil::xxHash64(absl::string_view(reinterpret_cast<char*>(&buffer), 16)); | ||
std::stringbuf buffer; | ||
buffer.sputn(reinterpret_cast<const char*>(&hash_), sizeof(hash_)); | ||
const auto& fragment_hash = fragment.hash(); | ||
buffer.sputn(reinterpret_cast<const char*>(&fragment_hash), sizeof(fragment_hash)); | ||
hash_ = HashUtil::xxHash64(buffer.str()); | ||
} | ||
|
||
uint64_t hash_{0}; | ||
|
@@ -147,36 +150,17 @@ class ScopeKeyBuilderImpl : public ScopeKeyBuilderBase { | |
class ScopedRouteInfo { | ||
public: | ||
ScopedRouteInfo(envoy::api::v2::ScopedRouteConfiguration&& config_proto, | ||
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.
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. nope, the constructor is expecting a rvalue to be moved into the proto member (per htuch@ pointing it out Envoy prefers more visible && than the copy-elision envoy::api::v2::ScopedRouteConfiguration parameter). |
||
std::unique_ptr<RouteConfigProvider>&& route_provider) | ||
: config_proto_(std::move(config_proto)), route_provider_(std::move(route_provider)) { | ||
ASSERT(route_provider_ != nullptr, "ScopedRouteInfo expects a valid RouteConfigProvider."); | ||
ASSERT( | ||
!route_provider_->configInfo().has_value() || | ||
route_provider_->config()->name() == config_proto_.route_configuration_name(), | ||
fmt::format("RouteConfigProvider's name '{}' doesn't match route_configuration_name '{}'.", | ||
route_provider_->config()->name(), config_proto_.route_configuration_name())); | ||
// TODO(stevenzzzz): Maybe worth a KeyBuilder abstraction when there are more than one type of | ||
// Fragment. | ||
for (const auto& fragment : config_proto_.key().fragments()) { | ||
switch (fragment.type_case()) { | ||
case envoy::api::v2::ScopedRouteConfiguration::Key::Fragment::kStringKey: | ||
scope_key_.addFragment(std::make_unique<StringKeyFragment>(fragment.string_key())); | ||
break; | ||
default: | ||
NOT_REACHED_GCOVR_EXCL_LINE; | ||
} | ||
} | ||
} | ||
ConfigConstSharedPtr&& route_config); | ||
|
||
Router::ConfigConstSharedPtr routeConfig() const { return route_provider_->config(); } | ||
ConfigConstSharedPtr routeConfig() const { return route_config_; } | ||
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: usually we return 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. This config is supposed to be shared between workers which do the actually routing, they need to take a share of the ownership of it. 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. Let me make it clear.
Of course it can never be wrong if you do the early copy at the 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. returning an reference also means the function makes a promise to callers about the life circle of the return object (personally I dont like returning reference), just imagine what if underlying obj is updated in one thread, and is read in another thread(we are distributing a scopedRouteInfo across threads). |
||
const ScopeKey& scopeKey() const { return scope_key_; } | ||
const envoy::api::v2::ScopedRouteConfiguration& configProto() const { return config_proto_; } | ||
const std::string& scopeName() const { return config_proto_.name(); } | ||
|
||
private: | ||
const envoy::api::v2::ScopedRouteConfiguration config_proto_; | ||
envoy::api::v2::ScopedRouteConfiguration config_proto_; | ||
ScopeKey scope_key_; | ||
std::unique_ptr<RouteConfigProvider> route_provider_; | ||
ConfigConstSharedPtr route_config_; | ||
}; | ||
using ScopedRouteInfoConstSharedPtr = std::shared_ptr<const ScopedRouteInfo>; | ||
// Ordered map for consistent config dumping. | ||
|
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.
nit: s/be teared/being torn/, s/been executed/being executed/
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.
done