From: Francis Dupont Date: Tue, 14 Apr 2020 13:16:20 +0000 (+0200) Subject: [#1005] Addressed comments X-Git-Tag: Kea-1.7.7~73 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f00f8bce1dde38e5fca675ef66ebb580d5b2a7c;p=thirdparty%2Fkea.git [#1005] Addressed comments --- diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index e89504cebd..ebbb15ecd7 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -639,9 +639,10 @@ ControlledDhcpv4Srv::commandStatusGetHandler(const string&, ConstElementPtr ControlledDhcpv4Srv::commandStatisticSetMaxSampleCountAllHandler(const string&, ConstElementPtr args) { - ConstElementPtr answer = StatsMgr::statisticSetMaxSampleCountAllHandler(args); + StatsMgr& stats_mgr = StatsMgr::instance(); + ConstElementPtr answer = stats_mgr.statisticSetMaxSampleCountAllHandler(args); // Update the default parameter. - long max_samples = StatsMgr::instance().getMaxSampleCountDefault(); + long max_samples = stats_mgr.getMaxSampleCountDefault(); CfgMgr::instance().getCurrentCfg()->addConfiguredGlobal( "statistic-default-sample-count", Element::create(max_samples)); return (answer); @@ -649,10 +650,11 @@ ControlledDhcpv4Srv::commandStatisticSetMaxSampleCountAllHandler(const string&, ConstElementPtr ControlledDhcpv4Srv::commandStatisticSetMaxSampleAgeAllHandler(const string&, - ConstElementPtr args) { - ConstElementPtr answer = StatsMgr::statisticSetMaxSampleAgeAllHandler(args); + ConstElementPtr args) { + StatsMgr& stats_mgr = StatsMgr::instance(); + ConstElementPtr answer = stats_mgr.statisticSetMaxSampleAgeAllHandler(args); // Update the default parameter. - auto duration = StatsMgr::instance().getMaxSampleAgeDefault(); + auto duration = stats_mgr.getMaxSampleAgeDefault(); long max_age = duration.total_seconds(); CfgMgr::instance().getCurrentCfg()->addConfiguredGlobal( "statistic-default-sample-age", Element::create(max_age)); diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.h b/src/bin/dhcp4/ctrl_dhcp4_srv.h index eeaf47e857..cc77f4727c 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.h +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.h @@ -332,7 +332,7 @@ private: /// @brief handler for processing 'statistic-sample-count-set-all' command /// /// This handler processes statistic-sample-count-set-all command, - /// which set max_sample_count_ limit of all statistics and the default. + /// which sets max_sample_count_ limit of all statistics and the default. /// @ref isc::stats::StatsMgr::statisticSetMaxSampleCountAllHandler /// /// @param command (ignored) @@ -345,7 +345,7 @@ private: /// @brief handler for processing 'statistic-sample-age-set-all' command /// /// This handler processes statistic-sample-age-set-all command, - /// which set max_sample_age_ limit of all statistics and the default. + /// which sets max_sample_age_ limit of all statistics and the default. /// @ref isc::stats::StatsMgr::statisticSetMaxSampleAgeAllHandler /// /// @param command (ignored) diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index bb7899cd57..c54256b15a 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -643,9 +643,10 @@ ControlledDhcpv6Srv::commandStatusGetHandler(const string&, ConstElementPtr ControlledDhcpv6Srv::commandStatisticSetMaxSampleCountAllHandler(const string&, ConstElementPtr args) { - ConstElementPtr answer = StatsMgr::statisticSetMaxSampleCountAllHandler(args); + StatsMgr& stats_mgr = StatsMgr::instance(); + ConstElementPtr answer = stats_mgr.statisticSetMaxSampleCountAllHandler(args); // Update the default parameter. - long max_samples = StatsMgr::instance().getMaxSampleCountDefault(); + long max_samples = stats_mgr.getMaxSampleCountDefault(); CfgMgr::instance().getCurrentCfg()->addConfiguredGlobal( "statistic-default-sample-count", Element::create(max_samples)); return (answer); @@ -653,10 +654,11 @@ ControlledDhcpv6Srv::commandStatisticSetMaxSampleCountAllHandler(const string&, ConstElementPtr ControlledDhcpv6Srv::commandStatisticSetMaxSampleAgeAllHandler(const string&, - ConstElementPtr args) { - ConstElementPtr answer = StatsMgr::statisticSetMaxSampleAgeAllHandler(args); + ConstElementPtr args) { + StatsMgr& stats_mgr = StatsMgr::instance(); + ConstElementPtr answer = stats_mgr.statisticSetMaxSampleAgeAllHandler(args); // Update the default parameter. - auto duration = StatsMgr::instance().getMaxSampleAgeDefault(); + auto duration = stats_mgr.getMaxSampleAgeDefault(); long max_age = duration.total_seconds(); CfgMgr::instance().getCurrentCfg()->addConfiguredGlobal( "statistic-default-sample-age", Element::create(max_age)); diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.h b/src/bin/dhcp6/ctrl_dhcp6_srv.h index a09f084c96..1dcf6e289a 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.h +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.h @@ -332,7 +332,7 @@ private: /// @brief handler for processing 'statistic-sample-count-set-all' command /// /// This handler processes statistic-sample-count-set-all command, - /// which set max_sample_count_ limit of all statistics and the default. + /// which sets max_sample_count_ limit of all statistics and the default. /// @ref isc::stats::StatsMgr::statisticSetMaxSampleCountAllHandler /// /// @param command (ignored) @@ -345,7 +345,7 @@ private: /// @brief handler for processing 'statistic-sample-age-set-all' command /// /// This handler processes statistic-sample-age-set-all command, - /// which set max_sample_age_ limit of all statistics and the default. + /// which sets max_sample_age_ limit of all statistics and the default. /// @ref isc::stats::StatsMgr::statisticSetMaxSampleAgeAllHandler /// /// @param command (ignored) diff --git a/src/lib/stats/stats_mgr.cc b/src/lib/stats/stats_mgr.cc index 026816299d..67f5e5a338 100644 --- a/src/lib/stats/stats_mgr.cc +++ b/src/lib/stats/stats_mgr.cc @@ -545,6 +545,7 @@ StatsMgr::statisticSetMaxSampleAgeAllHandler(const ConstElementPtr& params) { return (createAnswer(CONTROL_RESULT_ERROR, error)); } if (MultiThreadingMgr::instance().getMode()) { + lock_guard lock(*mutex_); StatsMgr::instance().setMaxSampleCountDefaultInternal(0); StatsMgr::instance().setMaxSampleAgeDefaultInternal(duration); StatsMgr::instance().setMaxSampleAgeAllInternal(duration); @@ -569,6 +570,7 @@ StatsMgr::statisticSetMaxSampleCountAllHandler(const ConstElementPtr& params) { return (createAnswer(CONTROL_RESULT_ERROR, error)); } if (MultiThreadingMgr::instance().getMode()) { + lock_guard lock(*mutex_); StatsMgr::instance().setMaxSampleCountDefaultInternal(max_samples); StatsMgr::instance().setMaxSampleCountAllInternal(max_samples); } else { diff --git a/src/lib/stats/stats_mgr.h b/src/lib/stats/stats_mgr.h index 845429c5f9..59ed8445e1 100644 --- a/src/lib/stats/stats_mgr.h +++ b/src/lib/stats/stats_mgr.h @@ -347,7 +347,7 @@ public: /// @brief Handles statistic-sample-age-set command /// /// This method handles statistic-sample-age-set command, - /// which set max_sample_age_ limit of a given statistic + /// which sets max_sample_age_ limit of a given statistic /// and leaves max_sample_count_ disabled. /// It expects two parameters stored in params map: /// name: name of the statistic @@ -369,7 +369,7 @@ public: /// @brief Handles statistic-sample-count-set command /// /// This method handles statistic-sample-count-set command, - /// which set max_sample_count_ limit of a given statistic + /// which sets max_sample_count_ limit of a given statistic /// and leaves max_sample_age_ disabled. /// It expects two parameters stored in params map: /// name: name of the statistic @@ -427,7 +427,7 @@ public: /// @brief Handles statistic-sample-age-set-all command /// /// This method handles statistic-sample-age-set-all command, - /// which set max_sample_age_ limit to all statistics and the default. + /// which sets max_sample_age_ limit to all statistics and the default. /// It expects one parameter stored in params map: /// duration: limit expressed as a number of seconds /// @@ -438,13 +438,13 @@ public: /// /// @param params structure containing a map that contains "duration" /// @return answer confirming success of this operation - static isc::data::ConstElementPtr + isc::data::ConstElementPtr statisticSetMaxSampleAgeAllHandler(const isc::data::ConstElementPtr& params); /// @brief Handles statistic-sample-count-set-all command /// /// This method handles statistic-sample-count-set-all command, - /// which set max_sample_count_ limit of all statistics and the default. + /// which sets max_sample_count_ limit of all statistics and the default. /// It expects one parameter stored in params map: /// max-samples: count limit /// The value 0 is out of range. @@ -456,7 +456,7 @@ public: /// /// @param params structure containing a map that contains "max-samples" /// @return answer confirming success of this operation - static isc::data::ConstElementPtr + isc::data::ConstElementPtr statisticSetMaxSampleCountAllHandler(const isc::data::ConstElementPtr& params); /// @} @@ -612,14 +612,14 @@ private: /// /// Should be called in a thread safe context. /// - /// @param duration determines default maximum age of samples + /// @param duration default maximum age of samples to keep. void setMaxSampleAgeDefaultInternal(const StatsDuration& duration); /// @brief Set default count limit. /// /// Should be called in a thread safe context. /// - /// @param max_samples default maximum number of samples to keep + /// @param max_samples default maximum number of samples to keep. /// (0 means to disable count limit and enable age limit) void setMaxSampleCountDefaultInternal(uint32_t max_samples);