mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-25 11:00:35 +00:00
Merge tag 'schema_properties-v2' from git@github.com:glommer/urchin.git schema_properties-v2
From Glauber: "In order to make describe tables work, we need to wire up a lot of options that cqlsh will expect to be present, and represent the status of the table. The options that I am wiring up here are ones that are more or less "self-suficient", in the sense that we don't need anything else outside the schema itself - that we don't have - to decide. Even is_super(), for instance: while marking a table as super has consequences, code in Origin is expect to explicitly set that value: we don't have to derive it. So we can, for now, just expose it (the same way we do for is_dense), and worry about setting it later. After this patchset, describing a particular table still does not work, *BUT*, it does if write synthetic values for the compaction string/options. I am not going to worry about it now, because Raphael is about to merge some patches that introduce the classes I need anyway. But with those patches here + the compaction data, then it all works"
This commit is contained in:
@@ -165,22 +165,54 @@ public:
|
||||
if (has_property(KW_COMMENT)) {
|
||||
builder.set_comment(get_string(KW_COMMENT, ""));
|
||||
}
|
||||
|
||||
if (has_property(KW_READREPAIRCHANCE)) {
|
||||
builder.set_read_repair_chance(get_double(KW_READREPAIRCHANCE, builder.get_read_repair_chance()));
|
||||
}
|
||||
|
||||
if (has_property(KW_DCLOCALREADREPAIRCHANCE)) {
|
||||
builder.set_dc_local_read_repair_chance(get_double(KW_DCLOCALREADREPAIRCHANCE, builder.get_dc_local_read_repair_chance()));
|
||||
}
|
||||
|
||||
if (has_property(KW_GCGRACESECONDS)) {
|
||||
builder.set_gc_grace_seconds(get_int(KW_GCGRACESECONDS, builder.get_gc_grace_seconds()));
|
||||
}
|
||||
|
||||
std::experimental::optional<sstring> tmp_value = {};
|
||||
if (has_property(KW_MINCOMPACTIONTHRESHOLD)) {
|
||||
if (get_compaction_options().count(KW_MINCOMPACTIONTHRESHOLD)) {
|
||||
tmp_value = get_compaction_options().at(KW_MINCOMPACTIONTHRESHOLD);
|
||||
}
|
||||
}
|
||||
int min_compaction_threshold = to_int(KW_MINCOMPACTIONTHRESHOLD, tmp_value, builder.get_min_compaction_threshold());
|
||||
|
||||
tmp_value = {};
|
||||
if (has_property(KW_MAXCOMPACTIONTHRESHOLD)) {
|
||||
if (get_compaction_options().count(KW_MAXCOMPACTIONTHRESHOLD)) {
|
||||
tmp_value = get_compaction_options().at(KW_MAXCOMPACTIONTHRESHOLD);
|
||||
}
|
||||
}
|
||||
int max_compaction_threshold = to_int(KW_MAXCOMPACTIONTHRESHOLD, tmp_value, builder.get_max_compaction_threshold());
|
||||
|
||||
if (min_compaction_threshold <= 0 || max_compaction_threshold <= 0)
|
||||
throw exceptions::configuration_exception("Disabling compaction by setting compaction thresholds to 0 has been deprecated, set the compaction option 'enabled' to false instead.");
|
||||
builder.set_min_compaction_threshold(min_compaction_threshold);
|
||||
builder.set_max_compaction_threshold(max_compaction_threshold);
|
||||
|
||||
#if 0
|
||||
cfm.readRepairChance(getDouble(KW_READREPAIRCHANCE, cfm.getReadRepairChance()));
|
||||
cfm.dcLocalReadRepairChance(getDouble(KW_DCLOCALREADREPAIRCHANCE, cfm.getDcLocalReadRepairChance()));
|
||||
cfm.gcGraceSeconds(getInt(KW_GCGRACESECONDS, cfm.getGcGraceSeconds()));
|
||||
int minCompactionThreshold = toInt(KW_MINCOMPACTIONTHRESHOLD, getCompactionOptions().get(KW_MINCOMPACTIONTHRESHOLD), cfm.getMinCompactionThreshold());
|
||||
int maxCompactionThreshold = toInt(KW_MAXCOMPACTIONTHRESHOLD, getCompactionOptions().get(KW_MAXCOMPACTIONTHRESHOLD), cfm.getMaxCompactionThreshold());
|
||||
if (minCompactionThreshold <= 0 || maxCompactionThreshold <= 0)
|
||||
throw new ConfigurationException("Disabling compaction by setting compaction thresholds to 0 has been deprecated, set the compaction option 'enabled' to false instead.");
|
||||
cfm.minCompactionThreshold(minCompactionThreshold);
|
||||
cfm.maxCompactionThreshold(maxCompactionThreshold);
|
||||
cfm.defaultTimeToLive(getInt(KW_DEFAULT_TIME_TO_LIVE, cfm.getDefaultTimeToLive()));
|
||||
cfm.speculativeRetry(CFMetaData.SpeculativeRetry.fromString(getString(KW_SPECULATIVE_RETRY, cfm.getSpeculativeRetry().toString())));
|
||||
cfm.memtableFlushPeriod(getInt(KW_MEMTABLE_FLUSH_PERIOD, cfm.getMemtableFlushPeriod()));
|
||||
cfm.minIndexInterval(getInt(KW_MIN_INDEX_INTERVAL, cfm.getMinIndexInterval()));
|
||||
cfm.maxIndexInterval(getInt(KW_MAX_INDEX_INTERVAL, cfm.getMaxIndexInterval()));
|
||||
#endif
|
||||
if (has_property(KW_MIN_INDEX_INTERVAL)) {
|
||||
builder.set_min_index_interval(get_int(KW_MIN_INDEX_INTERVAL, builder.get_min_index_interval()));
|
||||
}
|
||||
|
||||
if (has_property(KW_MAX_INDEX_INTERVAL)) {
|
||||
builder.set_max_index_interval(get_int(KW_MAX_INDEX_INTERVAL, builder.get_max_index_interval()));
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (compactionStrategyClass != null)
|
||||
{
|
||||
cfm.compactionStrategyClass(compactionStrategyClass);
|
||||
|
||||
@@ -1001,25 +1001,20 @@ future<> save_system_keyspace_schema() {
|
||||
mutation m{pkey, s};
|
||||
auto ckey = clustering_key::from_single_value(*s, to_bytes(table->cf_name()));
|
||||
m.set_clustered_cell(ckey, "cf_id", table->id(), timestamp);
|
||||
m.set_clustered_cell(ckey, "type", cf_type_to_sstring(table->type()), timestamp);
|
||||
|
||||
if (table->is_super()) {
|
||||
warn(unimplemented::cause::SUPER);
|
||||
#if 0
|
||||
m.set_clustered_cell(ckey, "type", table.cfType.toString(), timestamp);
|
||||
#endif
|
||||
#if 0
|
||||
if (table.isSuper())
|
||||
{
|
||||
// We need to continue saving the comparator and subcomparator separatly, otherwise
|
||||
// we won't know at deserialization if the subcomparator should be taken into account
|
||||
// TODO: we should implement an on-start migration if we want to get rid of that.
|
||||
adder.add("comparator", table.comparator.subtype(0).toString());
|
||||
adder.add("subcomparator", table.comparator.subtype(1).toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
} else {
|
||||
m.set_clustered_cell(ckey, "comparator", table->regular_column_name_type()->name(), timestamp);
|
||||
#if 0
|
||||
}
|
||||
#endif
|
||||
|
||||
m.set_clustered_cell(ckey, "bloom_filter_fp_chance", table->bloom_filter_fp_chance(), timestamp);
|
||||
#if 0
|
||||
@@ -1034,18 +1029,18 @@ future<> save_system_keyspace_schema() {
|
||||
m.set_clustered_cell(ckey, "compression_parameters", json::to_json(compression_options.get_options()), timestamp);
|
||||
m.set_clustered_cell(ckey, "default_time_to_live", table->default_time_to_live().count(), timestamp);
|
||||
m.set_clustered_cell(ckey, "default_validator", table->default_validator()->name(), timestamp);
|
||||
#if 0
|
||||
adder.add("gc_grace_seconds", table.getGcGraceSeconds());
|
||||
#endif
|
||||
m.set_clustered_cell(ckey, "gc_grace_seconds", table->gc_grace_seconds(), timestamp);
|
||||
m.set_clustered_cell(ckey, "key_validator", table->thrift_key_validator(), timestamp);
|
||||
m.set_clustered_cell(ckey, "local_read_repair_chance", table->dc_local_read_repair_chance(), timestamp);
|
||||
m.set_clustered_cell(ckey, "min_compaction_threshold", table->min_compaction_threshold(), timestamp);
|
||||
m.set_clustered_cell(ckey, "max_compaction_threshold", table->max_compaction_threshold(), timestamp);
|
||||
m.set_clustered_cell(ckey, "min_index_interval", table->min_index_interval(), timestamp);
|
||||
m.set_clustered_cell(ckey, "max_index_interval", table->max_index_interval(), 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());
|
||||
adder.add("memtable_flush_period_in_ms", table.getMemtableFlushPeriod());
|
||||
adder.add("min_compaction_threshold", table.getMinCompactionThreshold());
|
||||
adder.add("min_index_interval", table.getMinIndexInterval());
|
||||
adder.add("read_repair_chance", table.getReadRepairChance());
|
||||
#endif
|
||||
m.set_clustered_cell(ckey, "read_repair_chance", table->read_repair_chance(), timestamp);
|
||||
#if 0
|
||||
adder.add("speculative_retry", table.getSpeculativeRetry().toString());
|
||||
|
||||
for (Map.Entry<ColumnIdentifier, Long> entry : table.getDroppedColumns().entrySet())
|
||||
@@ -1225,16 +1220,24 @@ future<> save_system_keyspace_schema() {
|
||||
#if 0
|
||||
AbstractType<?> rawComparator = TypeParser.parse(result.getString("comparator"));
|
||||
AbstractType<?> subComparator = result.has("subcomparator") ? TypeParser.parse(result.getString("subcomparator")) : null;
|
||||
ColumnFamilyType cfType = ColumnFamilyType.valueOf(result.getString("type"));
|
||||
#endif
|
||||
|
||||
cf_type cf = cf_type::standard;
|
||||
if (table_row.has("type")) {
|
||||
cf = sstring_to_cf_type(table_row.get_nonnull<sstring>("type"));
|
||||
if (cf == cf_type::super) {
|
||||
fail(unimplemented::cause::SUPER);
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
AbstractType<?> fullRawComparator = CFMetaData.makeRawAbstractType(rawComparator, subComparator);
|
||||
#endif
|
||||
|
||||
std::vector<column_definition> column_defs = create_columns_from_column_rows(serialized_column_definitions,
|
||||
ks_name,
|
||||
cf_name/*,
|
||||
fullRawComparator,
|
||||
cfType == ColumnFamilyType.Super*/);
|
||||
cf_name,/*,
|
||||
fullRawComparator, */
|
||||
cf == cf_type::super);
|
||||
|
||||
bool is_dense;
|
||||
if (table_row.has("is_dense")) {
|
||||
@@ -1257,18 +1260,31 @@ future<> save_system_keyspace_schema() {
|
||||
#endif
|
||||
builder.set_is_dense(is_dense);
|
||||
|
||||
#if 0
|
||||
cfm.readRepairChance(result.getDouble("read_repair_chance"));
|
||||
cfm.dcLocalReadRepairChance(result.getDouble("local_read_repair_chance"));
|
||||
cfm.gcGraceSeconds(result.getInt("gc_grace_seconds"));
|
||||
#endif
|
||||
if (table_row.has("read_repair_chance")) {
|
||||
builder.set_read_repair_chance(table_row.get_nonnull<double>("read_repair_chance"));
|
||||
}
|
||||
|
||||
if (table_row.has("local_read_repair_chance")) {
|
||||
builder.set_dc_local_read_repair_chance(table_row.get_nonnull<double>("local_read_repair_chance"));
|
||||
}
|
||||
|
||||
if (table_row.has("gc_grace_seconds")) {
|
||||
builder.set_gc_grace_seconds(table_row.get_nonnull<int32_t>("gc_grace_seconds"));
|
||||
}
|
||||
|
||||
if (table_row.has("default_validator")) {
|
||||
builder.set_default_validator(parse_type(table_row.get_nonnull<sstring>("default_validator")));
|
||||
}
|
||||
|
||||
if (table_row.has("min_compaction_threshold")) {
|
||||
builder.set_min_compaction_threshold(table_row.get_nonnull<int>("min_compaction_threshold"));
|
||||
}
|
||||
|
||||
if (table_row.has("max_compaction_threshold")) {
|
||||
builder.set_max_compaction_threshold(table_row.get_nonnull<int>("max_compaction_threshold"));
|
||||
}
|
||||
|
||||
#if 0
|
||||
cfm.minCompactionThreshold(result.getInt("min_compaction_threshold"));
|
||||
cfm.maxCompactionThreshold(result.getInt("max_compaction_threshold"));
|
||||
if (result.has("comment"))
|
||||
cfm.comment(result.getString("comment"));
|
||||
if (result.has("memtable_flush_period_in_ms"))
|
||||
@@ -1285,14 +1301,16 @@ future<> save_system_keyspace_schema() {
|
||||
builder.set_compressor_params(cp);
|
||||
#if 0
|
||||
cfm.compactionStrategyOptions(fromJsonMap(result.getString("compaction_strategy_options")));
|
||||
|
||||
if (result.has("min_index_interval"))
|
||||
cfm.minIndexInterval(result.getInt("min_index_interval"));
|
||||
|
||||
if (result.has("max_index_interval"))
|
||||
cfm.maxIndexInterval(result.getInt("max_index_interval"));
|
||||
#endif
|
||||
|
||||
if (table_row.has("min_index_interval")) {
|
||||
builder.set_min_index_interval(table_row.get_nonnull<int>("min_index_interval"));
|
||||
}
|
||||
|
||||
if (table_row.has("max_index_interval")) {
|
||||
builder.set_max_index_interval(table_row.get_nonnull<int>("max_index_interval"));
|
||||
}
|
||||
|
||||
if (table_row.has("bloom_filter_fp_chance")) {
|
||||
builder.set_bloom_filter_fp_chance(table_row.get_nonnull<double>("bloom_filter_fp_chance"));
|
||||
} else {
|
||||
@@ -1383,22 +1401,22 @@ future<> save_system_keyspace_schema() {
|
||||
|
||||
std::vector<column_definition> create_columns_from_column_rows(const schema_result::mapped_type& rows,
|
||||
const sstring& keyspace,
|
||||
const sstring& table/*,
|
||||
AbstractType<?> rawComparator,
|
||||
boolean isSuper*/)
|
||||
const sstring& table, /*,
|
||||
AbstractType<?> rawComparator, */
|
||||
bool is_super)
|
||||
{
|
||||
std::vector<column_definition> columns;
|
||||
for (auto&& row : rows->rows()) {
|
||||
columns.emplace_back(std::move(create_column_from_column_row(row, keyspace, table/*, rawComparator, isSuper*/)));
|
||||
columns.emplace_back(std::move(create_column_from_column_row(row, keyspace, table, /*, rawComparator, */ is_super)));
|
||||
}
|
||||
return columns;
|
||||
}
|
||||
|
||||
column_definition create_column_from_column_row(const query::result_set_row& row,
|
||||
sstring keyspace,
|
||||
sstring table/*,
|
||||
AbstractType<?> rawComparator,
|
||||
boolean isSuper*/)
|
||||
sstring table, /*,
|
||||
AbstractType<?> rawComparator, */
|
||||
bool is_super)
|
||||
{
|
||||
auto kind = deserialize_kind(row.get_nonnull<sstring>("type"));
|
||||
|
||||
|
||||
@@ -85,15 +85,15 @@ void create_table_from_table_row_and_column_rows(schema_builder& builder, const
|
||||
|
||||
std::vector<column_definition> create_columns_from_column_rows(const schema_result::mapped_type& rows,
|
||||
const sstring& keyspace,
|
||||
const sstring& table/*,
|
||||
AbstractType<?> rawComparator,
|
||||
boolean isSuper*/);
|
||||
const sstring& table,/*,
|
||||
AbstractType<?> rawComparator, */
|
||||
bool is_super);
|
||||
|
||||
column_definition create_column_from_column_row(const query::result_set_row& row,
|
||||
sstring keyspace,
|
||||
sstring table/*,
|
||||
AbstractType<?> rawComparator,
|
||||
boolean isSuper*/);
|
||||
sstring table, /*,
|
||||
AbstractType<?> rawComparator, */
|
||||
bool is_super);
|
||||
|
||||
|
||||
void add_column_to_schema_mutation(schema_ptr table, const column_definition& column, api::timestamp_type timestamp, const partition_key& pkey, std::vector<mutation>& mutations);
|
||||
|
||||
68
schema.hh
68
schema.hh
@@ -31,6 +31,29 @@ enum class index_type {
|
||||
none, // cwi: added none to avoid "optional" bs.
|
||||
};
|
||||
|
||||
enum class cf_type : uint8_t {
|
||||
standard,
|
||||
super,
|
||||
};
|
||||
|
||||
inline sstring cf_type_to_sstring(cf_type t) {
|
||||
if (t == cf_type::standard) {
|
||||
return "Standard";
|
||||
} else if (t == cf_type::super) {
|
||||
return "Super";
|
||||
}
|
||||
throw std::invalid_argument(sprint("unknown type: %d\n", uint8_t(t)));
|
||||
}
|
||||
|
||||
inline cf_type sstring_to_cf_type(sstring name) {
|
||||
if (name == "Standard") {
|
||||
return cf_type::standard;
|
||||
} else if (name == "Super") {
|
||||
return cf_type::super;
|
||||
}
|
||||
throw std::invalid_argument(sprint("unknown type: %s\n", name));
|
||||
}
|
||||
|
||||
typedef std::unordered_map<sstring, sstring> index_options_map;
|
||||
|
||||
class schema;
|
||||
@@ -149,6 +172,14 @@ private:
|
||||
double _bloom_filter_fp_chance = 0.01;
|
||||
compression_parameters _compressor_params;
|
||||
bool _is_dense = false;
|
||||
cf_type _type = cf_type::standard;
|
||||
int32_t _gc_grace_seconds = 864000;
|
||||
double _dc_local_read_repair_chance = 0.1;
|
||||
double _read_repair_chance = 0.0;
|
||||
int32_t _min_compaction_threshold = 4;
|
||||
int32_t _max_compaction_threshold = 32;
|
||||
int32_t _min_index_interval = 128;
|
||||
int32_t _max_index_interval = 2048;
|
||||
};
|
||||
raw_schema _raw;
|
||||
thrift_schema _thrift;
|
||||
@@ -235,6 +266,43 @@ public:
|
||||
bool is_counter() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
const cf_type type() const {
|
||||
return _raw._type;
|
||||
}
|
||||
|
||||
bool is_super() const {
|
||||
return _raw._type == cf_type::super;
|
||||
}
|
||||
|
||||
int32_t gc_grace_seconds() const {
|
||||
return _raw._gc_grace_seconds;
|
||||
}
|
||||
|
||||
double dc_local_read_repair_chance() const {
|
||||
return _raw._dc_local_read_repair_chance;
|
||||
}
|
||||
|
||||
double read_repair_chance() const {
|
||||
return _raw._read_repair_chance;
|
||||
}
|
||||
|
||||
int32_t min_compaction_threshold() const {
|
||||
return _raw._min_compaction_threshold;
|
||||
}
|
||||
|
||||
int32_t max_compaction_threshold() const {
|
||||
return _raw._max_compaction_threshold;
|
||||
}
|
||||
|
||||
int32_t min_index_interval() const {
|
||||
return _raw._min_index_interval;
|
||||
}
|
||||
|
||||
int32_t max_index_interval() const {
|
||||
return _raw._max_index_interval;
|
||||
}
|
||||
|
||||
const column_definition* get_column_definition(const bytes& name) const;
|
||||
const_iterator regular_begin() const {
|
||||
return regular_columns().begin();
|
||||
|
||||
@@ -52,6 +52,62 @@ public:
|
||||
_raw._default_validator = validator;
|
||||
}
|
||||
|
||||
void set_gc_grace_seconds(int32_t gc_grace_seconds) {
|
||||
_raw._gc_grace_seconds = gc_grace_seconds;
|
||||
}
|
||||
|
||||
int32_t get_gc_grace_seconds() {
|
||||
return _raw._gc_grace_seconds;
|
||||
}
|
||||
|
||||
void set_dc_local_read_repair_chance(double chance) {
|
||||
_raw._dc_local_read_repair_chance = chance;
|
||||
}
|
||||
|
||||
double get_dc_local_read_repair_chance() {
|
||||
return _raw._dc_local_read_repair_chance;
|
||||
}
|
||||
|
||||
void set_read_repair_chance(double chance) {
|
||||
_raw._read_repair_chance = chance;
|
||||
}
|
||||
|
||||
double get_read_repair_chance() {
|
||||
return _raw._read_repair_chance;
|
||||
}
|
||||
|
||||
void set_min_compaction_threshold(int32_t t) {
|
||||
_raw._min_compaction_threshold = t;
|
||||
}
|
||||
|
||||
int32_t get_min_compaction_threshold() {
|
||||
return _raw._min_compaction_threshold;
|
||||
}
|
||||
|
||||
void set_max_compaction_threshold(int32_t t) {
|
||||
_raw._max_compaction_threshold = t;
|
||||
}
|
||||
|
||||
int32_t get_max_compaction_threshold() {
|
||||
return _raw._max_compaction_threshold;
|
||||
}
|
||||
|
||||
void set_min_index_interval(int32_t t) {
|
||||
_raw._min_index_interval = t;
|
||||
}
|
||||
|
||||
int32_t get_min_index_interval() {
|
||||
return _raw._min_index_interval;
|
||||
}
|
||||
|
||||
void set_max_index_interval(int32_t t) {
|
||||
_raw._max_index_interval = t;
|
||||
}
|
||||
|
||||
int32_t get_max_index_interval() {
|
||||
return _raw._max_index_interval;
|
||||
}
|
||||
|
||||
void set_bloom_filter_fp_chance(double fp) {
|
||||
_raw._bloom_filter_fp_chance = fp;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ std::ostream& operator<<(std::ostream& out, cause c) {
|
||||
case cause::NONATOMIC: return out << "NONATOMIC";
|
||||
case cause::CONSISTENCY: return out << "CONSISTENCY";
|
||||
case cause::HINT: return out << "HINT";
|
||||
case cause::SUPER: return out << "SUPER";
|
||||
}
|
||||
assert(0);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ enum class cause {
|
||||
NONATOMIC,
|
||||
CONSISTENCY,
|
||||
HINT,
|
||||
SUPER,
|
||||
};
|
||||
|
||||
void fail(cause what) __attribute__((noreturn));
|
||||
|
||||
Reference in New Issue
Block a user