Skip to content
This repository has been archived by the owner on Aug 19, 2019. It is now read-only.

Memoize owner objects instead of querying the master all the time. #46

Merged
merged 2 commits into from
Dec 20, 2017

Conversation

igorpeshansky
Copy link
Member

No description provided.

Copy link

@qingling128 qingling128 left a comment

Choose a reason for hiding this comment

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

LGTM with one minor thing.

const auto path_component = KindPath(api_version, kind);

const std::string encoded_ref = boost::algorithm::join(
std::vector<std::string>{api_version, kind, ns, name}, "/");

Choose a reason for hiding this comment

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

namespace instead of ns?

Copy link
Member Author

Choose a reason for hiding this comment

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

No can do, sorry -- namespace is a C++ keyword. :-)

@supriyagarg
Copy link
Contributor

LGTM

@igorpeshansky igorpeshansky force-pushed the igorp-kubernetes-refactoring branch from 02e756f to 38d3db0 Compare December 19, 2017 23:03
@igorpeshansky igorpeshansky force-pushed the igorp-kubernetes-memoize-owners branch from bad0e2d to 94f1019 Compare December 19, 2017 23:18
@igorpeshansky igorpeshansky changed the base branch from igorp-kubernetes-refactoring to master December 19, 2017 23:20
@bmoyles0117
Copy link
Contributor

There's an important question here that needs to be answered. Do we ever intend to use anything other than the topLevelControllerType and topLevelControllerName from the top level controller? If we don't for now, but may in the future, we should at least leave a comment in big scary letters that this memoizes by parent name, not parent uid. It's possible for someone to delete a deployment, and create a new one with the same name and the metadata agent will get "stuck" on the outdated deployment metadata.

return QueryMaster(path_component.first + "/namespaces/" + ns + "/" +
path_component.second + "/" + name);
owner = std::move(
QueryMaster(path_component.first + "/namespaces/" + ns + "/" +
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible that this throws an exception, without killing the thread, which would end up leaving owner null, which would end up throwing another exception the next time due to owner->Clone() being on a nullptr? If so, can we add a sanity check of if (owner == nullptr || found.second) {?

Copy link
Member Author

Choose a reason for hiding this comment

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

An exception will not allow the rest of this function to continue -- it'll be propagated up the stack, and caught, likely in KubernetesReader::MetadataQuery. So such a check would be superfluous.

const auto path_component = KindPath(api_version, kind);

const std::string encoded_ref = boost::algorithm::join(
std::vector<std::string>{api_version, kind, ns, name}, "/");
Copy link
Contributor

Choose a reason for hiding this comment

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

Long story short, it will likely be better to use the owner_ref->Get<json::String>("uid"); instead of name, to ensure that the parent we're caching is directly related to this object. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's an important question here that needs to be answered. Do we ever intend to use anything other than the topLevelControllerType and topLevelControllerName from the top level controller? If we don't for now, but may in the future, we should at least leave a comment in big scary letters that this memoizes by parent name, not parent uid. It's possible for someone to delete a deployment, and create a new one with the same name and the metadata agent will get "stuck" on the outdated deployment metadata.

Good point. I've changed the code to use the uid as the cache key.

Copy link
Member Author

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

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

Addressed feedback. PTAL.

return QueryMaster(path_component.first + "/namespaces/" + ns + "/" +
path_component.second + "/" + name);
owner = std::move(
QueryMaster(path_component.first + "/namespaces/" + ns + "/" +
Copy link
Member Author

Choose a reason for hiding this comment

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

An exception will not allow the rest of this function to continue -- it'll be propagated up the stack, and caught, likely in KubernetesReader::MetadataQuery. So such a check would be superfluous.

const auto path_component = KindPath(api_version, kind);

const std::string encoded_ref = boost::algorithm::join(
std::vector<std::string>{api_version, kind, ns, name}, "/");
Copy link
Member Author

Choose a reason for hiding this comment

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

There's an important question here that needs to be answered. Do we ever intend to use anything other than the topLevelControllerType and topLevelControllerName from the top level controller? If we don't for now, but may in the future, we should at least leave a comment in big scary letters that this memoizes by parent name, not parent uid. It's possible for someone to delete a deployment, and create a new one with the same name and the metadata agent will get "stuck" on the outdated deployment metadata.

Good point. I've changed the code to use the uid as the cache key.

Copy link
Contributor

@bmoyles0117 bmoyles0117 left a comment

Choose a reason for hiding this comment

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

LGTM 🎆

path_component.second + "/" + name));
// Sanity check: because we are looking up by name, the object we get
// back might have a different uid.
const json::Object* owner_obj = owner->As<json::Object>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: the naming of the variables seems inconsistent. owner_uid prevents a clash with uid, so perhaps we should have owner_metadata for consistency? Not important to address this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Funny you should mention that -- I initially had it as owner_metadata, but that caused some ugly line breaks, so I went with just metadata. I can change it if you insist.

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM!

@igorpeshansky igorpeshansky merged commit 234ffbb into master Dec 20, 2017
@igorpeshansky igorpeshansky deleted the igorp-kubernetes-memoize-owners branch December 20, 2017 19:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants