Skip to content

Commit 7c5617f

Browse files
committed
add more documents
1 parent 9a099b7 commit 7c5617f

File tree

5 files changed

+61
-46
lines changed

5 files changed

+61
-46
lines changed

orchagent/orch.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,22 +189,31 @@ bool Orch::addToRetry(const std::string &executorName, const Task &task, const C
189189
return false;
190190
}
191191

192-
size_t Orch::retryToSync(const std::string &executorName, size_t threshold)
192+
/**
193+
* @brief Check the consumer's RetryCache, if the set of resolved constraints is not empty,
194+
* query RetryMap for failed tasks indexed by these resolved constraints,
195+
* and move them back to the consumer's SyncMap, such that they can be retried in the next iteration.
196+
* @param executorName - name of the consumer
197+
* @param quota - maximum number of tasks to be moved back to SyncMap in a single call
198+
* @return number of tasks moved back to SyncMap
199+
*/
200+
size_t Orch::retryToSync(const std::string &executorName, size_t quota)
193201
{
194202
auto retryCache = getRetryCache(executorName);
195203

196-
if (!retryCache || threshold <= 0)
204+
// directly return 0 if no retry cache for this executor or quota is non-positive
205+
if (!retryCache || quota <= 0)
197206
return 0;
198207

199208
std::unordered_set<Constraint>& constraints = retryCache->getResolvedConstraints();
200209

201210
size_t count = 0;
202211

203-
while (!constraints.empty() && count < threshold)
212+
while (!constraints.empty() && count < quota)
204213
{
205214
auto cst = *constraints.begin();
206215

207-
auto tasks = retryCache->resolve(cst, threshold - count);
216+
auto tasks = retryCache->resolve(cst, quota - count);
208217

209218
count += tasks->size();
210219

@@ -812,7 +821,8 @@ string Orch::objectReferenceInfo(
812821

813822
void Orch::doTask()
814823
{
815-
824+
// limit the number of tasks moved from RetryMap to SyncMap in one iteration
825+
// to avoid starvation of new tasks in SyncMap
816826
auto threshold = gBatchSize == 0 ? 30000 : gBatchSize;
817827

818828
size_t count = 0;

orchagent/orch.h

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ class ConsumerBase : public Executor {
183183
size_t addToSync(std::shared_ptr<std::deque<swss::KeyOpFieldsValuesTuple>> entries, bool onRetry=false);
184184

185185
/**
186-
* Move a task to retry cache for future processing
187-
* @param task a task tuple
188-
* @param cst the constraint for the task
186+
* @brief Add the failed task and its constraint to the consumer's RetryCache
187+
* @param task - the task that has failed due to the unmet constraint
188+
* @param cst - the unmet constraint that blocks the task from being retried
189189
*/
190190
bool addToRetry(const Task &task, const Constraint &cst);
191191

@@ -322,19 +322,30 @@ class Orch
322322
RetryCache* getRetryCache(const std::string &executorName);
323323
ConsumerBase* getConsumerBase(const std::string &executorName);
324324

325-
// Add a task and its constraint to the retry cache
325+
/**
326+
* @brief Add the failed task and its constraint to the consumer's RetryCache
327+
* @param executorName - name of the consumer
328+
* @param task - the task that has failed due to the unmet constraint
329+
* @param cst - the unmet constraint that blocks the task from being retried
330+
* @return true only if the consumer has initialized a retry cache and the task is successfully added into it
331+
*/
326332
bool addToRetry(const std::string &executorName, const Task &task, const Constraint &cst);
327333

328-
/** Delete tasks whose constraints are resolved in this executor's retry cache , then add them back to its m_toSync.
329-
* @param executorName name of the executor (actually a ConsumerBase instance)
330-
* @param cst task constraint **/
331-
virtual size_t retryToSync(const std::string &executorName, size_t threshold=30000);
334+
/**
335+
* @brief Check the consumer's RetryCache for pending tasks with constraints already resolved.
336+
* If any, move them from RetryMap back to SyncMap, such that they can be retried when the consumer's execute() method is invoked.
337+
* Make sure to limit the number of tasks added to SyncMap in one call, to avoid starvation of new tasks in SyncMap.
338+
* @param executorName - name of the consumer
339+
* @param quota - maximum number of tasks to be moved back to SyncMap in a single call
340+
*/
341+
virtual size_t retryToSync(const std::string &executorName, size_t quota=30000);
332342

333-
/** Notify the executor that the constraint is already resolved
334-
* @param retryOrch the orch to be notified
335-
* @param executorName name of the executor to be notified
336-
* @param cst the constraint that can be resolved
337-
* **/
343+
/**
344+
* @brief Notify the consumer that the constraint is already resolved
345+
* @param retryOrch - the consumer's Orch instance, used to get the consumer's RetryCache
346+
* @param executorName - name of the consumer to be notified
347+
* @param cst - the constraint that is resolved
348+
*/
338349
virtual void notifyRetry(Orch *retryOrch, const std::string &executorName, const Constraint &cst);
339350

340351
/**

orchagent/retrycache.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,15 @@ using namespace swss;
1010
enum ConstraintType
1111
{
1212
RETRY_CST_DUMMY,
13-
RETRY_CST_NHG, // nhg doesn't exist
14-
RETRY_CST_NHG_REF, // nhg refcnt nonzero
1513
RETRY_CST_PIC, // context doesn't exist
16-
RETRY_CST_PIC_REF, // context refcnt nonzero
17-
RETRY_CST_ECMP // ecmp resources exhausted
14+
RETRY_CST_PIC_REF // context refcnt nonzero
1815
};
1916

2017
static inline std::ostream& operator<<(std::ostream& os, ConstraintType t) {
2118
switch(t) {
2219
case ConstraintType::RETRY_CST_DUMMY: return os << "RETRY_CST_DUMMY";
23-
case ConstraintType::RETRY_CST_NHG: return os << "RETRY_CST_NHG";
24-
case ConstraintType::RETRY_CST_NHG_REF: return os << "RETRY_CST_NHG_REF";
2520
case ConstraintType::RETRY_CST_PIC: return os << "RETRY_CST_PIC";
2621
case ConstraintType::RETRY_CST_PIC_REF: return os << "RETRY_CST_PIC_REF";
27-
case ConstraintType::RETRY_CST_ECMP: return os << "RETRY_CST_ECMP";
2822
default: return os << "UNKNOWN";
2923
}
3024
}

orchagent/routeorch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ void RouteOrch::doTask(ConsumerBase& consumer)
11711171
{
11721172
/* If any existing routes are updated to point to the
11731173
* above interfaces, remove them from the ASIC. */
1174-
if (removeRoutePost(ctx) || rc_inserted)
1174+
if (removeRoutePost(ctx) || rc_inserted)
11751175
it_prev = consumer.m_toSync.erase(it_prev);
11761176
else
11771177
it_prev++;
@@ -1182,7 +1182,7 @@ void RouteOrch::doTask(ConsumerBase& consumer)
11821182

11831183
if (nhg.getSize() == 1 && nhg.hasIntfNextHop())
11841184
{
1185-
if (addRoutePost(ctx, nhg) || rc_inserted)
1185+
if (addRoutePost(ctx, nhg) || rc_inserted)
11861186
it_prev = consumer.m_toSync.erase(it_prev);
11871187
else
11881188
it_prev++;

tests/mock_tests/retrycache_ut.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace retrycache_test
3838
std::cout << " CstResolver [Selected]: resolves the constraint and notifies." << std::endl;
3939
auto it = consumer.m_toSync.begin();
4040
consumer.m_toSync.erase(it);
41-
Constraint cst = make_constraint(RETRY_CST_NHG, "2");
41+
Constraint cst = make_constraint(RETRY_CST_PIC, "2");
4242
notifyRetry(this, "Dependent", cst);
4343
}
4444
else if (consumer.getName() == "Dependent")
@@ -64,7 +64,7 @@ namespace retrycache_test
6464
TestOrch* testOrch;
6565
Consumer *oftenFail, *cstResolver;
6666
RetryCache* cache;
67-
Constraint cst = make_constraint(RETRY_CST_NHG, "2");
67+
Constraint cst = make_constraint(RETRY_CST_PIC, "2");
6868

6969
void SetUp() override
7070
{
@@ -103,7 +103,7 @@ namespace retrycache_test
103103
ASSERT_TRUE(cache->getRetryMap().empty());
104104

105105
cache->insert({"key", "DEL", {}}, cst);
106-
Constraint _cst = make_constraint(RETRY_CST_NHG, "3");
106+
Constraint _cst = make_constraint(RETRY_CST_PIC, "3");
107107
cache->insert({"key", "SET", {{"nexthop_index", "3"}}}, _cst);
108108
tasks = cache->resolve(cst);
109109
ASSERT_EQ(tasks->size(), 1);
@@ -121,9 +121,9 @@ namespace retrycache_test
121121
std::cout << "Orchdaemon Event Loop 1: " << std::endl;
122122

123123
// Assume the Dependent Executor receives a task to process
124-
Task task{"TEST_ROUTE", "SET", {{"NHG", "2"}}};
124+
Task task{"TEST_ROUTE", "SET", {{"PIC", "2"}}};
125125
oftenFail->addToSync(task);
126-
// But it fails because of the constraint: nhg 2 doesn't exist
126+
// But it fails because of the constraint: PIC 2 doesn't exist
127127
// It moves the task from m_toSync to m_toRetry
128128
oftenFail->drain();
129129

@@ -150,7 +150,7 @@ namespace retrycache_test
150150
std::cout << "Orchdaemon Event Loop 2: " << std::endl;
151151

152152
// Assume in the next event loop, the cstResolver a task to process, which resolves the constraint for oftenFail.
153-
cstResolver->addToSync({"TEST_NHG", "SET", {{"ID", "2"}}});
153+
cstResolver->addToSync({"TEST_PIC", "SET", {{"ID", "2"}}});
154154
cstResolver->drain();
155155

156156
// Post-resolution
@@ -221,7 +221,7 @@ namespace retrycache_test
221221

222222
// Assume there are a SET and a DEL task in the retry cache
223223
cache->insert(setTask, cst);
224-
Constraint del_cst = make_constraint(RETRY_CST_NHG_REF, "");
224+
Constraint del_cst = make_constraint(RETRY_CST_PIC_REF, "");
225225
cache->insert(delTask, del_cst);
226226
ASSERT_EQ(cache->getRetryMap().size(), 2);
227227

@@ -239,24 +239,24 @@ namespace retrycache_test
239239
TEST_F(RetryCacheTest, NewSetTask)
240240
{
241241
// Assume there is an old SET task in the retry cache
242-
Task setTask{"TEST_ROUTE", "SET", {{"NHG", "1"}}};
243-
Constraint cst_nhg_1 = make_constraint(RETRY_CST_NHG, "1");
244-
cache->insert(setTask, cst_nhg_1);
242+
Task setTask{"TEST_ROUTE", "SET", {{"PIC", "1"}}};
243+
Constraint cst_pic_1 = make_constraint(RETRY_CST_PIC, "1");
244+
cache->insert(setTask, cst_pic_1);
245245

246246
// Assume there is a new task with same field, received by the consumer
247-
Task setTask2{"TEST_ROUTE", "SET", {{"NHG", "2"}}};
247+
Task setTask2{"TEST_ROUTE", "SET", {{"PIC", "2"}}};
248248
oftenFail->addToSync(setTask2);
249249
// Check if it clears the retrycache
250250
ASSERT_TRUE(cache->getRetryMap().empty());
251-
ASSERT_EQ(cache->m_retryKeys.find(cst_nhg_1), cache->m_retryKeys.end());
251+
ASSERT_EQ(cache->m_retryKeys.find(cst_pic_1), cache->m_retryKeys.end());
252252
// Check if it adds the task 2 into the sync queue
253253
auto iter = oftenFail->m_toSync.find("TEST_ROUTE");
254254
ASSERT_EQ(iter->second, setTask2);
255255

256-
// Assume NHG 2 also doesn't exist, the new task fails too
256+
// Assume PIC 2 also doesn't exist, the new task fails too
257257
oftenFail->m_toSync.erase(iter);
258-
Constraint cst_nhg2 = make_constraint(RETRY_CST_NHG, "2");
259-
cache->insert(setTask2, cst_nhg2);
258+
Constraint cst_pic_2 = make_constraint(RETRY_CST_PIC, "2");
259+
cache->insert(setTask2, cst_pic_2);
260260

261261
// Assume there is a new SET task with a new field, received by the consumer
262262
Task setTask3{"TEST_ROUTE", "SET", {{"VRF", "1"}}};
@@ -274,7 +274,7 @@ namespace retrycache_test
274274
{
275275
if (fvField(fv) == "VRF")
276276
ASSERT_EQ(fvValue(fv), "1");
277-
else if (fvField(fv) == "NHG")
277+
else if (fvField(fv) == "PIC")
278278
ASSERT_EQ(fvValue(fv), "2");
279279
else
280280
ASSERT_FALSE(true); // unexpected field
@@ -287,8 +287,8 @@ namespace retrycache_test
287287
// simulate by firstly adding a DEL, then adding a SET into the retry cache
288288
Task delTask{"TEST_ROUTE", "DEL", {{"", ""}}};
289289
cache->insert(delTask, DUMMY_CONSTRAINT);
290-
Task setTask{"TEST_ROUTE", "SET", {{"NHG", "1"}}};
291-
Constraint cst = make_constraint(RETRY_CST_NHG, "1");
290+
Task setTask{"TEST_ROUTE", "SET", {{"PIC", "1"}}};
291+
Constraint cst = make_constraint(RETRY_CST_PIC, "1");
292292
cache->insert(setTask, cst);
293293

294294
ASSERT_EQ(cache->getRetryMap().size(), 2);
@@ -308,7 +308,7 @@ namespace retrycache_test
308308
{
309309
if (fvField(fv) == "VRF")
310310
ASSERT_EQ(fvValue(fv), "1");
311-
else if (fvField(fv) == "NHG")
311+
else if (fvField(fv) == "PIC")
312312
ASSERT_EQ(fvValue(fv), "1");
313313
else
314314
ASSERT_FALSE(true); // unexpected field

0 commit comments

Comments
 (0)