-
Notifications
You must be signed in to change notification settings - Fork 580
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
[CORE-7061] sr/store: Deep copy schema_def iobufs at the interface #23114
Merged
michael-redpanda
merged 1 commit into
redpanda-data:dev
from
oleiman:sr/core-7061/get-subj-ver-segfault
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2024 Redpanda Data, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.md | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0 | ||
|
||
#include "pandaproxy/schema_registry/error.h" | ||
#include "pandaproxy/schema_registry/exceptions.h" | ||
#include "pandaproxy/schema_registry/protobuf.h" | ||
#include "pandaproxy/schema_registry/sharded_store.h" | ||
#include "pandaproxy/schema_registry/test/compatibility_protobuf.h" | ||
#include "pandaproxy/schema_registry/types.h" | ||
|
||
#include <seastar/core/loop.hh> | ||
#include <seastar/testing/thread_test_case.hh> | ||
#include <seastar/util/defer.hh> | ||
|
||
#include <boost/range/irange.hpp> | ||
#include <boost/test/unit_test.hpp> | ||
|
||
namespace pp = pandaproxy; | ||
namespace pps = pp::schema_registry; | ||
|
||
SEASTAR_THREAD_TEST_CASE(test_sharded_store_cross_shard_def) { | ||
constexpr size_t id_n = 1000; | ||
pps::sharded_store store; | ||
store.start(pps::is_mutable::yes, ss::default_smp_service_group()).get(); | ||
auto stop_store = ss::defer([&store] { store.stop().get(); }); | ||
|
||
const pps::schema_version ver1{1}; | ||
|
||
// Upsert a large(ish) number of schemas to the store, all with different | ||
// subject names and IDs, so they should hash to different shards. | ||
for (int i = 1; i <= id_n; ++i) { | ||
auto referenced_schema = pps::canonical_schema{ | ||
pps::subject{fmt::format("simple_{}.proto", i)}, simple.share()}; | ||
store | ||
.upsert( | ||
pps::seq_marker{ | ||
std::nullopt, | ||
std::nullopt, | ||
ver1, | ||
pps::seq_marker_key_type::schema}, | ||
referenced_schema.copy(), | ||
pps::schema_id{i}, | ||
ver1, | ||
pps::is_deleted::no) | ||
.get(); | ||
} | ||
|
||
BOOST_REQUIRE(store.has_schema(pps::schema_id{id_n}).get()); | ||
|
||
// for each upserted schema, submit a number of concurrent | ||
// get_schema_definition requests, spreading the requests across cores. the | ||
// goal here is to have copies of a particular schema live on shards other | ||
// than the "home" shard of that schema. previously, when | ||
// 'store::get_schema_definition' was implemented with an iobuf share at the | ||
// interface, this loop would reliably lead to a UAF segfault in | ||
// '~ss::deleter()', the refcounted, non-thread-safe deleter for the | ||
// temporary buffers underlying the shared iobuf. | ||
for (int i = 1; i <= id_n; ++i) { | ||
constexpr int num_parallel_requests = 20; | ||
ss::parallel_for_each( | ||
boost::irange(0, num_parallel_requests), | ||
[&store, i](auto shrd) { | ||
return ss::smp::submit_to(shrd % ss::smp::count, [&store, i]() { | ||
return store.get_schema_definition(pps::schema_id{i}) | ||
.discard_result(); | ||
}); | ||
}) | ||
.get(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same schema should end up with the same ID, so the comment is a little confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In real operation, yeah, but I thought that disambiguation happened somewhere else, like on the command apply path? it looks like when I directly upsert, sharded store is happy to shove an
(id, def)
pair into the schema map in memory on shardhash(id)
as requested. I might be missing/misreading something.