From d81a46d7b50f272efc19fd30822be216412910f9 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Mon, 7 Dec 2015 17:04:51 +0100 Subject: [PATCH] column_family: Add schema setters There is one current schema for given column_family. Entries in memtables and cache can be at any of the previous schemas, but they're always upgraded to current schema on access. --- database.cc | 12 ++++++++++++ database.hh | 1 + memtable.cc | 4 ++++ memtable.hh | 1 + row_cache.cc | 4 ++++ row_cache.hh | 1 + 6 files changed, 23 insertions(+) diff --git a/database.cc b/database.cc index 6c338916bd..0a8e56a545 100644 --- a/database.cc +++ b/database.cc @@ -2237,3 +2237,15 @@ std::ostream& operator<<(std::ostream& os, const keyspace_metadata& m) { os << "}"; return os; } + +void column_family::set_schema(schema_ptr s) { + dblog.debug("Changing schema version of {}.{} ({}) from {} to {}", + _schema->ks_name(), _schema->cf_name(), _schema->id(), _schema->version(), s->version()); + + for (auto& m : *_memtables) { + m->set_schema(s); + } + + _cache.set_schema(s); + _schema = std::move(s); +} diff --git a/database.hh b/database.hh index 5ba9795ac3..4a1db3c3be 100644 --- a/database.hh +++ b/database.hh @@ -228,6 +228,7 @@ public: column_family(column_family&&) = delete; // 'this' is being captured during construction ~column_family(); schema_ptr schema() const { return _schema; } + void set_schema(schema_ptr); db::commitlog* commitlog() { return _commitlog; } future find_partition(schema_ptr, const dht::decorated_key& key) const; future find_partition_slow(schema_ptr, const partition_key& key) const; diff --git a/memtable.cc b/memtable.cc index 8cefdca883..f0f5ed1b46 100644 --- a/memtable.cc +++ b/memtable.cc @@ -295,3 +295,7 @@ void memtable::upgrade_entry(partition_entry& e) { }); } } + +void memtable::set_schema(schema_ptr new_schema) noexcept { + _schema = std::move(new_schema); +} diff --git a/memtable.hh b/memtable.hh index 3f26a6d6c0..32f37753eb 100644 --- a/memtable.hh +++ b/memtable.hh @@ -114,6 +114,7 @@ public: explicit memtable(schema_ptr schema, logalloc::region_group* dirty_memory_region_group = nullptr); ~memtable(); schema_ptr schema() const { return _schema; } + void set_schema(schema_ptr) noexcept; future<> apply(memtable&); // Applies mutation to this memtable. // The mutation is upgraded to current schema. diff --git a/row_cache.cc b/row_cache.cc index 91d32edf6e..b679d1fdef 100644 --- a/row_cache.cc +++ b/row_cache.cc @@ -549,6 +549,10 @@ cache_entry::cache_entry(cache_entry&& o) noexcept } } +void row_cache::set_schema(schema_ptr new_schema) noexcept { + _schema = std::move(new_schema); +} + mutation cache_entry::read(const schema_ptr& s) { auto m = mutation(_schema, _key, _p); if (_schema != s) { diff --git a/row_cache.hh b/row_cache.hh index 730b5d2173..45f091f679 100644 --- a/row_cache.hh +++ b/row_cache.hh @@ -242,6 +242,7 @@ public: return _tracker; } + void set_schema(schema_ptr) noexcept; const schema_ptr& schema() const; friend class just_cache_scanning_reader;