Skip to content

Commit

Permalink
What I did
Browse files Browse the repository at this point in the history
Fix sonic-net/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
  • Loading branch information
bacrossland committed Oct 4, 2022
1 parent 499b7a7 commit 569c8b1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
1 change: 0 additions & 1 deletion orchagent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 23 additions & 11 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();

Expand Down
3 changes: 3 additions & 0 deletions orchagent/orchdaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
#include "natorch.h"
#include "muxorch.h"
#include "bfdorch.h"
#include <sairedis.h>

using namespace swss;
extern bool gSaiRedisLogRotate;

class OrchDaemon
{
Expand All @@ -49,6 +51,7 @@ class OrchDaemon
bool warmRestoreValidation();

bool warmRestartCheck();
void logRotate();
private:
DBConnector *m_applDb;
DBConnector *m_configDb;
Expand Down

0 comments on commit 569c8b1

Please sign in to comment.