From 77fa5a41d004631dc6389756d2231da2182929e2 Mon Sep 17 00:00:00 2001 From: Kamil Cudnik Date: Sun, 22 Dec 2019 14:20:25 +0100 Subject: [PATCH] Move away sairedis logrotate from signal handler (#1153) * Move away sairedis logrotate from signal handler * Update tests --- orchagent/main.cpp | 11 ++--------- orchagent/orchdaemon.cpp | 14 ++++++++++++++ tests/mock_tests/mock_orchagent_main.cpp | 3 ++- tests/mock_tests/mock_orchagent_main.h | 1 + 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/orchagent/main.cpp b/orchagent/main.cpp index a5591b9d0040..6d3d6d228ebb 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -47,6 +47,7 @@ int gBatchSize = DEFAULT_BATCH_SIZE; bool gSairedisRecord = true; bool gSwssRecord = true; bool gLogRotate = false; +bool gSaiRedisLogRotate = false; bool gSyncMode = false; ofstream gRecordOfs; @@ -73,15 +74,7 @@ void sighup_handler(int signo) * Don't do any logging since they are using mutexes. */ gLogRotate = true; - - sai_attribute_t attr; - attr.id = SAI_REDIS_SWITCH_ATTR_PERFORM_LOG_ROTATE; - attr.value.booldata = true; - - if (sai_switch_api != NULL) - { - sai_switch_api->set_switch_attribute(gSwitchId, &attr); - } + gSaiRedisLogRotate = true; } void syncd_apply_view() diff --git a/orchagent/orchdaemon.cpp b/orchagent/orchdaemon.cpp index 756b8a35eb3d..338b803dcea4 100644 --- a/orchagent/orchdaemon.cpp +++ b/orchagent/orchdaemon.cpp @@ -19,6 +19,7 @@ using namespace swss; extern sai_switch_api_t* sai_switch_api; extern sai_object_id_t gSwitchId; +extern bool gSaiRedisLogRotate; extern void syncd_apply_view(); /* @@ -400,6 +401,19 @@ void OrchDaemon::flush() SWSS_LOG_ERROR("Failed to flush redis pipeline %d", status); exit(EXIT_FAILURE); } + + // check if logroate is requested + if (gSaiRedisLogRotate) + { + SWSS_LOG_NOTICE("performing log rotate"); + + gSaiRedisLogRotate = false; + + attr.id = SAI_REDIS_SWITCH_ATTR_PERFORM_LOG_ROTATE; + attr.value.booldata = true; + + sai_switch_api->set_switch_attribute(gSwitchId, &attr); + } } void OrchDaemon::start() diff --git a/tests/mock_tests/mock_orchagent_main.cpp b/tests/mock_tests/mock_orchagent_main.cpp index 60b5f5e00f15..86651a7c949e 100644 --- a/tests/mock_tests/mock_orchagent_main.cpp +++ b/tests/mock_tests/mock_orchagent_main.cpp @@ -18,10 +18,11 @@ int gBatchSize = DEFAULT_BATCH_SIZE; bool gSairedisRecord = true; bool gSwssRecord = true; bool gLogRotate = false; +bool gSaiRedisLogRotate = false; ofstream gRecordOfs; string gRecordFile; MirrorOrch *gMirrorOrch; VRFOrch *gVrfOrch; -void syncd_apply_view() {} \ No newline at end of file +void syncd_apply_view() {} diff --git a/tests/mock_tests/mock_orchagent_main.h b/tests/mock_tests/mock_orchagent_main.h index 9971463ce45e..71bb522d778c 100644 --- a/tests/mock_tests/mock_orchagent_main.h +++ b/tests/mock_tests/mock_orchagent_main.h @@ -19,6 +19,7 @@ extern int gBatchSize; extern bool gSwssRecord; extern bool gSairedisRecord; extern bool gLogRotate; +extern bool gSaiRedisLogRotate; extern ofstream gRecordOfs; extern string gRecordFile;