mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-21 09:00:35 +00:00
db: make column_family a class, not a struct
Don't expose privates in public.
This commit is contained in:
20
database.cc
20
database.cc
@@ -174,6 +174,12 @@ future<> column_family::probe_file(sstring sstdir, sstring fname) {
|
||||
return make_ready_future<>();
|
||||
}
|
||||
|
||||
const std::map<dht::decorated_key, mutation_partition, dht::decorated_key::less_comparator>&
|
||||
column_family::all_partitions() const {
|
||||
return partitions;
|
||||
}
|
||||
|
||||
|
||||
future<> column_family::populate(sstring sstdir) {
|
||||
|
||||
return lister::scan_dir(sstdir, directory_entry_type::regular, [this, sstdir] (directory_entry de) {
|
||||
@@ -291,22 +297,22 @@ void database::drop_keyspace(const sstring& name) {
|
||||
}
|
||||
|
||||
void database::add_column_family(const utils::UUID& uuid, column_family&& cf) {
|
||||
if (_keyspaces.count(cf._schema->ks_name()) == 0) {
|
||||
throw std::invalid_argument("Keyspace " + cf._schema->ks_name() + " not defined");
|
||||
if (_keyspaces.count(cf.schema()->ks_name()) == 0) {
|
||||
throw std::invalid_argument("Keyspace " + cf.schema()->ks_name() + " not defined");
|
||||
}
|
||||
if (_column_families.count(uuid) != 0) {
|
||||
throw std::invalid_argument("UUID " + uuid.to_sstring() + " already mapped");
|
||||
}
|
||||
auto kscf = std::make_pair(cf._schema->ks_name(), cf._schema->cf_name());
|
||||
auto kscf = std::make_pair(cf.schema()->ks_name(), cf.schema()->cf_name());
|
||||
if (_ks_cf_to_uuid.count(kscf) != 0) {
|
||||
throw std::invalid_argument("Column family " + cf._schema->cf_name() + " exists");
|
||||
throw std::invalid_argument("Column family " + cf.schema()->cf_name() + " exists");
|
||||
}
|
||||
_column_families.emplace(uuid, std::move(cf));
|
||||
_ks_cf_to_uuid.emplace(std::move(kscf), uuid);
|
||||
}
|
||||
|
||||
void database::add_column_family(column_family&& cf) {
|
||||
auto id = cf._schema->id();
|
||||
auto id = cf.schema()->id();
|
||||
add_column_family(id, std::move(cf));
|
||||
}
|
||||
|
||||
@@ -406,7 +412,7 @@ schema_ptr database::find_schema(const sstring& ks_name, const sstring& cf_name)
|
||||
}
|
||||
|
||||
schema_ptr database::find_schema(const utils::UUID& uuid) const throw (no_such_column_family) {
|
||||
return find_column_family(uuid)._schema;
|
||||
return find_column_family(uuid).schema();
|
||||
}
|
||||
|
||||
keyspace&
|
||||
@@ -553,7 +559,7 @@ std::ostream& operator<<(std::ostream& out, const database& db) {
|
||||
out << "{\n";
|
||||
for (auto&& e : db._column_families) {
|
||||
auto&& cf = e.second;
|
||||
out << "(" << e.first.to_sstring() << ", " << cf._schema->cf_name() << ", " << cf._schema->ks_name() << "): " << cf << "\n";
|
||||
out << "(" << e.first.to_sstring() << ", " << cf.schema()->cf_name() << ", " << cf.schema()->ks_name() << "): " << cf << "\n";
|
||||
}
|
||||
out << "}";
|
||||
return out;
|
||||
|
||||
15
database.hh
15
database.hh
@@ -53,30 +53,35 @@ class commitlog;
|
||||
class config;
|
||||
}
|
||||
|
||||
struct column_family {
|
||||
class column_family {
|
||||
schema_ptr _schema;
|
||||
std::map<dht::decorated_key, mutation_partition, dht::decorated_key::less_comparator> partitions;
|
||||
// generation -> sstable. Ordered by key so we can easily get the most recent.
|
||||
std::map<unsigned long, std::unique_ptr<sstables::sstable>> _sstables;
|
||||
public:
|
||||
column_family(schema_ptr schema);
|
||||
column_family(column_family&&) = default;
|
||||
~column_family();
|
||||
schema_ptr schema() const { return _schema; }
|
||||
mutation_partition& find_or_create_partition(const dht::decorated_key& key);
|
||||
mutation_partition& find_or_create_partition_slow(const partition_key& key);
|
||||
const mutation_partition* find_partition(const dht::decorated_key& key) const;
|
||||
const mutation_partition* find_partition_slow(const partition_key& key) const;
|
||||
row& find_or_create_row_slow(const partition_key& partition_key, const clustering_key& clustering_key);
|
||||
const row* find_row(const dht::decorated_key& partition_key, const clustering_key& clustering_key) const;
|
||||
schema_ptr _schema;
|
||||
std::map<dht::decorated_key, mutation_partition, dht::decorated_key::less_comparator> partitions;
|
||||
void apply(const mutation& m);
|
||||
// Returns at most "cmd.limit" rows
|
||||
future<lw_shared_ptr<query::result>> query(const query::read_command& cmd) const;
|
||||
|
||||
future<> populate(sstring datadir);
|
||||
const std::map<dht::decorated_key, mutation_partition, dht::decorated_key::less_comparator>& all_partitions() const;
|
||||
private:
|
||||
// generation -> sstable. Ordered by key so we can easily get the most recent.
|
||||
std::map<unsigned long, std::unique_ptr<sstables::sstable>> _sstables;
|
||||
future<> probe_file(sstring sstdir, sstring fname);
|
||||
// Returns at most "limit" rows. The limit must be greater than 0.
|
||||
void get_partition_slice(mutation_partition& partition, const query::partition_slice& slice,
|
||||
uint32_t limit, query::result::partition_writer&);
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& out, const column_family& cf);
|
||||
};
|
||||
|
||||
class user_types_metadata {
|
||||
|
||||
@@ -984,11 +984,11 @@ future<> write_datafile(column_family& cf, sstring datafile) {
|
||||
|
||||
// Iterate through CQL partitions, then CQL rows, then CQL columns.
|
||||
// Each cf.partitions entry is a set of clustered rows sharing the same partition key.
|
||||
return do_for_each(cf.partitions,
|
||||
[w, &cf] (std::pair<const dht::decorated_key, mutation_partition>& partition_entry) {
|
||||
return do_for_each(cf.all_partitions(),
|
||||
[w, &cf] (const std::pair<const dht::decorated_key, mutation_partition>& partition_entry) {
|
||||
// TODO: Write index and summary files on-the-fly.
|
||||
|
||||
key partition_key = key::from_partition_key(*cf._schema, partition_entry.first._key);
|
||||
key partition_key = key::from_partition_key(*cf.schema(), partition_entry.first._key);
|
||||
|
||||
return do_with(std::move(partition_key), [w, &partition_entry] (auto& partition_key) {
|
||||
disk_string_view<uint16_t> p_key;
|
||||
@@ -1015,11 +1015,11 @@ future<> write_datafile(column_family& cf, sstring datafile) {
|
||||
auto& partition = partition_entry.second;
|
||||
|
||||
auto& static_row = partition.static_row();
|
||||
return write_static_row(*w, cf._schema, static_row).then([w, &cf, &partition] {
|
||||
return write_static_row(*w, cf.schema(), static_row).then([w, &cf, &partition] {
|
||||
|
||||
// Write all CQL rows from a given mutation partition.
|
||||
return do_for_each(partition.clustered_rows(), [w, &cf] (const rows_entry& clustered_row) {
|
||||
return write_clustered_row(*w, cf._schema, clustered_row);
|
||||
return write_clustered_row(*w, cf.schema(), clustered_row);
|
||||
}).then([w] {
|
||||
// end_of_row is appended to the end of each partition.
|
||||
int16_t end_of_row = 0;
|
||||
|
||||
@@ -118,7 +118,7 @@ public:
|
||||
boost::any expected) override {
|
||||
auto& db = _db->local();
|
||||
auto& cf = db.find_column_family(ks_name, table_name);
|
||||
auto schema = cf._schema;
|
||||
auto schema = cf.schema();
|
||||
auto pkey = partition_key::from_deeply_exploded(*schema, pk);
|
||||
auto dk = dht::global_partitioner().decorate_key(*schema, pkey);
|
||||
auto shard = db.shard_of(dk._token);
|
||||
@@ -129,7 +129,7 @@ public:
|
||||
expected = std::move(expected),
|
||||
table_name = std::move(table_name)] (database& db) {
|
||||
auto& cf = db.find_column_family(ks_name, table_name);
|
||||
auto schema = cf._schema;
|
||||
auto schema = cf.schema();
|
||||
auto p = cf.find_partition_slow(pkey);
|
||||
assert(p != nullptr);
|
||||
auto row = p->find_row(clustering_key::from_deeply_exploded(*schema, ck));
|
||||
|
||||
@@ -133,15 +133,15 @@ public:
|
||||
throw unimplemented_exception();
|
||||
} else if (predicate.__isset.slice_range) {
|
||||
auto&& range = predicate.slice_range;
|
||||
const row* rw = cf.find_row(dk, clustering_key::make_empty(*cf._schema));
|
||||
const row* rw = cf.find_row(dk, clustering_key::make_empty(*cf.schema()));
|
||||
if (rw) {
|
||||
auto beg = cf._schema->regular_begin();
|
||||
auto beg = cf.schema()->regular_begin();
|
||||
if (!range.start.empty()) {
|
||||
beg = cf._schema->regular_lower_bound(to_bytes(range.start));
|
||||
beg = cf.schema()->regular_lower_bound(to_bytes(range.start));
|
||||
}
|
||||
auto end = cf._schema->regular_end();
|
||||
auto end = cf.schema()->regular_end();
|
||||
if (!range.finish.empty()) {
|
||||
end = cf._schema->regular_upper_bound(to_bytes(range.finish));
|
||||
end = cf.schema()->regular_upper_bound(to_bytes(range.finish));
|
||||
}
|
||||
auto count = range.count;
|
||||
// FIXME: force limit count?
|
||||
@@ -253,15 +253,15 @@ public:
|
||||
sstring cf_name = cf_mutations.first;
|
||||
const std::vector<Mutation>& mutations = cf_mutations.second;
|
||||
auto& cf = lookup_column_family(_db.local(), _ks_name, cf_name);
|
||||
mutation m_to_apply(key_from_thrift(cf._schema, thrift_key), cf._schema);
|
||||
auto empty_clustering_key = clustering_key::make_empty(*cf._schema);
|
||||
mutation m_to_apply(key_from_thrift(cf.schema(), thrift_key), cf.schema());
|
||||
auto empty_clustering_key = clustering_key::make_empty(*cf.schema());
|
||||
for (const Mutation& m : mutations) {
|
||||
if (m.__isset.column_or_supercolumn) {
|
||||
auto&& cosc = m.column_or_supercolumn;
|
||||
if (cosc.__isset.column) {
|
||||
auto&& col = cosc.column;
|
||||
bytes cname = to_bytes(col.name);
|
||||
auto def = cf._schema->get_column_definition(cname);
|
||||
auto def = cf.schema()->get_column_definition(cname);
|
||||
if (!def) {
|
||||
throw make_exception<InvalidRequestException>("column %s not found", col.name);
|
||||
}
|
||||
@@ -273,7 +273,7 @@ public:
|
||||
ttl = std::chrono::duration_cast<gc_clock::duration>(std::chrono::seconds(col.ttl));
|
||||
}
|
||||
if (ttl.count() <= 0) {
|
||||
ttl = cf._schema->default_time_to_live();
|
||||
ttl = cf.schema()->default_time_to_live();
|
||||
}
|
||||
auto ttl_option = ttl.count() > 0 ? ttl_opt(gc_clock::now() + ttl) : ttl_opt();
|
||||
m_to_apply.set_clustered_cell(empty_clustering_key, *def,
|
||||
|
||||
Reference in New Issue
Block a user