CARMA C++
carma::dbms::TableManager Class Reference

This class is responsible for managing the large, short lived tables produced by CARMA. More...

#include <carma/dbms/TableManager.h>

Public Member Functions

virtual int createMonitorDataTable (const carma::dbms::MonitorAverageType &averageType, const carma::dbms::MonitorAggregateType &aggType, const unsigned &requiredSpace, std::string &tableName, const std::string &tag)
 create a monitor data table table More...
 
void loadConfigurationInformation ()
 (re)load config info regarding partitions from the db this is called by the constructor and can be called periodically after construction to check for configuration changes More...
 
 TableManager (const bool &persistentConnection=true, DBConfigurator *dbconf=NULL)
 constructor More...
 
void updateMonitorIndexTable (const std::string &tableName, const MonitorAverageType &averageType)
 insert the max and min frame counts into the specified row in the volatile tables table. More...
 

Protected Member Functions

void closeDBConnection ()
 close the DBConnection More...
 
void closeDBConnectionIfNecessary ()
 close the db connection and delete the db connection object if !persistentConnection_ More...
 
void dropTable (const std::string &tableName) const
 removes a table from the db and removes its entry in MONITOR_INDEX_TABLE Callers from this class must already have opened a DBConnection More...
 
virtual int getAvailablePartition (const int &requiredSpace, const bool &connectionIsOpen)
 find a partition on which a new table can be created. More...
 
std::map< int, Partition > getEmptyPartitions (const bool &connectionIsOpen)
 get the partitions which do not have any volatile tables on them This method queries the database to determine this; it does not interrogate the filesystem the returned map has partition IDs as its keys and Partition objects as its values More...
 
unsigned getFreeMB (const std::string &partition) const
 get the available space (for normal users) in MB of the specified partition More...
 
unsigned getTotalMB (const std::string &partition) const
 get the total (used+free) size, in megabytes, of the specified partition More...
 
void openDBConnectionIfNecessary ()
 open a connection to the database if one is not currently established More...
 

Protected Attributes

carma::dbms::DBConnectiondbc_
 
DBConfiguratordbconf_
 
std::map< int, Partition > partitions_
 
bool persistentConnection_
 
std::string rdbms_
 
bool useProductionDB_
 

Static Protected Attributes

static int minimumCorrelRetentionFrames_
 
static int minimumFrameRetentionFrames_
 
static int minimumMinuteRetentionFrames_
 

Detailed Description

This class is responsible for managing the large, short lived tables produced by CARMA.

Examples of such tables are the monitor data tables and the log tables. All requests to create new tables therefore must be submitted via this class. An object of this class maintains a map of partitions where tables can be located. Once partitions fill up, this class will drop old tables as it receives create table requests.

Todo:
it would be nice to have paritition/minimum space info in a config file, rather than hardcoded in the header file, which is read as necessary (ie, without having to restart the app should this file be updated).

Definition at line 34 of file TableManager.h.

Constructor & Destructor Documentation

carma::dbms::TableManager::TableManager ( const bool &  persistentConnection = true,
DBConfigurator dbconf = NULL 
)

constructor

Parameters
persistentConnectionmaintain a persistent connection to the db for the life of this object?
dbconfDBConfigurator object used to configure the DBConnection objects this class creates. To guard against the caller deleting this pointer after a TableManager has been created, this constructor creates a copy of the dbconf object which is pointed to
Exceptions
DBConnectionException

Member Function Documentation

void carma::dbms::TableManager::closeDBConnection ( )
protected

close the DBConnection

void carma::dbms::TableManager::closeDBConnectionIfNecessary ( )
protected

close the db connection and delete the db connection object if !persistentConnection_

virtual int carma::dbms::TableManager::createMonitorDataTable ( const carma::dbms::MonitorAverageType averageType,
const carma::dbms::MonitorAggregateType aggType,
const unsigned &  requiredSpace,
std::string &  tableName,
const std::string &  tag 
)
virtual

create a monitor data table table

Parameters
averageType[in] averageType the average type of the table
aggType[in] dataType the type of data that will be loaded into the table
requiredSpace[in] requiredSpace the space required for the table, in MB
tableName[out] tableName the name of the created table which will have the tag parameter at the end
tag[in] tag string to append to the end of the table base name to assure that the table name is unique
Returns
the partition ID of the partition on which the table was created or < 0 if the table couldn't be created
Exceptions
DBConnectionException
void carma::dbms::TableManager::dropTable ( const std::string &  tableName) const
protected

removes a table from the db and removes its entry in MONITOR_INDEX_TABLE Callers from this class must already have opened a DBConnection

Parameters
tableNamethe table to be removed
Exceptions
DBConnectionException
virtual int carma::dbms::TableManager::getAvailablePartition ( const int &  requiredSpace,
const bool &  connectionIsOpen 
)
protectedvirtual

find a partition on which a new table can be created.

This method will delete tables to free up the specified amount of disk space if necessary. The target partition will be the partition with the oldest table which contains at least the required amount of space when empty

Parameters
requiredSpacethe amount of space (in MB) above the minimum allowed space that must be made available
connectionIsOpenthe caller (a method from this class) has already opened the connection to the database
Returns
partition ID for the partition on which the table should be created
Exceptions
TableManagerExceptionif no available partition can be found
std::map<int, Partition> carma::dbms::TableManager::getEmptyPartitions ( const bool &  connectionIsOpen)
protected

get the partitions which do not have any volatile tables on them This method queries the database to determine this; it does not interrogate the filesystem the returned map has partition IDs as its keys and Partition objects as its values

Parameters
connectionIsOpenthe caller (a method from this class) has already opened the connection to the database
Returns
map of partitionIDs -> partition objects for partitions with no volatile tables on them
unsigned carma::dbms::TableManager::getFreeMB ( const std::string &  partition) const
protected

get the available space (for normal users) in MB of the specified partition

Parameters
partitionthe partition for which to get the available space
Returns
available space, in MB
unsigned carma::dbms::TableManager::getTotalMB ( const std::string &  partition) const
protected

get the total (used+free) size, in megabytes, of the specified partition

Parameters
partitionthe partition for which to get the total size
Returns
the total partition size in megabytes
void carma::dbms::TableManager::loadConfigurationInformation ( )

(re)load config info regarding partitions from the db this is called by the constructor and can be called periodically after construction to check for configuration changes

Exceptions
DBConnectionException
void carma::dbms::TableManager::openDBConnectionIfNecessary ( )
protected

open a connection to the database if one is not currently established

Exceptions
DBConnectionException
void carma::dbms::TableManager::updateMonitorIndexTable ( const std::string &  tableName,
const MonitorAverageType averageType 
)

insert the max and min frame counts into the specified row in the volatile tables table.

Generally called after data has been copletely loaded into a table

Parameters
tableNameupdate the data for this table
Exceptions
DBConnectionException

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