Skip to content
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

use hash func that generates deterministic result for protobuf #5814

Merged
merged 10 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions source/common/router/rds_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ StaticRouteConfigProviderImpl::~StaticRouteConfigProviderImpl() {
// initialization needs to be fixed.
RdsRouteConfigSubscription::RdsRouteConfigSubscription(
const envoy::config::filter::network::http_connection_manager::v2::Rds& rds,
const std::string& manager_identifier, Server::Configuration::FactoryContext& factory_context,
const uint64_t manager_identifier, Server::Configuration::FactoryContext& factory_context,
const std::string& stat_prefix,
Envoy::Router::RouteConfigProviderManagerImpl& route_config_provider_manager)
: route_config_name_(rds.route_config_name()),
Expand Down Expand Up @@ -194,9 +194,7 @@ Router::RouteConfigProviderPtr RouteConfigProviderManagerImpl::createRdsRouteCon
Server::Configuration::FactoryContext& factory_context, const std::string& stat_prefix) {

// RdsRouteConfigSubscriptions are unique based on their serialized RDS config.
// TODO(htuch): Full serialization here gives large IDs, could get away with a
// strong hash instead.
const std::string manager_identifier = rds.SerializeAsString();
const uint64_t manager_identifier = MessageUtil::hash(rds);

RdsRouteConfigSubscriptionSharedPtr subscription;

Expand Down
6 changes: 3 additions & 3 deletions source/common/router/rds_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class RdsRouteConfigSubscription

RdsRouteConfigSubscription(
const envoy::config::filter::network::http_connection_manager::v2::Rds& rds,
const std::string& manager_identifier, Server::Configuration::FactoryContext& factory_context,
const uint64_t manager_identifier, Server::Configuration::FactoryContext& factory_context,
const std::string& stat_prefix,
RouteConfigProviderManagerImpl& route_config_provider_manager);

Expand All @@ -134,7 +134,7 @@ class RdsRouteConfigSubscription
Stats::ScopePtr scope_;
RdsStats stats_;
RouteConfigProviderManagerImpl& route_config_provider_manager_;
const std::string manager_identifier_;
const uint64_t manager_identifier_;
TimeSource& time_source_;
SystemTime last_updated_;
absl::optional<LastConfigInfo> config_info_;
Expand Down Expand Up @@ -202,7 +202,7 @@ class RouteConfigProviderManagerImpl : public RouteConfigProviderManager,
// TODO(jsedgwick) These two members are prime candidates for the owned-entry list/map
// as in ConfigTracker. I.e. the ProviderImpls would have an EntryOwner for these lists
// Then the lifetime management stuff is centralized and opaque.
std::unordered_map<std::string, std::weak_ptr<RdsRouteConfigSubscription>>
std::unordered_map<uint64_t, std::weak_ptr<RdsRouteConfigSubscription>>
route_config_subscriptions_;
std::unordered_set<RouteConfigProvider*> static_route_config_providers_;
Server::ConfigTracker::EntryOwnerPtr config_tracker_entry_;
Expand Down
3 changes: 2 additions & 1 deletion source/common/secret/secret_manager_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class SecretManagerImpl : public SecretManager {
findOrCreate(const envoy::api::v2::core::ConfigSource& sds_config_source,
const std::string& config_name,
Server::Configuration::TransportSocketFactoryContext& secret_provider_context) {
const std::string map_key = sds_config_source.SerializeAsString() + config_name;
const std::string map_key =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just use uint64_t for map_key type and change type elsewhere, no need convert to string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since resourcename is also needed to construct mapkey, are you suggesting using something like MessageUtil::hash(sds_config_source+config_name) ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry I meant rds_impl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

std::to_string(MessageUtil::hash(sds_config_source)) + config_name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will a number started config_name potentially conflicts with other hashes? i.e. a config hash 123 with config name 0-abc conflicts with a config hash 12 with config name 30-abc, this happens much easier than hash conflict.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially, yes, though I'm not sure how well do we guard against that in rest of the codebase.

@quanjielin could you add a separator? e.g.

const std::string map_key =
    absl::StrCat(MessageUtil::hash(sds_config_source), ".", config_name);

Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that will be good enough

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


std::shared_ptr<SecretType> secret_provider = dynamic_secret_providers_[map_key].lock();
if (!secret_provider) {
Expand Down