Skip to content

Change accessor of filterstate to a const shared_ptr ref#9845

Merged
mattklein123 merged 17 commits intoenvoyproxy:masterfrom
gargnupur:nup_filter_state
Jan 31, 2020
Merged

Change accessor of filterstate to a const shared_ptr ref#9845
mattklein123 merged 17 commits intoenvoyproxy:masterfrom
gargnupur:nup_filter_state

Conversation

@gargnupur
Copy link
Copy Markdown
Contributor

@gargnupur gargnupur commented Jan 27, 2020

Ref: envoyproxy/envoy-wasm#291

Description: This is part one of the change to add an option to support looking up filterstate from upstream filters. This change just changes the non-const accessor of filterstate to a const shared_ptr ref of non-const filterstate object.
Risk Level: Low
Testing:
Docs Changes:
Release Notes:
[Optional Fixes #Issue]
[Optional Deprecated:]

@gargnupur
Copy link
Copy Markdown
Contributor Author

/cc @mandarjog

@mattklein123 mattklein123 self-assigned this Jan 28, 2020
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

At a high level LGTM but some small comments and also needs tests. Thanks!

/wait

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you just make the reference method above return the shared_ptr? You can return a const reference to the shared_ptr which should make this just as efficient in the common case. Then we don't need this new method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@mattklein123 : Won't that mean changing a lot more files because we would be changing a commonly used signature?
I agree it would be better going forward...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I doubt there are that many call-sites. I would just fix them.

Copy link
Copy Markdown
Contributor Author

@gargnupur gargnupur Jan 28, 2020

Choose a reason for hiding this comment

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

sure.. updating it then..

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

define FilterStateSharedPtr (i.e. using FilterStateSharedPtr = std::shared_ptr<FilterState>;) in filter_state.h and use it everywhere possible.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

const FilterStateSharedPtr filterState() const override { return filter_state_;} is not correct, as you are returning a const shared_ptr by value. Just leave the const version as it was, or change it to return a shared_ptr to a const object.

also, it's better to return shared_ptr by value as compared to reference, so as to avoid lifecycle issues

We do this in many places to avoid the copy/inc where necessary. Please return by const ref. Thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback. PTAL at the PR again!

(I have to say, I learnt about constness with respect to shared_ptr's)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Return const ref shared_ptr

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not needed here and elsewhere.

@gargnupur gargnupur requested a review from jplevyak January 29, 2020 21:17
@gargnupur gargnupur force-pushed the nup_filter_state branch 3 times, most recently from 4cb26f3 to 66b7d9f Compare January 29, 2020 22:39
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Please split this into two changes. The first can just be the shared_ptr conversion with no other upstream changes, and then we can do the upstream change and make sure we have sufficient testing for that. Thank you!

/wait

@gargnupur gargnupur changed the title Share filterstate between upstream and downstream filters Change accessor of filterstate to a const shared_ptr ref Jan 30, 2020
@gargnupur gargnupur force-pushed the nup_filter_state branch 2 times, most recently from cfca724 to 559cb1c Compare January 30, 2020 00:40
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Generally LGTM with small comments, thank you.

/wait

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In many places in this change you have added a nullptr check where it did not exist before. This pointer should never be null, so you can remove this check here and elsewhere.

Copy link
Copy Markdown
Contributor Author

@gargnupur gargnupur Jan 31, 2020

Choose a reason for hiding this comment

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

I just feel better to have null protection for ptrs :) so that it doesn't bite later on...

removing the extra protection I added

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: '{}' not needed here and elsewhere.

Signed-off-by: gargnupur <gargnupur@google.com>
Signed-off-by: gargnupur <gargnupur@google.com>
Signed-off-by: gargnupur <gargnupur@google.com>
Signed-off-by: gargnupur <gargnupur@google.com>
Signed-off-by: gargnupur <gargnupur@google.com>
Signed-off-by: gargnupur <gargnupur@google.com>
Signed-off-by: gargnupur <gargnupur@google.com>
Signed-off-by: gargnupur <gargnupur@google.com>
Signed-off-by: gargnupur <gargnupur@google.com>
Signed-off-by: gargnupur <gargnupur@google.com>
Signed-off-by: gargnupur <gargnupur@google.com>
Signed-off-by: gargnupur <gargnupur@google.com>
Signed-off-by: gargnupur <gargnupur@google.com>
Signed-off-by: gargnupur <gargnupur@google.com>
Signed-off-by: gargnupur <gargnupur@google.com>
…impl.cc

Signed-off-by: gargnupur <gargnupur@google.com>
Signed-off-by: gargnupur <gargnupur@google.com>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants