Skip to content

Commit

Permalink
[5649] Implemented syncing timeout configuration for HA.
Browse files Browse the repository at this point in the history
  • Loading branch information
msiodelski committed Jun 14, 2018
1 parent e72a065 commit aa53aca
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/hooks/dhcp/high_availability/ha_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/hooks/dhcp/high_availability/ha_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,20 @@ class HAConfig {
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
Expand Down Expand Up @@ -377,6 +391,7 @@ class HAConfig {
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.
Expand Down
5 changes: 5 additions & 0 deletions src/hooks/dhcp/high_availability/ha_config_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down Expand Up @@ -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<uint16_t>(c, "sync-timeout");
config_storage->setSyncTimeout(sync_timeout);

// Get 'heartbeat-delay'.
uint16_t heartbeat_delay = getAndValidateInteger<uint16_t>(c, "heartbeat-delay");
config_storage->setHeartbeatDelay(heartbeat_delay);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/dhcp/high_availability/ha_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ HAService::asyncSyncLeases(http::HttpClient& http_client,
post_sync_action(error_message.empty(),
error_message);
}
});
}, HttpClient::RequestTimeout(config_->getSyncTimeout()));
}

ConstElementPtr
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/dhcp/high_availability/tests/ha_config_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,"
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit aa53aca

Please sign in to comment.