rstatus_t server_pool_init(struct array *server_pool, struct array *conf_pool, struct context *ctx) { rstatus_t status; uint32_t npool; npool = array_n(conf_pool); ASSERT(npool != 0); ASSERT(array_n(server_pool) == 0); status = array_init(server_pool, npool, sizeof(struct server_pool)); if (status != NC_OK) { return status; } /* transform conf pool to server pool */ status = array_each(conf_pool, conf_pool_each_transform, server_pool); if (status != NC_OK) { server_pool_deinit(server_pool); return status; } ASSERT(array_n(server_pool) == npool); /* set ctx as the server pool owner */ status = array_each(server_pool, server_pool_each_set_owner, ctx); if (status != NC_OK) { server_pool_deinit(server_pool); return status; } /* compute max server connections */ ctx->max_nsconn = 0; status = array_each(server_pool, server_pool_each_calc_connections, ctx); if (status != NC_OK) { server_pool_deinit(server_pool); return status; } /* update server pool continuum */ status = array_each(server_pool, server_pool_each_run, NULL); if (status != NC_OK) { server_pool_deinit(server_pool); return status; } log_debug(LOG_DEBUG, "init %"PRIu32" pools", npool); return NC_OK; }
void server_pool_deinit(struct array *server_pool) { uint32_t i, npool; for (i = 0, npool = array_n(server_pool); i < npool; i++) { struct server_pool *sp; sp = array_pop(server_pool); ASSERT(sp->p_conn == NULL); ASSERT(TAILQ_EMPTY(&sp->c_conn_q) && sp->dn_conn_q == 0); server_deinit(&sp->server); if (array_n(&sp->racks) != 0) array_each(&sp->racks, rack_deinit, NULL); array_deinit(&sp->racks); sp->nlive_server = 0; log_debug(LOG_DEBUG, "deinit pool %"PRIu32" '%.*s'", sp->idx, sp->name.len, sp->name.data); } array_deinit(server_pool); log_debug(LOG_DEBUG, "deinit %"PRIu32" pools", npool); }
rstatus_t tw_master_conf_init(struct array *server_pool, struct array *conf_pool) { rstatus_t status; uint32_t npool; npool = array_n(conf_pool); ASSERT(npool != 0); ASSERT(array_n(server_pool) == 0); status = array_init(server_pool, npool, sizeof(struct server_pool)); if (status != NC_OK) { return status; } /* transform conf pool to server pool */ status = array_each(conf_pool, conf_pool_master, server_pool); if (status != NC_OK) { //server_pool_deinit(server_pool); return status; } ASSERT(array_n(server_pool) == npool); return NC_OK; }
void dnode_peer_pool_deinit(struct array *server_pool) { uint32_t i, npool; for (i = 0, npool = array_n(server_pool); i < npool; i++) { struct server_pool *sp; sp = array_pop(server_pool); ASSERT(sp->p_conn == NULL); //fixe me to use different variables ASSERT(TAILQ_EMPTY(&sp->c_conn_q) && sp->dn_conn_q == 0); dnode_peer_deinit(&sp->peers); array_each(&sp->racks, rack_destroy, NULL); sp->nlive_server = 0; log_debug(LOG_DEBUG, "dyn: deinit peer pool %"PRIu32" '%.*s'", sp->idx, sp->name.len, sp->name.data); } //array_deinit(server_pool); log_debug(LOG_DEBUG, "deinit %"PRIu32" peer pools", npool); }
rstatus_t dc_deinit(struct datacenter *dc) { array_each(&dc->racks, rack_destroy, NULL); string_deinit(dc->name); //dictRelease(dc->dict_rack); return DN_OK; }
rstatus_t server_pool_preconnect(struct context *ctx) { rstatus_t status; status = array_each(&ctx->pool, server_pool_each_preconnect, NULL); if (status != DN_OK) { return status; } return DN_OK; }
rstatus_t gossip_pool_init(struct context *ctx) { rstatus_t status; status = array_each(&ctx->pool, gossip_pool_each_init, NULL); if (status != DN_OK) { return status; } return DN_OK; }
static rstatus_t server_pool_each_disconnect(void *elem, void *data) { rstatus_t status; struct server_pool *sp = elem; status = array_each(&sp->server, server_each_disconnect, NULL); if (status != DN_OK) { return status; } return DN_OK; }
rstatus_t dnode_peer_init(struct array *server_pool, struct context *ctx) { rstatus_t status; status = array_each(server_pool, dnode_peer_each_pool_init, ctx); if (status != DN_OK) { server_pool_deinit(server_pool); return status; } return DN_OK; }
rstatus_t server_init(struct array *servers, struct array *conf_server, struct server_pool *sp) { rstatus_t status; uint32_t nserver; nserver = array_n(conf_server); ASSERT(nserver != 0); ASSERT(array_n(servers) == 0); status = array_init(servers, nserver, sizeof(struct server)); if (status != DN_OK) { return status; } /* transform conf server to server */ status = array_each(conf_server, conf_server_each_transform, servers); if (status != DN_OK) { server_deinit(servers); return status; } ASSERT(array_n(servers) == nserver); /* set server owner */ status = array_each(servers, server_each_set_owner, sp); if (status != DN_OK) { server_deinit(servers); return status; } log_debug(LOG_DEBUG, "init %"PRIu32" servers in pool %"PRIu32" '%.*s'", nserver, sp->idx, sp->name.len, sp->name.data); return DN_OK; }
void proxy_deinit(struct context *ctx) { rstatus_t status; ASSERT(array_n(&ctx->pool) != 0); status = array_each(&ctx->pool, proxy_each_deinit, NULL); if (status != DN_OK) { return; } log_debug(LOG_VVERB, "deinit proxy with %"PRIu32" pools", array_n(&ctx->pool)); }
static rstatus_t server_pool_each_preconnect(void *elem, void *data) { rstatus_t status; struct server_pool *sp = elem; if (!sp->preconnect) { return NC_OK; } status = array_each(&sp->server, server_each_preconnect, NULL); if (status != NC_OK) { return status; } return NC_OK; }
rstatus_t dnode_init(struct context *ctx) { rstatus_t status; ASSERT(array_n(&ctx->pool) != 0); status = array_each(&ctx->pool, dnode_each_init, NULL); if (status != DN_OK) { dnode_deinit(ctx); return status; } log_debug(LOG_VVERB, "init dnode with %"PRIu32" pools", array_n(&ctx->pool)); return DN_OK; }
rstatus_t proxy_init(struct context *ctx) { rstatus_t status; ASSERT(array_n(&ctx->pool) != 0); status = array_each(&ctx->pool, proxy_each_init, NULL); if (status != NC_OK) { proxy_deinit(ctx); return status; } log_debug(LOG_VVERB, "init proxy with %"PRIu32" pools", array_n(&ctx->pool)); return NC_OK; }
rstatus_t dnode_peer_each_pool_init(void *elem, void *context) { struct server_pool *sp = (struct server_pool *) elem; //struct context *ctx = context; struct array *conf_seeds = &sp->conf_pool->dyn_seeds; struct array * seeds = &sp->seeds; struct array * peers = &sp->peers; rstatus_t status; uint32_t nseed; /* init seeds list */ nseed = array_n(conf_seeds); if(nseed == 0) { log_debug(LOG_INFO, "dyn: look like you are running with no seeds deifined. This is ok for running with just one node."); // add current node to peers array status = array_init(peers, CONF_DEFAULT_PEERS, sizeof(struct server)); if (status != DN_OK) { return status; } struct server *peer = array_push(peers); ASSERT(peer != NULL); status = dnode_peer_add_local(sp, peer); if (status != DN_OK) { dnode_peer_deinit(peers); } dnode_peer_pool_run(sp); return status; } ASSERT(array_n(seeds) == 0); status = array_init(seeds, nseed, sizeof(struct server)); if (status != DN_OK) { return status; } /* transform conf seeds to seeds */ status = array_each(conf_seeds, conf_seed_each_transform, seeds); if (status != DN_OK) { dnode_peer_deinit(seeds); return status; } ASSERT(array_n(seeds) == nseed); /* set seed owner */ status = array_each(seeds, dnode_peer_each_set_owner, sp); if (status != DN_OK) { dnode_peer_deinit(seeds); return status; } /* initialize peers list = seeds list */ ASSERT(array_n(peers) == 0); // add current node to peers array uint32_t peer_cnt = nseed + 1; status = array_init(peers, CONF_DEFAULT_PEERS, sizeof(struct server)); if (status != DN_OK) { return status; } struct server *peer = array_push(peers); ASSERT(peer != NULL); status = dnode_peer_add_local(sp, peer); if (status != DN_OK) { dnode_peer_deinit(seeds); dnode_peer_deinit(peers); return status; } status = array_each(conf_seeds, conf_seed_each_transform, peers); if (status != DN_OK) { dnode_peer_deinit(seeds); dnode_peer_deinit(peers); return status; } ASSERT(array_n(peers) == peer_cnt); status = array_each(peers, dnode_peer_each_set_owner, sp); if (status != DN_OK) { dnode_peer_deinit(seeds); dnode_peer_deinit(peers); return status; } dnode_peer_pool_run(sp); log_debug(LOG_DEBUG, "init %"PRIu32" seeds and peers in pool %"PRIu32" '%.*s'", nseed, sp->idx, sp->name.len, sp->name.data); return DN_OK; }
void server_pool_disconnect(struct context *ctx) { array_each(&ctx->pool, server_pool_each_disconnect, NULL); }
void dnode_peer_pool_disconnect(struct context *ctx) { array_each(&ctx->pool, dnode_peer_pool_each_disconnect, NULL); }