Browse Source

Differentiate a dead proxy from a deleted one

master
Con Kolivas 8 years ago
parent
commit
ee17b24b9b
  1. 15
      src/generator.c
  2. 21
      src/stratifier.c

15
src/generator.c

@ -969,6 +969,9 @@ static void store_proxy(gdata_t *gdata, proxy_instance_t *proxy)
mutex_unlock(&gdata->lock);
}
/* The difference between a dead proxy and a deleted one is the parent proxy entry
* is not removed from the stratifier as it assumes it is down whereas a deleted
* proxy has had its entry removed from the generator. */
static void send_stratifier_deadproxy(ckpool_t *ckp, const int id, const int subid)
{
char buf[256];
@ -979,6 +982,16 @@ static void send_stratifier_deadproxy(ckpool_t *ckp, const int id, const int sub
send_proc(ckp->stratifier, buf);
}
static void send_stratifier_delproxy(ckpool_t *ckp, const int id, const int subid)
{
char buf[256];
if (ckp->passthrough)
return;
sprintf(buf, "delproxy=%d:%d", id, subid);
send_proc(ckp->stratifier, buf);
}
/* Remove the subproxy from the proxi list and put it on the dead list.
* Further use of the subproxy pointer may point to a new proxy but will not
* dereference. This will only disable subproxies so parent proxies need to
@ -2447,7 +2460,7 @@ static void delete_proxy(ckpool_t *ckp, gdata_t *gdata, proxy_instance_t *proxy)
mutex_unlock(&proxy->proxy_lock);
if (subproxy) {
send_stratifier_deadproxy(ckp, subproxy->id, subproxy->subid);
send_stratifier_delproxy(ckp, subproxy->id, subproxy->subid);
if (proxy != subproxy)
store_proxy(gdata, subproxy);
}

21
src/stratifier.c

@ -366,6 +366,7 @@ struct proxy_base {
proxy_t *subproxies; /* Hashlist of subproxies sorted by subid */
sdata_t *sdata; /* Unique stratifer data for each subproxy */
bool dead;
bool deleted;
};
typedef struct session session_t;
@ -2283,7 +2284,7 @@ static void check_bestproxy(sdata_t *sdata)
LOGNOTICE("Stratifier setting active proxy to %d", changed_id);
}
static void dead_proxyid(sdata_t *sdata, const int id, const int subid, const bool replaced)
static void dead_proxyid(sdata_t *sdata, const int id, const int subid, const bool replaced, const bool deleted)
{
stratum_instance_t *client, *tmp;
int reconnects = 0, proxyid = 0;
@ -2293,6 +2294,7 @@ static void dead_proxyid(sdata_t *sdata, const int id, const int subid, const bo
proxy = existing_subproxy(sdata, id, subid);
if (proxy) {
proxy->dead = true;
proxy->deleted = deleted;
if (!replaced && proxy->global)
check_bestproxy(sdata);
}
@ -2374,7 +2376,7 @@ static void update_subscribe(ckpool_t *ckp, const char *cmd)
/* Is this a replacement for an existing proxy id? */
old = existing_subproxy(sdata, id, subid);
if (old) {
dead_proxyid(sdata, id, subid, true);
dead_proxyid(sdata, id, subid, true, false);
proxy = old;
proxy->dead = false;
} else
@ -2729,7 +2731,7 @@ static void reap_proxies(ckpool_t *ckp, sdata_t *sdata)
free_proxy(subproxy);
}
/* Should we reap the parent proxy too?*/
if (!proxy->dead || proxy->subproxy_count > 1 || proxy->bound_clients)
if (!proxy->deleted || proxy->subproxy_count > 1 || proxy->bound_clients)
continue;
HASH_DELETE(hh, sdata->proxies, proxy);
free_proxy(proxy);
@ -3425,7 +3427,16 @@ static void dead_proxy(ckpool_t *ckp, sdata_t *sdata, const char *buf)
int id = 0, subid = 0;
sscanf(buf, "deadproxy=%d:%d", &id, &subid);
dead_proxyid(sdata, id, subid, false);
dead_proxyid(sdata, id, subid, false, false);
reap_proxies(ckp, sdata);
}
static void del_proxy(ckpool_t *ckp, sdata_t *sdata, const char *buf)
{
int id = 0, subid = 0;
sscanf(buf, "delproxy=%d:%d", &id, &subid);
dead_proxyid(sdata, id, subid, false, true);
reap_proxies(ckp, sdata);
}
@ -4116,6 +4127,8 @@ retry:
request_reconnect(sdata, buf);
} else if (cmdmatch(buf, "deadproxy")) {
dead_proxy(ckp, sdata, buf);
} else if (cmdmatch(buf, "delproxy")) {
del_proxy(ckp, sdata, buf);
} else if (cmdmatch(buf, "loglevel")) {
sscanf(buf, "loglevel=%d", &ckp->loglevel);
} else if (cmdmatch(buf, "ckdbflush")) {

Loading…
Cancel
Save