Skip to content

Commit c4db46e

Browse files
Update upon self review - mostly on comments
1 parent 94153f5 commit c4db46e

File tree

3 files changed

+31
-37
lines changed

3 files changed

+31
-37
lines changed

common/events.h

+11-23
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
*
77
* APIs are for publishing & receiving events with source, tag and params along with timestamp.
88
* Used by event publishers and those interested in receiving published events.
9-
* Publishers are multiple sources, as processes running in hosts & containers.
9+
* Publishers are multiple run from different contexts, as processes running in hosts & containers.
1010
* Receiver are often few. Telmetry container runs a receiver.
1111
*
1212
*/
1313

1414

15+
/* Handle for a publisher / subscriber instance */
1516
typedef void* event_handle_t;
1617

1718
/*
@@ -20,8 +21,6 @@ typedef void* event_handle_t;
2021
* A single publisher instance is maintained for a source.
2122
* Any duplicate init call for a source will return the same instance.
2223
*
23-
* Choosing cache will help read cached data, during downtime, if any.
24-
*
2524
* NOTE:
2625
* The initialization occurs asynchronously.
2726
* Any event published before init is complete, is blocked until the init
@@ -47,7 +46,7 @@ event_handle_t events_init_publisher(const std::string event_source);
4746
* Handle returned from events_init_publisher
4847
*
4948
* Output:
50-
* None
49+
* Handle is nullified.
5150
*/
5251
void events_deinit_publisher(event_handle_t &handle);
5352

@@ -101,8 +100,6 @@ int event_publish(event_handle_t handle, const std::string event_tag,
101100

102101

103102

104-
typedef std::vector<std::string> event_subscribe_sources_t;
105-
106103
/*
107104
* Initialize subscriber.
108105
* Init subscriber, optionally to filter by event-source.
@@ -112,6 +109,7 @@ typedef std::vector<std::string> event_subscribe_sources_t;
112109
* When set to true, it will make use of the cache service transparently.
113110
* The cache service caches events during session down time. The deinit
114111
* start the caching and init call stops the caching.
112+
* default: false
115113
*
116114
* recv_timeout
117115
* Read blocks by default until an event is available for read.
@@ -124,11 +122,14 @@ typedef std::vector<std::string> event_subscribe_sources_t;
124122
* List of subscription sources of interest.
125123
* The source value is the corresponding YANG module name.
126124
* e.g. "sonic-events-bgp " is the source modulr name for bgp.
125+
* default: All sources, if none provided.
127126
*
128127
* Return:
129128
* Non NULL handle on success
130129
* NULL on failure
131130
*/
131+
typedef std::vector<std::string> event_subscribe_sources_t;
132+
132133
event_handle_t events_init_subscriber(bool use_cache=false,
133134
int recv_timeout = -1,
134135
const event_subscribe_sources_t *sources=NULL);
@@ -140,17 +141,18 @@ event_handle_t events_init_subscriber(bool use_cache=false,
140141
* Handle returned from events_init_subscriber
141142
*
142143
* Output:
143-
* None
144+
* Handle is nullified.
144145
*/
145146
void events_deinit_subscriber(event_handle_t &handle);
146147

148+
147149
/*
148150
* Receive an event.
149-
* A blocking call.
151+
* A blocking call unless the subscriber is created with a timeout.
150152
*
151153
* This API maintains an expected sequence number and use the received
152154
* sequence in event to compute missed events count. The missed count
153-
* set of events missed from this sender.
155+
* provides the count of events missed from this sender.
154156
*
155157
* Received event:
156158
* It is a form of JSON struct, with a single key and
@@ -198,18 +200,4 @@ int event_receive(event_handle_t handle, std::string &key,
198200
*/
199201
int event_last_error();
200202

201-
202-
/*
203-
* Cache drain timeout.
204-
*
205-
* When de-init is called, it calls stop cache service.
206-
* But before this point, there could be events received in zmq's
207-
* local cache pending read and those that arrived since last read.
208-
* These events will not be seen by cache service.
209-
* So read those off and give it to cache service as starting stock.
210-
* As we don't have a clue on count in zmq's cache, read in non-block
211-
* mode for a period.
212-
*/
213-
#define CACHE_DRAIN_IN_MILLISECS 1000
214-
215203
#endif /* !_EVENTS_H */

common/events_common.h

+7-14
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@ extern int recv_last_err;
2929

3030
/*
3131
* Max count of possible concurrent event publishers
32-
* A rough estimate only, more as a guideline than strict.
33-
SWSS_LOG_ERROR(fmt.c_str(), e, zerrno __VA_OPT__(,) __VA_ARGS__); \
34-
* So this does not limit any usage
32+
* We maintain a cache of last seen sequence number per publisher.
33+
* This provides a MAX ceiling for cache.
34+
* Any more publishers over this count should indicate a serious bug.
3535
*/
3636
#define MAX_PUBLISHERS_COUNT 1000
3737

3838
extern int running_ut;
3939

4040

41-
/* TODO: Combine two SWSS_LOG_ERROR into one */
4241
#define RET_ON_ERR(res, msg, ...)\
4342
if (!(res)) {\
4443
int _e = errno; \
@@ -50,9 +49,6 @@ extern int running_ut;
5049
printf("last:errno=%d zerr=%d\n", _e, zerrno); }\
5150
goto out; }
5251

53-
#define ERR_CHECK(res, ...) {\
54-
if (!(res)) \
55-
SWSS_LOG_ERROR(__VA_ARGS__); }
5652

