]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1959] Bump unsent updates count in partner-down
authorMarcin Siodelski <marcin@isc.org>
Thu, 29 Jul 2021 20:03:40 +0000 (22:03 +0200)
committerMarcin Siodelski <marcin@isc.org>
Wed, 22 Sep 2021 06:13:15 +0000 (08:13 +0200)
src/hooks/dhcp/high_availability/ha_service.cc
src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc

index e61a91f8270022a4c63922789beab5246279662a..81a72f1a83dd4af4c09175e5132bf0f7ee3646a7 100644 (file)
@@ -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;
         }
 
index 8b16f19e7910c41fb362893192deae95be761b74..03ee3a162bf5b7a711b500610503b0589dfcc6b2 100644 (file)
@@ -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",