/** Update the configuration from a server. */ lcb_error_t lcb_cccp_update(clconfig_provider *provider, const char *host, lcb_string *data) { VBUCKET_CONFIG_HANDLE vbc; clconfig_info *new_config; cccp_provider *cccp = (cccp_provider *)provider; vbc = vbucket_config_create(); if (!vbc) { return LCB_CLIENT_ENOMEM; } if (vbucket_config_parse2(vbc, LIBVBUCKET_SOURCE_MEMORY, data->base, host)) { vbucket_config_destroy(vbc); return LCB_PROTOCOL_ERROR; } new_config = lcb_clconfig_create(vbc, data, LCB_CLCONFIG_CCCP); if (!new_config) { vbucket_config_destroy(vbc); return LCB_CLIENT_ENOMEM; } if (cccp->config) { lcb_clconfig_decref(cccp->config); } /** TODO: Figure out the comparison vector */ new_config->cmpclock = gethrtime(); cccp->config = new_config; lcb_confmon_set_next(provider->parent, new_config, 0); return LCB_SUCCESS; }
/** Update the configuration from a server. */ lcb_error_t lcb_cccp_update(clconfig_provider *provider, const char *host, lcb_string *data) { VBUCKET_CONFIG_HANDLE vbc; lcb_string sanitized; int rv; clconfig_info *new_config; cccp_provider *cccp = (cccp_provider *)provider; vbc = vbucket_config_create(); if (!vbc) { return LCB_CLIENT_ENOMEM; } lcb_string_init(&sanitized); sanitize_config(data, host, &sanitized); rv = vbucket_config_parse(vbc, LIBVBUCKET_SOURCE_MEMORY, sanitized.base); if (rv) { lcb_string_release(&sanitized); vbucket_config_destroy(vbc); lcb_string_release(&sanitized); return LCB_PROTOCOL_ERROR; } new_config = lcb_clconfig_create(vbc, &sanitized, LCB_CLCONFIG_CCCP); lcb_string_release(&sanitized); if (!new_config) { vbucket_config_destroy(vbc); return LCB_CLIENT_ENOMEM; } if (cccp->config) { lcb_clconfig_decref(cccp->config); } /** TODO: Figure out the comparison vector */ new_config->cmpclock = gethrtime(); cccp->config = new_config; lcb_confmon_provider_success(provider, new_config); return LCB_SUCCESS; }
static lcb_error_t set_next_config(struct htvb_st *vbs) { VBUCKET_CONFIG_HANDLE new_config = NULL; new_config = vbucket_config_create(); if (!new_config) { return LCB_CLIENT_ENOMEM; } if (vbucket_config_parse(new_config, LIBVBUCKET_SOURCE_MEMORY, vbs->input.base)) { vbucket_config_destroy(new_config); return LCB_PROTOCOL_ERROR; } if (vbs->config) { /** We have a previous configuration... */ VBUCKET_CHANGE_STATUS chstatus = VBUCKET_NO_CHANGES; VBUCKET_CONFIG_DIFF *diff = NULL; VBUCKET_CONFIG_HANDLE old_config = vbs->config->vbc; diff = vbucket_compare(old_config, new_config); if (diff) { chstatus = vbucket_what_changed(diff); vbucket_free_diff(diff); } if (chstatus == VBUCKET_NO_CHANGES) { vbs->config->cmpclock = gethrtime(); vbucket_config_destroy(new_config); return LCB_SUCCESS; } } if (vbs->config) { lcb_clconfig_decref(vbs->config); } vbs->config = lcb_clconfig_create(new_config, &vbs->input, LCB_CLCONFIG_HTTP); vbs->config->cmpclock = gethrtime(); vbs->generation++; return LCB_SUCCESS; }
static void configure_nodes(clconfig_provider *pb, const hostlist_t hl) { bc_MCRAW *mcr = (bc_MCRAW *)pb; lcbvb_SERVER *servers; lcbvb_CONFIG *newconfig; unsigned ii, nsrv; nsrv = hl->nentries; if (!nsrv) { lcb_log(LOGARGS(mcr, FATAL), "No nodes provided"); return; } servers = calloc(nsrv, sizeof(*servers)); for (ii = 0; ii < nsrv; ii++) { int itmp; const lcb_host_t *curhost = hl->entries + ii; lcbvb_SERVER *srv = servers + ii; /* just set the memcached port and hostname */ srv->hostname = (char *)curhost->host; sscanf(curhost->port, "%d", &itmp); srv->svc.data = itmp; if (pb->parent->settings->sslopts) { srv->svc_ssl.data = itmp; } } newconfig = lcbvb_create(); lcbvb_genconfig_ex(newconfig, "NOBUCKET", "deadbeef", servers, nsrv, 0, 2); lcbvb_make_ketama(newconfig); newconfig->revid = -1; if (mcr->config) { lcb_clconfig_decref(mcr->config); mcr->config = NULL; } mcr->config = lcb_clconfig_create(newconfig, LCB_CLCONFIG_MCRAW); mcr->config->cmpclock = gethrtime(); }
static lcb_error_t set_next_config(struct htvb_st *vbs) { VBUCKET_CONFIG_HANDLE new_config = NULL; new_config = vbucket_config_create(); if (!new_config) { return LCB_CLIENT_ENOMEM; } if (vbucket_config_parse(new_config, LIBVBUCKET_SOURCE_MEMORY, vbs->input.base)) { vbucket_config_destroy(new_config); return LCB_PROTOCOL_ERROR; } if (vbs->config) { lcb_clconfig_decref(vbs->config); } vbs->config = lcb_clconfig_create(new_config, &vbs->input, LCB_CLCONFIG_HTTP); vbs->config->cmpclock = gethrtime(); vbs->generation++; return LCB_SUCCESS; }
static int load_cache(file_provider *provider) { lcb_string str; char line[1024]; lcb_ssize_t nr; int fail; FILE *fp = NULL; lcbvb_CONFIG *config = NULL; char *end; struct stat st; int status = -1; lcb_string_init(&str); if (provider->filename == NULL) { return -1; } fp = fopen(provider->filename, "r"); if (fp == NULL) { int save_errno = errno; lcb_log(LOGARGS(provider, ERROR), LOGFMT "Couldn't open for reading: %s", LOGID(provider), strerror(save_errno)); return -1; } if (fstat(fileno(fp), &st)) { provider->last_errno = errno; goto GT_DONE; } if (provider->last_mtime == st.st_mtime) { lcb_log(LOGARGS(provider, WARN), LOGFMT "Modification time too old", LOGID(provider)); goto GT_DONE; } config = lcbvb_create(); if (config == NULL) { goto GT_DONE; } lcb_string_init(&str); while ((nr = fread(line, 1, sizeof(line), fp)) > 0) { if (lcb_string_append(&str, line, nr)) { goto GT_DONE; } } if (ferror(fp)) { goto GT_DONE; } fclose(fp); fp = NULL; if (!str.nused) { status = -1; goto GT_DONE; } end = strstr(str.base, CONFIG_CACHE_MAGIC); if (end == NULL) { lcb_log(LOGARGS(provider, ERROR), LOGFMT "Couldn't find magic", LOGID(provider)); if (!provider->ro_mode) { remove(provider->filename); } status = -1; goto GT_DONE; } fail = lcbvb_load_json(config, str.base); if (fail) { status = -1; lcb_log(LOGARGS(provider, ERROR), LOGFMT "Couldn't parse configuration", LOGID(provider)); lcb_log_badconfig(LOGARGS(provider, ERROR), config, str.base); if (!provider->ro_mode) { remove(provider->filename); } goto GT_DONE; } if (lcbvb_get_distmode(config) != LCBVB_DIST_VBUCKET) { status = -1; lcb_log(LOGARGS(provider, ERROR), LOGFMT "Not applying cached memcached config", LOGID(provider)); goto GT_DONE; } if (strcmp(config->bname, PROVIDER_SETTING(&provider->base, bucket)) != 0) { status = -1; lcb_log(LOGARGS(provider, ERROR), LOGFMT "Bucket name in file is different from the one requested", LOGID(provider)); } if (provider->config) { lcb_clconfig_decref(provider->config); } provider->config = lcb_clconfig_create(config, LCB_CLCONFIG_FILE); provider->config->cmpclock = gethrtime(); provider->config->origin = provider->base.type; provider->last_mtime = st.st_mtime; status = 0; config = NULL; GT_DONE: if (fp != NULL) { fclose(fp); } if (config != NULL) { lcbvb_destroy(config); } lcb_string_release(&str); return status; }
static int load_cache(file_provider *provider) { lcb_string str; char line[1024]; lcb_ssize_t nr; int fail; FILE *fp = NULL; VBUCKET_CONFIG_HANDLE config = NULL; char *end; struct stat st; int status = -1; lcb_string_init(&str); if (provider->filename == NULL) { return -1; } fp = fopen(provider->filename, "r"); if (fp == NULL) { LOG(provider, ERROR, "Couldn't open filename"); return -1; } if (fstat(fileno(fp), &st)) { provider->last_errno = errno; goto GT_DONE; } if (provider->last_mtime == st.st_mtime) { LOG(provider, INFO, "Rejecting file. Modification time too old"); goto GT_DONE; } config = vbucket_config_create(); if (config == NULL) { goto GT_DONE; } lcb_string_init(&str); while ((nr = fread(line, 1, sizeof(line), fp)) > 0) { if (lcb_string_append(&str, line, nr)) { goto GT_DONE; } } if (ferror(fp)) { goto GT_DONE; } fclose(fp); fp = NULL; if (!str.nused) { status = -1; goto GT_DONE; } end = strstr(str.base, CONFIG_CACHE_MAGIC); if (end == NULL) { LOG(provider, ERROR, "Couldn't find magic in file"); remove(provider->filename); status = -1; goto GT_DONE; } fail = vbucket_config_parse(config, LIBVBUCKET_SOURCE_MEMORY, str.base); if (fail) { status = -1; LOG(provider, ERROR, "Couldn't parse configuration"); remove(provider->filename); goto GT_DONE; } if (vbucket_config_get_distribution_type(config) != VBUCKET_DISTRIBUTION_VBUCKET) { status = -1; LOG(provider, ERROR, "Not applying cached memcached config"); goto GT_DONE; } if (provider->config) { lcb_clconfig_decref(provider->config); } provider->config = lcb_clconfig_create(config, &str, LCB_CLCONFIG_FILE); provider->config->cmpclock = gethrtime(); provider->config->origin = provider->base.type; provider->last_mtime = st.st_mtime; status = 0; config = NULL; GT_DONE: if (fp != NULL) { fclose(fp); } if (config != NULL) { vbucket_config_destroy(config); } lcb_string_release(&str); return status; }