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{
@@ -81,6 +86,9 @@ void WarmStart::initialize(const std::string &app_name,
8186 return ;
8287 }
8388
89+ warmStart.m_appName = app_name;
90+ warmStart.m_dockerName = docker_name;
91+
8492 /* Use unix socket for db connection by default */
8593 warmStart.m_stateDb =
8694 std::make_shared<swss::DBConnector>(" STATE_DB" , db_timeout, isTcpConn);
@@ -97,6 +105,70 @@ void WarmStart::initialize(const std::string &app_name,
97105 warmStart.m_initialized = true ;
98106}
99107
108+ /*
109+ * registerWarmBootInfo
110+ *
111+ * Register an application with NSF Manager.
112+ *
113+ * Returns: true on success, false otherwise.
114+ *
115+ * wait_for_freeze: if true, NSF Manager waits for application to freeze
116+ * and become quiescent before proceeding to state
117+ * verification and checkpointing
118+ * wait_for_checkpoint: if true, NSF Manager waits for application to
119+ * complete checkpointing before reboot
120+ * wait_for_reconciliation: if true, NSF Manager waits for application to
121+ * complete reconciliation before unfreeze
122+ */
123+ bool WarmStart::registerWarmBootInfo (bool wait_for_freeze,
124+ bool wait_for_checkpoint,
125+ bool wait_for_reconciliation) {
126+ auto & warmStart = getInstance ();
127+
128+ if (!warmStart.m_initialized ) {
129+ SWSS_LOG_ERROR (" registerWarmBootInfo called before initialized" );
130+ return false ;
131+ }
132+
133+ if (warmStart.m_dockerName .empty ()) {
134+ SWSS_LOG_ERROR (" registerWarmBootInfo: m_dockerName is empty" );
135+ return false ;
136+ }
137+
138+ if (warmStart.m_appName .empty ()) {
139+ SWSS_LOG_ERROR (" registerWarmBootInfo: m_appName is empty" );
140+ return false ;
141+ }
142+
143+ std::unique_ptr<Table> stateWarmRestartRegistrationTable =
144+ std::unique_ptr<Table>(
145+ new Table (warmStart.m_stateDb .get (),
146+ STATE_WARM_RESTART_REGISTRATION_TABLE_NAME));
147+
148+ std::string separator =
149+ TableBase::getTableSeparator (warmStart.m_stateDb ->getDbId ());
150+ std::string tableName =
151+ warmStart.m_dockerName + separator + warmStart.m_appName ;
152+
153+ std::vector<FieldValueTuple> values;
154+
155+ values.push_back (swss::FieldValueTuple (WarmStart::kRegistrationFreezeKey ,
156+ wait_for_freeze ? " true" : " false" ));
157+ values.push_back (swss::FieldValueTuple (
158+ WarmStart::kRegistrationCheckpointKey ,
159+ wait_for_checkpoint ? " true" : " false" ));
160+ values.push_back (swss::FieldValueTuple (
161+ WarmStart::kRegistrationReconciliationKey ,
162+ wait_for_reconciliation ? " true" : " false" ));
163+ values.push_back (swss::FieldValueTuple (
164+ WarmStart::kRegistrationTimestampKey ,
165+ getTimestamp ()));
166+
167+ stateWarmRestartRegistrationTable->set (tableName, values);
168+
169+ return true ;
170+ }
171+
100172/*
101173 * <1> Upon system reboot, the system enable knob will be checked.
102174 * If enabled, database data will be preserved, if not, database will be flushed.
0 commit comments