Skip to content

Commit

Permalink
db::extensions: Allow extensions to modify (system) schemas
Browse files Browse the repository at this point in the history
Allows extensions/config listeners to potentially augument
(system) schemas at boot time. This is only useful for schemas
who do not pass through system_schema tables.
  • Loading branch information
Calle Wilund committed Mar 26, 2018
1 parent bb1a2c6 commit ff41f47
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions db/extensions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "extensions.hh"
#include "sstables/sstables.hh"
#include "commitlog/commitlog_extensions.hh"
#include "schema.hh"

db::extensions::extensions()
{}
Expand All @@ -36,3 +37,7 @@ void db::extensions::add_sstable_file_io_extension(sstring n, sstable_file_io_ex
void db::extensions::add_commitlog_file_extension(sstring n, commitlog_file_extension_ptr f) {
_commitlog_file_extensions[n] = std::move(f);
}

void db::extensions::add_extension_to_schema(schema_ptr s, const sstring& name, shared_ptr<schema_extension> ext) {
const_cast<schema *>(s.get())->extensions()[name] = std::move(ext);
}
9 changes: 9 additions & 0 deletions db/extensions.hh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "stdx.hh"
#include "bytes.hh"
#include "cql3/statements/property_definitions.hh"
#include "schema.hh"

class schema_extension;

Expand Down Expand Up @@ -118,6 +119,14 @@ public:
* Init time method to add sstable extension
*/
void add_commitlog_file_extension(sstring n, commitlog_file_extension_ptr);

/**
* Allows forcible modification of schema extensions of a schema. This should
* not be done lightly however. In fact, it should only be done on startup
* at most, and thus this method is non-const, i.e. you can only use it on
* config apply.
*/
void add_extension_to_schema(schema_ptr, const sstring&, shared_ptr<schema_extension>);
private:
std::map<sstring, schema_ext_create_func> _schema_extensions;
std::map<sstring, sstable_file_io_extension> _sstable_file_io_extensions;
Expand Down
1 change: 1 addition & 0 deletions db/system_keyspace.hh
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ struct range_estimates {

extern schema_ptr hints();
extern schema_ptr batchlog();
extern schema_ptr paxos();
extern schema_ptr built_indexes(); // TODO (from Cassandra): make private

namespace legacy {
Expand Down
8 changes: 8 additions & 0 deletions schema.hh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ bool check_compound(sstring comparator);
void read_collections(schema_builder& builder, sstring comparator);
}

namespace db {
class extensions;
}
// make sure these match the order we like columns back from schema
enum class column_kind { partition_key, clustering_key, static_column, regular_column };

Expand Down Expand Up @@ -515,6 +518,11 @@ private:
column_mapping _column_mapping;
shared_ptr<query::partition_slice> _full_slice;

extensions_map& extensions() {
return _raw._extensions;
}

friend class db::extensions;
friend class schema_builder;
public:
using row_column_ids_are_ordered_by_name = std::true_type;
Expand Down

0 comments on commit ff41f47

Please sign in to comment.