Schema specification. More...
#include <Schema.h>
Public Member Functions | |
Schema () | |
Default constructor. More... | |
Schema (const Schema &other) | |
Copy constructor. More... | |
~Schema () | |
Destructor. More... | |
void | clear_generation () |
Clears generation values. More... | |
bool | clear_generation_if_changed (Schema &original) |
Clears generation if different than original . More... | |
void | update_generation (int64_t generation) |
Updates generation and assigns column family IDs. More... | |
const std::string | render_xml (bool with_ids=false) |
Renders schema in XML format. More... | |
const std::string | render_hql (const std::string &table_name) |
Renders schema as HQL CREATE TABLE statement. More... | |
int64_t | get_generation () const |
Gets generation. More... | |
void | set_generation (int64_t generation) |
Sets generation. More... | |
int32_t | get_version () const |
Gets version number. More... | |
void | set_version (int32_t version) |
Sets version number. More... | |
int32_t | get_max_column_family_id () |
Gets the maximum column family ID. More... | |
TableParts | get_table_parts () |
Gets table parts. More... | |
AccessGroupSpecs & | get_access_groups () |
Returns reference to access group vector. More... | |
AccessGroupSpec * | get_access_group (const std::string &name) |
Gets an access group specification given its name. More... | |
AccessGroupSpec * | get_access_group (const char *name) |
ColumnFamilySpecs & | get_column_families () |
Returns reference to column family vector. More... | |
ColumnFamilySpec * | get_column_family (const std::string &name) |
Gets a column family specification given its name. More... | |
ColumnFamilySpec * | get_column_family (const char *name) |
ColumnFamilySpec * | remove_column_family (const std::string &name) |
Removes column family. More... | |
ColumnFamilySpec * | get_column_family (int32_t id, bool get_deleted=false) |
Gets a column family specification given its ID. More... | |
void | add_access_group (AccessGroupSpec *ag) |
Adds access group specification. More... | |
AccessGroupSpec * | replace_access_group (AccessGroupSpec *new_ag) |
Replaces access group specification. More... | |
bool | access_group_exists (const std::string &name) const |
Checks if access group exists. More... | |
bool | column_family_exists (int32_t id, bool get_deleted=false) const |
Checks if column family exists. More... | |
void | drop_column_family (const String &name) |
Drops column family. More... | |
void | rename_column_family (const String &old_name, const String &new_name) |
Renames a column family. More... | |
bool | column_is_counter (int id) |
Checks if column is a counter column. More... | |
void | set_group_commit_interval (int32_t interval) |
Sets group commit interval. More... | |
int32_t | get_group_commit_interval () |
Gets group commit interval. More... | |
void | set_access_group_defaults (const AccessGroupOptions &defaults) |
Sets default access group options. More... | |
AccessGroupOptions & | access_group_defaults () |
Returns reference to default access group options. More... | |
void | set_column_family_defaults (const ColumnFamilyOptions &defaults) |
Sets default column family options. More... | |
ColumnFamilyOptions & | column_family_defaults () |
Returns reference to default column family options. More... | |
void | validate () |
Validates schema and reconstructs data structures. More... | |
Static Public Member Functions | |
static Schema * | new_instance (const std::string &buf) |
Creates schema object from XML schema string. More... | |
Private Types | |
typedef PageArenaAllocator < const char * > | CstrAlloc |
typedef std::map< const char *, AccessGroupSpec *, LtCstr, CstrAlloc > | CstrAccessGroupMap |
Map of access group specifications. More... | |
typedef std::map< const char *, ColumnFamilySpec *, LtCstr, CstrAlloc > | CstrColumnFamilyMap |
Map of column family specifications (key == name) More... | |
Private Member Functions | |
void | merge_table_defaults (ColumnFamilySpec *cf_spec) |
Merges default column family options into a column family spec. More... | |
void | merge_table_defaults (AccessGroupSpec *ag_spec) |
Merges default access group options into access group spec. More... | |
Private Attributes | |
CharArena | m_arena |
int64_t | m_generation |
Generation. More... | |
int32_t | m_version {} |
Version number. More... | |
int32_t | m_group_commit_interval {} |
Group commit interval. More... | |
AccessGroupOptions | m_ag_defaults |
Default access group options. More... | |
ColumnFamilyOptions | m_cf_defaults |
Default column family options. More... | |
AccessGroupSpecs | m_access_groups |
Access group specifications. More... | |
CstrAccessGroupMap | m_access_group_map |
ColumnFamilySpecs | m_column_families |
&Column family specifications More... | |
CstrColumnFamilyMap | m_column_family_map |
std::map< int32_t, ColumnFamilySpec * > | m_column_family_id_map |
Map of column family specifications (key == ID) More... | |
std::vector< bool > | m_counter_mask |
Bitmask describing which column families are counters. More... | |
|
private |
|
private |
|
private |
Schema::Schema | ( | const Schema & | other | ) |
Copy constructor.
Assumes src_schema has been checked for validity.
Copies contents of other
schema into this one and then calls validate().
other | Other schema from which to copy |
Schema::~Schema | ( | ) |
Destructor.
Deletes all access group specifications in m_access_groups
|
inline |
bool Schema::access_group_exists | ( | const std::string & | name | ) | const |
Checks if access group exists.
Looks up name
in m_access_group_map and returns true if it is found.
name | Access group name |
void Schema::add_access_group | ( | AccessGroupSpec * | ag | ) |
Adds access group specification.
Merges access group defaults (m_ag_defaults) into ag
and merges column family defaults (m_cf_defaults) into each of its column family specs. Pushes ag
onto the end of m_access_groups and inserts it into m_access_group_map.
ag | Access group specification |
Exception | with code set to Error::TOO_MANY_COLUMNS if added access group pushes the number of column families past the maximum, or Error::BAD_SCHEMA if access group or any of its colums already exist. |
void Schema::clear_generation | ( | ) |
Clears generation values.
Sets m_generation to 0 and sets the generation value of all column families within all access groups to 0.
bool Schema::clear_generation_if_changed | ( | Schema & | original | ) |
Clears generation if different than original
.
Compares this object with original
and if then differ, sets m_generation to 0 and returns true. Comparison of each member access group is compared with AccessGroupSpec::clear_generation_if_changed() causing the access group spec's generation to be set to 0 if they differ.
original | Original schema with which to compare |
original
, false otherwise.
|
inline |
bool Schema::column_family_exists | ( | int32_t | id, |
bool | get_deleted = false |
||
) | const |
Checks if column family exists.
Checks if the column family with ID, id
, exists by searching for it in m_column_family_id_map. Returns true if column family exists and either a) is not deleted, or b) is deleted and the value passed in for get_deleted
is true.
id | ID of column family to search for |
get_deleted | Return |
|
inline |
Checks if column is a counter column.
Returns the value of the id
th bit of m_counter_mask.
id | Column family ID |
void Schema::drop_column_family | ( | const String & | name | ) |
Drops column family.
Locates access group for column family name
and marks it as deleted with a call to AccessGroupSpec::drop_column(), then re-inserts the column family back into m_column_family_map with its new new ("!<id>").
name | Name of column family to drop |
|
inline |
Gets an access group specification given its name.
Searches m_access_group_map for the access group named name
, returning it if it exists or nullptr if it does not.
name | Name of access group to return |
name
, or nullptr if it does not exist.
|
inline |
|
inline |
|
inline |
|
inline |
Gets a column family specification given its name.
Searches m_column_family_map for the column family named name
, returning it if it exists or nullptr if it does not.
name | Name of column family to return |
name
, or nullptr if it does not exist.
|
inline |
|
inline |
Gets a column family specification given its ID.
Searches m_column_family_id_map for the column family with ID id
, returning it if it exists and is not deleted or get_deleted
is true. Otherwise, nullptr is returned.
id | Column family ID of specification to fetch |
get_deleted | Return specification even if it is deleted |
id
if it exists and it is not deleted or get_deleted
is true. Otherwise, nullptr is returned.
|
inline |
|
inline |
int32_t Schema::get_max_column_family_id | ( | ) |
TableParts Schema::get_table_parts | ( | ) |
Gets table parts.
|
inline |
|
private |
|
private |
|
static |
Creates schema object from XML schema string.
Constructs a new schema from the XML specification held in buf
and them calls validate().
buf | Buffer holding XML schema string. |
ColumnFamilySpec * Schema::remove_column_family | ( | const std::string & | name | ) |
Removes column family.
Removes column family named name
from m_column_family_map. If column family ID is non-zero, then the column family is removed from m_column_family_id_map and the corresponding entry in m_counter_mask is set to false. If column family exists in m_column_family_map, then it is returned, otherwise, nullptr is returned.
name | Name of column family to remove |
Renames a column family.
Locates column family old_name
in m_column_family_map, renames it to new_name
and sets its generation to 0.
old_name | Name of existing column family to be renamed |
new_name | New name for column family |
const string Schema::render_hql | ( | const std::string & | table_name | ) |
Renders schema as HQL CREATE TABLE
statement.
The following is example output produced by this member function with "MyTable" passed in as table_name
.
CREATE TABLE MyTable ( actions MAX_VERSIONS 3 TTL 2592000, language MAX_VERSIONS 2, checksum MAX_VERSIONS 1, ACCESS GROUP default (actions) BLOCKSIZE 65000, ACCESS GROUP meta (language, checksum) BLOCKSIZE 65000 MAX_VERSIONS 2 ) GROUP_COMMIT_INTERVAL 200 BLOCKSIZE 65000
table_name | Name of table |
CREATE TABLE
statement. const string Schema::render_xml | ( | bool | with_ids = false | ) |
Renders schema in XML format.
The name of the toplevel element of the output is Schema and contains the following child elements:
Element | Description |
---|---|
Generation | Generation number |
GroupCommitInterval | Group commit interval |
AccessGroupDefaults | Default access group options |
ColumnFamilyDefaults | Default column family options |
AccessGroup | Access group specification (see AccessGroupSpec::render_xml()) |
The following is example output produced by this member function.
<Schema> <Generation>42</Generation> <GroupCommitInterval>100</GroupCommitInterval> <AccessGroupDefaults> <BlockSize>65000</BlockSize> </AccessGroupDefaults> <ColumnFamilyDefaults> </ColumnFamilyDefaults> <AccessGroup name="default"> <Options> <BlockSize>65000</BlockSize> </Options> <ColumnFamilyDefaults> </ColumnFamilyDefaults> <ColumnFamily id="1"> <Generation>42</Generation> <Name>actions</Name> <AccessGroup>default</AccessGroup> <Deleted>false</Deleted> <Options> <MaxVersions>3</MaxVersions> <TTL>2592000</TTL> </Options> </ColumnFamily> </AccessGroup> <AccessGroup name="meta"> <Options> <BlockSize>65000</BlockSize> </Options> <ColumnFamilyDefaults> <MaxVersions>2</MaxVersions> </ColumnFamilyDefaults> <ColumnFamily id="2"> <Generation>42</Generation> <Name>language</Name> <AccessGroup>meta</AccessGroup> <Deleted>false</Deleted> <Options> <MaxVersions>2</MaxVersions> </Options> </ColumnFamily> <ColumnFamily id="3"> <Generation>42</Generation> <Name>checksum</Name> <AccessGroup>meta</AccessGroup> <Deleted>false</Deleted> <Options> <MaxVersions>1</MaxVersions> </Options> </ColumnFamily> </AccessGroup> </Schema>
with_ids | Include generation and column IDs in output |
AccessGroupSpec * Schema::replace_access_group | ( | AccessGroupSpec * | new_ag | ) |
Replaces access group specification.
Removes access group specification with the same name as the name of new_ag
from m_access_groups and then adds new_ag
with a call to add_access_group().
new_ag | Replacement access group specification |
|
inline |
Sets default access group options.
Sets m_ag_defaults to defaults
defaults | Access group options to use as table defaults |
|
inline |
Sets default column family options.
Sets m_cf_defaults to defaults
defaults | Column family options to use as table defaults |
|
inline |
|
inline |
Sets group commit interval.
Sets m_group_commit_interval to interval
.
interval | New value for group commit interval |
|
inline |
void Schema::update_generation | ( | int64_t | generation | ) |
Updates generation and assigns column family IDs.
For each column family specification that has a generation value of zero, its generation is set to generation
, and if its ID is also zero, it is assigned an ID that is one larger than the maximum column family ID of all of the column families. If any column family was assigned the new generation value, generation
, then m_generation is also set to generation
. Lastly, validate() is called.
generation | New generation |
void Schema::validate | ( | ) |
Validates schema and reconstructs data structures.
Reconstructs m_column_families, m_column_family_map, m_column_family_id_map, and m_counter_mask by recursing through m_access_groups. During the data structure reconstruction, validation checks are performed to make sure there aren't too many columns or there exists a column that is assigned to two different access groups.
Exception | with code set to Error::TOO_MANY_COLUMNS if too many columns are defined, or Error::BAD_SCHEMA if the same column is assigned to two different access groups. |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |