Skip to content

Commit

Permalink
schema: make private constructor invokable via make_lw_shared
Browse files Browse the repository at this point in the history
The schema has a private constructor, which means it can't be
constructed with `make_lw_shared()` even by classes which are otherwise
able to invoke the private constructor themselves.
This results in such classes (`schema_builder`) resorting to building a
local schema object, then invoking `make_lw_shared()` with the schema's
public move constructor. Moving a schema is not cheap at all however, so
each `schema_builder::build()` call results in two expensive schema
construction operations.
We could make `make_lw_shared()` a friend of `schema` to resolve this,
but then we'd de-facto open the private consctructor to the world.
Instead this patch introduces a private tag type, which is added to the
private constructor, which is then made public. Everybody can invoke the
constructor but only friends can create the private tag instance
required to actually call it.

Signed-off-by: Botond Dénes <bdenes@scylladb.com>
Message-Id: <20211105085940.359708-1-bdenes@scylladb.com>
  • Loading branch information
denesb authored and avikivity committed Nov 7, 2021
1 parent 31bc1eb commit e991604
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ schema::raw_schema::raw_schema(utils::UUID id)
, _sharder(::get_sharder(smp::count, default_partitioner_ignore_msb))
{ }

schema::schema(const raw_schema& raw, std::optional<raw_view_info> raw_view_info)
schema::schema(private_tag, const raw_schema& raw, std::optional<raw_view_info> raw_view_info)
: _raw(raw)
, _offsets([this] {
if (_raw._columns.size() > std::numeric_limits<column_count_type>::max()) {
Expand Down Expand Up @@ -1227,7 +1227,7 @@ schema_ptr schema_builder::build() {
dynamic_pointer_cast<db::paxos_grace_seconds_extension>(it->second)->get_paxos_grace_seconds();
}

return make_lw_shared<schema>(schema(new_raw, _view_info));
return make_lw_shared<schema>(schema::private_tag{}, new_raw, _view_info);
}

const cdc::options& schema::cdc_options() const {
Expand Down
3 changes: 2 additions & 1 deletion schema.hh
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,10 @@ private:

lw_shared_ptr<cql3::column_specification> make_column_specification(const column_definition& def);
void rebuild();
schema(const raw_schema&, std::optional<raw_view_info>);
schema(const schema&, const std::function<void(schema&)>&);
class private_tag{};
public:
schema(private_tag, const raw_schema&, std::optional<raw_view_info>);
schema(const schema&);
// See \ref make_reversed().
schema(reversed_tag, const schema&);
Expand Down

0 comments on commit e991604

Please sign in to comment.