From: Marcin Siodelski Date: Thu, 29 Jul 2021 20:03:40 +0000 (+0200) Subject: [#1959] Bump unsent updates count in partner-down X-Git-Tag: Kea-2.0.0~80 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=22b0e27f5416da9855455ec945fe9f59db048291;p=thirdparty%2Fkea.git [#1959] Bump unsent updates count in partner-down --- diff --git a/src/hooks/dhcp/high_availability/ha_service.cc b/src/hooks/dhcp/high_availability/ha_service.cc index e61a91f827..81a72f1a83 100644 --- a/src/hooks/dhcp/high_availability/ha_service.cc +++ b/src/hooks/dhcp/high_availability/ha_service.cc @@ -1162,6 +1162,14 @@ HAService::asyncSendLeaseUpdates(const dhcp::Pkt4Ptr& query, // Check if the lease update should be sent to the server. If we're in // the partner-down state we don't send lease updates to the partner. if (!shouldSendLeaseUpdates(conf)) { + // If we decide to not send the lease updates to an active partner, we + // should make a record of it in the communication state. The partner + // can check if there were any unsent lease updates when he determines + // whether it should synchronize its database or not when it recovers + // from the partner-down state. + if (conf->getRole() != HAConfig::PeerConfig::BACKUP) { + communication_state_->increaseUnsentUpdateCount(); + } continue; } @@ -1222,6 +1230,14 @@ HAService::asyncSendLeaseUpdates(const dhcp::Pkt6Ptr& query, // Check if the lease update should be sent to the server. If we're in // the partner-down state we don't send lease updates to the partner. if (!shouldSendLeaseUpdates(conf)) { + // If we decide to not send the lease updates to an active partner, we + // should make a record of it in the communication state. The partner + // can check if there were any unsent lease updates when he determines + // whether it should synchronize its database or not when it recovers + // from the partner-down state. + if (conf->getRole() != HAConfig::PeerConfig::BACKUP) { + communication_state_->increaseUnsentUpdateCount(); + } continue; } diff --git a/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc b/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc index 8b16f19e79..03ee3a162b 100644 --- a/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc +++ b/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc @@ -1076,6 +1076,9 @@ public: // updates are expected to be successful. EXPECT_TRUE(unpark_called); + // Updates have been sent so this counter should remain 0. + EXPECT_EQ(0, service_->communication_state_->getUnsentUpdateCount()); + // The server 2 should have received two commands. EXPECT_EQ(2, factory2_->getResponseCreator()->getReceivedRequests().size()); @@ -1268,6 +1271,13 @@ public: // such situation the packet is not parked either. EXPECT_FALSE(unpark_called); + // In the partner-down state we don't send lease updates. We + // should count transactions for which lease updates were not sent. + // This is later returned in the heartbeat so the partner can + // determine whether it should synchronize its lease database or + // not. + EXPECT_EQ(1, service_->communication_state_->getUnsentUpdateCount()); + // Server 2 should not receive lease4-update. auto update_request2 = factory2_->getResponseCreator()->findRequest("lease4-update", @@ -1457,6 +1467,9 @@ public: // updates are expected to be successful. EXPECT_TRUE(unpark_called); + // Updates have been sent so this counter should remain 0. + EXPECT_EQ(0, service_->communication_state_->getUnsentUpdateCount()); + // The server 2 should have received one command. EXPECT_EQ(1, factory2_->getResponseCreator()->getReceivedRequests().size()); @@ -1634,6 +1647,13 @@ public: // situation the packet is not parked either. EXPECT_FALSE(unpark_called); + // In the partner-down state we don't send lease updates. We + // should count transactions for which lease updates were not sent. + // This is later returned in the heartbeat so the partner can + // determine whether it should synchronize its lease database or + // not. + EXPECT_EQ(1, service_->communication_state_->getUnsentUpdateCount()); + // Server 2 should not receive lease6-bulk-apply. auto update_request2 = factory2_->getResponseCreator()->findRequest("lease6-bulk-apply",