In the following patch we plan to remove the base schema from the base_info to make the base_info immutable. To do that, we first prepare the schema registry for the change; we need to be able to create view schemas from frozen schemas there and frozen schemas have no information about the base table. Unless we do this change, after base schemas are removed from the base info, we'll no longer be able to load a view schema to the schema registry without looking up the base schema in the database. This change also required some updates to schema building: * we add a method for unfreezing a view schema with base info instead of a base schema * we make it possible to use schema_builder with a base info instead of a base schema * we add a method for creating a view schema from mutations with a base info instead of a base schema * we add a view_info constructor withat base info instead of a base schema * we update the naming in schema_registry to reflect the usage of base info instead of base schema
51 lines
1.6 KiB
C++
51 lines
1.6 KiB
C++
/*
|
|
* Copyright 2015-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
|
|
*/
|
|
|
|
#include "frozen_schema.hh"
|
|
#include "db/schema_tables.hh"
|
|
#include "db/view/view.hh"
|
|
#include "mutation/canonical_mutation.hh"
|
|
#include "schema_mutations.hh"
|
|
#include "idl/frozen_schema.dist.hh"
|
|
#include "idl/frozen_schema.dist.impl.hh"
|
|
|
|
frozen_schema::frozen_schema(const schema_ptr& s)
|
|
: _data([&s] {
|
|
schema_mutations sm = db::schema_tables::make_schema_mutations(s, api::new_timestamp(), true);
|
|
bytes_ostream out;
|
|
ser::writer_of_schema<bytes_ostream> wr(out);
|
|
std::move(wr).write_version(s->version())
|
|
.write_mutations(sm)
|
|
.end_schema();
|
|
return out;
|
|
}())
|
|
{ }
|
|
|
|
schema_ptr frozen_schema::unfreeze(const db::schema_ctxt& ctxt, std::optional<db::view::base_dependent_view_info> base_info) const {
|
|
auto in = ser::as_input_stream(_data);
|
|
auto sv = ser::deserialize(in, std::type_identity<ser::schema_view>());
|
|
auto sm = sv.mutations();
|
|
if (sm.is_view()) {
|
|
return db::schema_tables::create_view_from_mutations(ctxt, std::move(sm), std::move(base_info), sv.version());
|
|
} else {
|
|
if (base_info) {
|
|
throw std::runtime_error("Trying to unfreeze regular table schema with base info");
|
|
}
|
|
return db::schema_tables::create_table_from_mutations(ctxt, std::move(sm), sv.version());
|
|
}
|
|
}
|
|
|
|
frozen_schema::frozen_schema(bytes_ostream b)
|
|
: _data(std::move(b))
|
|
{ }
|
|
|
|
const bytes_ostream& frozen_schema::representation() const
|
|
{
|
|
return _data;
|
|
}
|