mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-04 16:05:17 +00:00
[#2757] Rebased from #275[23]
This commit is contained in:
@@ -162,6 +162,15 @@ tagged_statements = { {
|
||||
"WHERE address > ? "
|
||||
"ORDER BY address "
|
||||
"LIMIT ?"},
|
||||
{MySqlLeaseMgr::GET_LEASE4_UCTX_PAGE,
|
||||
"SELECT address, hwaddr, client_id, "
|
||||
"valid_lifetime, expire, subnet_id, "
|
||||
"fqdn_fwd, fqdn_rev, hostname, "
|
||||
"state, user_context, relay_id, remote_id "
|
||||
"FROM lease4 "
|
||||
"WHERE address > ? AND user_context IS NOT NULL "
|
||||
"ORDER BY address "
|
||||
"LIMIT ?"},
|
||||
{MySqlLeaseMgr::GET_LEASE4_SUBID,
|
||||
"SELECT address, hwaddr, client_id, "
|
||||
"valid_lifetime, expire, subnet_id, "
|
||||
@@ -330,6 +339,17 @@ tagged_statements = { {
|
||||
"WHERE address > ? "
|
||||
"ORDER BY address "
|
||||
"LIMIT ?"},
|
||||
{MySqlLeaseMgr::GET_LEASE6_UCTX_PAGE,
|
||||
"SELECT address, duid, valid_lifetime, "
|
||||
"expire, subnet_id, pref_lifetime, "
|
||||
"lease_type, iaid, prefix_len, "
|
||||
"fqdn_fwd, fqdn_rev, hostname, "
|
||||
"hwaddr, hwtype, hwaddr_source, "
|
||||
"state, user_context "
|
||||
"FROM lease6 "
|
||||
"WHERE address > ? AND user_context IS NOT NULL "
|
||||
"ORDER BY address "
|
||||
"LIMIT ?"},
|
||||
{MySqlLeaseMgr::GET_LEASE6_SUBID,
|
||||
"SELECT address, duid, valid_lifetime, "
|
||||
"expire, subnet_id, pref_lifetime, "
|
||||
@@ -3875,6 +3895,95 @@ MySqlLeaseMgr::getLeases4ByRemoteId(const OptionBuffer& remote_id,
|
||||
return (result);
|
||||
}
|
||||
|
||||
size_t
|
||||
MySqlLeaseMgr::upgradeExtendedInfo(const LeasePageSize& page_size) {
|
||||
auto check = CfgMgr::instance().getCurrentCfg()->
|
||||
getConsistency()->getExtendedInfoSanityCheck();
|
||||
|
||||
size_t pages = 0;
|
||||
size_t updated = 0;
|
||||
IOAddress start_addr = IOAddress::IPV4_ZERO_ADDRESS();
|
||||
for (;;) {
|
||||
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
|
||||
DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO4_PAGE)
|
||||
.arg(pages)
|
||||
.arg(start_addr.toText())
|
||||
.arg(updated);
|
||||
|
||||
// Prepare WHERE clause.
|
||||
MYSQL_BIND inbind[2];
|
||||
memset(inbind, 0, sizeof(inbind));
|
||||
|
||||
// Bind start address.
|
||||
uint32_t start_addr_data = start_addr.toUint32();
|
||||
inbind[0].buffer_type = MYSQL_TYPE_LONG;
|
||||
inbind[0].buffer = reinterpret_cast<char*>(&start_addr_data);
|
||||
inbind[0].is_unsigned = MLM_TRUE;
|
||||
|
||||
// Bind page size value.
|
||||
uint32_t ps = static_cast<uint32_t>(page_size.page_size_);
|
||||
inbind[1].buffer_type = MYSQL_TYPE_LONG;
|
||||
inbind[1].buffer = reinterpret_cast<char*>(&ps);
|
||||
inbind[1].is_unsigned = MLM_TRUE;
|
||||
|
||||
Lease4Collection leases;
|
||||
|
||||
// Get a context.
|
||||
{
|
||||
MySqlLeaseContextAlloc get_context(*this);
|
||||
MySqlLeaseContextPtr ctx = get_context.ctx_;
|
||||
|
||||
getLeaseCollection(ctx, GET_LEASE4_UCTX_PAGE, inbind, leases);
|
||||
}
|
||||
|
||||
if (leases.empty()) {
|
||||
// Done.
|
||||
break;
|
||||
}
|
||||
|
||||
++pages;
|
||||
start_addr = leases.back()->addr_;
|
||||
for (auto lease : leases) {
|
||||
ConstElementPtr previous_user_context = lease->getContext();
|
||||
vector<uint8_t> previous_relay_id = lease->relay_id_;
|
||||
vector<uint8_t> previous_remote_id = lease->remote_id_;
|
||||
if (!previous_user_context &&
|
||||
previous_relay_id.empty() &&
|
||||
previous_remote_id.empty()) {
|
||||
continue;
|
||||
}
|
||||
bool modified = upgradeLease4ExtendedInfo(lease, check);
|
||||
try {
|
||||
lease->relay_id_.clear();
|
||||
lease->remote_id_.clear();
|
||||
extractLease4ExtendedInfo(lease, false);
|
||||
if (modified ||
|
||||
(previous_relay_id != lease->relay_id_) ||
|
||||
(previous_remote_id != lease->remote_id_)) {
|
||||
updateLease4(lease);
|
||||
++updated;
|
||||
}
|
||||
} catch (const NoSuchLease&) {
|
||||
// The lease was modified in parallel:
|
||||
// as its extended info was processed just ignore.
|
||||
continue;
|
||||
} catch (const std::exception& ex) {
|
||||
// Something when wrong, for instance extract failed.
|
||||
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE,
|
||||
DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO4_ERROR)
|
||||
.arg(lease->addr_.toText())
|
||||
.arg(ex.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LOG_INFO(dhcpsrv_logger, DHCPSRV_MYSQL_UPGRADE_EXTENDED_INFO4)
|
||||
.arg(pages)
|
||||
.arg(updated);
|
||||
|
||||
return (updated);
|
||||
}
|
||||
|
||||
Lease6Collection
|
||||
MySqlLeaseMgr::getLeases6ByRelayId(const DUID& /* relay_id */,
|
||||
const IOAddress& /* link_addr */,
|
||||
|
Reference in New Issue
Block a user