Skip to content

Commit

Permalink
mod_sonic wait for SYSTEM_READY with timeout (default=180S)
Browse files Browse the repository at this point in the history
  • Loading branch information
sflow committed Jun 3, 2023
1 parent efb344a commit b9b61bc
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion hsflowd.spec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Summary: host sFlow daemon
Name: hsflowd
Version: 2.0.51
Release: 25
Release: 26
License: http://sflow.net/license.html
Group: Applications/Internet
URL: http://sflow.net
Expand Down
4 changes: 4 additions & 0 deletions src/Linux/hsflowconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,7 @@ extern "C" {
if((tok = expectToken(sp, tok, HSPTOKEN_STARTOBJ)) == NULL) return NO;
sp->sonic.sonic = YES;
sp->sonic.unixsock = YES;
sp->sonic.waitReady = HSP_SONIC_DEFAULT_WAITREADY_SECS;
level[++depth] = HSPOBJ_SONIC;
break;
case HSPTOKEN_DBUS:
Expand Down Expand Up @@ -1931,6 +1932,9 @@ extern "C" {
case HSPTOKEN_DBCONFIG:
if((tok = expectString(sp, tok, &sp->sonic.dbconfig, "path")) == NULL) return NO;
break;
case HSPTOKEN_WAITREADY:
if((tok = expectInteger32(sp, tok, &sp->sonic.waitReady, 0, 0xFFFFFFFF)) == NULL) return NO;
break;
default:
unexpectedToken(sp, tok, level[depth]);
return NO;
Expand Down
1 change: 1 addition & 0 deletions src/Linux/hsflowd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2069,6 +2069,7 @@ extern "C" {
sp->sonic.unixsock = YES;
sp->sonic.setIfAlias = YES;
sp->sonic.setIfName = YES;
sp->sonic.waitReady = HSP_SONIC_DEFAULT_WAITREADY_SECS;
sp->psample.psample = YES;
sp->psample.ingress = YES;
sp->psample.egress = YES;
Expand Down
2 changes: 2 additions & 0 deletions src/Linux/hsflowd.h
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,8 @@ extern "C" {
bool setIfAlias;
bool setIfName;
char *dbconfig;
uint32_t waitReady; // seconds
#define HSP_SONIC_DEFAULT_WAITREADY_SECS 180
} sonic;
struct {
bool nvml;
Expand Down
1 change: 1 addition & 0 deletions src/Linux/hsflowtokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@ HSPTOKEN_DATA( HSPTOKEN_UNIXSOCK, "unixsock", HSPTOKENTYPE_ATTRIB, NULL)
HSPTOKEN_DATA( HSPTOKEN_INGRESS, "ingress", HSPTOKENTYPE_ATTRIB, NULL)
HSPTOKEN_DATA( HSPTOKEN_EGRESS, "egress", HSPTOKENTYPE_ATTRIB, NULL)
HSPTOKEN_DATA( HSPTOKEN_K8S, "k8s", HSPTOKENTYPE_OBJ, NULL)
HSPTOKEN_DATA( HSPTOKEN_WAITREADY, "waitReady", HSPTOKENTYPE_ATTRIB, NULL)
23 changes: 19 additions & 4 deletions src/Linux/mod_sonic.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ extern "C" {
bool changedPortPriority:1;
u_char actorSystemMAC[8];
uint32_t localAS;
time_t waitReadyStart;
bool system_ready;
bool sflow_enable;
uint32_t sflow_polling;
Expand Down Expand Up @@ -673,8 +674,10 @@ extern "C" {
myDebug(1, "sonic db_connectCB: status= %d", status);
if(status == REDIS_OK) {
db->connected = YES;
if(db_allConnected(db->mod))
if(db_allConnected(db->mod)) {
mdata->state = HSP_SONIC_STATE_WAIT_READY;
mdata->waitReadyStart = mdata->pollBus->now.tv_sec;
}
}
}

Expand Down Expand Up @@ -1234,6 +1237,7 @@ extern "C" {
HSPSonicDBClient *db = (HSPSonicDBClient *)ctx->ev.data;
EVMod *mod = db->mod;
HSP *sp = (HSP *)EVROOTDATA(mod);
HSP_mod_SONIC *mdata = (HSP_mod_SONIC *)mod->data;
redisReply *reply = (redisReply *)magic;
HSPSonicPort *prt = (HSPSonicPort *)req_magic;

Expand Down Expand Up @@ -1299,7 +1303,7 @@ extern "C" {
| HSP_ETCTR_OPER
| HSP_ETCTR_ADMIN;
accumulateNioCounters(sp, adaptor, &prt->ctrs, &prt->et_ctrs);
nio->last_update = sp->pollBus->now.tv_sec;
nio->last_update = mdata->pollBus->now.tv_sec;
}
}
}
Expand Down Expand Up @@ -1862,6 +1866,7 @@ extern "C" {
*/

static void evt_tick(EVMod *mod, EVEvent *evt, void *data, size_t dataLen) {
HSP *sp = (HSP *)EVROOTDATA(mod);
HSP_mod_SONIC *mdata = (HSP_mod_SONIC *)mod->data;

switch(mdata->state) {
Expand All @@ -1879,10 +1884,20 @@ extern "C" {
db_connect(mod);
break;
case HSP_SONIC_STATE_WAIT_READY:
db_getSystemReady(mod);
// all dbs connected - wait for SYSTEM_READY
{
time_t waiting = mdata->pollBus->now.tv_sec - mdata->waitReadyStart;
if(waiting < sp->sonic.waitReady) {
db_getSystemReady(mod);
}
else {
myDebug(1, "sonic: waitReady timeout after %u seconds", waiting);
mdata->state = HSP_SONIC_STATE_CONNECTED;
}
}
break;
case HSP_SONIC_STATE_CONNECTED:
// connected - learn config
// connected and ready - learn config
db_getMeta(mod);
dbEvt_subscribe(mod);
// the next step is to read the starting agent/polling/collector
Expand Down

0 comments on commit b9b61bc

Please sign in to comment.