Fix rand initialization, add etcd connection/disconnection logging
parent
a43ef525a2
commit
098e369a3b
|
@ -194,9 +194,16 @@ void etcd_state_client_t::pick_next_etcd()
|
||||||
std::vector<int> ns;
|
std::vector<int> ns;
|
||||||
for (int i = 0; i < etcd_addresses.size(); i++)
|
for (int i = 0; i < etcd_addresses.size(); i++)
|
||||||
ns.push_back(i);
|
ns.push_back(i);
|
||||||
|
if (!rand_initialized)
|
||||||
|
{
|
||||||
|
timespec tv;
|
||||||
|
clock_gettime(CLOCK_REALTIME, &tv);
|
||||||
|
srand48(tv.tv_sec*1000000000 + tv.tv_nsec);
|
||||||
|
rand_initialized = true;
|
||||||
|
}
|
||||||
while (ns.size())
|
while (ns.size())
|
||||||
{
|
{
|
||||||
int i = rand() % ns.size();
|
int i = lrand48() % ns.size();
|
||||||
addresses_to_try.push_back(etcd_addresses[ns[i]]);
|
addresses_to_try.push_back(etcd_addresses[ns[i]]);
|
||||||
ns.erase(ns.begin()+i, ns.begin()+i+1);
|
ns.erase(ns.begin()+i, ns.begin()+i+1);
|
||||||
}
|
}
|
||||||
|
@ -244,6 +251,8 @@ void etcd_state_client_t::start_etcd_watcher()
|
||||||
{
|
{
|
||||||
if (data["result"]["created"].bool_value())
|
if (data["result"]["created"].bool_value())
|
||||||
{
|
{
|
||||||
|
if (etcd_watches_initialised == 3 && this->log_level > 0)
|
||||||
|
fprintf(stderr, "Successfully subscribed to etcd at %s\n", selected_etcd_address.c_str());
|
||||||
etcd_watches_initialised++;
|
etcd_watches_initialised++;
|
||||||
}
|
}
|
||||||
if (data["result"]["canceled"].bool_value())
|
if (data["result"]["canceled"].bool_value())
|
||||||
|
@ -309,8 +318,11 @@ void etcd_state_client_t::start_etcd_watcher()
|
||||||
{
|
{
|
||||||
if (cur_addr == selected_etcd_address)
|
if (cur_addr == selected_etcd_address)
|
||||||
{
|
{
|
||||||
|
fprintf(stderr, "Disconnected from etcd %s\n", selected_etcd_address.c_str());
|
||||||
selected_etcd_address = "";
|
selected_etcd_address = "";
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
fprintf(stderr, "Disconnected from etcd\n");
|
||||||
http_close(etcd_watch_ws);
|
http_close(etcd_watch_ws);
|
||||||
etcd_watch_ws = NULL;
|
etcd_watch_ws = NULL;
|
||||||
if (etcd_watches_initialised == 0)
|
if (etcd_watches_initialised == 0)
|
||||||
|
@ -374,6 +386,10 @@ void etcd_state_client_t::start_etcd_watcher()
|
||||||
}
|
}
|
||||||
else if (!ws_alive)
|
else if (!ws_alive)
|
||||||
{
|
{
|
||||||
|
if (this->log_level > 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Websocket ping failed, disconnecting from etcd %s\n", selected_etcd_address.c_str());
|
||||||
|
}
|
||||||
http_close(etcd_watch_ws);
|
http_close(etcd_watch_ws);
|
||||||
etcd_watch_ws = NULL;
|
etcd_watch_ws = NULL;
|
||||||
start_etcd_watcher();
|
start_etcd_watcher();
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#define ETCD_PG_HISTORY_WATCH_ID 3
|
#define ETCD_PG_HISTORY_WATCH_ID 3
|
||||||
#define ETCD_OSD_STATE_WATCH_ID 4
|
#define ETCD_OSD_STATE_WATCH_ID 4
|
||||||
|
|
||||||
|
// FIXME: Remove hardcode
|
||||||
#define MAX_ETCD_ATTEMPTS 5
|
#define MAX_ETCD_ATTEMPTS 5
|
||||||
#define ETCD_SLOW_TIMEOUT 5000
|
#define ETCD_SLOW_TIMEOUT 5000
|
||||||
#define ETCD_QUICK_TIMEOUT 1000
|
#define ETCD_QUICK_TIMEOUT 1000
|
||||||
|
@ -85,6 +86,7 @@ protected:
|
||||||
http_co_t *etcd_watch_ws = NULL, *keepalive_client = NULL;
|
http_co_t *etcd_watch_ws = NULL, *keepalive_client = NULL;
|
||||||
int ws_keepalive_timer = -1;
|
int ws_keepalive_timer = -1;
|
||||||
int ws_alive = 0;
|
int ws_alive = 0;
|
||||||
|
bool rand_initialized = false;
|
||||||
uint64_t bs_block_size = DEFAULT_BLOCK_SIZE;
|
uint64_t bs_block_size = DEFAULT_BLOCK_SIZE;
|
||||||
int etcd_keepalive_interval = 10;
|
int etcd_keepalive_interval = 10;
|
||||||
void add_etcd_url(std::string);
|
void add_etcd_url(std::string);
|
||||||
|
|
|
@ -58,7 +58,9 @@ msgr_rdma_context_t *msgr_rdma_context_t::create(const char *ib_devname, uint8_t
|
||||||
msgr_rdma_context_t *ctx = new msgr_rdma_context_t();
|
msgr_rdma_context_t *ctx = new msgr_rdma_context_t();
|
||||||
ctx->mtu = mtu;
|
ctx->mtu = mtu;
|
||||||
|
|
||||||
srand48(time(NULL));
|
timespec tv;
|
||||||
|
clock_gettime(CLOCK_REALTIME, &tv);
|
||||||
|
srand48(tv.tv_sec*1000000000 + tv.tv_nsec);
|
||||||
dev_list = ibv_get_device_list(NULL);
|
dev_list = ibv_get_device_list(NULL);
|
||||||
if (!dev_list)
|
if (!dev_list)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue