forked from vitalif/vitastor
Make monitor stick to one etcd until the restart
parent
ad577c4aac
commit
7006875a24
13
mon/mon.js
13
mon/mon.js
|
@ -317,8 +317,14 @@ class Mon
|
||||||
ok(false);
|
ok(false);
|
||||||
}, this.config.etcd_mon_timeout);
|
}, this.config.etcd_mon_timeout);
|
||||||
this.ws = new WebSocket(base+'/watch');
|
this.ws = new WebSocket(base+'/watch');
|
||||||
|
const fail = () =>
|
||||||
|
{
|
||||||
|
ok(false);
|
||||||
|
};
|
||||||
|
this.ws.on('error', fail);
|
||||||
this.ws.on('open', () =>
|
this.ws.on('open', () =>
|
||||||
{
|
{
|
||||||
|
this.ws.removeListener('error', fail);
|
||||||
if (timer_id)
|
if (timer_id)
|
||||||
clearTimeout(timer_id);
|
clearTimeout(timer_id);
|
||||||
ok(true);
|
ok(true);
|
||||||
|
@ -445,7 +451,7 @@ class Mon
|
||||||
async get_lease()
|
async get_lease()
|
||||||
{
|
{
|
||||||
const max_ttl = this.config.etcd_mon_ttl + this.config.etcd_mon_timeout/1000*this.config.etcd_mon_retries;
|
const max_ttl = this.config.etcd_mon_ttl + this.config.etcd_mon_timeout/1000*this.config.etcd_mon_retries;
|
||||||
const res = await this.etcd_call('/lease/grant', { TTL: max_ttl }, this.config.etcd_mon_timeout, this.config.etcd_mon_retries);
|
const res = await this.etcd_call('/lease/grant', { TTL: max_ttl }, this.config.etcd_mon_timeout, -1);
|
||||||
this.etcd_lease_id = res.ID;
|
this.etcd_lease_id = res.ID;
|
||||||
setInterval(async () =>
|
setInterval(async () =>
|
||||||
{
|
{
|
||||||
|
@ -1241,6 +1247,11 @@ class Mon
|
||||||
console.error('etcd returned error: '+res.json.error);
|
console.error('etcd returned error: '+res.json.error);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (this.etcd_urls.length > 1)
|
||||||
|
{
|
||||||
|
// Stick to the same etcd for the rest of calls
|
||||||
|
this.etcd_urls = [ base ];
|
||||||
|
}
|
||||||
return res.json;
|
return res.json;
|
||||||
}
|
}
|
||||||
retry++;
|
retry++;
|
||||||
|
|
Loading…
Reference in New Issue