Skip to content

Commit 24d29f1

Browse files
authored
[orchdaemon]: Fixed sairedis record file rotation (#2299)
* [orchdaemon]: Fixed sairedis record file rotation * What I did Fix #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 [email protected]
1 parent b8ee07d commit 24d29f1

File tree

8 files changed

+84
-17
lines changed

8 files changed

+84
-17
lines changed

orchagent/main.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ bool gSairedisRecord = true;
5858
bool gSwssRecord = true;
5959
bool gResponsePublisherRecord = false;
6060
bool gLogRotate = false;
61-
bool gSaiRedisLogRotate = false;
6261
bool gResponsePublisherLogRotate = false;
6362
bool gSyncMode = false;
6463
sai_redis_communication_mode_t gRedisCommunicationMode = SAI_REDIS_COMMUNICATION_MODE_REDIS_ASYNC;

orchagent/orchdaemon.cpp

+24-10
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ FlowCounterRouteOrch *gFlowCounterRouteOrch;
5757
DebugCounterOrch *gDebugCounterOrch;
5858

5959
bool gIsNatSupported = false;
60+
bool gSaiRedisLogRotate = false;
6061
event_handle_t g_events_handle;
6162

6263
#define DEFAULT_MAX_BULK_SIZE 1000
@@ -676,24 +677,26 @@ void OrchDaemon::flush()
676677
SWSS_LOG_ERROR("Failed to flush redis pipeline %d", status);
677678
abort();
678679
}
680+
}
679681

680-
// check if logroate is requested
681-
if (gSaiRedisLogRotate)
682+
/* Release the file handle so the log can be rotated */
683+
void OrchDaemon::logRotate() {
684+
SWSS_LOG_ENTER();
685+
sai_attribute_t attr;
686+
attr.id = SAI_REDIS_SWITCH_ATTR_PERFORM_LOG_ROTATE;
687+
attr.value.booldata = true;
688+
sai_status_t status = sai_switch_api->set_switch_attribute(gSwitchId, &attr);
689+
if (status != SAI_STATUS_SUCCESS)
682690
{
683-
SWSS_LOG_NOTICE("performing log rotate");
684-
685-
gSaiRedisLogRotate = false;
686-
687-
attr.id = SAI_REDIS_SWITCH_ATTR_PERFORM_LOG_ROTATE;
688-
attr.value.booldata = true;
689-
690-
sai_switch_api->set_switch_attribute(gSwitchId, &attr);
691+
SWSS_LOG_ERROR("Failed to release the file handle on sairedis log %d", status);
691692
}
692693
}
693694

695+
694696
void OrchDaemon::start()
695697
{
696698
SWSS_LOG_ENTER();
699+
gSaiRedisLogRotate = false;
697700

698701
for (Orch *o : m_orchList)
699702
{
@@ -737,6 +740,17 @@ void OrchDaemon::start()
737740
continue;
738741
}
739742

743+
// check if logroate is requested
744+
if (gSaiRedisLogRotate)
745+
{
746+
SWSS_LOG_NOTICE("performing log rotate");
747+
748+
gSaiRedisLogRotate = false;
749+
750+
logRotate();
751+
continue;
752+
}
753+
740754
auto *c = (Executor *)s;
741755
c->execute();
742756

orchagent/orchdaemon.h

+3
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@
4545
#include "bfdorch.h"
4646
#include "srv6orch.h"
4747
#include "nvgreorch.h"
48+
#include <sairedis.h>
4849

4950
using namespace swss;
51+
extern bool gSaiRedisLogRotate;
5052

5153
class OrchDaemon
5254
{
@@ -67,6 +69,7 @@ class OrchDaemon
6769
{
6870
m_fabricEnabled = enabled;
6971
}
72+
void logRotate();
7073
private:
7174
DBConnector *m_applDb;
7275
DBConnector *m_configDb;

orchagent/p4orch/tests/test_main.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ size_t gMaxBulkSize = DEFAULT_MAX_BULK_SIZE;
4343
bool gSairedisRecord = true;
4444
bool gSwssRecord = true;
4545
bool gLogRotate = false;
46-
bool gSaiRedisLogRotate = false;
4746
bool gResponsePublisherRecord = false;
4847
bool gResponsePublisherLogRotate = false;
4948
bool gSyncMode = false;

tests/mock_tests/Makefile.am

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ LDADD_GTEST = -L/usr/src/gtest
2121

2222
## Orchagent Unit Tests
2323

24-
tests_INCLUDES = -I $(FLEX_CTR_DIR) -I $(DEBUG_CTR_DIR) -I $(top_srcdir)/lib -I$(top_srcdir)/cfgmgr -I$(top_srcdir)/orchagent
24+
tests_INCLUDES = -I $(FLEX_CTR_DIR) -I $(DEBUG_CTR_DIR) -I $(top_srcdir)/lib -I$(top_srcdir)/cfgmgr -I$(top_srcdir)/orchagent -I$(P4_ORCH_DIR)/tests
2525

2626
tests_SOURCES = aclorch_ut.cpp \
2727
portsorch_ut.cpp \
@@ -47,6 +47,7 @@ tests_SOURCES = aclorch_ut.cpp \
4747
fake_response_publisher.cpp \
4848
swssnet_ut.cpp \
4949
flowcounterrouteorch_ut.cpp \
50+
orchdaemon_ut.cpp \
5051
$(top_srcdir)/lib/gearboxutils.cpp \
5152
$(top_srcdir)/lib/subintf.cpp \
5253
$(top_srcdir)/orchagent/orchdaemon.cpp \
@@ -120,12 +121,13 @@ tests_SOURCES += $(P4_ORCH_DIR)/p4orch.cpp \
120121
$(P4_ORCH_DIR)/wcmp_manager.cpp \
121122
$(P4_ORCH_DIR)/mirror_session_manager.cpp \
122123
$(P4_ORCH_DIR)/gre_tunnel_manager.cpp \
123-
$(P4_ORCH_DIR)/l3_admit_manager.cpp
124+
$(P4_ORCH_DIR)/l3_admit_manager.cpp \
125+
$(P4_ORCH_DIR)/tests/mock_sai_switch.cpp
124126

125127
tests_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI)
126128
tests_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI) $(tests_INCLUDES)
127129
tests_LDADD = $(LDADD_GTEST) $(LDADD_SAI) -lnl-genl-3 -lhiredis -lhiredis -lpthread \
128-
-lswsscommon -lswsscommon -lgtest -lgtest_main -lzmq -lnl-3 -lnl-route-3
130+
-lswsscommon -lswsscommon -lgtest -lgtest_main -lzmq -lnl-3 -lnl-route-3 -lgmock -lgmock_main
129131

