Skip to content

Commit d1a6f83

Browse files
minor: name change for a typedef
1 parent 9ba11ed commit d1a6f83

8 files changed

+64
-47
lines changed

common/events.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ EventSubscriber::~EventSubscriber()
197197
int rc = 0;
198198

199199
if (m_event_service.is_active()) {
200-
events_data_lst_t events;
200+
event_serialized_lst_t events;
201201

202202
rc = m_event_service.cache_init();
203203
RET_ON_ERR(rc == 0, "Failed to init the cache");
@@ -212,7 +212,8 @@ EventSubscriber::~EventSubscriber()
212212
*/
213213
chrono::steady_clock::time_point start = chrono::steady_clock::now();
214214
while(true) {
215-
string source, evt_str;
215+
string source;
216+
event_serialized_t evt_str;
216217
internal_event_t evt_data;
217218

218219
rc = zmq_message_read(m_socket, ZMQ_DONTWAIT, source, evt_data);
@@ -335,7 +336,7 @@ EventSubscriber::event_receive(string &key, event_params_t &params, int &missed_
335336

336337
if (!m_from_cache.empty()) {
337338

338-
events_data_lst_t::iterator it = m_from_cache.begin();
339+
event_serialized_lst_t::iterator it = m_from_cache.begin();
339340
rc = deserialize(*it, event_data);
340341
m_from_cache.erase(it);
341342
RET_ON_ERR(rc == 0, "Failed to deserialize message from cache");

common/events_common.h

+30-5
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,11 @@ typedef string runtime_id_t;
261261
* { EVENT_SEQUENCE, "" } };
262262
*/
263263

264+
typedef vector<internal_event_t> internal_events_lst_t;
265+
264266
/* Cache maintains the part 2 of an event as serialized string. */
265-
typedef string events_data_type_t;
266-
typedef vector<events_data_type_t> events_data_lst_t;
267+
typedef string event_serialized_t; // events_data_type_t;
268+
typedef vector<event_serialized_t> event_serialized_lst_t; // events_data_lst_t;
267269

268270

269271
sequence_t str_to_seq(const string s);
@@ -278,9 +280,11 @@ zmq_read_part(void *sock, int flag, int &more, DT &data)
278280
more = 0;
279281
zmq_msg_init(&msg);
280282
int rc = zmq_msg_recv(&msg, sock, flag);
281-
recv_last_err = zerrno;
282-
283-
if (rc != -1) {
283+
if (rc == -1) {
284+
recv_last_err = zerrno;
285+
}
286+
else {
287+
recv_last_err = 0;
284288
size_t more_size = sizeof (more);
285289

286290
rc = zmsg_to_map(msg, data);
@@ -350,4 +354,25 @@ zmq_message_read(void *sock, int flag, P1 &pt1, P2 &pt2)
350354
return rc;
351355
}
352356

357+
/*
358+
* Cache drain timeout.
359+
*
360+
* When subscriber's de-init is called, it calls start cache service.
361+
* When subscriber init is called, it calls cache stop service.
362+
*
363+
* In either scenario, an entity stops reading and let other start.
364+
* The entity that stops may have to read little longer to drain any
365+
* events in local ZMQ cache.
366+
*
367+
* This timeout helps with that.
368+
*
369+
* In case of subscriber de-init, the events read during this period
370+
* is given to cache as start-up or initial stock.
371+
* In case of init where cache service reads for this period, gives
372+
* those as part of cache read and subscriber service will be diligent
373+
* about reading the same event from the channel, hence duplicate
374+
* for next one second.
375+
*/
376+
#define CACHE_DRAIN_IN_MILLISECS 1000
377+
353378
#endif /* !_EVENTS_COMMON_H */

common/events_pi.h

+1-14
Original file line numberDiff line numberDiff line change
@@ -122,23 +122,10 @@ class EventSubscriber : public events_base
122122
* List of cached events.
123123
* Only part 2 / internal_event_t is cached as serialized string.
124124
*/
125-
events_data_lst_t m_from_cache;
125+
event_serialized_lst_t m_from_cache;
126126

127127
};
128128

129-
/*
130-
* Cache drain timeout.
131-
*
132-
* When de-init is called, it calls stop cache service.
133-
* But before this point, there could be events received in zmq's
134-
* local cache pending read and those that arrived since last read.
135-
* These events will not be seen by cache service.
136-
* So read those off and give it to cache service as starting stock.
137-
* As we don't have a clue on count in zmq's cache, read in non-block
138-
* mode for a period.
139-
*/
140-
#define CACHE_DRAIN_IN_MILLISECS 1000
141-
142129
/*
143130
* The uuid_unparse() function converts the supplied UUID uu from
144131
* the binary representation into a 36-byte string (plus trailing

common/events_service.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ event_service::init_server(void *zmq_ctx, int block_ms)
7373
int
7474
event_service::echo_send(const string s)
7575
{
76-
events_data_lst_t l = { s };
76+
event_serialized_lst_t l = { s };
7777

7878
return channel_write(EVENT_ECHO, l);
7979

@@ -83,7 +83,7 @@ event_service::echo_send(const string s)
8383
int
8484
event_service::echo_receive(string &outs)
8585
{
86-
events_data_lst_t l;
86+
event_serialized_lst_t l;
8787
int code;
8888

8989
int rc = channel_read(code, l);
@@ -112,7 +112,7 @@ event_service::cache_init()
112112

113113

114114
int
115-
event_service::cache_start(const events_data_lst_t &lst)
115+
event_service::cache_start(const event_serialized_lst_t &lst)
116116
{
117117
int rc;
118118

@@ -136,7 +136,7 @@ event_service::cache_stop()
136136

137137

138138
int
139-
event_service::cache_read(events_data_lst_t &lst)
139+
event_service::cache_read(event_serialized_lst_t &lst)
140140
{
141141
int rc;
142142

@@ -148,25 +148,25 @@ event_service::cache_read(events_data_lst_t &lst)
148148

149149

150150
int
151-
event_service::channel_read(int &code, events_data_lst_t &data)
151+
event_service::channel_read(int &code, event_serialized_lst_t &data)
152152
{
153-
events_data_lst_t().swap(data);
153+
event_serialized_lst_t().swap(data);
154154
return zmq_message_read(m_socket, 0, code, data);
155155
}
156156

157157

158158
int
159-
event_service::channel_write(int code, const events_data_lst_t &data)
159+
event_service::channel_write(int code, const event_serialized_lst_t &data)
160160
{
161161
return zmq_message_send(m_socket, code, data);
162162
}
163163

164164

165165
int
166-
event_service::send_recv(int code, const events_data_lst_t *lst_in,
167-
events_data_lst_t *lst_out)
166+
event_service::send_recv(int code, const event_serialized_lst_t *lst_in,
167+
event_serialized_lst_t *lst_out)
168168
{
169-
events_data_lst_t l;
169+
event_serialized_lst_t l;
170170
int resp;
171171

172172
if(lst_in == NULL) {

common/events_service.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* In case of data, it comes in seccond part.
2626
*
2727
* Type of data is one or multiple strings, which is sent as serialized vector
28-
* of strings. events_data_lst_t
28+
* of strings. event_serialized_lst_t
2929
*
3030
* In case of echo, part2 is the vector of single string as provided in the request.
3131
*
@@ -133,7 +133,7 @@ class event_service {
133133
* 1 - Already running
134134
* -1 - On failure.
135135
*/
136-
int cache_start(const events_data_lst_t &lst);
136+
int cache_start(const event_serialized_lst_t &lst);
137137

138138
/*
139139
* Called to stop caching events
@@ -179,7 +179,7 @@ class event_service {
179179
* 0 - On success.
180180
* -1 - On failure.
181181
*/
182-
int cache_read(events_data_lst_t &lst);
182+
int cache_read(event_serialized_lst_t &lst);
183183

184184
/*
185185
* Echo send service.
@@ -231,7 +231,7 @@ class event_service {
231231
* 0 - On success
232232
* -1 - On failure
233233
*/
234-
int channel_read(int &code, events_data_lst_t &data);
234+
int channel_read(int &code, event_serialized_lst_t &data);
235235

236236
/*
237237
* The under lying write for req/resp from client/server
@@ -247,12 +247,12 @@ class event_service {
247247
* 0 - On success
248248
* -1 - On failure
249249
*/
250-
int channel_write(int code, const events_data_lst_t &data);
250+
int channel_write(int code, const event_serialized_lst_t &data);
251251

252252
/*
253253
* send and receive helper.
254254
* Writes given code & data and reads back data into
255-
* provided events_data_lst_t arg and response read is
255+
* provided event_serialized_lst_t arg and response read is
256256
* returned.
257257
*
258258
* input:
@@ -265,8 +265,8 @@ class event_service {
265265
* return:
266266
* Any failure or response code from server.
267267
*/
268-
int send_recv(int code, const events_data_lst_t *lst_in = NULL,
269-
events_data_lst_t *lst_out = NULL);
268+
int send_recv(int code, const event_serialized_lst_t *lst_in = NULL,
269+
event_serialized_lst_t *lst_out = NULL);
270270

271271
/*
272272
* de-init/close service

tests/events_common_ut.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ TEST(events_common, send_recv)
9090
/* Direct log messages to stdout */
9191
string dummy, op("STDOUT");
9292
swss::Logger::swssOutputNotify(dummy, op);
93+
swss::Logger::setMinPrio(swss::Logger::SWSS_DEBUG);
9394
}
9495
#endif
9596

tests/events_service_ut.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ static bool do_terminate = false;
1414
static void *zmq_ctx = NULL;
1515
static event_service service_cl, service_svr;
1616
static int server_rd_code, server_ret;
17-
static events_data_lst_t server_rd_lst, server_wr_lst;
17+
static event_serialized_lst_t server_rd_lst, server_wr_lst;
1818

1919
/* Mimic the eventd service that handles service requests via dedicated thread */
2020
void serve_commands()
2121
{
2222
int code;
23-
events_data_lst_t lst;
23+
event_serialized_lst_t lst;
2424
EXPECT_EQ(0, service_svr.init_server(zmq_ctx, 1000));
2525
while(!do_terminate) {
2626
if (0 != service_svr.channel_read(code, lst)) {
@@ -65,13 +65,14 @@ void serve_commands()
6565

6666
TEST(events_common, cache_cmds)
6767
{
68-
events_data_lst_t lst_start, lst;
68+
event_serialized_lst_t lst_start, lst;
6969

7070
#if 0
7171
{
7272
/* Direct log messages to stdout */
7373
string dummy, op("STDOUT");
7474
swss::Logger::swssOutputNotify(dummy, op);
75+
swss::Logger::setMinPrio(swss::Logger::SWSS_DEBUG);
7576
}
7677
#endif
7778

@@ -93,7 +94,7 @@ TEST(events_common, cache_cmds)
9394
* Bunch of serialized internal_event_t as strings
9495
* Sending random for test purpose
9596
*/
96-
lst_start = events_data_lst_t(
97+
lst_start = event_serialized_lst_t(
9798
{ "hello", "world", "ok" });
9899
EXPECT_EQ(0, service_cl.cache_start(lst_start));
99100
EXPECT_EQ(EVENT_CACHE_START, server_rd_code);

tests/events_ut.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int last_svc_code = -1;
1818

1919
void events_validate_ts(const string s);
2020

21-
events_data_lst_t lst_cache;
21+
event_serialized_lst_t lst_cache;
2222

2323
#define ARRAY_SIZE(d) (sizeof(d) / sizeof((d)[0]))
2424

@@ -34,7 +34,7 @@ void pub_serve_commands()
3434
EXPECT_EQ(0, service_svr.init_server(zmq_ctx, 1000));
3535
while(!terminate_svc) {
3636
int code, resp;
37-
events_data_lst_t lst;
37+
event_serialized_lst_t lst;
3838

3939
if (0 != service_svr.channel_read(code, lst)) {
4040
/* check client service status, before blocking on read */
@@ -74,7 +74,7 @@ void pub_serve_commands()
7474
EXPECT_FALSE(service_svr.is_active());
7575
terminate_svc = false;
7676
last_svc_code = -1;
77-
events_data_lst_t().swap(lst_cache);
77+
event_serialized_lst_t().swap(lst_cache);
7878
}
7979

8080

@@ -167,6 +167,7 @@ TEST(events, publish)
167167
/* Direct log messages to stdout */
168168
string dummy, op("STDOUT");
169169
swss::Logger::swssOutputNotify(dummy, op);
170+
swss::Logger::setMinPrio(swss::Logger::SWSS_DEBUG);
170171
}
171172

172173
string evt_source0("sonic-events-bgp");
@@ -476,6 +477,7 @@ TEST(events, subscribe)
476477
/* Direct log messages to stdout */
477478
string dummy, op("STDOUT");
478479
swss::Logger::swssOutputNotify(dummy, op);
480+
swss::Logger::setMinPrio(swss::Logger::SWSS_DEBUG);
479481
}
480482
#endif
481483

0 commit comments

Comments
 (0)