Skip to content

Commit

Permalink
Optimizations to metadata path
Browse files Browse the repository at this point in the history
We see out of memory errors on the metadata path for large
partition counts. One problematic place would have 3 or 4 copies of the
partition list in flight at once.

This change avoids this code entirely in the usual case that the
metadata request isn't having a side effect of creating new topics
and reduces copies even if it is.

Issue redpanda-data#5563.
  • Loading branch information
travisdowns committed Aug 11, 2022
1 parent 161811a commit 42b4efa
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/v/kafka/server/handlers/metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <seastar/core/coroutine.hh>
#include <seastar/core/future-util.hh>
#include <seastar/core/future.hh>
#include <seastar/core/thread.hh>

#include <boost/numeric/conversion/cast.hpp>
Expand Down Expand Up @@ -280,12 +281,19 @@ get_topic_metadata(request_context& ctx, metadata_request& request) {
new_topics.push_back(create_topic(ctx, std::move(topic.name)));
}

return ss::when_all_succeed(new_topics.begin(), new_topics.end())
.then([res = std::move(res)](
std::vector<metadata_response::topic> topics) mutable {
res.insert(res.end(), topics.begin(), topics.end());
return res;
});
if (new_topics.empty()) {
// if we have no new topics to create (which is the overwhelmingly
// common case), we just return the ready future as an optimization
return ss::make_ready_future<std::vector<metadata_response::topic>>(
std::move(res));
} else {
return ss::when_all_succeed(new_topics.begin(), new_topics.end())
.then([res = std::move(res)](
const std::vector<metadata_response::topic>& topics) mutable {
res.insert(res.end(), topics.begin(), topics.end());
return std::move(res);
});
}
}

/**
Expand Down

0 comments on commit 42b4efa

Please sign in to comment.