From 569c8b1a64c4a1a6284941bbfd9447984f6c0bc1 Mon Sep 17 00:00:00 2001 From: Bryan Crossland Date: Mon, 3 Oct 2022 22:35:11 -0500 Subject: [PATCH] What I did Fix Azure/sonic-buildimage#8162 Moved sairedis record file rotation logic out of flush() to fix issue. Why I did it Sairedis record file was not releasing the file handle on rotation. This is because the file handle release was inside the flush() which was only being called if a select timeout was triggered. Moved the logic to its own function which is called in the start() loop. How I verified it Ran a script to fill log and verified that rotation was happening correctly. Signed-off-by: Bryan Crossland bryan.crossland@target.com --- orchagent/main.cpp | 1 - orchagent/orchdaemon.cpp | 34 +++++++++++++++++++++++----------- orchagent/orchdaemon.h | 3 +++ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/orchagent/main.cpp b/orchagent/main.cpp index a4f30a9f2d..119d8fb4b7 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -55,7 +55,6 @@ int gBatchSize = DEFAULT_BATCH_SIZE; bool gSairedisRecord = true; bool gSwssRecord = true; bool gLogRotate = false; -bool gSaiRedisLogRotate = false; bool gSyncMode = false; sai_redis_communication_mode_t gRedisCommunicationMode = SAI_REDIS_COMMUNICATION_MODE_REDIS_ASYNC; string gAsicInstance; diff --git a/orchagent/orchdaemon.cpp b/orchagent/orchdaemon.cpp index dad916f1a9..3ab58e4fa6 100644 --- a/orchagent/orchdaemon.cpp +++ b/orchagent/orchdaemon.cpp @@ -43,6 +43,7 @@ BfdOrch *gBfdOrch; QosOrch *gQosOrch; bool gIsNatSupported = false; +bool gSaiRedisLogRotate = false; #define DEFAULT_MAX_BULK_SIZE 1000 size_t gMaxBulkSize = DEFAULT_MAX_BULK_SIZE; @@ -529,24 +530,24 @@ 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); +/* Release the file handle so the log can be rotated */ +void OrchDaemon::logRotate() { + SWSS_LOG_ENTER(); + sai_attribute_t attr; + attr.id = SAI_REDIS_SWITCH_ATTR_PERFORM_LOG_ROTATE; + attr.value.booldata = true; + sai_status_t status = sai_switch_api->set_switch_attribute(gSwitchId, &attr); + if (status != SAI_STATUS_SUCCESS) { + SWSS_LOG_ERROR("Failed to release the file handle on sairedis log %d", status); } } void OrchDaemon::start() { SWSS_LOG_ENTER(); + gSaiRedisLogRotate = false; for (Orch *o : m_orchList) { @@ -590,6 +591,17 @@ void OrchDaemon::start() continue; } + // check if logroate is requested + if (gSaiRedisLogRotate) + { + SWSS_LOG_NOTICE("performing log rotate"); + + gSaiRedisLogRotate = false; + + logRotate(); + continue; + } + auto *c = (Executor *)s; c->execute(); diff --git a/orchagent/orchdaemon.h b/orchagent/orchdaemon.h index 725c94be85..d6dcb66b37 100644 --- a/orchagent/orchdaemon.h +++ b/orchagent/orchdaemon.h @@ -33,8 +33,10 @@ #include "natorch.h" #include "muxorch.h" #include "bfdorch.h" +#include using namespace swss; +extern bool gSaiRedisLogRotate; class OrchDaemon { @@ -49,6 +51,7 @@ class OrchDaemon bool warmRestoreValidation(); bool warmRestartCheck(); + void logRotate(); private: DBConnector *m_applDb; DBConnector *m_configDb;