materialized views: Add view class
This patch adds the view class, which will contains functions related to populating a view, either from the base table's write path or from the view building mechanism which copies over already existing data in the base table. Signed-off-by: Duarte Nunes <duarte@scylladb.com>
This commit is contained in:
23
database.cc
23
database.cc
@@ -3446,3 +3446,26 @@ void column_family::set_schema(schema_ptr s) {
|
||||
set_compaction_strategy(_schema->compaction_strategy());
|
||||
trigger_compaction();
|
||||
}
|
||||
|
||||
void column_family::update_view_schemas() {
|
||||
_view_schemas = boost::copy_range<std::vector<view_ptr>>(_views | boost::adaptors::map_values | boost::adaptors::transformed([] (auto&& s) {
|
||||
return view_ptr(s.schema());
|
||||
}));
|
||||
}
|
||||
|
||||
void column_family::add_or_update_view(view_ptr v) {
|
||||
auto e = _views.emplace(v->cf_name(), v);
|
||||
if (!e.second) {
|
||||
e.first->second.update(v);
|
||||
}
|
||||
update_view_schemas();
|
||||
}
|
||||
|
||||
void column_family::remove_view(view_ptr v) {
|
||||
_views.erase(v->cf_name());
|
||||
update_view_schemas();
|
||||
}
|
||||
|
||||
const std::vector<view_ptr>& column_family::views() const {
|
||||
return _view_schemas;
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@
|
||||
#include <seastar/core/shared_future.hh>
|
||||
#include "tracing/trace_state.hh"
|
||||
#include <boost/intrusive/parent_from_member.hpp>
|
||||
#include "db/view/view.hh"
|
||||
|
||||
class frozen_mutation;
|
||||
class reconcilable_result;
|
||||
@@ -510,6 +511,8 @@ private:
|
||||
// Last but not least, we seldom need to guarantee any ordering here: as long
|
||||
// as all data is waited for, we're good.
|
||||
seastar::gate _streaming_flush_gate;
|
||||
std::unordered_map<sstring, db::view::view> _views;
|
||||
std::vector<view_ptr> _view_schemas;
|
||||
private:
|
||||
void update_stats_for_new_sstable(uint64_t disk_space_used_by_sstable);
|
||||
void add_sstable(sstables::sstable&& sstable);
|
||||
@@ -796,7 +799,13 @@ public:
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void add_or_update_view(view_ptr v);
|
||||
void remove_view(view_ptr v);
|
||||
const std::vector<view_ptr>& views() const;
|
||||
private:
|
||||
void update_view_schemas();
|
||||
|
||||
// One does not need to wait on this future if all we are interested in, is
|
||||
// initiating the write. The writes initiated here will eventually
|
||||
// complete, and the seastar::gate below will make sure they are all
|
||||
|
||||
48
db/view/view.hh
Normal file
48
db/view/view.hh
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2016 ScyllaDB
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is part of Scylla.
|
||||
*
|
||||
* Scylla is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Scylla is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "schema.hh"
|
||||
|
||||
namespace db {
|
||||
|
||||
namespace view {
|
||||
|
||||
class view final {
|
||||
view_ptr _schema;
|
||||
public:
|
||||
view(view_ptr schema)
|
||||
: _schema(schema)
|
||||
{ }
|
||||
|
||||
view_ptr schema() const {
|
||||
return _schema;
|
||||
}
|
||||
|
||||
void update(view_ptr new_schema) {
|
||||
_schema = new_schema;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user