Skip to content

Commit c6644b6

Browse files
committed
enable task retry recording
1 parent ddc5be1 commit c6644b6

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

lib/recorder.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const std::string Recorder::REC_START = "|recording started";
1010
const std::string Recorder::SWSS_FNAME = "swss.rec";
1111
const std::string Recorder::SAIREDIS_FNAME = "sairedis.rec";
1212
const std::string Recorder::RESPPUB_FNAME = "responsepublisher.rec";
13-
13+
const std::string Recorder::RETRY_FNAME = "retry.rec";
1414

1515
Recorder& Recorder::Instance()
1616
{
@@ -19,6 +19,35 @@ Recorder& Recorder::Instance()
1919
}
2020

2121

22+
RetryRec::RetryRec()
23+
{
24+
/* Set Default values */
25+
setRecord(true);
26+
setRotate(false);
27+
setLocation(Recorder::DEFAULT_DIR);
28+
setFileName(Recorder::RETRY_FNAME);
29+
setName("Retry");
30+
}
31+
32+
void RetryRec::record(const std::string& val, bool ADD_TO_CACHE)
33+
{
34+
if (!isRecord())
35+
{
36+
return ;
37+
}
38+
if (isRotate())
39+
{
40+
setRotate(false);
41+
logfileReopen();
42+
}
43+
44+
if (ADD_TO_CACHE) {
45+
record_ofs << getTimestamp() << "| ++++ |" << val << std::endl;
46+
} else {
47+
record_ofs << getTimestamp() << "| ---- |" << val << std::endl;
48+
}
49+
}
50+
2251
SwSSRec::SwSSRec()
2352
{
2453
/* Set Default values */

lib/recorder.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ class RecWriter : public RecBase {
4848
std::string fname;
4949
};
5050

51+
class RetryRec : public RecWriter {
52+
public:
53+
RetryRec();
54+
void record(const std::string& val, bool ADD_TO_CACHE=true);
55+
};
56+
5157
class SwSSRec : public RecWriter {
5258
public:
5359
SwSSRec();
@@ -73,12 +79,14 @@ class Recorder {
7379
static const std::string SWSS_FNAME;
7480
static const std::string SAIREDIS_FNAME;
7581
static const std::string RESPPUB_FNAME;
82+
static const std::string RETRY_FNAME;
7683

7784
Recorder() = default;
7885
/* Individual Handlers */
7986
SwSSRec swss;
8087
SaiRedisRec sairedis;
8188
ResPubRec respub;
89+
RetryRec retry;
8290
};
8391

8492
}

orchagent/main.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ extern bool gIsNatSupported;
6262
#define SAIREDIS_RECORD_ENABLE 0x1
6363
#define SWSS_RECORD_ENABLE (0x1 << 1)
6464
#define RESPONSE_PUBLISHER_RECORD_ENABLE (0x1 << 2)
65+
#define RETRY_RECORD_ENABLE (0x1 << 3)
6566

6667
/* orchagent heart beat message interval */
6768
#define HEART_BEAT_INTERVAL_MSECS_DEFAULT 10 * 1000
@@ -109,6 +110,7 @@ void sighup_handler(int signo)
109110
/*
110111
* Don't do any logging since they are using mutexes.
111112
*/
113+
Recorder::Instance().retry.setRotate(true);
112114
Recorder::Instance().swss.setRotate(true);
113115
Recorder::Instance().sairedis.setRotate(true);
114116
Recorder::Instance().respub.setRotate(true);
@@ -361,6 +363,7 @@ int main(int argc, char **argv)
361363
string record_location = Recorder::DEFAULT_DIR;
362364
string swss_rec_filename = Recorder::SWSS_FNAME;
363365
string sairedis_rec_filename = Recorder::SAIREDIS_FNAME;
366+
string retry_rec_filename = Recorder::RETRY_FNAME;
364367
string zmq_server_address = "tcp://127.0.0.1:" + to_string(ORCH_ZMQ_PORT);
365368
string vrf;
366369
bool enable_zmq = false;
@@ -395,7 +398,7 @@ int main(int argc, char **argv)
395398
// Disable all recordings if atoi() fails i.e. returns 0 due to
396399
// invalid command line argument.
397400
record_type = atoi(optarg);
398-
if (record_type < 0 || record_type > 7)
401+
if (record_type < 0 || record_type > 15)
399402
{
400403
usage();
401404
exit(EXIT_FAILURE);
@@ -522,6 +525,13 @@ int main(int argc, char **argv)
522525
Recorder::Instance().respub.setFileName(responsepublisher_rec_filename);
523526
Recorder::Instance().respub.startRec(false);
524527

528+
Recorder::Instance().retry.setRecord(
529+
(record_type & RETRY_RECORD_ENABLE) == RETRY_RECORD_ENABLE
530+
);
531+
Recorder::Instance().retry.setLocation(record_location);
532+
Recorder::Instance().retry.setFileName(retry_rec_filename);
533+
Recorder::Instance().retry.startRec(true);
534+
525535
// Instantiate database connectors
526536
DBConnector appl_db("APPL_DB", 0);
527537
DBConnector config_db("CONFIG_DB", 0);

orchagent/orch.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,12 @@ ConsumerBase* Orch::getConsumerBase(const std::string &executorName)
168168
}
169169

170170
void ConsumerBase::addToRetry(Task &&task, Constraint &&cst) {
171+
Recorder::Instance().retry.record(dumpTuple(task), CACHE);
171172
getOrch()->getRetryCache(getName())->insert_failed_task(std::move(task), std::move(cst));
172173
}
173174

174175
void Orch::addToRetry(std::string &&executorName, Task &&task, Constraint &&cst) {
176+
Recorder::Instance().retry.record(getConsumerBase(executorName)->dumpTuple(task), CACHE);
175177
getRetryCache(executorName)->insert_failed_task(std::move(task), std::move(cst));
176178
}
177179

@@ -192,8 +194,11 @@ void ConsumerBase::addToSync(const KeyOpFieldsValuesTuple &entry, bool onRetry)
192194
string key = kfvKey(entry);
193195
string op = kfvOp(entry);
194196

195-
/* Record incoming tasks */
196-
Recorder::Instance().swss.record(dumpTuple(entry));
197+
if (!onRetry)
198+
/* Record incoming tasks */
199+
Recorder::Instance().swss.record(dumpTuple(entry));
200+
else
201+
Recorder::Instance().retry.record(dumpTuple(entry), DECACHE);
197202

198203
auto retryCache = getOrch()->getRetryCache(getName());
199204

@@ -203,6 +208,7 @@ void ConsumerBase::addToSync(const KeyOpFieldsValuesTuple &entry, bool onRetry)
203208
assert(!onRetry); // a retry task is already cleared from the cache before trying to add to m_toSync
204209
assert(m_toSync.find(key) == m_toSync.end());
205210
auto cache = retryCache->erase_failed_task(key);
211+
Recorder::Instance().retry.record(dumpTuple(*cache), DECACHE);
206212
m_toSync.emplace(key, std::move(*cache));
207213
}
208214

orchagent/orch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ typedef enum
272272
typedef std::pair<swss::DBConnector *, std::string> TableConnector;
273273
typedef std::pair<swss::DBConnector *, std::vector<std::string>> TablesConnector;
274274

275+
#define CACHE true
276+
#define DECACHE false
277+
275278

276279
class Orch
277280
{

0 commit comments

Comments
 (0)