From: Marcin Siodelski Date: Thu, 14 Jun 2018 10:05:00 +0000 (+0200) Subject: [5649] Implemented syncing timeout configuration for HA. X-Git-Tag: Kea-1.4.0~1^2~3^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa53aca33b453c10e0bfbcf8b739bb4e987956ca;p=thirdparty%2Fkea.git [5649] Implemented syncing timeout configuration for HA. --- diff --git a/src/hooks/dhcp/high_availability/ha_config.cc b/src/hooks/dhcp/high_availability/ha_config.cc index 3f73d167e0..77bd58672d 100644 --- a/src/hooks/dhcp/high_availability/ha_config.cc +++ b/src/hooks/dhcp/high_availability/ha_config.cc @@ -78,8 +78,9 @@ HAConfig::PeerConfig::roleToString(const HAConfig::PeerConfig::Role& role) { HAConfig::HAConfig() : this_server_name_(), ha_mode_(HOT_STANDBY), send_lease_updates_(true), - sync_leases_(true), heartbeat_delay_(10), max_response_delay_(60), - max_ack_delay_(10), max_unacked_clients_(10), peers_() { + sync_leases_(true), sync_timeout_(60000), heartbeat_delay_(10000), + max_response_delay_(60000), max_ack_delay_(10000), max_unacked_clients_(10), + peers_() { } HAConfig::PeerConfigPtr diff --git a/src/hooks/dhcp/high_availability/ha_config.h b/src/hooks/dhcp/high_availability/ha_config.h index 6d78c96601..12146ad6cf 100644 --- a/src/hooks/dhcp/high_availability/ha_config.h +++ b/src/hooks/dhcp/high_availability/ha_config.h @@ -252,6 +252,20 @@ public: sync_leases_ = sync_leases; } + /// @brief Returns timeout for lease database synchronization. + /// + /// @return Timeout in milliseconds. + long getSyncTimeout() const { + return (sync_timeout_); + } + + /// @brief Sets new lease database syncing timeout in milliseconds. + /// + /// @param sync_timeout new timeout for lease database synchornization. + void setSyncTimeout(const long sync_timeout) { + sync_timeout_ = sync_timeout; + } + /// @brief Returns heartbeat delay in milliseconds. /// /// This value indicates the delay in sending a heartbeat command after @@ -377,6 +391,7 @@ private: HAMode ha_mode_; ///< Mode of operation. bool send_lease_updates_; ///< Send lease updates to partner? bool sync_leases_; ///< Synchronize databases on startup? + long sync_timeout_; ///< Timeout for syncing lease database (ms) uint32_t heartbeat_delay_; ///< Heartbeat delay in milliseconds. uint32_t max_response_delay_; ///< Max delay in response to heartbeats. uint32_t max_ack_delay_; ///< Maximum DHCP message ack delay. diff --git a/src/hooks/dhcp/high_availability/ha_config_parser.cc b/src/hooks/dhcp/high_availability/ha_config_parser.cc index 88b8aea610..551f1a9113 100644 --- a/src/hooks/dhcp/high_availability/ha_config_parser.cc +++ b/src/hooks/dhcp/high_availability/ha_config_parser.cc @@ -20,6 +20,7 @@ namespace { const SimpleDefaults HA_CONFIG_DEFAULTS = { { "send-lease-updates", Element::boolean, "true" }, { "sync-leases", Element::boolean, "true" }, + { "sync-timeout", Element::integer, "60000" }, { "heartbeat-delay", Element::integer, "10000" }, { "max-response-delay", Element::integer, "60000" }, { "max-ack-delay", Element::integer, "10000" }, @@ -109,6 +110,10 @@ HAConfigParser::parseInternal(const HAConfigPtr& config_storage, // Get 'sync-leases'. config_storage->setSyncLeases(getBoolean(c, "sync-leases")); + // Get 'sync-timeout'. + uint16_t sync_timeout = getAndValidateInteger(c, "sync-timeout"); + config_storage->setSyncTimeout(sync_timeout); + // Get 'heartbeat-delay'. uint16_t heartbeat_delay = getAndValidateInteger(c, "heartbeat-delay"); config_storage->setHeartbeatDelay(heartbeat_delay); diff --git a/src/hooks/dhcp/high_availability/ha_service.cc b/src/hooks/dhcp/high_availability/ha_service.cc index 84cbf1511d..f4e04cf818 100644 --- a/src/hooks/dhcp/high_availability/ha_service.cc +++ b/src/hooks/dhcp/high_availability/ha_service.cc @@ -1215,7 +1215,7 @@ HAService::asyncSyncLeases(http::HttpClient& http_client, post_sync_action(error_message.empty(), error_message); } - }); + }, HttpClient::RequestTimeout(config_->getSyncTimeout())); } ConstElementPtr diff --git a/src/hooks/dhcp/high_availability/tests/ha_config_unittest.cc b/src/hooks/dhcp/high_availability/tests/ha_config_unittest.cc index c84eea4f60..25dd017bd7 100644 --- a/src/hooks/dhcp/high_availability/tests/ha_config_unittest.cc +++ b/src/hooks/dhcp/high_availability/tests/ha_config_unittest.cc @@ -63,6 +63,7 @@ TEST_F(HAConfigTest, configureLoadBalancing) { " \"mode\": \"load-balancing\"," " \"send-lease-updates\": false," " \"sync-leases\": false," + " \"sync-timeout\": 20000," " \"heartbeat-delay\": 8," " \"max-response-delay\": 11," " \"max-ack-delay\": 5," @@ -95,6 +96,7 @@ TEST_F(HAConfigTest, configureLoadBalancing) { EXPECT_EQ(HAConfig::LOAD_BALANCING, impl->getConfig()->getHAMode()); EXPECT_FALSE(impl->getConfig()->amSendingLeaseUpdates()); EXPECT_FALSE(impl->getConfig()->amSyncingLeases()); + EXPECT_EQ(20000, impl->getConfig()->getSyncTimeout()); EXPECT_EQ(8, impl->getConfig()->getHeartbeatDelay()); EXPECT_EQ(11, impl->getConfig()->getMaxResponseDelay()); EXPECT_EQ(5, impl->getConfig()->getMaxAckDelay()); @@ -161,6 +163,7 @@ TEST_F(HAConfigTest, configureHotStandby) { EXPECT_EQ(HAConfig::HOT_STANDBY, impl->getConfig()->getHAMode()); EXPECT_TRUE(impl->getConfig()->amSendingLeaseUpdates()); EXPECT_TRUE(impl->getConfig()->amSyncingLeases()); + EXPECT_EQ(60000, impl->getConfig()->getSyncTimeout()); EXPECT_EQ(10000, impl->getConfig()->getHeartbeatDelay()); EXPECT_EQ(10000, impl->getConfig()->getMaxAckDelay()); EXPECT_EQ(10, impl->getConfig()->getMaxUnackedClients());