Skip to content

Fix issue with Envoy not reference counting across scopes under not-hot restart#3212

Closed
ambuc wants to merge 20 commits intoenvoyproxy:masterfrom
ambuc:refcount-stats-in-heap-alloc
Closed

Fix issue with Envoy not reference counting across scopes under not-hot restart#3212
ambuc wants to merge 20 commits intoenvoyproxy:masterfrom
ambuc:refcount-stats-in-heap-alloc

Conversation

@ambuc
Copy link
Copy Markdown
Contributor

@ambuc ambuc commented Apr 25, 2018

Signed-off-by: James Buckland jbuckland@google.com

title: Fixes issue with Envoy not reference counting stats across scopes under not-hot restart.

Description: Simpler solution to issue #2453 than pull #3163, continuing draft work in ambuc#1 and ambuc#2. Summary of changes:

  • adds an unordered_map named stats_set_ as a member variable of HeapRawStatDataAllocator, and implements reference counting / dedup on allocated stats.

Risk Level: Low.

Testing: Add a test to stats_impl_test. Passes bazel test test/....

Docs Changes: N/A

Release Notes: This is user-facing in that non-hot restart stat allocation now resolves namespace properly, but no effect on user configs.

Fixes: #2453

ambuc added 8 commits April 25, 2018 16:40
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
…ators

Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
ggreenway and others added 10 commits April 25, 2018 15:30
ASAN does not allow *(nullptr) being converted to a reference.

Fixes envoyproxy#3208

Signed-off-by: Greg Greenway <ggreenway@apple.com>
…y#3140)" (envoyproxy#3213)

This reverts commit e293ffb.

Signed-off-by: Matt Klein <mklein@lyft.com>
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
…ators

Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
TEST(RawStatDataTest, HeapAlloc) {
HeapRawStatDataAllocator alloc;
RawStatData* stat_1 = alloc.alloc("ref_name");
RawStatData* stat_2 = alloc.alloc("ref_name");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe also do stat_3 with "not_ref_name" and check it's not equal, and that none of these are nullptr.

key.size(), Stats::RawStatData::maxNameLength());
}

auto ret = stats_set_.insert(std::pair<std::string, RawStatData*>(std::string(key), nullptr));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd specify a typedef StringRawDataMap for the map type in the header, and then use StringRawDataMap::value_type here rather than spelling out the pair.

auto ret = stats_set_.insert(std::pair<std::string, RawStatData*>(std::string(key), nullptr));
RawStatData*& data = ret.first->second;
if (ret.second) {
data = static_cast<RawStatData*>(::calloc(RawStatData::size(), 1));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

RELEASE_ASSERT(data)

RawStatData* stat_1 = alloc.alloc("ref_name");
RawStatData* stat_2 = alloc.alloc("ref_name");
EXPECT_EQ(stat_1, stat_2);
::free(stat_1);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

alloc.free(stat_1);

that's probably the source of the CI failures

Copy link
Copy Markdown
Contributor

@jmarantz jmarantz left a comment

Choose a reason for hiding this comment

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

mostly nits except the test bug.

ambuc added 2 commits April 27, 2018 13:30
…uc/envoy into refcount-stats-in-heap-alloc

Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
@ambuc
Copy link
Copy Markdown
Contributor Author

ambuc commented Apr 27, 2018

Closing and re-opening due to 3b4badd and some DCO business. See #3249

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.

!ENVOY_HOT_RESTART does not reference count across scopes

5 participants