Kea  2.3.4-git File Reference

This file holds the implementation of the Lease Manager using MySQL. More...

#include <config.h>
#include <asiolink/io_address.h>
#include <dhcp/duid.h>
#include <dhcp/hwaddr.h>
#include <dhcpsrv/cfg_db_access.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/dhcpsrv_log.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcpsrv/mysql_lease_mgr.h>
#include <dhcpsrv/timer_mgr.h>
#include <mysql/mysql_connection.h>
#include <util/multi_threading_mgr.h>
#include <boost/array.hpp>
#include <boost/make_shared.hpp>
#include <boost/static_assert.hpp>
#include <mysqld_error.h>
#include <iostream>
#include <iomanip>
#include <limits>
#include <sstream>
#include <string>
#include <time.h>
+ Include dependency graph for

Go to the source code of this file.


class  isc::dhcp::MySqlLease4Exchange
 Exchange MySQL and Lease4 Data. More...
class  isc::dhcp::MySqlLease6Exchange
 Exchange MySQL and Lease6 Data. More...
class  isc::dhcp::MySqlLeaseExchange
 Common MySQL and Lease Data Methods. More...
class  isc::dhcp::MySqlLeaseStatsQuery
 MySql derivation of the statistical lease data query. More...


 Defines the logger used by the top-level component of kea-lfc.

Detailed Description

This file holds the implementation of the Lease Manager using MySQL.

The implementation uses MySQL's C API, as it comes as standard with the MySQL client libraries.

In general, each of the database access methods corresponds to one SQL statement. To avoid the overhead of parsing a statement every time it is used, when the database is opened "prepared statements" are created - essentially doing the SQL parsing up front. Every time a method is used to access data, the corresponding prepared statement is referenced. Each prepared statement contains a set of placeholders for data, each placeholder being for:

  • data being added to the database (as in adding or updating a lease)
  • data being retrieved from the database (as in getting lease information)
  • selection criteria used to determine which records to update/retrieve.

All such data is associated with the prepared statement using an array of MYSQL_BIND structures. Each element in the array corresponds to one parameter in the prepared statement - the first element in the array is associated with the first parameter, the second element with the second parameter etc.

Within this file, the setting up of the MYSQL_BIND arrays for data being passed to and retrieved from the database is handled in the isc::dhcp::MySqlLease4Exchange and isc::dhcp::MySqlLease6Exchange classes. The classes also hold intermediate variables required for exchanging some of the data.

With these exchange objects in place, many of the methods follow similar logic:

  • Set up the MYSQL_BIND array for data being transferred to/from the database. For data being transferred to the database, some of the data is extracted from the lease to intermediate variables, whilst in other cases the MYSQL_BIND arrays point to the data in the lease.
  • Set up the MYSQL_BIND array for the data selection parameters.
  • Bind these arrays to the prepared statement.
  • Execute the statement.
  • If there is output, copy the data from the bound variables to the output lease object.

Definition in file