Skip to content
This repository has been archived by the owner on May 9, 2018. It is now read-only.

Commit

Permalink
Reverting/fixing off-by-one error. Adding reconnect_ivl to mqexec
Browse files Browse the repository at this point in the history
The off-by-one error fixed in the last commit is better fixed by
setting the initial size of the hash table appropriately.

This also adds the reconnect_ivl (reconnect_interval) option to
mqexec, and sets the default reconnect interval to 1 second
instead of 100 ms. This prevents connection storms when keys
aren't yet added to nagios, but clients are trying to connect.
  • Loading branch information
jbreams committed Aug 9, 2014
1 parent ef7a484 commit 99116ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
13 changes: 9 additions & 4 deletions dnxmq/mqexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ int main(int argc, char ** argv) {
char ch, *configobj = "executor", *tmprootpath = NULL,
*tmpunprivpath = NULL, *tmpunprivuser = NULL;
json_error_t jsonerr;
int reconnect_ivl = 1000;

while((ch = getopt(argc, argv, "vsdhc:")) != -1) {
switch(ch) {
Expand Down Expand Up @@ -720,25 +721,26 @@ int main(int argc, char ** argv) {

#if ZMQ_VERSION_MAJOR < 4
if(json_unpack_ex(config, &jsonerr, 0,
"{s:{s?:o s:o s?i s?b s?b s?:o s?o s?s s?s s?s}}",
"{s:{s?:o s:o s?i s?b s?b s?:o s?o s?s s?s s?s s?i}}",
configobj, "jobs", &jobs, "results", &results,
"iothreads", &iothreads, "verbose", &verbose,
"syslog", &usesyslog, "filter", &filter,
"publisher", &publisher, "rootpath", &tmprootpath,
"unprivpath", &tmpunprivpath, "unprivuser", &tmpunprivuser) != 0) {
"unprivpath", &tmpunprivpath, "unprivuser", &tmpunprivuser,
"reconnect_ivl", &reconnect_ivl) != 0) {
logit(ERR, "Error getting config %s", jsonerr.text);
exit(-1);
}
#else
if(json_unpack_ex(config, &jsonerr, 0,
"{s:{s?:o s:o s?i s?b s?b s?:o s?o s?s s?s s?s s?{s:s s:s s:s}}}",
"{s:{s?:o s:o s?i s?b s?b s?:o s?o s?s s?s s?s s?{s:s s:s s:s} s?i}}",
configobj, "jobs", &jobs, "results", &results,
"iothreads", &iothreads, "verbose", &verbose,
"syslog", &usesyslog, "filter", &filter,
"publisher", &publisher, "rootpath", &tmprootpath,
"unprivpath", &tmpunprivpath, "unprivuser", &tmpunprivuser,
"curve", "publickey", &curve_public, "privatekey", &curve_private,
"serverkey", &curve_server) != 0) {
"serverkey", &curve_server, "reconnect_ivl", &reconnect_ivl) != 0) {
logit(ERR, "Error getting config: %s", jsonerr.text);
exit(-1);
}
Expand Down Expand Up @@ -818,6 +820,9 @@ int main(int argc, char ** argv) {
exit(-1);
}

zmq_setsockopt(pullsock, ZMQ_RECONNECT_IVL, &reconnect_ivl, sizeof(int));
zmq_setsockopt(pushsock, ZMQ_RECONNECT_IVL, &reconnect_ivl, sizeof(int));

zmq_getsockopt(pullsock, ZMQ_FD, &pullfd, &pullfds);
if(pullfd == -1) {
logit(ERR, "Error getting fd for pullsock");
Expand Down
8 changes: 1 addition & 7 deletions mods/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,6 @@ int rehash_keybags(struct keybaghash * o) {
struct keybag * curkey = o->data[kiter], *savekey;
while(curkey) {
uint32_t hash = fnv_hash(curkey->key) & newsize;
if(hash == newsize)
hash -= 1;
savekey = curkey->next;
curkey->next = newdata[hash];
newdata[hash] = curkey;
Expand Down Expand Up @@ -427,8 +425,6 @@ int read_keyfile(const char * path, struct keybaghash * o) {
}

uint32_t hashval = fnv_hash(nk->key) & o->buckets;
if(hashval == o->buckets)
hashval -= 1;

nk->next = o->data[hashval];
o->data[hashval] = nk;
Expand Down Expand Up @@ -477,7 +473,7 @@ int send_zap_resp(zmq_msg_t * reqid, char * code, char * text,
void * zap_handler(void* zapsock) {
struct keybaghash bag;
bag.buckets = 63;
bag.data = calloc(63, sizeof(struct keybag*));
bag.data = calloc(64, sizeof(struct keybag*));
bag.count = 0;
time_t last_refresh = 0;
int keeprunning = 1, i;
Expand Down Expand Up @@ -544,8 +540,6 @@ void * zap_handler(void* zapsock) {

uint32_t hashval = fnv_hash(creds);
hashval &= bag.buckets;
if(hashval == bag.buckets)
hashval -= 1;

struct keybag * search = bag.data[hashval];

Expand Down

0 comments on commit 99116ab

Please sign in to comment.