Introduce schema_mutations

This commit is contained in:
Tomasz Grabiec
2015-12-11 19:53:26 +01:00
parent a6084ee007
commit a861b74b7e
4 changed files with 114 additions and 0 deletions

View File

@@ -240,6 +240,7 @@ scylla_core = (['database.cc',
'row_cache.cc',
'frozen_mutation.cc',
'memtable.cc',
'schema_mutations.cc',
'release.cc',
'utils/logalloc.cc',
'utils/large_bitset.cc',

View File

@@ -32,6 +32,9 @@ class mutation_partition;
class schema;
class column_definition;
// schema_mutations.hh
class schema_mutations;
// keys.hh
class exploded_clustering_prefix;
class partition_key;

50
schema_mutations.cc Normal file
View File

@@ -0,0 +1,50 @@
/*
* Copyright 2015 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/>.
*/
#include "schema_mutations.hh"
#include "canonical_mutation.hh"
#include "db/schema_tables.hh"
#include "md5_hasher.hh"
void schema_mutations::copy_to(std::vector<mutation>& dst) const {
dst.push_back(_columnfamilies);
dst.push_back(_columns);
}
table_schema_version schema_mutations::digest() const {
md5_hasher h;
feed_hash(h, _columnfamilies);
feed_hash(h, _columns);
return utils::UUID_gen::get_name_UUID(h.finalize());
}
bool schema_mutations::operator==(const schema_mutations& other) const {
return _columnfamilies == other._columnfamilies
&& _columns == other._columns;
}
bool schema_mutations::operator!=(const schema_mutations& other) const {
return !(*this == other);
}
bool schema_mutations::live() const {
return _columnfamilies.live_row_count() > 0 || _columns.live_row_count() > 0;
}

60
schema_mutations.hh Normal file
View File

@@ -0,0 +1,60 @@
/*
* Copyright 2015 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 <vector>
#include "mutation.hh"
#include "schema.hh"
// Commutative representation of table schema
class schema_mutations {
mutation _columnfamilies;
mutation _columns;
public:
schema_mutations(mutation columnfamilies, mutation columns)
: _columnfamilies(std::move(columnfamilies))
, _columns(std::move(columns))
{ }
schema_mutations(schema_mutations&&) = default;
schema_mutations& operator=(schema_mutations&&) = default;
schema_mutations(const schema_mutations&) = default;
schema_mutations& operator=(const schema_mutations&) = default;
void copy_to(std::vector<mutation>& dst) const;
const mutation& columnfamilies_mutation() const {
return _columnfamilies;
}
const mutation& columns_mutation() const {
return _columns;
}
table_schema_version digest() const;
bool operator==(const schema_mutations&) const;
bool operator!=(const schema_mutations&) const;
// Returns true iff any mutations contain any live cells
bool live() const;
};