redblacktree::redblacktree(){ cr = cl = cp = " "; //inicjalizacja stringow do wypisywania /* 218 - haczyk prawo w gore 192 - haczyk w prawo w dol 196 - myslnik 179 - pionowa prosta */ cr[0] = 218; cr[1] = 196; cl[0] = 192; cl[1] = 196; cp[0] = 179; sentinel_init(); this->setroot(this->getsentinel()); }
static struct context * core_ctx_create(struct instance *nci) { rstatus_t status; struct context *ctx; struct conn *sentinel_conn; ctx = nc_alloc(sizeof(*ctx)); if (ctx == NULL) { return NULL; } ctx->id = ++ctx_id; ctx->cf = NULL; ctx->stats = NULL; array_null(&ctx->pool); ctx->ep = -1; ctx->nevent = EVENT_SIZE_HINT; ctx->max_timeout = nci->stats_interval; ctx->timeout = ctx->max_timeout; ctx->event = NULL; ctx->server_reconnect_interval = nci->server_reconnect_interval; ctx->whitelist = nci->whitelist; /* parse and create configuration */ ctx->cf = conf_create(nci->conf_filename); if (ctx->cf == NULL) { nc_free(ctx); return NULL; } /* initialize server pool from configuration */ status = server_pool_init(&ctx->pool, &ctx->cf->pool, ctx); if (status != NC_OK) { conf_destroy(ctx->cf); nc_free(ctx); return NULL; } /* initialize sentinel server */ ctx->sentinel = sentinel_init(nci->sentinel_port, nci->sentinel_addr); if (ctx->sentinel == NULL) { server_pool_deinit(&ctx->pool); conf_destroy(ctx->cf); nc_free(ctx); return NULL; } /* create stats per server pool */ ctx->stats = stats_create(nci->stats_port, nci->stats_addr, nci->stats_interval, nci->hostname, &ctx->pool); if (ctx->stats == NULL) { sentinel_deinit(ctx->sentinel); server_pool_deinit(&ctx->pool); conf_destroy(ctx->cf); nc_free(ctx); return NULL; } /* initialize event handling for client, proxy and server */ status = event_init(ctx, EVENT_SIZE_HINT); if (status != NC_OK) { stats_destroy(ctx->stats); sentinel_deinit(ctx->sentinel); server_pool_deinit(&ctx->pool); conf_destroy(ctx->cf); nc_free(ctx); return NULL; } /* preconnect? servers in server pool */ status = server_pool_preconnect(ctx); if (status != NC_OK) { server_pool_disconnect(ctx); event_deinit(ctx); stats_destroy(ctx->stats); sentinel_deinit(ctx->sentinel); server_pool_deinit(&ctx->pool); conf_destroy(ctx->cf); nc_free(ctx); return NULL; } /* initialize sentinel server conn */ sentinel_conn = sentinel_connect(ctx); if (sentinel_conn == NULL) { server_pool_disconnect(ctx); event_deinit(ctx); stats_destroy(ctx->stats); sentinel_deinit(ctx->sentinel); server_pool_deinit(&ctx->pool); conf_destroy(ctx->cf); nc_free(ctx); } /* initialize proxy per server pool */ status = proxy_init(ctx); if (status != NC_OK) { sentinel_conn->close(ctx, sentinel_conn); server_pool_disconnect(ctx); event_deinit(ctx); stats_destroy(ctx->stats); sentinel_deinit(ctx->sentinel); server_pool_deinit(&ctx->pool); conf_destroy(ctx->cf); nc_free(ctx); return NULL; } log_debug(LOG_VVERB, "created ctx %p id %"PRIu32"", ctx, ctx->id); return ctx; }
rstatus_t conf_pool_each_transform(void *elem, void *data) { rstatus_t status; struct conf_pool *cp = elem; struct array *server_pool = data; struct server_pool *sp; ASSERT(cp->valid); sp = array_push(server_pool); ASSERT(sp != NULL); sp->idx = array_idx(server_pool, sp); sp->ctx = NULL; sp->p_conn = NULL; sp->nc_conn_q = 0; TAILQ_INIT(&sp->c_conn_q); sp->state = STATE_UNINITLIAZED; array_null(&sp->groups); array_null(&sp->sentinels); sp->sentinel = NULL; sp->sentinel_heartbeat = (uint32_t)cp->sentinel_heartbeat; array_null(&sp->server); sp->ncontinuum = 0; sp->nserver_continuum = 0; sp->continuum = NULL; sp->nlive_server = 0; sp->name = cp->name; sp->addrstr = cp->listen.pname; sp->port = (uint16_t)cp->listen.port; nc_memcpy(&sp->info, &cp->listen.info, sizeof(cp->listen.info)); sp->perm = cp->listen.perm; sp->dist_type = cp->distribution; sp->key_hash_type = cp->hash; sp->key_hash = hash_algos[cp->hash]; sp->hash_tag = cp->hash_tag; sp->timeout = cp->timeout; sp->backlog = cp->backlog; sp->redis_db = cp->redis_db; sp->client_connections = (uint32_t)cp->client_connections; sp->server_connections = (uint32_t)cp->server_connections; sp->redis_auth = cp->redis_auth; sp->require_auth = cp->redis_auth.len > 0 ? 1 : 0; sp->tcpkeepalive = cp->tcpkeepalive ? 1 : 0; sp->groups = cp->groups; status = server_init(&sp->server, &sp->groups, sp); if (status != NC_OK) { return status; } status = sentinel_init(&sp->sentinels, &cp->sentinels, sp); if (status != NC_OK) { return status; } log_debug(LOG_VERB, "transform to pool %"PRIu32" '%.*s'", sp->idx, sp->name.len, sp->name.data); return NC_OK; }