Skip to content

Commit 77fa5a4

Browse files
authored
Move away sairedis logrotate from signal handler (#1153)
* Move away sairedis logrotate from signal handler * Update tests
1 parent 9f6efa0 commit 77fa5a4

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

orchagent/main.cpp

+2-9
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ int gBatchSize = DEFAULT_BATCH_SIZE;
4747
bool gSairedisRecord = true;
4848
bool gSwssRecord = true;
4949
bool gLogRotate = false;
50+
bool gSaiRedisLogRotate = false;
5051
bool gSyncMode = false;
5152

5253
ofstream gRecordOfs;
@@ -73,15 +74,7 @@ void sighup_handler(int signo)
7374
* Don't do any logging since they are using mutexes.
7475
*/
7576
gLogRotate = true;
76-
77-
sai_attribute_t attr;
78-
attr.id = SAI_REDIS_SWITCH_ATTR_PERFORM_LOG_ROTATE;
79-
attr.value.booldata = true;
80-
81-
if (sai_switch_api != NULL)
82-
{
83-
sai_switch_api->set_switch_attribute(gSwitchId, &attr);
84-
}
77+
gSaiRedisLogRotate = true;
8578
}
8679

8780
void syncd_apply_view()

orchagent/orchdaemon.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ using namespace swss;
1919

2020
extern sai_switch_api_t* sai_switch_api;
2121
extern sai_object_id_t gSwitchId;
22+
extern bool gSaiRedisLogRotate;
2223

2324
extern void syncd_apply_view();
2425
/*
@@ -400,6 +401,19 @@ void OrchDaemon::flush()
400401
SWSS_LOG_ERROR("Failed to flush redis pipeline %d", status);
401402
exit(EXIT_FAILURE);
402403
}
404+
405+
// check if logroate is requested
406+
if (gSaiRedisLogRotate)
407+
{
408+
SWSS_LOG_NOTICE("performing log rotate");
409+
410+
gSaiRedisLogRotate = false;
411+
412+
attr.id = SAI_REDIS_SWITCH_ATTR_PERFORM_LOG_ROTATE;
413+
attr.value.booldata = true;
414+
415+
sai_switch_api->set_switch_attribute(gSwitchId, &attr);
416+
}
403417
}
404418

405419
void OrchDaemon::start()

tests/mock_tests/mock_orchagent_main.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ int gBatchSize = DEFAULT_BATCH_SIZE;
1818
bool gSairedisRecord = true;
1919
bool gSwssRecord = true;
2020
bool gLogRotate = false;
21+
bool gSaiRedisLogRotate = false;
2122
ofstream gRecordOfs;
2223
string gRecordFile;
2324

2425
MirrorOrch *gMirrorOrch;
2526
VRFOrch *gVrfOrch;
2627

27-
void syncd_apply_view() {}
28+
void syncd_apply_view() {}

tests/mock_tests/mock_orchagent_main.h

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extern int gBatchSize;
1919
extern bool gSwssRecord;
2020
extern bool gSairedisRecord;
2121
extern bool gLogRotate;
22+
extern bool gSaiRedisLogRotate;
2223
extern ofstream gRecordOfs;
2324
extern string gRecordFile;
2425

0 commit comments

Comments
 (0)