mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 22:15:23 +00:00
[#1074] implemented connection pool for pgsql host mgr
This commit is contained in:
@@ -17,6 +17,15 @@ namespace dhcp {
|
||||
/// Forward declaration to the implementation of the @ref PgSqlHostDataSource.
|
||||
class PgSqlHostDataSourceImpl;
|
||||
|
||||
/// @brief Type of pointers to PgSqlHostDataSourceImpl.
|
||||
typedef boost::shared_ptr<PgSqlHostDataSourceImpl> PgSqlHostDataSourceImplPtr;
|
||||
|
||||
/// Forward declaration for the thread context for the manager pool.
|
||||
class PgSqlHostContext;
|
||||
|
||||
/// @brief Type of pointers to contexts.
|
||||
typedef boost::shared_ptr<PgSqlHostContext> PgSqlHostContextPtr;
|
||||
|
||||
/// @brief PostgreSQL Host Data Source
|
||||
///
|
||||
/// This class implements the @ref isc::dhcp::BaseHostDataSource interface to
|
||||
@@ -32,7 +41,7 @@ class PgSqlHostDataSourceImpl;
|
||||
/// - IDENT_CIRCUIT_ID
|
||||
/// - IDENT_CLIENT_ID
|
||||
///
|
||||
class PgSqlHostDataSource: public BaseHostDataSource {
|
||||
class PgSqlHostDataSource : public BaseHostDataSource {
|
||||
public:
|
||||
|
||||
/// @brief Constructor
|
||||
@@ -107,7 +116,8 @@ public:
|
||||
/// @param addr specified address.
|
||||
/// @return true if deletion was successful, false if the host was not there.
|
||||
/// @throw various exceptions in case of errors
|
||||
virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr);
|
||||
virtual bool del(const SubnetID& subnet_id,
|
||||
const asiolink::IOAddress& addr);
|
||||
|
||||
/// @brief Attempts to delete a host by (subnet4-id, identifier type, identifier)
|
||||
///
|
||||
@@ -123,7 +133,8 @@ public:
|
||||
/// @throw various exceptions in case of errors
|
||||
virtual bool del4(const SubnetID& subnet_id,
|
||||
const Host::IdentifierType& identifier_type,
|
||||
const uint8_t* identifier_begin, const size_t identifier_len);
|
||||
const uint8_t* identifier_begin,
|
||||
const size_t identifier_len);
|
||||
|
||||
/// @brief Attempts to delete a host by (subnet6-id, identifier type, identifier)
|
||||
///
|
||||
@@ -139,7 +150,8 @@ public:
|
||||
/// @throw various exceptions in case of errors
|
||||
virtual bool del6(const SubnetID& subnet_id,
|
||||
const Host::IdentifierType& identifier_type,
|
||||
const uint8_t* identifier_begin, const size_t identifier_len);
|
||||
const uint8_t* identifier_begin,
|
||||
const size_t identifier_len);
|
||||
|
||||
/// @brief Return all hosts connected to any subnet for which reservations
|
||||
/// have been made using a specified identifier.
|
||||
@@ -154,9 +166,9 @@ public:
|
||||
/// @param identifier_len Identifier length.
|
||||
///
|
||||
/// @return Collection of const @c Host objects.
|
||||
virtual ConstHostCollection
|
||||
getAll(const Host::IdentifierType& identifier_type,
|
||||
const uint8_t* identifier_begin, const size_t identifier_len) const;
|
||||
virtual ConstHostCollection getAll(const Host::IdentifierType& identifier_type,
|
||||
const uint8_t* identifier_begin,
|
||||
const size_t identifier_len) const;
|
||||
|
||||
/// @brief Return all hosts in a DHCPv4 subnet.
|
||||
///
|
||||
@@ -167,8 +179,7 @@ public:
|
||||
/// @param subnet_id subnet identifier to filter by
|
||||
///
|
||||
/// @return Collection of const @ref Host objects.
|
||||
virtual ConstHostCollection
|
||||
getAll4(const SubnetID& subnet_id) const;
|
||||
virtual ConstHostCollection getAll4(const SubnetID& subnet_id) const;
|
||||
|
||||
/// @brief Return all hosts in a DHCPv6 subnet.
|
||||
///
|
||||
@@ -179,8 +190,7 @@ public:
|
||||
/// @param subnet_id subnet identifier to filter by
|
||||
///
|
||||
/// @return Collection of const @ref Host objects.
|
||||
virtual ConstHostCollection
|
||||
getAll6(const SubnetID& subnet_id) const;
|
||||
virtual ConstHostCollection getAll6(const SubnetID& subnet_id) const;
|
||||
|
||||
/// @brief Return all hosts with a hostname.
|
||||
///
|
||||
@@ -192,8 +202,7 @@ public:
|
||||
/// @param hostname The lower case hostname.
|
||||
///
|
||||
/// @return Collection of const @c Host objects.
|
||||
virtual ConstHostCollection
|
||||
getAllbyHostname(const std::string& hostname) const;
|
||||
virtual ConstHostCollection getAllbyHostname(const std::string& hostname) const;
|
||||
|
||||
/// @brief Return all hosts with a hostname in a DHCPv4 subnet.
|
||||
///
|
||||
@@ -204,8 +213,8 @@ public:
|
||||
/// @param subnet_id Subnet identifier.
|
||||
///
|
||||
/// @return Collection of const @c Host objects.
|
||||
virtual ConstHostCollection
|
||||
getAllbyHostname4(const std::string& hostname, const SubnetID& subnet_id) const;
|
||||
virtual ConstHostCollection getAllbyHostname4(const std::string& hostname,
|
||||
const SubnetID& subnet_id) const;
|
||||
|
||||
/// @brief Return all hosts with a hostname in a DHCPv6 subnet.
|
||||
///
|
||||
@@ -216,8 +225,8 @@ public:
|
||||
/// @param subnet_id Subnet identifier.
|
||||
///
|
||||
/// @return Collection of const @c Host objects.
|
||||
virtual ConstHostCollection
|
||||
getAllbyHostname6(const std::string& hostname, const SubnetID& subnet_id) const;
|
||||
virtual ConstHostCollection getAllbyHostname6(const std::string& hostname,
|
||||
const SubnetID& subnet_id) const;
|
||||
|
||||
/// @brief Returns range of hosts in a DHCPv4 subnet.
|
||||
///
|
||||
@@ -236,11 +245,10 @@ public:
|
||||
/// @param page_size maximum size of the page returned.
|
||||
///
|
||||
/// @return Collection of const @c Host objects (may be empty).
|
||||
virtual ConstHostCollection
|
||||
getPage4(const SubnetID& subnet_id,
|
||||
size_t& source_index,
|
||||
uint64_t lower_host_id,
|
||||
const HostPageSize& page_size) const;
|
||||
virtual ConstHostCollection getPage4(const SubnetID& subnet_id,
|
||||
size_t& source_index,
|
||||
uint64_t lower_host_id,
|
||||
const HostPageSize& page_size) const;
|
||||
|
||||
/// @brief Returns range of hosts in a DHCPv6 subnet.
|
||||
///
|
||||
@@ -259,11 +267,10 @@ public:
|
||||
/// @param page_size maximum size of the page returned.
|
||||
///
|
||||
/// @return Collection of const @c Host objects (may be empty).
|
||||
virtual ConstHostCollection
|
||||
getPage6(const SubnetID& subnet_id,
|
||||
size_t& source_index,
|
||||
uint64_t lower_host_id,
|
||||
const HostPageSize& page_size) const;
|
||||
virtual ConstHostCollection getPage6(const SubnetID& subnet_id,
|
||||
size_t& source_index,
|
||||
uint64_t lower_host_id,
|
||||
const HostPageSize& page_size) const;
|
||||
|
||||
/// @brief Returns a collection of hosts using the specified IPv4 address.
|
||||
///
|
||||
@@ -273,8 +280,7 @@ public:
|
||||
/// @param address IPv4 address for which the @c Host object is searched.
|
||||
///
|
||||
/// @return Collection of const @c Host objects.
|
||||
virtual ConstHostCollection
|
||||
getAll4(const asiolink::IOAddress& address) const;
|
||||
virtual ConstHostCollection getAll4(const asiolink::IOAddress& address) const;
|
||||
|
||||
/// @brief Returns a host connected to the IPv4 subnet.
|
||||
///
|
||||
@@ -286,9 +292,10 @@ public:
|
||||
///
|
||||
/// @return Const @c Host object for which reservation has been made using
|
||||
/// the specified identifier.
|
||||
virtual ConstHostPtr
|
||||
get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
|
||||
const uint8_t* identifier_begin, const size_t identifier_len) const;
|
||||
virtual ConstHostPtr get4(const SubnetID& subnet_id,
|
||||
const Host::IdentifierType& identifier_type,
|
||||
const uint8_t* identifier_begin,
|
||||
const size_t identifier_len) const;
|
||||
|
||||
/// @brief Returns a host connected to the IPv4 subnet and having
|
||||
/// a reservation for a specified IPv4 address.
|
||||
@@ -304,8 +311,8 @@ public:
|
||||
///
|
||||
/// @return Const @c Host object using a specified IPv4 address.
|
||||
/// @throw BadValue is given an IPv6 address
|
||||
virtual ConstHostPtr
|
||||
get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
|
||||
virtual ConstHostPtr get4(const SubnetID& subnet_id,
|
||||
const asiolink::IOAddress& address) const;
|
||||
|
||||
/// @brief Returns a host connected to the IPv6 subnet.
|
||||
///
|
||||
@@ -317,9 +324,10 @@ public:
|
||||
///
|
||||
/// @return Const @c Host object for which reservation has been made using
|
||||
/// the specified identifier.
|
||||
virtual ConstHostPtr
|
||||
get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
|
||||
const uint8_t* identifier_begin, const size_t identifier_len) const;
|
||||
virtual ConstHostPtr get6(const SubnetID& subnet_id,
|
||||
const Host::IdentifierType& identifier_type,
|
||||
const uint8_t* identifier_begin,
|
||||
const size_t identifier_len) const;
|
||||
|
||||
/// @brief Returns a host using the specified IPv6 prefix.
|
||||
///
|
||||
@@ -327,8 +335,8 @@ public:
|
||||
/// @param prefix_len IPv6 prefix length.
|
||||
///
|
||||
/// @return Const @c Host object using a specified IPv6 prefix.
|
||||
virtual ConstHostPtr
|
||||
get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const;
|
||||
virtual ConstHostPtr get6(const asiolink::IOAddress& prefix,
|
||||
const uint8_t prefix_len) const;
|
||||
|
||||
/// @brief Returns a host connected to the IPv6 subnet and having
|
||||
/// a reservation for a specified IPv6 address or prefix.
|
||||
@@ -337,8 +345,8 @@ public:
|
||||
/// @param address reserved IPv6 address/prefix.
|
||||
///
|
||||
/// @return Const @c Host object using a specified IPv6 address/prefix.
|
||||
virtual ConstHostPtr
|
||||
get6(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
|
||||
virtual ConstHostPtr get6(const SubnetID& subnet_id,
|
||||
const asiolink::IOAddress& address) const;
|
||||
|
||||
/// @brief Return backend type
|
||||
///
|
||||
@@ -387,9 +395,34 @@ public:
|
||||
/// Rolls back all pending database operations.
|
||||
virtual void rollback();
|
||||
|
||||
/// @brief Context RAII Allocator.
|
||||
class PgSqlHostContextAlloc {
|
||||
public:
|
||||
|
||||
/// @brief Constructor
|
||||
///
|
||||
/// This constructor takes a context of the pool if one is available
|
||||
/// or creates a new one.
|
||||
///
|
||||
/// @param mgr A parent instance
|
||||
PgSqlHostContextAlloc(const PgSqlHostDataSourceImpl& mgr);
|
||||
|
||||
/// @brief Destructor
|
||||
///
|
||||
/// This destructor puts back the context in the pool.
|
||||
~PgSqlHostContextAlloc();
|
||||
|
||||
/// @brief The context
|
||||
PgSqlHostContextPtr ctx_;
|
||||
|
||||
private:
|
||||
/// @brief The manager
|
||||
const PgSqlHostDataSourceImpl& mgr_;
|
||||
};
|
||||
|
||||
private:
|
||||
/// @brief Pointer to the implementation of the @ref PgSqlHostDataSource.
|
||||
PgSqlHostDataSourceImpl* impl_;
|
||||
PgSqlHostDataSourceImplPtr impl_;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user