mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-31 20:16:43 +00:00
schema: add column_definition::_dropped_at
When a column is dropped its name and deletion timestamp are added to schema::_raw._dropped_columns to prevent data resurrection in case a column with the same name is added. To reduce the number of lookups in _dropped_columns this patch makes each instance of column_definition to caches this information (i.e. timestamp of the latest removal of a column with the same name). Signed-off-by: Paweł Dziepak <pdziepak@scylladb.com>
This commit is contained in:
committed by
Tomasz Grabiec
parent
42dc4ce715
commit
3cbfa0e52f
13
schema.cc
13
schema.cc
@@ -232,6 +232,11 @@ schema::schema(const raw_schema& raw)
|
||||
assert(!def.id || def.id == id - column_offset(def.kind));
|
||||
def.id = id - column_offset(def.kind);
|
||||
|
||||
auto dropped_at_it = _raw._dropped_columns.find(def.name_as_text());
|
||||
if (dropped_at_it != _raw._dropped_columns.end()) {
|
||||
def._dropped_at = std::max(def._dropped_at, dropped_at_it->second);
|
||||
}
|
||||
|
||||
def._thrift_bits = column_definition::thrift_bits();
|
||||
|
||||
{
|
||||
@@ -368,8 +373,8 @@ index_info::index_info(::index_type idx_type,
|
||||
: index_type(idx_type), index_name(idx_name), index_options(idx_options)
|
||||
{}
|
||||
|
||||
column_definition::column_definition(bytes name, data_type type, column_kind kind, column_id component_index, index_info idx)
|
||||
: _name(std::move(name)), type(std::move(type)), id(component_index), kind(kind), idx_info(std::move(idx))
|
||||
column_definition::column_definition(bytes name, data_type type, column_kind kind, column_id component_index, index_info idx, api::timestamp_type dropped_at)
|
||||
: _name(std::move(name)), _dropped_at(dropped_at), type(std::move(type)), id(component_index), kind(kind), idx_info(std::move(idx))
|
||||
{}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const column_definition& cd) {
|
||||
@@ -380,6 +385,7 @@ std::ostream& operator<<(std::ostream& os, const column_definition& cd) {
|
||||
os << ", componentIndex=" << (cd.has_component_index() ? std::to_string(cd.component_index()) : "null");
|
||||
os << ", indexName=" << (cd.idx_info.index_name ? *cd.idx_info.index_name : "null");
|
||||
os << ", indexType=" << to_sstring(cd.idx_info.index_type);
|
||||
os << ", droppedAt=" << cd._dropped_at;
|
||||
os << "}";
|
||||
return os;
|
||||
}
|
||||
@@ -484,7 +490,8 @@ bool operator==(const column_definition& x, const column_definition& y)
|
||||
return x._name == y._name
|
||||
&& x.type->equals(y.type)
|
||||
&& x.id == y.id
|
||||
&& x.kind == y.kind;
|
||||
&& x.kind == y.kind
|
||||
&& x._dropped_at == y._dropped_at;
|
||||
}
|
||||
|
||||
// Based on org.apache.cassandra.config.CFMetaData#generateLegacyCfId
|
||||
|
||||
@@ -194,6 +194,7 @@ public:
|
||||
};
|
||||
private:
|
||||
bytes _name;
|
||||
api::timestamp_type _dropped_at;
|
||||
|
||||
struct thrift_bits {
|
||||
thrift_bits()
|
||||
@@ -206,7 +207,9 @@ private:
|
||||
thrift_bits _thrift_bits;
|
||||
friend class schema;
|
||||
public:
|
||||
column_definition(bytes name, data_type type, column_kind kind, column_id component_index = 0, index_info = index_info());
|
||||
column_definition(bytes name, data_type type, column_kind kind,
|
||||
column_id component_index = 0, index_info = index_info(),
|
||||
api::timestamp_type dropped_at = api::missing_timestamp);
|
||||
|
||||
data_type type;
|
||||
|
||||
@@ -252,6 +255,7 @@ public:
|
||||
bool is_part_of_cell_name() const {
|
||||
return is_regular() || is_static();
|
||||
}
|
||||
api::timestamp_type dropped_at() const { return _dropped_at; }
|
||||
friend bool operator==(const column_definition&, const column_definition&);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user