Skip to content

Commit 837effa

Browse files
zhenggen-xulguohan
authored andcommitted
Add a common function to get the warm-start timer (sonic-net#589)
* Add common getWarmStartTimer function * simplify the warm-start timer schema * Add timer details in the schema and fix a few things in gettimer common function
1 parent 9b3c309 commit 837effa

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

doc/swss-schema.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -634,17 +634,18 @@ Equivalent RedisDB entry:
634634
;Stores system warm start configuration
635635
;Status: work in progress
636636

637-
key = WARM_RESTART:name ; name is the name of SONiC docker or "system" for global configuration.
638-
639-
enable = "true" / "false" ; Default value as false.
640-
; If "system" warm start knob is true, docker level knob will be ignored.
641-
; If "system" warm start knob is false, docker level knob takes effect.
642-
643-
timer_name = 1*255VCHAR, ; timer_name is the name of warm start timer for the whole system or the specific docker,
644-
; Ex. "neighbor_timer", "bgp_timer". The name should not contain "," character.
645-
; There could be more than one timer in a docker or the system, separated by ",".
646-
647-
timer_duration = 1*4DIGIT, ; timer duration, in seconds. Separated by "," if there are more than on timer.
637+
key = WARM_RESTART:name ; name is the name of SONiC docker or "system" for global configuration.
638+
639+
enable = "true" / "false" ; Default value as false.
640+
; If "system" warm start knob is true, docker level knob will be ignored.
641+
; If "system" warm start knob is false, docker level knob takes effect.
642+
643+
neighsyncd_timer = 1*4DIGIT ; neighsyncd_timer is the timer used for neighsyncd during the warm restart.
644+
; Timer is started after we restored the neighborTable to internal data structures.
645+
; neighborsyncd then starts to read all linux kernel entries and mark the entries in
646+
; the data structures accordingly. Once the timer is expired, we will do reconciliation
647+
; and push the delta to appDB
648+
; Valid value is 1-9999. 0 is invalid.
648649

649650

650651
## State DB schema

warmrestart/warm_restart.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <string>
22
#include "logger.h"
33
#include "schema.h"
4+
#include <climits>
45
#include "warm_restart.h"
56

67
namespace swss {
@@ -96,6 +97,34 @@ bool WarmStart::checkWarmStart(const std::string &app_name, const std::string &d
9697
return true;
9798
}
9899

100+
/*
101+
* Get warmStartTimer for an application in a docker (default to be swss)
102+
* return timer value. Value 0 means invalid.
103+
*/
104+
uint32_t WarmStart::getWarmStartTimer(const std::string &app_name,
105+
const std::string &docker_name)
106+
{
107+
auto& warmStart = getInstance();
108+
std::string timer_name = app_name + "_timer";
109+
std::string timer_value_str;
110+
111+
warmStart.m_cfgWarmRestartTable->hget(docker_name, timer_name, timer_value_str);
112+
113+
unsigned long int temp_value = strtoul(timer_value_str.c_str(), NULL, 0);
114+
if (temp_value != 0 && temp_value != ULONG_MAX && temp_value <= MAXIMUN_WARMRESTART_TIMER_VALUE)
115+
{
116+
SWSS_LOG_NOTICE("Getting warmStartTimer for docker: %s, app: %s, value: %lu",
117+
docker_name.c_str(), app_name.c_str(), temp_value);
118+
return (uint32_t)temp_value;
119+
}
120+
else
121+
{
122+
SWSS_LOG_NOTICE("warmStartTimer is not configured or invalid for docker: %s, app: %s",
123+
docker_name.c_str(), app_name.c_str());
124+
return 0;
125+
}
126+
}
127+
99128
bool WarmStart::isWarmStart()
100129
{
101130
auto& warmStart = getInstance();

warmrestart/warm_restart.h

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "dbconnector.h"
66
#include "table.h"
77

8+
#define MAXIMUN_WARMRESTART_TIMER_VALUE 9999
9+
810
namespace swss {
911

1012
class WarmStart
@@ -23,6 +25,8 @@ class WarmStart
2325
static WarmStart &getInstance();
2426

2527
static bool checkWarmStart(const std::string &app_name, const std::string &docker_name = "swss");
28+
static uint32_t getWarmStartTimer(const std::string &app_name,
29+
const std::string &docker_name ="swss");
2630
static bool isWarmStart();
2731
static void setWarmStartState(const std::string &app_name, WarmStartState state);
2832
private:

0 commit comments

Comments
 (0)