Skip to content

Commit

Permalink
db/legacy_schema_tables: Store CF key validator in system tables
Browse files Browse the repository at this point in the history
Store the column family key validator in system tables. Please note that
we derive the validator from CQL partition keys and never actually read
it from the database. This is different from Origin which uses
CompositeType that is both stored and read from the system tables.

Fixes #7.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Tested-by: Pekka Enberg <penberg@cloudius-systems.com>
  • Loading branch information
Pekka Enberg authored and avikivity committed Jul 6, 2015
1 parent 93bf8fa commit c24b7d4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 0 additions & 1 deletion cql3/statements/create_table_statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ void create_table_statement::apply_properties_to(schema_builder& builder) {
}
#if 0
cfmd.defaultValidator(defaultValidator)
.keyValidator(keyValidator)
.addAllColumnDefinitions(getColumns(cfmd))
.isDense(isDense);
#endif
Expand Down
5 changes: 3 additions & 2 deletions db/legacy_schema_tables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,9 @@ std::vector<const char*> ALL { KEYSPACES, COLUMNFAMILIES, COLUMNS, TRIGGERS, USE
#if 0
adder.add("default_validator", table.getDefaultValidator().toString());
adder.add("gc_grace_seconds", table.getGcGraceSeconds());
adder.add("key_validator", table.getKeyValidator().toString());
#endif
m.set_clustered_cell(ckey, "key_validator", table->thrift_key_validator(), timestamp);
#if 0
adder.add("local_read_repair_chance", table.getDcLocalReadRepairChance());
adder.add("max_compaction_threshold", table.getMaxCompactionThreshold());
adder.add("max_index_interval", table.getMaxIndexInterval());
Expand Down Expand Up @@ -1247,7 +1249,6 @@ std::vector<const char*> ALL { KEYSPACES, COLUMNFAMILIES, COLUMNS, TRIGGERS, USE
cfm.dcLocalReadRepairChance(result.getDouble("local_read_repair_chance"));
cfm.gcGraceSeconds(result.getInt("gc_grace_seconds"));
cfm.defaultValidator(TypeParser.parse(result.getString("default_validator")));
cfm.keyValidator(TypeParser.parse(result.getString("key_validator")));
cfm.minCompactionThreshold(result.getInt("min_compaction_threshold"));
cfm.maxCompactionThreshold(result.getInt("max_compaction_threshold"));
if (result.has("comment"))
Expand Down
12 changes: 12 additions & 0 deletions schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "schema.hh"
#include "schema_builder.hh"
#include <boost/algorithm/cxx11/any_of.hpp>
#include <boost/range/adaptor/transformed.hpp>

constexpr int32_t schema::NAME_LENGTH;

Expand Down Expand Up @@ -155,6 +156,17 @@ schema::schema(const schema& o)
rebuild();
}

sstring schema::thrift_key_validator() const {
if (partition_key_size() == 1) {
return partition_key_columns().begin()->type->name();
} else {
sstring type_params = ::join(", ", partition_key_columns()
| boost::adaptors::transformed(std::mem_fn(&column_definition::type))
| boost::adaptors::transformed(std::mem_fn(&abstract_type::name)));
return "org.apache.cassandra.db.marshal.CompositeType(" + type_params + ")";
}
}

bool
schema::has_collections() const {
return boost::algorithm::any_of(all_columns_in_select_order(), [] (const column_definition& cdef) {
Expand Down
2 changes: 1 addition & 1 deletion schema.hh
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public:
_raw._bloom_filter_fp_chance = fp;
return *this;
}

sstring thrift_key_validator() const;
void set_compressor_params(compression_parameters c) {
_raw._compressor_params = c;
}
Expand Down

0 comments on commit c24b7d4

Please sign in to comment.