/// @return The number of updates in the database.
virtual size_t upgradeExtendedInfo4(const LeasePageSize& page_size) = 0;
- /// @brief Returns the setting indicating if lease extended info tables
+ /// @brief Returns the setting indicating if lease6 extended info tables
/// are enabled.
///
- /// @return true if lease extended info tables are enabled or false
+ /// @return true if lease6 extended info tables are enabled or false
/// if they are disabled.
bool getExtendedInfoTablesEnabled() const {
return (extended_info_tables_enabled_);
}
+ /// @brief Modifies the setting whether the lease6 extended info tables
+ /// are enabled.
+ ///
+ /// @param enabled new setting.
+ void setExtendedInfoTablesEnabled(const bool enabled) {
+ extended_info_tables_enabled_ = enabled;
+ }
+
/// @brief Build extended info v6 tables.
///
/// @param update Update extended info in database.
/// Extended information / Bulk Lease Query shared interface.
- /// @brief Modifies the setting whether the lease extended info tables
- /// are enabled.
- ///
- /// @note This method is virtual so backend doing specific action
- /// on value changes can intercept it by redefining it.
- ///
- /// @param enabled new setting.
- virtual void setExtendedInfoTablesEnabled(const bool enabled) {
- extended_info_tables_enabled_ = enabled;
- }
-
/// @brief Decode parameters to set whether the lease extended info tables
/// are enabled.
///
/// @note: common code in constructors.
///
/// @param parameters The parameter map.
- virtual void setExtendedInfoTablesEnabled(const db::DatabaseConnection::ParameterMap& parameters);
+ void setExtendedInfoTablesEnabled(const db::DatabaseConnection::ParameterMap& parameters);
/// @brief Extract extended info from a lease6 and add it into tables.
///
// If running in single-threaded mode, there's nothing to do here.
}
-void
-MySqlLeaseMgr::setExtendedInfoTablesEnabled(const db::DatabaseConnection::ParameterMap& /* parameters */) {
- isc_throw(isc::NotImplemented, "extended info tables are not yet supported by mysql");
-}
-
// MySqlLeaseMgr Constructor and Destructor
MySqlLeaseMgr::MySqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters)
: TrackingLeaseMgr(), parameters_(parameters), timer_name_("") {
// Check if the extended info tables are enabled.
- LeaseMgr::setExtendedInfoTablesEnabled(parameters);
+ setExtendedInfoTablesEnabled(parameters);
// Create unique timer name per instance.
timer_name_ = "MySqlLeaseMgr[";
.arg(lease->addr_.toText())
.arg(lease->type_);
+ lease->extended_info_action_ = Lease6::ACTION_IGNORE;
+
// Get a context
MySqlLeaseTrackingContextAlloc get_context(*this, lease);
MySqlLeaseContextPtr ctx = get_context.ctx_;
// of the Lease up to the point of insertion in the database).
lease->updateCurrentExpirationTime();
+ if (getExtendedInfoTablesEnabled()) {
+ // Expired leases can be removed leaving entries in extended info tables.
+ deleteExtendedInfo6(lease->addr_);
+ static_cast<void>(addExtendedInfo6(lease));
+ }
+
// Run installed callbacks.
if (hasCallbacks()) {
trackAddLease(lease, false);
.arg(lease->addr_.toText())
.arg(lease->type_);
+ // Get the recorded action and reset it.
+ Lease6::ExtendedInfoAction recorded_action = lease->extended_info_action_;
+ lease->extended_info_action_ = Lease6::ACTION_IGNORE;
+
// Get a context
MySqlLeaseTrackingContextAlloc get_context(*this, lease);
MySqlLeaseContextPtr ctx = get_context.ctx_;
// Update lease current expiration time.
lease->updateCurrentExpirationTime();
+ // Update extended info tables.
+ if (getExtendedInfoTablesEnabled()) {
+ switch (recorded_action) {
+ case Lease6::ACTION_IGNORE:
+ break;
+
+ case Lease6::ACTION_DELETE:
+ deleteExtendedInfo6(lease->addr_);
+ break;
+
+ case Lease6::ACTION_UPDATE:
+ deleteExtendedInfo6(lease->addr_);
+ static_cast<void>(addExtendedInfo6(lease));
+ break;
+ }
+ }
+
// Run installed callbacks.
if (hasCallbacks()) {
trackUpdateLease(lease, false);
DHCPSRV_MYSQL_DELETE_ADDR)
.arg(addr.toText());
+ lease->extended_info_action_ = Lease6::ACTION_IGNORE;
+
// Set up the WHERE clause value
MYSQL_BIND inbind[2];
memset(inbind, 0, sizeof(inbind));
// Check success case first as it is the most likely outcome.
if (affected_rows == 1) {
+ // Delete references from extended info tables.
+ if (getExtendedInfoTablesEnabled()) {
+ deleteExtendedInfo6(lease->addr_);
+ }
+
+ // Run installed callbacks.
if (hasCallbacks()) {
trackDeleteLease(lease, false);
}
std::vector<uint8_t> lease_addr_data = lease_addr.toBytes();
unsigned long lease_addr_length = lease_addr_data.size();
if (lease_addr_length != 16) {
- isc_throw(DbOperationError, "lease6 address is not 16 byte long");
+ isc_throw(DbOperationError, "lease6 address is not 16 bytes long");
}
bind[1].buffer_type = MYSQL_TYPE_BLOB;
bind[1].buffer = reinterpret_cast<char*>(&lease_addr_data[0]);
std::vector<uint8_t> lease_addr_data = lease_addr.toBytes();
unsigned long lease_addr_length = lease_addr_data.size();
if (lease_addr_length != 16) {
- isc_throw(DbOperationError, "lease6 address is not 16 byte long");
+ isc_throw(DbOperationError, "lease6 address is not 16 bytes long");
}
bind[1].buffer_type = MYSQL_TYPE_BLOB;
bind[1].buffer = reinterpret_cast<char*>(&lease_addr_data[0]);
std::list<IOAddress> result;
while ((status = mysql_stmt_fetch(ctx->conn_.statements_[stindex])) == 0) {
if (addr_size != 16) {
- isc_throw(BadValue, "received lease6 address is not 16 byte long");
+ isc_throw(BadValue, "received lease6 address is not 16 bytes long");
}
result.push_back(IOAddress::fromBytes(AF_INET6, addr_data));
}
std::vector<uint8_t> lb_addr_data = lower_bound_address.toBytes();
unsigned long lb_addr_size = lb_addr_data.size();
if (lb_addr_size != 16) {
- isc_throw(DbOperationError, "lower bound address is not 16 byte long");
+ isc_throw(DbOperationError, "lower bound address is not 16 bytes long");
}
bind[1].buffer_type = MYSQL_TYPE_BLOB;
bind[1].buffer = reinterpret_cast<char*>(&lb_addr_data[0]);
std::vector<uint8_t> start_addr_data = start_addr.toBytes();
unsigned long start_addr_size = start_addr_data.size();
if (start_addr_size != 16) {
- isc_throw(DbOperationError, "start address is not 16 byte long");
+ isc_throw(DbOperationError, "start address is not 16 bytes long");
}
bind[1].buffer_type = MYSQL_TYPE_BLOB;
bind[1].buffer = reinterpret_cast<char*>(&start_addr_data[0]);
std::vector<uint8_t> last_addr_data = last_addr.toBytes();
unsigned long last_addr_size = last_addr_data.size();
if (last_addr_size != 16) {
- isc_throw(DbOperationError, "last address is not 16 byte long");
+ isc_throw(DbOperationError, "last address is not 16 bytes long");
}
bind[2].buffer_type = MYSQL_TYPE_BLOB;
bind[2].buffer = reinterpret_cast<char*>(&last_addr_data[0]);
std::vector<uint8_t> lb_addr_data = lower_bound_address.toBytes();
unsigned long lb_addr_size = lb_addr_data.size();
if (lb_addr_size != 16) {
- isc_throw(DbOperationError, "lower bound address is not 16 byte long");
+ isc_throw(DbOperationError, "lower bound address is not 16 bytes long");
}
bind[1].buffer_type = MYSQL_TYPE_BLOB;
bind[1].buffer = reinterpret_cast<char*>(&lb_addr_data[0]);
std::vector<uint8_t> start_addr_data = start_addr.toBytes();
unsigned long start_addr_size = start_addr_data.size();
if (start_addr_size != 16) {
- isc_throw(DbOperationError, "start address is not 16 byte long");
+ isc_throw(DbOperationError, "start address is not 16 bytes long");
}
bind[1].buffer_type = MYSQL_TYPE_BLOB;
bind[1].buffer = reinterpret_cast<char*>(&start_addr_data[0]);
std::vector<uint8_t> last_addr_data = last_addr.toBytes();
unsigned long last_addr_size = last_addr_data.size();
if (last_addr_size != 16) {
- isc_throw(DbOperationError, "last address is not 16 byte long");
+ isc_throw(DbOperationError, "last address is not 16 bytes long");
}
bind[2].buffer_type = MYSQL_TYPE_BLOB;
bind[2].buffer = reinterpret_cast<char*>(&last_addr_data[0]);
/// Extended information / Bulk Lease Query shared interface.
- /// @brief Modifies the setting whether the lease extended info tables
- /// are enabled.
- ///
- /// Transient redefine to refuse the enable setting.
- /// @param enabled new setting.
- virtual void setExtendedInfoTablesEnabled(const bool enabled) override {
- if (enabled) {
- isc_throw(isc::NotImplemented,
- "extended info tables are not yet supported by mysql");
- }
- }
-
- /// @brief Decode parameters to set whether the lease extended info tables
- /// are enabled.
- ///
- /// @note: common code in constructors.
- ///
- /// @param parameters The parameter map.
- virtual void setExtendedInfoTablesEnabled(const db::DatabaseConnection::ParameterMap& parameters) override;
-
/// @brief Delete lease6 extended info from tables.
///
/// @param addr The address of the lease.
// If running in single-threaded mode, there's nothing to do here.
}
-void
-PgSqlLeaseMgr::setExtendedInfoTablesEnabled(const db::DatabaseConnection::ParameterMap& /* parameters */) {
- isc_throw(isc::NotImplemented, "extended info tables are not yet supported by mysql");
-}
-
// PgSqlLeaseMgr Constructor and Destructor
PgSqlLeaseMgr::PgSqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters)
: TrackingLeaseMgr(), parameters_(parameters), timer_name_("") {
// Check if the extended info tables are enabled.
- LeaseMgr::setExtendedInfoTablesEnabled(parameters);
+ setExtendedInfoTablesEnabled(parameters);
// Create unique timer name per instance.
timer_name_ = "PgSqlLeaseMgr[";
.arg(lease->addr_.toText())
.arg(lease->type_);
+ lease->extended_info_action_ = Lease6::ACTION_IGNORE;
+
// Get a context
PgSqlLeaseTrackingContextAlloc get_context(*this, lease);
PgSqlLeaseContextPtr ctx = get_context.ctx_;
// of the Lease up to the point of insertion in the database).
lease->updateCurrentExpirationTime();
+ if (getExtendedInfoTablesEnabled()) {
+ // Expired leases can be removed leaving entries in extended info tables.
+ deleteExtendedInfo6(lease->addr_);
+ static_cast<void>(addExtendedInfo6(lease));
+ }
+
// Run installed callbacks.
if (hasCallbacks()) {
trackAddLease(lease, false);
.arg(lease->addr_.toText())
.arg(lease->type_);
+ // Get the recorded action and reset it.
+ Lease6::ExtendedInfoAction recorded_action = lease->extended_info_action_;
+ lease->extended_info_action_ = Lease6::ACTION_IGNORE;
+
// Get a context
PgSqlLeaseTrackingContextAlloc get_context(*this, lease);
PgSqlLeaseContextPtr ctx = get_context.ctx_;
// Update lease current expiration time.
lease->updateCurrentExpirationTime();
+ // Update extended info tables.
+ if (getExtendedInfoTablesEnabled()) {
+ switch (recorded_action) {
+ case Lease6::ACTION_IGNORE:
+ break;
+
+ case Lease6::ACTION_DELETE:
+ deleteExtendedInfo6(lease->addr_);
+ break;
+
+ case Lease6::ACTION_UPDATE:
+ deleteExtendedInfo6(lease->addr_);
+ static_cast<void>(addExtendedInfo6(lease));
+ break;
+ }
+ }
+
// Run installed callbacks.
if (hasCallbacks()) {
trackUpdateLease(lease, false);
DHCPSRV_PGSQL_DELETE_ADDR)
.arg(addr.toText());
+ lease->extended_info_action_ = Lease6::ACTION_IGNORE;
+
// Set up the WHERE clause value
PsqlBindArray bind_array;
// Check success case first as it is the most likely outcome.
if (affected_rows == 1) {
+ // Delete references from extended info tables.
+ if (getExtendedInfoTablesEnabled()) {
+ deleteExtendedInfo6(lease->addr_);
+ }
+
+ // Run installed callbacks.
if (hasCallbacks()) {
trackDeleteLease(lease, false);
}
// Bind the lease address.
std::vector<uint8_t> lease_addr_data = lease_addr.toBytes();
if (lease_addr_data.size() != 16) {
- isc_throw(DbOperationError, "lease6 address is not 16 byte long");
+ isc_throw(DbOperationError, "lease6 address is not 16 bytes long");
}
bind_array.add(lease_addr_data);
// Bind the lease address.
std::vector<uint8_t> lease_addr_data = lease_addr.toBytes();
if (lease_addr_data.size() != 16) {
- isc_throw(DbOperationError, "lease6 address is not 16 byte long");
+ isc_throw(DbOperationError, "lease6 address is not 16 bytes long");
}
bind_array.add(lease_addr_data);
std::vector<uint8_t> addr_data;
PgSqlLeaseExchange::convertFromBytea(r, i, 0, addr_data);
if (addr_data.size() != 16) {
- isc_throw(BadValue, "received lease6 address is not 16 byte long");
+ isc_throw(BadValue, "received lease6 address is not 16 bytes long");
}
result.push_back(IOAddress::fromBytes(AF_INET6, &addr_data[0]));
}
// Bind the lower bound address.
std::vector<uint8_t> lb_addr_data = lower_bound_address.toBytes();
if (lb_addr_data.size() != 16) {
- isc_throw(DbOperationError, "lower bound address is not 16 byte long");
+ isc_throw(DbOperationError, "lower bound address is not 16 bytes long");
}
bind_array.add(lb_addr_data);
// Bind the start address.
std::vector<uint8_t> start_addr_data = start_addr.toBytes();
if (start_addr_data.size() != 16) {
- isc_throw(DbOperationError, "start address is not 16 byte long");
+ isc_throw(DbOperationError, "start address is not 16 bytes long");
}
bind_array.add(start_addr_data);
// Bind the last address.
std::vector<uint8_t> last_addr_data = last_addr.toBytes();
if (last_addr_data.size() != 16) {
- isc_throw(DbOperationError, "last address is not 16 byte long");
+ isc_throw(DbOperationError, "last address is not 16 bytes long");
}
bind_array.add(last_addr_data);
// Bind the lower bound address.
std::vector<uint8_t> lb_addr_data = lower_bound_address.toBytes();
if (lb_addr_data.size() != 16) {
- isc_throw(DbOperationError, "lower bound address is not 16 byte long");
+ isc_throw(DbOperationError, "lower bound address is not 16 bytes long");
}
bind_array.add(lb_addr_data);
// Bind the start address.
std::vector<uint8_t> start_addr_data = start_addr.toBytes();
if (start_addr_data.size() != 16) {
- isc_throw(DbOperationError, "start address is not 16 byte long");
+ isc_throw(DbOperationError, "start address is not 16 bytes long");
}
bind_array.add(start_addr_data);
// Bind the last address.
std::vector<uint8_t> last_addr_data = last_addr.toBytes();
if (last_addr_data.size() != 16) {
- isc_throw(DbOperationError, "last address is not 16 byte long");
+ isc_throw(DbOperationError, "last address is not 16 bytes long");
}
bind_array.add(last_addr_data);
/// Extended information / Bulk Lease Query shared interface.
- /// @brief Modifies the setting whether the lease extended info tables
- /// are enabled.
- ///
- /// Transient redefine to refuse the enable setting.
- /// @param enabled new setting.
- virtual void setExtendedInfoTablesEnabled(const bool enabled) override {
- if (enabled) {
- isc_throw(isc::NotImplemented,
- "extended info tables are not yet supported by postgresql");
- }
- }
-
- /// @brief Decode parameters to set whether the lease extended info tables
- /// are enabled.
- ///
- /// @note: common code in constructors.
- ///
- /// @param parameters The parameter map.
- virtual void setExtendedInfoTablesEnabled(const db::DatabaseConnection::ParameterMap& parameters) override;
-
/// @brief Delete lease6 extended info from tables.
///
/// @param addr The address of the lease.
}
/// @brief Exposes protected methods and members.
- using LeaseMgr::setExtendedInfoTablesEnabled;
using Memfile_LeaseMgr::relay_id6_;
using Memfile_LeaseMgr::remote_id6_;
using Memfile_LeaseMgr::deleteExtendedInfo6;
}
using Memfile_LeaseMgr::lfcCallback;
- using Memfile_LeaseMgr::setExtendedInfoTablesEnabled;
using Memfile_LeaseMgr::relay_id6_;
using Memfile_LeaseMgr::remote_id6_;
using Memfile_LeaseMgr::buildExtendedInfoTables6;