db/view: add clustering_or_static_row

Adds a `clustering_or_static_row`, which is a common, immutable
representation of either a static or clustering row. It will allow to
handle view update generation based on static or clustering rows in a
uniform way.
This commit is contained in:
Piotr Dulikowski
2022-07-28 18:51:14 +02:00
parent 05d4328f02
commit 986ab6034c
2 changed files with 54 additions and 0 deletions

View File

@@ -233,6 +233,20 @@ bool view_info::has_base_non_pk_columns_in_view_pk() const {
return _base_info->has_base_non_pk_columns_in_view_pk;
}
clustering_row db::view::clustering_or_static_row::as_clustering_row(const schema& s) const {
if (!is_clustering_row()) {
on_internal_error(vlogger, "Tried to interpret a static row as a clustering row");
}
return clustering_row(*_key, tomb(), marker(), row(s, column_kind::regular_column, cells()));
}
static_row db::view::clustering_or_static_row::as_static_row(const schema& s) const {
if (!is_static_row()) {
on_internal_error(vlogger, "Tried to interpret a clustering row as a static row");
}
return static_row(s, cells());
}
namespace db {
namespace view {

View File

@@ -80,6 +80,46 @@ struct view_and_base {
base_info_ptr base;
};
// An immutable representation of a clustering or static row of the base table.
struct clustering_or_static_row {
private:
std::optional<clustering_key_prefix> _key;
deletable_row _row;
public:
explicit clustering_or_static_row(clustering_row&& cr)
: _key(std::move(cr.key()))
, _row(std::move(cr).as_deletable_row())
{}
explicit clustering_or_static_row(static_row&& sr)
: _key()
, _row(row_tombstone(), row_marker(), std::move(sr.cells()))
{}
bool is_static_row() const { return !_key.has_value(); }
bool is_clustering_row() const { return _key.has_value(); }
const std::optional<clustering_key_prefix>& key() const { return _key; }
row_tombstone tomb() const { return _row.deleted_at(); }
const row_marker& marker() const { return _row.marker(); }
const row& cells() const { return _row.cells(); }
bool empty() const { return _row.empty(); }
bool is_live(const schema& s, tombstone base_tombstone = tombstone(), gc_clock::time_point now = gc_clock::time_point::min()) const {
return _row.is_live(s, column_kind(), base_tombstone, now);
}
column_kind column_kind() const {
return _key.has_value()
? column_kind::regular_column : column_kind::static_column;
}
clustering_row as_clustering_row(const schema& s) const;
static_row as_static_row(const schema& s) const;
};
/**
* Whether the view filter considers the specified partition key.
*