0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Hypertable::Schema Class Reference

Schema specification. More...

#include <Schema.h>

Collaboration diagram for Hypertable::Schema:
Collaboration graph
[legend]

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...
 
AccessGroupSpecsget_access_groups ()
 Returns reference to access group vector. More...
 
AccessGroupSpecget_access_group (const std::string &name)
 Gets an access group specification given its name. More...
 
AccessGroupSpecget_access_group (const char *name)
 
ColumnFamilySpecsget_column_families ()
 Returns reference to column family vector. More...
 
ColumnFamilySpecget_column_family (const std::string &name)
 Gets a column family specification given its name. More...
 
ColumnFamilySpecget_column_family (const char *name)
 
ColumnFamilySpecremove_column_family (const std::string &name)
 Removes column family. More...
 
ColumnFamilySpecget_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...
 
AccessGroupSpecreplace_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...
 
AccessGroupOptionsaccess_group_defaults ()
 Returns reference to default access group options. More...
 
void set_column_family_defaults (const ColumnFamilyOptions &defaults)
 Sets default column family options. More...
 
ColumnFamilyOptionscolumn_family_defaults ()
 Returns reference to default column family options. More...
 
void validate ()
 Validates schema and reconstructs data structures. More...
 

Static Public Member Functions

static Schemanew_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...
 

Detailed Description

Schema specification.

Definition at line 52 of file Schema.h.

Member Typedef Documentation

typedef std::map<const char*, AccessGroupSpec*, LtCstr, CstrAlloc> Hypertable::Schema::CstrAccessGroupMap
private

Map of access group specifications.

Definition at line 447 of file Schema.h.

typedef PageArenaAllocator<const char*> Hypertable::Schema::CstrAlloc
private

Definition at line 425 of file Schema.h.

typedef std::map<const char*, ColumnFamilySpec*, LtCstr, CstrAlloc> Hypertable::Schema::CstrColumnFamilyMap
private

Map of column family specifications (key == name)

Definition at line 454 of file Schema.h.

Constructor & Destructor Documentation

Hypertable::Schema::Schema ( )
inline

Default constructor.

Definition at line 56 of file Schema.h.

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().

Parameters
otherOther schema from which to copy

Definition at line 77 of file Schema.cc.

Schema::~Schema ( )

Destructor.

Deletes all access group specifications in m_access_groups

Definition at line 130 of file Schema.cc.

Member Function Documentation

AccessGroupOptions& Hypertable::Schema::access_group_defaults ( )
inline

Returns reference to default access group options.

Returns
Reference to default access group options.

Definition at line 381 of file Schema.h.

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.

Parameters
nameAccess group name
Returns
true if access group exists, false otherwise

Definition at line 441 of file Schema.cc.

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.

Parameters
agAccess group specification
Exceptions
Exceptionwith 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.

Definition at line 354 of file Schema.cc.

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.

Definition at line 216 of file Schema.cc.

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.

Parameters
originalOriginal schema with which to compare
Returns
true if this object differs from original, false otherwise.

Definition at line 223 of file Schema.cc.

ColumnFamilyOptions& Hypertable::Schema::column_family_defaults ( )
inline

Returns reference to default column family options.

Returns
Reference to default column family options.

Definition at line 392 of file Schema.h.

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.

Parameters
idID of column family to search for
get_deletedReturn
Returns
true if column family exists, false otherwise.

Definition at line 431 of file Schema.cc.

bool Hypertable::Schema::column_is_counter ( int  id)
inline

Checks if column is a counter column.

Returns the value of the idth bit of m_counter_mask.

Parameters
idColumn family ID
Returns
true if column is a counter, false otherwise.

Definition at line 357 of file Schema.h.

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>").

Parameters
nameName of column family to drop

Definition at line 470 of file Schema.cc.

AccessGroupSpec* Hypertable::Schema::get_access_group ( const std::string &  name)
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.

Parameters
nameName of access group to return
Returns
Access group specification corresponding to name, or nullptr if it does not exist.

Definition at line 242 of file Schema.h.

AccessGroupSpec* Hypertable::Schema::get_access_group ( const char *  name)
inline

Definition at line 245 of file Schema.h.

AccessGroupSpecs& Hypertable::Schema::get_access_groups ( )
inline

Returns reference to access group vector.

Returns
Reference to access group vector.

Definition at line 234 of file Schema.h.

ColumnFamilySpecs& Hypertable::Schema::get_column_families ( )
inline

Returns reference to column family vector.

Returns
Reference to column family vector.

Definition at line 254 of file Schema.h.

ColumnFamilySpec* Hypertable::Schema::get_column_family ( const std::string &  name)
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.

Parameters
nameName of column family to return
Returns
Column family specification corresponding to name, or nullptr if it does not exist.

Definition at line 262 of file Schema.h.

ColumnFamilySpec* Hypertable::Schema::get_column_family ( const char *  name)
inline

Definition at line 265 of file Schema.h.

ColumnFamilySpec* Hypertable::Schema::get_column_family ( int32_t  id,
bool  get_deleted = false 
)
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.

Parameters
idColumn family ID of specification to fetch
get_deletedReturn specification even if it is deleted
Returns
Column family specification with ID id if it exists and it is not deleted or get_deleted is true. Otherwise, nullptr is returned.

Definition at line 292 of file Schema.h.

