![]() |
Kea
1.5.0
|
Implementation of the MySqlHostDataSource. More...
Public Types | |
| enum | StatementIndex { GET_HOST_DHCPID, GET_HOST_ADDR, GET_HOST_SUBID4_DHCPID, GET_HOST_SUBID6_DHCPID, GET_HOST_SUBID_ADDR, GET_HOST_PREFIX, GET_HOST_SUBID6_ADDR, INSERT_HOST, INSERT_V6_RESRV, INSERT_V4_OPTION, INSERT_V6_OPTION, DEL_HOST_ADDR4, DEL_HOST_SUBID4_ID, DEL_HOST_SUBID6_ID, NUM_STATEMENTS } |
| Statement Tags. More... | |
Public Member Functions | |
| MySqlHostDataSourceImpl (const MySqlConnection::ParameterMap ¶meters) | |
| Constructor. More... | |
| ~MySqlHostDataSourceImpl () | |
| Destructor. More... | |
| void | addOption (const MySqlHostDataSourceImpl::StatementIndex &stindex, const OptionDescriptor &opt_desc, const std::string &opt_space, const OptionalValue< SubnetID > &subnet_id, const HostID &host_id) |
| Inserts a single DHCP option into the database. More... | |
| void | addOptions (const StatementIndex &stindex, const ConstCfgOptionPtr &options_cfg, const uint64_t host_id) |
| Inserts multiple options into the database. More... | |
| void | addResv (const IPv6Resrv &resv, const HostID &id) |
| Inserts IPv6 Reservation into ipv6_reservation table. More... | |
| void | addStatement (MySqlHostDataSourceImpl::StatementIndex stindex, std::vector< MYSQL_BIND > &bind) |
| Executes statements which inserts a row into one of the tables. More... | |
| void | checkError (const int status, const StatementIndex index, const char *what) const |
| Check Error and Throw Exception. More... | |
| void | checkReadOnly () const |
| Throws exception if database is read only. More... | |
| bool | delStatement (StatementIndex stindex, MYSQL_BIND *bind) |
| Executes statements that delete records. More... | |
| ConstHostPtr | getHost (const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, StatementIndex stindex, boost::shared_ptr< MySqlHostExchange > exchange) const |
| Retrieves a host by subnet and client's unique identifier. More... | |
| void | getHostCollection (StatementIndex stindex, MYSQL_BIND *bind, boost::shared_ptr< MySqlHostExchange > exchange, ConstHostCollection &result, bool single) const |
| Creates collection of Host objects with associated information such as IPv6 reservations and/or DHCP options. More... | |
| std::pair< uint32_t, uint32_t > | getVersion () const |
| Returns backend version. More... | |
Public Attributes | |
| MySqlConnection | conn_ |
| MySQL connection. More... | |
| boost::shared_ptr< MySqlHostWithOptionsExchange > | host_exchange_ |
| Pointer to the object representing an exchange which can be used to retrieve hosts and DHCPv4 options. More... | |
| boost::shared_ptr< MySqlHostIPv6Exchange > | host_ipv46_exchange_ |
| Pointer to an object representing an exchange which can be used to retrieve hosts, DHCPv4 and DHCPv6 options, and IPv6 reservations using a single query. More... | |
| boost::shared_ptr< MySqlHostIPv6Exchange > | host_ipv6_exchange_ |
| Pointer to an object representing an exchange which can be used to retrieve hosts, DHCPv6 options and IPv6 reservations. More... | |
| boost::shared_ptr< MySqlIPv6ReservationExchange > | host_ipv6_reservation_exchange_ |
| Pointer to an object representing an exchange which can be used to insert new IPv6 reservation. More... | |
| boost::shared_ptr< MySqlOptionExchange > | host_option_exchange_ |
| Pointer to an object representing an exchange which can be used to insert DHCPv4 or DHCPv6 option into dhcp4_options or dhcp6_options table. More... | |
| bool | is_readonly_ |
| Indicates if the database is opened in read only mode. More... | |
Static Public Attributes | |
| static const StatementIndex | WRITE_STMTS_BEGIN = INSERT_HOST |
| Index of first statement performing write to the database. More... | |
Implementation of the MySqlHostDataSource.
Definition at line 1930 of file mysql_host_data_source.cc.
Statement Tags.
The contents of the enum are indexes into the list of SQL statements. It is assumed that the order is such that the indices of statements reading the database are less than those of statements modifying the database.
Definition at line 1939 of file mysql_host_data_source.cc.
| isc::dhcp::MySqlHostDataSourceImpl::MySqlHostDataSourceImpl | ( | const MySqlConnection::ParameterMap & | parameters | ) |
Constructor.
This constructor opens database connection and initializes prepared statements used in the queries.
Definition at line 2338 of file mysql_host_data_source.cc.
References isc::db::DatabaseConnection::configuredReadOnly(), conn_, isc::dhcp::dhcpsrv_logger, getVersion(), is_readonly_, isc_throw, LOG_INFO, isc::db::MySqlConnection::mysql_, isc::db::MYSQL_SCHEMA_VERSION_MAJOR, isc::db::MYSQL_SCHEMA_VERSION_MINOR, isc::db::MySqlConnection::openDatabase(), isc::db::MySqlConnection::prepareStatements(), isc::dhcp::tagged_statements, and WRITE_STMTS_BEGIN.
Here is the call graph for this function:| isc::dhcp::MySqlHostDataSourceImpl::~MySqlHostDataSourceImpl | ( | ) |
Destructor.
Definition at line 2396 of file mysql_host_data_source.cc.
References conn_, and isc::db::MySqlConnection::statements_.
| void isc::dhcp::MySqlHostDataSourceImpl::addOption | ( | const MySqlHostDataSourceImpl::StatementIndex & | stindex, |
| const OptionDescriptor & | opt_desc, | ||
| const std::string & | opt_space, | ||
| const OptionalValue< SubnetID > & | subnet_id, | ||
| const HostID & | host_id | ||
| ) |
Inserts a single DHCP option into the database.
| stindex | Index of a statement being executed. |
| opt_desc | Option descriptor holding information about an option to be inserted into the database. |
| opt_space | Option space name. |
| subnet_id | Subnet identifier. |
| host_id | Host identifier. |
Definition at line 2521 of file mysql_host_data_source.cc.
References addStatement(), and host_option_exchange_.
Referenced by addOptions().
Here is the call graph for this function:| void isc::dhcp::MySqlHostDataSourceImpl::addOptions | ( | const StatementIndex & | stindex, |
| const ConstCfgOptionPtr & | options_cfg, | ||
| const uint64_t | host_id | ||
| ) |
Inserts multiple options into the database.
| stindex | Index of a statement being executed. |
| options_cfg | An object holding a collection of options to be inserted into the database. |
| host_id | Host identifier retrieved using mysql_insert_id. |
Definition at line 2534 of file mysql_host_data_source.cc.
References addOption().
Referenced by isc::dhcp::MySqlHostDataSource::add().
Here is the call graph for this function:Inserts IPv6 Reservation into ipv6_reservation table.
| resv | IPv6 Reservation to be added |
| id | ID of a host owning this reservation |
Definition at line 2512 of file mysql_host_data_source.cc.
References addStatement(), host_ipv6_reservation_exchange_, and INSERT_V6_RESRV.
Referenced by isc::dhcp::MySqlHostDataSource::add().
Here is the call graph for this function:| void isc::dhcp::MySqlHostDataSourceImpl::addStatement | ( | MySqlHostDataSourceImpl::StatementIndex | stindex, |
| std::vector< MYSQL_BIND > & | bind | ||
| ) |
Executes statements which inserts a row into one of the tables.
| stindex | Index of a statement being executed. |
| bind | Vector of MYSQL_BIND objects to be used when making the query. |
| isc::db::DuplicateEntry | Database throws duplicate entry error |
Definition at line 2473 of file mysql_host_data_source.cc.
References checkError(), conn_, isc_throw, isc::db::MySqlConnection::mysql_, and isc::db::MySqlConnection::statements_.
Referenced by isc::dhcp::MySqlHostDataSource::add(), addOption(), and addResv().
Here is the call graph for this function:| void isc::dhcp::MySqlHostDataSourceImpl::checkError | ( | const int | status, |
| const StatementIndex | index, | ||
| const char * | what | ||
| ) | const |
Check Error and Throw Exception.
This method invokes db::MySqlConnection::checkError.
| status | Status code: non-zero implies an error |
| index | Index of statement that caused the error |
| what | High-level description of the error |
| isc::dhcp::DbOperationError | An operation on the open database has failed. |
Definition at line 2560 of file mysql_host_data_source.cc.
References isc::db::MySqlConnection::checkError(), and conn_.
Referenced by addStatement(), delStatement(), and getHostCollection().
Here is the call graph for this function:| void isc::dhcp::MySqlHostDataSourceImpl::checkReadOnly | ( | ) | const |
Throws exception if database is read only.
This method should be called by the methods which write to the database. If the backend is operating in read-only mode this method will throw exception.
| DbReadOnly | if backend is operating in read only mode. |
Definition at line 2673 of file mysql_host_data_source.cc.
References is_readonly_, and isc_throw.
Referenced by isc::dhcp::MySqlHostDataSource::add(), isc::dhcp::MySqlHostDataSource::commit(), isc::dhcp::MySqlHostDataSource::del(), isc::dhcp::MySqlHostDataSource::del4(), isc::dhcp::MySqlHostDataSource::del6(), and isc::dhcp::MySqlHostDataSource::rollback().
| bool isc::dhcp::MySqlHostDataSourceImpl::delStatement | ( | StatementIndex | stindex, |
| MYSQL_BIND * | bind | ||
| ) |
Executes statements that delete records.
| stindex | Index of a statement being executed. |
| bind | Vector of MYSQL_BIND objects to be used when making the query. |
Definition at line 2493 of file mysql_host_data_source.cc.
References checkError(), conn_, and isc::db::MySqlConnection::statements_.
Referenced by isc::dhcp::MySqlHostDataSource::del(), isc::dhcp::MySqlHostDataSource::del4(), and isc::dhcp::MySqlHostDataSource::del6().
Here is the call graph for this function:| ConstHostPtr isc::dhcp::MySqlHostDataSourceImpl::getHost | ( | const SubnetID & | subnet_id, |
| const Host::IdentifierType & | identifier_type, | ||
| const uint8_t * | identifier_begin, | ||
| const size_t | identifier_len, | ||
| StatementIndex | stindex, | ||
| boost::shared_ptr< MySqlHostExchange > | exchange | ||
| ) | const |
Retrieves a host by subnet and client's unique identifier.
This method is used by both MySqlHostDataSource::get4 and MySqlHOstDataSource::get6 methods.
| subnet_id | Subnet identifier. |
| identifier_type | Identifier type. |
| identifier_begin | Pointer to a beginning of a buffer containing an identifier. |
| identifier_len | Identifier length. |
| stindex | Statement index. |
| exchange | Pointer to the exchange object used for the particular query. |
Definition at line 2629 of file mysql_host_data_source.cc.
References getHostCollection(), and isc::db::MLM_TRUE.
Referenced by isc::dhcp::MySqlHostDataSource::get4(), and isc::dhcp::MySqlHostDataSource::get6().
Here is the call graph for this function:| void isc::dhcp::MySqlHostDataSourceImpl::getHostCollection | ( | StatementIndex | stindex, |
| MYSQL_BIND * | bind, | ||
| boost::shared_ptr< MySqlHostExchange > | exchange, | ||
| ConstHostCollection & | result, | ||
| bool | single | ||
| ) | const |
Creates collection of Host objects with associated information such as IPv6 reservations and/or DHCP options.
This method performs a query which returns host information from the 'hosts' table. The query may also use LEFT JOIN clause to retrieve information from other tables, e.g. ipv6_reservations, dhcp4_options and dhcp6_options. Whether IPv6 reservations and/or options are assigned to the Host objects depends on the type of the exchange object.
| stindex | Statement index. | |
| bind | Pointer to an array of MySQL bindings. | |
| exchange | Pointer to the exchange object used for the particular query. | |
| [out] | result | Reference to the collection of hosts returned. |
| single | A boolean value indicating if a single host is expected to be returned, or multiple hosts. |
Definition at line 2567 of file mysql_host_data_source.cc.
References checkError(), conn_, isc_throw, isc::db::MLM_MYSQL_FETCH_FAILURE, isc::db::MLM_MYSQL_FETCH_SUCCESS, isc::db::MySqlConnection::statements_, isc::db::MySqlConnection::text_statements_, and isc::Exception::what().
Referenced by isc::dhcp::MySqlHostDataSource::get4(), isc::dhcp::MySqlHostDataSource::get6(), isc::dhcp::MySqlHostDataSource::getAll(), isc::dhcp::MySqlHostDataSource::getAll4(), and getHost().
Here is the call graph for this function:| std::pair< uint32_t, uint32_t > isc::dhcp::MySqlHostDataSourceImpl::getVersion | ( | ) | const |
Returns backend version.
The method is called by the constructor after opening the database but prior to preparing SQL statements, to verify that the schema version is correct. Thus it must not rely on a pre-prepared statement or formal statement execution error checking.
| isc::dhcp::DbOperationError | An operation on the open database has failed. |
Definition at line 2412 of file mysql_host_data_source.cc.
References conn_, isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL, isc::dhcp::dhcpsrv_logger, isc_throw, LOG_DEBUG, and isc::db::MySqlConnection::mysql_.
Referenced by isc::dhcp::MySqlHostDataSource::getVersion(), and MySqlHostDataSourceImpl().
| MySqlConnection isc::dhcp::MySqlHostDataSourceImpl::conn_ |
MySQL connection.
Definition at line 2125 of file mysql_host_data_source.cc.
Referenced by isc::dhcp::MySqlHostDataSource::add(), addStatement(), checkError(), isc::dhcp::MySqlHostDataSource::commit(), delStatement(), getHostCollection(), isc::dhcp::MySqlHostDataSource::getName(), getVersion(), MySqlHostDataSourceImpl(), isc::dhcp::MySqlHostDataSource::rollback(), and ~MySqlHostDataSourceImpl().
| boost::shared_ptr<MySqlHostWithOptionsExchange> isc::dhcp::MySqlHostDataSourceImpl::host_exchange_ |
Pointer to the object representing an exchange which can be used to retrieve hosts and DHCPv4 options.
Definition at line 2104 of file mysql_host_data_source.cc.
Referenced by isc::dhcp::MySqlHostDataSource::add(), isc::dhcp::MySqlHostDataSource::get4(), and isc::dhcp::MySqlHostDataSource::getAll4().
| boost::shared_ptr<MySqlHostIPv6Exchange> isc::dhcp::MySqlHostDataSourceImpl::host_ipv46_exchange_ |
Pointer to an object representing an exchange which can be used to retrieve hosts, DHCPv4 and DHCPv6 options, and IPv6 reservations using a single query.
Definition at line 2113 of file mysql_host_data_source.cc.
Referenced by isc::dhcp::MySqlHostDataSource::getAll().
| boost::shared_ptr<MySqlHostIPv6Exchange> isc::dhcp::MySqlHostDataSourceImpl::host_ipv6_exchange_ |
Pointer to an object representing an exchange which can be used to retrieve hosts, DHCPv6 options and IPv6 reservations.
Definition at line 2108 of file mysql_host_data_source.cc.
Referenced by isc::dhcp::MySqlHostDataSource::get6().
| boost::shared_ptr<MySqlIPv6ReservationExchange> isc::dhcp::MySqlHostDataSourceImpl::host_ipv6_reservation_exchange_ |
Pointer to an object representing an exchange which can be used to insert new IPv6 reservation.
Definition at line 2117 of file mysql_host_data_source.cc.
Referenced by addResv().
| boost::shared_ptr<MySqlOptionExchange> isc::dhcp::MySqlHostDataSourceImpl::host_option_exchange_ |
Pointer to an object representing an exchange which can be used to insert DHCPv4 or DHCPv6 option into dhcp4_options or dhcp6_options table.
Definition at line 2122 of file mysql_host_data_source.cc.
Referenced by addOption().
| bool isc::dhcp::MySqlHostDataSourceImpl::is_readonly_ |
Indicates if the database is opened in read only mode.
Definition at line 2128 of file mysql_host_data_source.cc.
Referenced by checkReadOnly(), and MySqlHostDataSourceImpl().
|
static |
Index of first statement performing write to the database.
This value is used to mark border line between queries and other statements and statements performing write operation on the database, such as INSERT, DELETE, UPDATE.
Definition at line 1962 of file mysql_host_data_source.cc.
Referenced by MySqlHostDataSourceImpl().