130132
## portsyncd unit tests
131133

tests/mock_tests/mock_orchagent_main.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ int gBatchSize = DEFAULT_BATCH_SIZE;
1818
bool gSairedisRecord = true;
1919
bool gSwssRecord = true;
2020
bool gLogRotate = false;
21-
bool gSaiRedisLogRotate = false;
2221
ofstream gRecordOfs;
2322
string gRecordFile;
2423
string gMySwitchType = "switch";

tests/mock_tests/mock_orchagent_main.h

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ extern int gBatchSize;
3030
extern bool gSwssRecord;
3131
extern bool gSairedisRecord;
3232
extern bool gLogRotate;
33-
extern bool gSaiRedisLogRotate;
3433
extern ofstream gRecordOfs;
3534
extern string gRecordFile;
3635

tests/mock_tests/orchdaemon_ut.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "orchdaemon.h"
2+
#include "dbconnector.h"
3+
#include <gtest/gtest.h>
4+
#include <gmock/gmock.h>
5+
#include "mock_sai_switch.h"
6+
7+
extern sai_switch_api_t* sai_switch_api;
8+
sai_switch_api_t test_sai_switch;
9+
10+
namespace orchdaemon_test
11+
{
12+
13+
using ::testing::_;
14+
using ::testing::Return;
15+
using ::testing::StrictMock;
16+
17+
DBConnector appl_db("APPL_DB", 0);
18+
DBConnector state_db("STATE_DB", 0);
19+
DBConnector config_db("CONFIG_DB", 0);
20+
DBConnector counters_db("COUNTERS_DB", 0);
21+
22+
class OrchDaemonTest : public ::testing::Test
23+
{
24+
public:
25+
StrictMock<MockSaiSwitch> mock_sai_switch_;
26+
27+
OrchDaemon* orchd;
28+
29+
OrchDaemonTest()
30+
{
31+
mock_sai_switch = &mock_sai_switch_;
32+
sai_switch_api = &test_sai_switch;
33+
sai_switch_api->get_switch_attribute = &mock_get_switch_attribute;
34+
sai_switch_api->set_switch_attribute = &mock_set_switch_attribute;
35+
36+
orchd = new OrchDaemon(&appl_db, &config_db, &state_db, &counters_db);
37+
38+
};
39+
40+
~OrchDaemonTest()
41+
{
42+
43+
};
44+
};
45+
46+
TEST_F(OrchDaemonTest, logRotate)
47+
{
48+
EXPECT_CALL(mock_sai_switch_, set_switch_attribute( _, _)).WillOnce(Return(SAI_STATUS_SUCCESS));
49+
50+
orchd->logRotate();
51+
}
52+
}

0 commit comments

Comments
 (0)