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

schemata: use chunked_vector for createable_topic #16529

Conversation

travisdowns
Copy link
Member

Override the decode path to use chunked_vector for createable_topic as we may have 10,000s of these in a single API request.

Arguably, we could use chunked_vector everywhere now in schemata and get rid of this override, but let's do that later.

Fixes #16521.

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v23.3.x
  • v23.2.x
  • v23.1.x

Release Notes

Bug Fixes

  • Avoid a large contiguous allocation when creating thousands of topics in a single CreateTopics request.

* In the same manner as the corresponding std::vector method.
*/
fragmented_vector(std::initializer_list<value_type> elems)
: fragmented_vector(elems.begin(), elems.end()) {}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the only new code, the other constructor was just moved to keep all constructors together at the start of the member list.

@travisdowns travisdowns force-pushed the td-16521-chunked-vector-create-topics branch from e99567b to 879ae45 Compare February 7, 2024 20:12
@@ -199,7 +199,8 @@ ss::future<response_ptr> create_topics_handler::handle(
}

if (!ctx.audit()) {
request.data.topics.erase(valid_range_end, request.data.topics.end());
Copy link
Member Author

Choose a reason for hiding this comment

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

chunked_vector does not have erase()

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if an chunked_vector::erase_to_end(iterator) would be an easier drop in replacement instead of pop_back_n.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I had the same thought and this comment pushed me over the the edge to add it, it's in this PR as of the latest push.

@@ -24,7 +24,8 @@
class create_topic_fixture : public redpanda_thread_fixture {
public:
kafka::create_topics_request make_req(
std::vector<kafka::creatable_topic> topics, bool validate_only = false) {
chunked_vector<kafka::creatable_topic> topics,
Copy link
Member Author

Choose a reason for hiding this comment

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

The edits in this file are because chunked_vector does not have a copy constructor, so we need to move the request object around now.

This means copying some stuff out here where we used the request after passing it down, and more use of std::move.

rockwotj
rockwotj previously approved these changes Feb 7, 2024
Copy link
Contributor

@rockwotj rockwotj left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -199,7 +199,8 @@ ss::future<response_ptr> create_topics_handler::handle(
}

if (!ctx.audit()) {
request.data.topics.erase(valid_range_end, request.data.topics.end());
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if an chunked_vector::erase_to_end(iterator) would be an easier drop in replacement instead of pop_back_n.

*
* This has the same semantics as the corresponding std::vector
* constructor.
*/
template<typename Iter>
requires std::input_iterator<Iter>
fragmented_vector(Iter begin, Iter end)
Copy link
Member

Choose a reason for hiding this comment

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

nit: would it be possible to change commit message to keep the naming consistent i.e. fragemented_vector ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, updated to use fragmented_vector.

We add a std::initalizer_list constructor to fragmented_vector.

This is present in std::vector making some swap-outs more
difficult.
@travisdowns travisdowns force-pushed the td-16521-chunked-vector-create-topics branch from a2bff73 to 1377c44 Compare February 8, 2024 14:43
@travisdowns travisdowns force-pushed the td-16521-chunked-vector-create-topics branch from 1377c44 to bb23a02 Compare February 8, 2024 15:35
rockwotj
rockwotj previously approved these changes Feb 8, 2024
Copy link
Contributor

@rockwotj rockwotj left a comment

Choose a reason for hiding this comment

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

LGTM

src/v/container/include/container/fragmented_vector.h Outdated Show resolved Hide resolved
This is similar to pop_back_n but takes an iterator and is a more
directly replacement for use cases which are already using iterators.

Additionally, allow const_iterator to be converted to iterator, which
is what standard containers do and is important for ergonomics.
rockwotj
rockwotj previously approved these changes Feb 8, 2024
Override the decode path to use chunked_vector for creatable_topic as
we may have 10,000s of these in a single API request.

Arguably, we could use chunked_vector everywhere now in schemata and
get rid of this override, but let's do that later.

Fixes redpanda-data#16521.
@vbotbuildovich
Copy link
Collaborator

@travisdowns travisdowns merged commit 02ef9fb into redpanda-data:dev Feb 9, 2024
18 checks passed
@vbotbuildovich
Copy link
Collaborator

/backport v23.3.x

@vbotbuildovich
Copy link
Collaborator

Failed to create a backport PR to v23.3.x branch. I tried:

git remote add upstream https://github.com/redpanda-data/redpanda.git
git fetch --all
git checkout -b backport-pr-16529-v23.3.x-907 remotes/upstream/v23.3.x
git cherry-pick -x 0eaea00d9f8f034fc2177540cc88266543c64f00 5e5b4e885e5104ae7bc958dc6b88601320946f30 51fda27d0da756376929f2c2b864f8b186dd91d1

Workflow run logs.

@travisdowns
Copy link
Member Author

/backport v23.3.x

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

Successfully merging this pull request may close these issues.

Redpanda reports oversized allocation when trying to create topics near the partition limit
4 participants