Skip to content

Commit ea34b92

Browse files
andriymoroz-mlnxlguohan
authored andcommitted
Fix tables handling race condition in buffermgr (sonic-net#484)
* Fix tables handling race condition in buffermgr Signed-off-by: Andriy Moroz <[email protected]> * Fixed status lose in loop Signed-off-by: Andriy Moroz <[email protected]>
1 parent 53831be commit ea34b92

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

cfgmgr/buffermgr.cpp

+29-11
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ void BufferMgr::readPgProfileLookupFile(string file)
7272
infile.close();
7373
}
7474

75-
void BufferMgr::doCableTask(string port, string cable_length)
75+
task_process_status BufferMgr::doCableTask(string port, string cable_length)
7676
{
7777
m_cableLenLookup[port] = cable_length;
78+
return task_process_status::task_success;
7879
}
7980

8081
string BufferMgr::getPgPoolMode()
@@ -108,15 +109,15 @@ Create/update two tables: profile (in m_cfgBufferProfileTable) and port buffer (
108109
}
109110
}
110111
*/
111-
void BufferMgr::doSpeedUpdateTask(string port, string speed)
112+
task_process_status BufferMgr::doSpeedUpdateTask(string port, string speed)
112113
{
113114
vector<FieldValueTuple> fvVector;
114115
string cable;
115116

116117
if (m_cableLenLookup.count(port) == 0)
117118
{
118-
SWSS_LOG_ERROR("Unable to create/update PG profile for port %s. Cable length is not set", port.c_str());
119-
return;
119+
SWSS_LOG_WARN("Unable to create/update PG profile for port %s. Cable length is not set", port.c_str());
120+
return task_process_status::task_need_retry;
120121
}
121122

122123
cable = m_cableLenLookup[port];
@@ -125,7 +126,7 @@ void BufferMgr::doSpeedUpdateTask(string port, string speed)
125126
{
126127
SWSS_LOG_ERROR("Unable to create/update PG profile for port %s. No PG profile configured for speed %s and cable length %s",
127128
port.c_str(), speed.c_str(), cable.c_str());
128-
return;
129+
return task_process_status::task_failed;
129130
}
130131

131132
// Crete record in BUFFER_PROFILE table
@@ -143,8 +144,8 @@ void BufferMgr::doSpeedUpdateTask(string port, string speed)
143144
if (mode.empty())
144145
{
145146
// this should never happen if switch initialized properly
146-
SWSS_LOG_ERROR("PG lossless pool is not yet created");
147-
return;
147+
SWSS_LOG_WARN("PG lossless pool is not yet created");
148+
return task_process_status::task_need_retry;
148149
}
149150

150151
// profile threshold field name
@@ -170,6 +171,7 @@ void BufferMgr::doSpeedUpdateTask(string port, string speed)
170171
string profile_ref = string("[") + CFG_BUFFER_PROFILE_TABLE_NAME + CONFIGDB_TABLE_NAME_SEPARATOR + buffer_profile_key + "]";
171172
fvVector.push_back(make_pair("profile", profile_ref));
172173
m_cfgBufferPgTable.set(buffer_pg_key, fvVector);
174+
return task_process_status::task_success;
173175
}
174176

175177
void BufferMgr::doTask(Consumer &consumer)
@@ -188,25 +190,41 @@ void BufferMgr::doTask(Consumer &consumer)
188190
string port(keys[0]);
189191

190192
string op = kfvOp(t);
193+
task_process_status task_status = task_process_status::task_success;
191194
if (op == SET_COMMAND)
192195
{
193196
for (auto i : kfvFieldsValues(t))
194197
{
195198
if (table_name == CFG_PORT_CABLE_LEN_TABLE_NAME)
196199
{
197200
// receive and cache cable length table
198-
doCableTask(fvField(i), fvValue(i));
201+
task_status = doCableTask(fvField(i), fvValue(i));
199202
}
200203
// In case of PORT table update, Buffer Manager is interested in speed update only
201204
if (table_name == CFG_PORT_TABLE_NAME && fvField(i) == "speed")
202205
{
203206
// create/update profile for port
204-
doSpeedUpdateTask(port, fvValue(i));
207+
task_status = doSpeedUpdateTask(port, fvValue(i));
208+
}
209+
if (task_status != task_process_status::task_success)
210+
{
211+
break;
205212
}
206213
}
207214
}
208215

209-
it = consumer.m_toSync.erase(it);
210-
continue;
216+
switch (task_status)
217+
{
218+
case task_process_status::task_failed:
219+
SWSS_LOG_ERROR("Failed to process table update");
220+
return;
221+
case task_process_status::task_need_retry:
222+
SWSS_LOG_INFO("Unable to process table update. Will retry...");
223+
++it;
224+
break;
225+
default:
226+
it = consumer.m_toSync.erase(it);
227+
break;
228+
}
211229
}
212230
}

cfgmgr/buffermgr.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class BufferMgr : public Orch
4444
port_cable_length_t m_cableLenLookup;
4545
std::string getPgPoolMode();
4646
void readPgProfileLookupFile(std::string);
47-
void doCableTask(string port, string cable_length);
48-
void doSpeedUpdateTask(string port, string speed);
47+
task_process_status doCableTask(string port, string cable_length);
48+
task_process_status doSpeedUpdateTask(string port, string speed);
4949

5050
void doTask(Consumer &consumer);
5151
};

0 commit comments

Comments
 (0)