int cluster_config_reconfigure(struct cluster_config *config,
                               char **server_list, size_t num_servers)
{
    assert(config);
    assert(server_list);

    uint32_t self_id = 0;
    size_t num_continuum = 0;
    struct server_item *servers = NULL;
    struct continuum_item *continuum = NULL;
    bool populated, generated;
    int ret = 0;

    do {
        populated = server_item_populate(config, server_list, num_servers,
                                         config->self_hostport, &servers, &self_id);
        if (!populated) {
            config->logger->log(EXTENSION_LOG_WARNING, NULL,
                                "reconfiguration failed: server_item_populate\n");
            ret = -1; break;
        }
        generated = ketama_continuum_generate(config, servers, num_servers,
                                              &continuum, &num_continuum);
        if (!generated) {
            config->logger->log(EXTENSION_LOG_WARNING, NULL,
                                "reconfiguration failed: ketama_continuum_generate\n");
            server_item_free(servers, num_servers);
            free(servers); servers = NULL;
            ret = -1; break;
        }
    } while(0);

    pthread_mutex_lock(&config->lock);
    if (ret == 0) {
        server_item_free(config->servers, config->num_servers);
        free(config->servers);
        free(config->continuum);

        config->self_id = self_id;
        config->num_servers = num_servers;
        config->servers = servers;
        config->continuum = continuum;
        config->num_continuum = num_continuum;
        config->is_valid = true;
    } else {
        config->is_valid = false;
    }
    pthread_mutex_unlock(&config->lock);

    if (config->is_valid) {
        if (config->verbose > 2) {
            cluster_config_print_node_list(config);
            cluster_config_print_continuum(config);
        }
    }
    return ret;
}
Esempio n. 2
0
bool cluster_config_reconfigure(struct cluster_config *config, char **server_list, size_t num_servers)
{
    assert(config);
    assert(server_list);

    uint32_t self_id = 0;
    size_t num_continuum = 0;
    struct server_item *servers = NULL;
    struct continuum_item *continuum = NULL;

    bool populated, generated;

    populated = server_item_populate(config, server_list, num_servers, config->self_hostport,
                                     &servers, &self_id);
    if (!populated) {
        config->logger->log(EXTENSION_LOG_WARNING, NULL, "reconfiguration failed: server_item_populate\n");
        goto RECONFIG_FAILED;
    }

    generated = ketama_continuum_generate(config, servers, num_servers,
                                          &continuum, &num_continuum);
    if (!generated) {
        config->logger->log(EXTENSION_LOG_WARNING, NULL, "reconfiguration failed: ketama_continuum_generate\n");
        server_item_free(servers, num_servers);
        free(servers);
        servers = NULL;
        goto RECONFIG_FAILED;
    }

    pthread_mutex_lock(&config->lock);

    server_item_free(config->servers, config->num_servers);
    free(config->servers);
    free(config->continuum);

    config->self_id = self_id;
    config->num_servers = num_servers;
    config->servers = servers;
    config->continuum = continuum;
    config->num_continuum = num_continuum;
    config->is_valid = true;

    pthread_mutex_unlock(&config->lock);

    return true;

RECONFIG_FAILED:
    pthread_mutex_lock(&config->lock);
    config->is_valid = false;
    pthread_mutex_unlock(&config->lock);

    return false;
}