5753
/* helper API to print variable type */
5854
/*
@@ -67,7 +63,6 @@ extern int running_ut;
6763
* std::cout << type_name<decltype(t)>() << '\n';
6864
* std::cout << type_name<decltype(tt_t)>() << '\n';
6965
*/
70-
7166
template <typename T> std::string type_name();
7267

7368
template <class T>
@@ -102,6 +97,7 @@ get_typename(T &val)
10297
}
10398

10499

100+
/* map to human readable str; Useful for error reporting. */
105101
template <typename Map>
106102
string
107103
map_to_str(const Map &m)
@@ -170,8 +166,8 @@ const string get_timestamp();
170166
* Way to serialize map or vector
171167
* boost::archive::text_oarchive could be used to archive any struct/class
172168
* but that class needs some additional support, that declares
173-
* boost::serialization::access as private friend and couple more tweaks
174-
* std::map inherently supports serialization
169+
* boost::serialization::access as private friend and couple more tweaks.
170+
* The std::map & vector inherently supports serialization.
175171
*/
176172
template <typename Map>
177173
int
@@ -249,9 +245,6 @@ zmsg_to_map(zmq_msg_t &msg, Map& data)
249245
* filter by source.
250246
*
251247
* Second part contains serialized form of map as defined in internal_event_t.
252-
* The map is serialized and sent as string events_data_type_t.
253-
* Caching that handles of set of events, handleas ordered events
254-
* as declared in events_data_lst_t.
255248
*/
256249
/*
257250
* This is data going over wire and using cache. So be conservative
@@ -274,7 +267,7 @@ typedef string runtime_id_t;
274267
* { EVENT_SEQUENCE, "" } };
275268
*/
276269

277-
/* ZMQ message part 2 contains serialized version of internal_event_t */
270+
/* Cache maintains the part 2 of an event as serialized string. */
278271
typedef string events_data_type_t;
279272
typedef vector<events_data_type_t> events_data_lst_t;
280273

common/events_pi.h

+13
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,17 @@ class EventSubscriber : public events_base
130130

131131
};
132132

133+
/*
134+
* Cache drain timeout.
135+
*
136+
* When de-init is called, it calls stop cache service.
137+
* But before this point, there could be events received in zmq's
138+
* local cache pending read and those that arrived since last read.
139+
* These events will not be seen by cache service.
140+
* So read those off and give it to cache service as starting stock.
141+
* As we don't have a clue on count in zmq's cache, read in non-block
142+
* mode for a period.
143+
*/
144+
#define CACHE_DRAIN_IN_MILLISECS 1000
145+
133146
#endif /* !_EVENTS_SERVICE_H */

0 commit comments

Comments
 (0)