Browse Source

Avoid extra call to get subscription from generator by pushing it with the subscribe message to the stratifier

master
Con Kolivas 10 years ago
parent
commit
836f2f3ff2
  1. 31
      src/generator.c
  2. 16
      src/stratifier.c

31
src/generator.c

@ -1131,30 +1131,22 @@ static proxy_instance_t *proxy_by_id(gdata_t *gdata, const int id)
return proxi;
}
static void send_subscribe(gdata_t *gdata, proxy_instance_t *cproxy, int *sockd, const char *buf)
static proxy_instance_t *current_proxy(gdata_t *gdata);
static char *get_subscribe(ckpool_t *ckp, proxy_instance_t *proxi)
{
proxy_instance_t *proxi;
gdata_t *gdata = ckp->data;
json_t *json_msg;
int id = 0;
char *msg;
sscanf(buf, "getsubscribe=%d", &id);
proxi = proxy_by_id(gdata, id);
if (unlikely(!proxi || !proxi->nonce2len)) {
ASPRINTF(&msg, "notready");
goto out_send;
}
JSON_CPACK(json_msg, "{sisssisb}",
"proxy", proxi->id,
"enonce1", proxi->enonce1,
"nonce2len", proxi->nonce2len,
"reconnect", proxi == cproxy ? true : false);
"reconnect", proxi == current_proxy(gdata) ? true : false);
msg = json_dumps(json_msg, JSON_NO_UTF8);
json_decref(json_msg);
out_send:
send_unix_msg(*sockd, msg);
free(msg);
_Close(sockd);
return msg;
}
static void send_notify(gdata_t *gdata, int *sockd, const char *buf)
@ -1421,11 +1413,14 @@ out:
/* Close and invalidate the file handle */
Close(cs->fd);
} else {
char msg[128];
char *msg, *buf;
keep_sockalive(cs->fd);
snprintf(msg, 127, "subscribe=%d", proxi->id);
send_proc(ckp->stratifier, msg);
msg = get_subscribe(ckp, proxi);
ASPRINTF(&buf, "subscribe=%s", msg);
free(msg);
send_proc(ckp->stratifier, buf);
free(buf);
proxi->notified = false;
}
return ret;
@ -1734,8 +1729,6 @@ retry:
if (cmdmatch(buf, "shutdown")) {
ret = 0;
goto out;
} else if (cmdmatch(buf, "getsubscribe")) {
send_subscribe(gdata, proxi, &sockd, buf);
} else if (cmdmatch(buf, "getnotify")) {
send_notify(gdata, &sockd, buf);
} else if (cmdmatch(buf, "getdiff")) {

16
src/stratifier.c

@ -1044,31 +1044,27 @@ static void update_subscribe(ckpool_t *ckp, const char *cmd)
{
sdata_t *sdata = ckp->data;
bool reconnect = true;
char *buf, *msg;
const char *buf;
proxy_t *proxy;
json_t *val;
int id = 0;
sscanf(cmd, "subscribe=%d", &id);
ASPRINTF(&msg, "getsubscribe=%d", id);
buf = send_recv_proc(ckp->generator, msg);
dealloc(msg);
if (unlikely(!buf)) {
LOGWARNING("Failed to get subscribe from generator in update_subscribe");
drop_allclients(ckp);
if (unlikely(strlen(cmd) < 11)) {
LOGWARNING("Received zero length string for subscribe in update_subscribe");
return;
}
buf = cmd + 10;
LOGDEBUG("Update subscribe: %s", buf);
if (unlikely(!safecmp(buf, "notready"))) {
LOGNOTICE("Generator not ready to send subscribe for proxy %d", id);
return;
}
val = json_loads(buf, 0, NULL);
free(buf);
if (unlikely(!val)) {
LOGWARNING("Failed to json decode getsubscribe response in update_subscribe");
LOGWARNING("Failed to json decode subscribe response in update_subscribe");
return;
}
json_get_int(&id, val, "proxy");
LOGNOTICE("Got updated subscribe for proxy %d", id);

Loading…
Cancel
Save