22#include < climits>
33#include " logger.h"
44#include " schema.h"
5+ #include " timestamp.h"
56#include " warm_restart.h"
67
78namespace swss {
89
910const std::string WarmStart::kNsfManagerNotificationChannel =
1011 " NSF_MANAGER_COMMON_NOTIFICATION_CHANNEL" ;
12+ const std::string WarmStart::kRegistrationFreezeKey = " freeze" ;
13+ const std::string WarmStart::kRegistrationCheckpointKey = " checkpoint" ;
14+ const std::string WarmStart::kRegistrationReconciliationKey = " reconciliation" ;
15+ const std::string WarmStart::kRegistrationTimestampKey = " timestamp" ;
1116
1217const WarmStart::WarmStartStateNameMap WarmStart::warmStartStateNameMap =
1318{
@@ -69,6 +74,9 @@ void WarmStart::initialize(const std::string &app_name,
6974 return ;
7075 }
7176
77+ warmStart.m_appName = app_name;
78+ warmStart.m_dockerName = docker_name;
79+
7280 /* Use unix socket for db connection by default */
7381 warmStart.m_stateDb =
7482 std::make_shared<swss::DBConnector>(" STATE_DB" , db_timeout, isTcpConn);
@@ -85,6 +93,70 @@ void WarmStart::initialize(const std::string &app_name,
8593 warmStart.m_initialized = true ;
8694}
8795
96+ /*
97+ * registerWarmBootInfo
98+ *
99+ * Register an application with NSF Manager.
100+ *
101+ * Returns: true on success, false otherwise.
102+ *
103+ * wait_for_freeze: if true, NSF Manager waits for application to freeze
104+ * and become quiescent before proceeding to state
105+ * verification and checkpointing
106+ * wait_for_checkpoint: if true, NSF Manager waits for application to
107+ * complete checkpointing before reboot
108+ * wait_for_reconciliation: if true, NSF Manager waits for application to
109+ * complete reconciliation before unfreeze
110+ */
111+ bool WarmStart::registerWarmBootInfo (bool wait_for_freeze,
112+ bool wait_for_checkpoint,
113+ bool wait_for_reconciliation) {
114+ auto & warmStart = getInstance ();
115+
116+ if (!warmStart.m_initialized ) {
117+ SWSS_LOG_ERROR (" registerWarmBootInfo called before initialized" );
118+ return false ;
119+ }
120+
121+ if (warmStart.m_dockerName .empty ()) {
122+ SWSS_LOG_ERROR (" registerWarmBootInfo: m_dockerName is empty" );
123+ return false ;
124+ }
125+
126+ if (warmStart.m_appName .empty ()) {
127+ SWSS_LOG_ERROR (" registerWarmBootInfo: m_appName is empty" );
128+ return false ;
129+ }
130+
131+ std::unique_ptr<Table> stateWarmRestartRegistrationTable =
132+ std::unique_ptr<Table>(
133+ new Table (warmStart.m_stateDb .get (),
134+ STATE_WARM_RESTART_REGISTRATION_TABLE_NAME));
135+
136+ std::string separator =
137+ TableBase::getTableSeparator (warmStart.m_stateDb ->getDbId ());
138+ std::string tableName =
139+ warmStart.m_dockerName + separator + warmStart.m_appName ;
140+
141+ std::vector<FieldValueTuple> values;
142+
143+ values.push_back (swss::FieldValueTuple (WarmStart::kRegistrationFreezeKey ,
144+ wait_for_freeze ? " true" : " false" ));
145+ values.push_back (swss::FieldValueTuple (
146+ WarmStart::kRegistrationCheckpointKey ,
147+ wait_for_checkpoint ? " true" : " false" ));
148+ values.push_back (swss::FieldValueTuple (
149+ WarmStart::kRegistrationReconciliationKey ,
150+ wait_for_reconciliation ? " true" : " false" ));
151+ values.push_back (swss::FieldValueTuple (
152+ WarmStart::kRegistrationTimestampKey ,
153+ getTimestamp ()));
154+
155+ stateWarmRestartRegistrationTable->set (tableName, values);
156+
157+ return true ;
158+ }
159+
88160/*
89161 * <1> Upon system reboot, the system enable knob will be checked.
90162 * If enabled, database data will be preserved, if not, database will be flushed.
0 commit comments