Skip to content

Commit

Permalink
[orchdaemon]: Fixed sairedis record file rotation
Browse files Browse the repository at this point in the history
Signed-off-by: Bryan Crossland bryan.crossland@target.com
  • Loading branch information
bacrossland committed May 27, 2022
1 parent 4d6fa42 commit 01cb5df
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
1 change: 0 additions & 1 deletion orchagent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ bool gSairedisRecord = true;
bool gSwssRecord = true;
bool gResponsePublisherRecord = false;
bool gLogRotate = false;
bool gSaiRedisLogRotate = false;
bool gResponsePublisherLogRotate = false;
bool gSyncMode = false;
sai_redis_communication_mode_t gRedisCommunicationMode = SAI_REDIS_COMMUNICATION_MODE_REDIS_ASYNC;
Expand Down
35 changes: 22 additions & 13 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ 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();
/*
Expand Down Expand Up @@ -57,6 +56,7 @@ FlowCounterRouteOrch *gFlowCounterRouteOrch;
DebugCounterOrch *gDebugCounterOrch;

bool gIsNatSupported = false;
bool gSaiRedisLogRotate = false;

#define DEFAULT_MAX_BULK_SIZE 1000
size_t gMaxBulkSize = DEFAULT_MAX_BULK_SIZE;
Expand Down Expand Up @@ -658,24 +658,22 @@ void OrchDaemon::flush()
SWSS_LOG_ERROR("Failed to flush redis pipeline %d", status);
abort();
}
}

// 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_switch_api->set_switch_attribute(gSwitchId, &attr);
}


void OrchDaemon::start()
{
SWSS_LOG_ENTER();
gSaiRedisLogRotate = false;

for (Orch *o : m_orchList)
{
Expand Down Expand Up @@ -719,6 +717,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
2 changes: 2 additions & 0 deletions orchagent/orchdaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "nvgreorch.h"

using namespace swss;
extern bool gSaiRedisLogRotate;

class OrchDaemon
{
Expand Down Expand Up @@ -79,6 +80,7 @@ class OrchDaemon
Select *m_select;

void flush();
void logRotate();
};

class FabricOrchDaemon : public OrchDaemon
Expand Down
1 change: 0 additions & 1 deletion orchagent/p4orch/tests/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ int gBatchSize = DEFAULT_BATCH_SIZE;
bool gSairedisRecord = true;
bool gSwssRecord = true;
bool gLogRotate = false;
bool gSaiRedisLogRotate = false;
bool gResponsePublisherRecord = false;
bool gResponsePublisherLogRotate = false;
bool gSyncMode = false;
Expand Down
1 change: 0 additions & 1 deletion tests/mock_tests/mock_orchagent_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ int gBatchSize = DEFAULT_BATCH_SIZE;
bool gSairedisRecord = true;
bool gSwssRecord = true;
bool gLogRotate = false;
bool gSaiRedisLogRotate = false;
ofstream gRecordOfs;
string gRecordFile;
string gMySwitchType = "switch";
Expand Down
1 change: 0 additions & 1 deletion tests/mock_tests/mock_orchagent_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ extern int gBatchSize;
extern bool gSwssRecord;
extern bool gSairedisRecord;
extern bool gLogRotate;
extern bool gSaiRedisLogRotate;
extern ofstream gRecordOfs;
extern string gRecordFile;

Expand Down

0 comments on commit 01cb5df

Please sign in to comment.