int64_t Hypertable::Schema::get_generation ( ) const
inline

Gets generation.

Returns the value of m_generation.

Returns
Generation

Definition at line 207 of file Schema.h.

int32_t Hypertable::Schema::get_group_commit_interval ( )
inline

Gets group commit interval.

Returns
Group commit interval

Definition at line 370 of file Schema.h.

int32_t Schema::get_max_column_family_id ( )

Gets the maximum column family ID.

Protected methods.

Returns
Maximum column family ID.

Definition at line 328 of file Schema.cc.

TableParts Schema::get_table_parts ( )

Gets table parts.

Returns
TableParts object describing table parts defined by this schema.

Definition at line 337 of file Schema.cc.

int32_t Hypertable::Schema::get_version ( ) const
inline

Gets version number.

Returns the value of m_version.

Returns
Version Number

Definition at line 217 of file Schema.h.

void Schema::merge_table_defaults ( ColumnFamilySpec cf_spec)
private

Merges default column family options into a column family spec.

Parameters
cf_specColumn family spec into which table defaults are to be merged

Definition at line 540 of file Schema.cc.

void Schema::merge_table_defaults ( AccessGroupSpec ag_spec)
private

Merges default access group options into access group spec.

Parameters
ag_specAccess group spec into which table defaults are to be merged

Definition at line 550 of file Schema.cc.

Schema * Schema::new_instance ( const std::string &  buf)
static

Creates schema object from XML schema string.

Constructs a new schema from the XML specification held in buf and them calls validate().

Parameters
bufBuffer holding XML schema string.
Returns
Pointer to newly allocated Schema object.

Definition at line 202 of file Schema.cc.

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.

Parameters
nameName of column family to remove
Returns
Removed column family

Definition at line 396 of file Schema.cc.

void Schema::rename_column_family ( const String old_name,
const String new_name 
)

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.

Parameters
old_nameName of existing column family to be renamed
new_nameNew name for column family

Definition at line 447 of file Schema.cc.

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
Parameters
table_nameName of table
Returns
String representation of schema as HQL CREATE TABLE statement.

Definition at line 292 of file Schema.cc.

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>
Parameters
with_idsInclude generation and column IDs in output
Returns
String representation of schema in XML format

Definition at line 265 of file Schema.cc.

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().

Parameters
new_agReplacement access group specification
Returns
Old access group specification

Definition at line 414 of file Schema.cc.

void Hypertable::Schema::set_access_group_defaults ( const AccessGroupOptions defaults)
inline

Sets default access group options.

Sets m_ag_defaults to defaults

Parameters
defaultsAccess group options to use as table defaults

Definition at line 375 of file Schema.h.

void Hypertable::Schema::set_column_family_defaults ( const ColumnFamilyOptions defaults)
inline

Sets default column family options.

Sets m_cf_defaults to defaults

Parameters
defaultsColumn family options to use as table defaults

Definition at line 386 of file Schema.h.

void Hypertable::Schema::set_generation ( int64_t  generation)
inline

Sets generation.

Sets m_generation to generation

Parameters
generationNew generation value

Definition at line 212 of file Schema.h.

void Hypertable::Schema::set_group_commit_interval ( int32_t  interval)
inline

Sets group commit interval.

Sets m_group_commit_interval to interval.

Parameters
intervalNew value for group commit interval

Definition at line 364 of file Schema.h.

void Hypertable::Schema::set_version ( int32_t  version)
inline

Sets version number.

Sets m_version to version

Parameters
versionNew version number

Definition at line 222 of file Schema.h.

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.

Parameters
generationNew generation

Definition at line 244 of file Schema.cc.

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.

Exceptions
Exceptionwith 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.

Definition at line 505 of file Schema.cc.

Member Data Documentation

CstrAccessGroupMap Hypertable::Schema::m_access_group_map
private

Definition at line 448 of file Schema.h.

AccessGroupSpecs Hypertable::Schema::m_access_groups
private

Access group specifications.

Definition at line 444 of file Schema.h.

AccessGroupOptions Hypertable::Schema::m_ag_defaults
private

Default access group options.

Definition at line 438 of file Schema.h.

CharArena Hypertable::Schema::m_arena
private

Definition at line 426 of file Schema.h.

ColumnFamilyOptions Hypertable::Schema::m_cf_defaults
private

Default column family options.

Definition at line 441 of file Schema.h.

ColumnFamilySpecs Hypertable::Schema::m_column_families
private

&Column family specifications

Definition at line 451 of file Schema.h.

std::map<int32_t, ColumnFamilySpec *> Hypertable::Schema::m_column_family_id_map
private

Map of column family specifications (key == ID)

Definition at line 458 of file Schema.h.

CstrColumnFamilyMap Hypertable::Schema::m_column_family_map
private

Definition at line 455 of file Schema.h.

std::vector<bool> Hypertable::Schema::m_counter_mask
private

Bitmask describing which column families are counters.

Definition at line 461 of file Schema.h.

int64_t Hypertable::Schema::m_generation
private

Generation.

Definition at line 429 of file Schema.h.

int32_t Hypertable::Schema::m_group_commit_interval {}
private

Group commit interval.

Definition at line 435 of file Schema.h.

int32_t Hypertable::Schema::m_version {}
private

Version number.

Definition at line 432 of file Schema.h.


The documentation for this class was generated from the following files: