@@ -98,6 +98,24 @@ FlexCounterOrch::FlexCounterOrch(DBConnector *db, vector<string> &tableNames):
9898 m_deviceMetadataConfigTable(db, CFG_DEVICE_METADATA_TABLE_NAME)
9999{
100100 SWSS_LOG_ENTER ();
101+
102+ // Read create_only_config_db_buffers configuration once during initialization
103+ std::string createOnlyConfigDbBuffersValue;
104+ try
105+ {
106+ if (m_deviceMetadataConfigTable.hget (" localhost" , " create_only_config_db_buffers" , createOnlyConfigDbBuffersValue))
107+ {
108+ if (createOnlyConfigDbBuffersValue == " true" )
109+ {
110+ m_createOnlyConfigDbBuffers = true ;
111+ }
112+ }
113+ }
114+ catch (const std::system_error& e)
115+ {
116+ SWSS_LOG_ERROR (" System error reading create_only_config_db_buffers: %s" , e.what ());
117+ }
118+
101119 m_delayTimer = std::make_unique<SelectableTimer>(timespec{.tv_sec = FLEX_COUNTER_DELAY_SEC, .tv_nsec = 0 });
102120 if (WarmStart::isWarmStart ())
103121 {
@@ -120,6 +138,13 @@ void FlexCounterOrch::doTask(Consumer &consumer)
120138{
121139 SWSS_LOG_ENTER ();
122140
141+ // Handle DEVICE_METADATA table changes for create_only_config_db_buffers
142+ if (consumer.getTableName () == CFG_DEVICE_METADATA_TABLE_NAME)
143+ {
144+ handleDeviceMetadataTable (consumer);
145+ return ;
146+ }
147+
123148 if (!m_delayTimerExpired)
124149 {
125150 return ;
@@ -394,39 +419,59 @@ bool FlexCounterOrch::getWredPortCountersState() const
394419 return m_wred_port_counter_enabled;
395420}
396421
397- bool FlexCounterOrch::bake ()
422+ bool FlexCounterOrch::isCreateOnlyConfigDbBuffers () const
398423{
399- /*
400- * bake is called during warmreboot reconciling procedure.
401- * By default, it should fetch items from the tables the sub agents listen to,
402- * and then push them into m_toSync of each sub agent.
403- * The motivation is to make sub agents handle the saved entries first and then handle the upcoming entries.
404- * The FCs are not data plane configuration required during reconciling process, hence don't do anything in bake.
405- */
406-
407- return true ;
424+ return m_createOnlyConfigDbBuffers;
408425}
409426
410- static bool isCreateOnlyConfigDbBuffers (Table& deviceMetadataConfigTable )
427+ void FlexCounterOrch::handleDeviceMetadataTable (Consumer &consumer )
411428{
412- std::string createOnlyConfigDbBuffersValue ;
429+ SWSS_LOG_ENTER () ;
413430
414- try
431+ auto it = consumer.m_toSync .begin ();
432+ while (it != consumer.m_toSync .end ())
415433 {
416- if (deviceMetadataConfigTable.hget (" localhost" , " create_only_config_db_buffers" , createOnlyConfigDbBuffersValue))
434+ KeyOpFieldsValuesTuple t = it->second ;
435+ string key = kfvKey (t);
436+ string op = kfvOp (t);
437+ auto data = kfvFieldsValues (t);
438+
439+ // Only process localhost entries
440+ if (key == " localhost" && op == SET_COMMAND)
417441 {
418- if (createOnlyConfigDbBuffersValue == " true " )
442+ for ( auto valuePair : data )
419443 {
420- return true ;
444+ const auto &field = fvField (valuePair);
445+ const auto &value = fvValue (valuePair);
446+
447+ if (field == " create_only_config_db_buffers" )
448+ {
449+ bool newValue = (value == " true" );
450+ if (m_createOnlyConfigDbBuffers != newValue)
451+ {
452+ SWSS_LOG_NOTICE (" Updating create_only_config_db_buffers from %s to %s" ,
453+ m_createOnlyConfigDbBuffers ? " true" : " false" ,
454+ value.c_str ());
455+ m_createOnlyConfigDbBuffers = newValue;
456+ }
457+ }
421458 }
422459 }
460+ consumer.m_toSync .erase (it++);
423461 }
424- catch (const std::system_error& e)
425- {
426- SWSS_LOG_ERROR (" System error: %s" , e.what ());
427- }
462+ }
428463
429- return false ;
464+ bool FlexCounterOrch::bake ()
465+ {
466+ /*
467+ * bake is called during warmreboot reconciling procedure.
468+ * By default, it should fetch items from the tables the sub agents listen to,
469+ * and then push them into m_toSync of each sub agent.
470+ * The motivation is to make sub agents handle the saved entries first and then handle the upcoming entries.
471+ * The FCs are not data plane configuration required during reconciling process, hence don't do anything in bake.
472+ */
473+
474+ return true ;
430475}
431476
432477map<string, FlexCounterQueueStates> FlexCounterOrch::getQueueConfigurations ()
@@ -435,7 +480,7 @@ map<string, FlexCounterQueueStates> FlexCounterOrch::getQueueConfigurations()
435480
436481 map<string, FlexCounterQueueStates> queuesStateVector;
437482
438- if (!isCreateOnlyConfigDbBuffers (m_deviceMetadataConfigTable ))
483+ if (!isCreateOnlyConfigDbBuffers ())
439484 {
440485 FlexCounterQueueStates flexCounterQueueState (0 );
441486 queuesStateVector.insert (make_pair (createAllAvailableBuffersStr, flexCounterQueueState));
@@ -504,7 +549,7 @@ map<string, FlexCounterPgStates> FlexCounterOrch::getPgConfigurations()
504549
505550 map<string, FlexCounterPgStates> pgsStateVector;
506551
507- if (!isCreateOnlyConfigDbBuffers (m_deviceMetadataConfigTable ))
552+ if (!isCreateOnlyConfigDbBuffers ())
508553 {
509554 FlexCounterPgStates flexCounterPgState (0 );
510555 pgsStateVector.insert (make_pair (createAllAvailableBuffersStr, flexCounterPgState));
0 commit comments