From 13a42599ea0c56d3bdd4dfaa078df93008863002 Mon Sep 17 00:00:00 2001 From: Unbit Date: Thu, 24 Jan 2013 10:24:46 +0100 Subject: [PATCH] corerouters --*-use-cache option can take an optional cache name --- plugins/corerouter/corerouter.c | 4 ++++ plugins/corerouter/cr.h | 3 ++- plugins/corerouter/cr_map.c | 4 +++- plugins/fastrouter/fastrouter.c | 2 +- plugins/http/http.c | 2 +- plugins/rawrouter/rawrouter.c | 2 +- 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/plugins/corerouter/corerouter.c b/plugins/corerouter/corerouter.c index ef4ec875..20bc81e4 100644 --- a/plugins/corerouter/corerouter.c +++ b/plugins/corerouter/corerouter.c @@ -652,6 +652,10 @@ void uwsgi_corerouter_loop(int id, void *data) { ucr->mapper = uwsgi_cr_map_use_void; if (ucr->use_cache) { + ucr->cache = uwsgi_cache_by_name(ucr->use_cache); + if (!ucr->cache) { + uwsgi_log("unable to find cache \"%s\"\n", ucr->use_cache); + } ucr->mapper = uwsgi_cr_map_use_cache; } else if (ucr->pattern) { diff --git a/plugins/corerouter/cr.h b/plugins/corerouter/cr.h index 80a93d1d..1a23d1c5 100644 --- a/plugins/corerouter/cr.h +++ b/plugins/corerouter/cr.h @@ -197,7 +197,8 @@ struct uwsgi_corerouter { struct rb_root *timeouts; - int use_cache; + char *use_cache; + struct uwsgi_cache *cache; int nevents; int max_retries; diff --git a/plugins/corerouter/cr_map.c b/plugins/corerouter/cr_map.c index 06443cf9..471aabae 100644 --- a/plugins/corerouter/cr_map.c +++ b/plugins/corerouter/cr_map.c @@ -9,12 +9,14 @@ int uwsgi_cr_map_use_void(struct uwsgi_corerouter *ucr, struct corerouter_peer * } int uwsgi_cr_map_use_cache(struct uwsgi_corerouter *ucr, struct corerouter_peer *peer) { - peer->instance_address = uwsgi_cache_get(peer->key, peer->key_len, &peer->instance_address_len); + uwsgi_rlock(ucr->cache->lock); + peer->instance_address = uwsgi_cache_get2(ucr->cache, peer->key, peer->key_len, &peer->instance_address_len); char *cs_mod = uwsgi_str_contains(peer->instance_address, peer->instance_address_len, ','); if (cs_mod) { peer->modifier1 = uwsgi_str_num(cs_mod + 1, (peer->instance_address_len - (cs_mod - peer->instance_address)) - 1); peer->instance_address_len = (cs_mod - peer->instance_address); } + uwsgi_rwunlock(ucr->cache->lock); return 0; } diff --git a/plugins/fastrouter/fastrouter.c b/plugins/fastrouter/fastrouter.c index 26cf06b8..7c22ffd5 100644 --- a/plugins/fastrouter/fastrouter.c +++ b/plugins/fastrouter/fastrouter.c @@ -23,7 +23,7 @@ struct uwsgi_option fastrouter_options[] = { {"fastrouter-processes", required_argument, 0, "prefork the specified number of fastrouter processes", uwsgi_opt_set_int, &ufr.cr.processes, 0}, {"fastrouter-workers", required_argument, 0, "prefork the specified number of fastrouter processes", uwsgi_opt_set_int, &ufr.cr.processes, 0}, {"fastrouter-zerg", required_argument, 0, "attach the fastrouter to a zerg server", uwsgi_opt_corerouter_zerg, &ufr, 0}, - {"fastrouter-use-cache", no_argument, 0, "use uWSGI cache as hostname->server mapper for the fastrouter", uwsgi_opt_true, &ufr.cr.use_cache, 0}, + {"fastrouter-use-cache", optional_argument, 0, "use uWSGI cache as hostname->server mapper for the fastrouter", uwsgi_opt_set_str, &ufr.cr.use_cache, 0}, {"fastrouter-use-pattern", required_argument, 0, "use a pattern for fastrouter hostname->server mapping", uwsgi_opt_corerouter_use_pattern, &ufr, 0}, {"fastrouter-use-base", required_argument, 0, "use a base dir for fastrouter hostname->server mapping", uwsgi_opt_corerouter_use_base, &ufr, 0}, diff --git a/plugins/http/http.c b/plugins/http/http.c index f9819720..8c480806 100644 --- a/plugins/http/http.c +++ b/plugins/http/http.c @@ -24,7 +24,7 @@ struct uwsgi_option http_options[] = { {"http-zerg", required_argument, 0, "attach the http router to a zerg server", uwsgi_opt_corerouter_zerg, &uhttp, 0 }, {"http-fallback", required_argument, 0, "fallback to the specified node in case of error", uwsgi_opt_add_string_list, &uhttp.cr.fallback, 0}, {"http-modifier1", required_argument, 0, "set uwsgi protocol modifier1", uwsgi_opt_set_int, &uhttp.modifier1, 0}, - {"http-use-cache", no_argument, 0, "use uWSGI cache as key->value virtualhost mapper", uwsgi_opt_true, &uhttp.cr.use_cache, 0}, + {"http-use-cache", optional_argument, 0, "use uWSGI cache as key->value virtualhost mapper", uwsgi_opt_set_str, &uhttp.cr.use_cache, 0}, {"http-use-pattern", required_argument, 0, "use the specified pattern for mapping requests to unix sockets", uwsgi_opt_corerouter_use_pattern, &uhttp, 0}, {"http-use-base", required_argument, 0, "use the specified base for mapping requests to unix sockets", uwsgi_opt_corerouter_use_base, &uhttp, 0}, {"http-use-cluster", no_argument, 0, "load balance to nodes subscribed to the cluster", uwsgi_opt_true, &uhttp.cr.use_cluster, 0}, diff --git a/plugins/rawrouter/rawrouter.c b/plugins/rawrouter/rawrouter.c index c5d80bdb..8f113036 100644 --- a/plugins/rawrouter/rawrouter.c +++ b/plugins/rawrouter/rawrouter.c @@ -31,7 +31,7 @@ struct uwsgi_option rawrouter_options[] = { {"rawrouter-processes", required_argument, 0, "prefork the specified number of rawrouter processes", uwsgi_opt_set_int, &urr.cr.processes, 0}, {"rawrouter-workers", required_argument, 0, "prefork the specified number of rawrouter processes", uwsgi_opt_set_int, &urr.cr.processes, 0}, {"rawrouter-zerg", required_argument, 0, "attach the rawrouter to a zerg server", uwsgi_opt_corerouter_zerg, &urr, 0}, - {"rawrouter-use-cache", no_argument, 0, "use uWSGI cache as hostname->server mapper for the rawrouter", uwsgi_opt_true, &urr.cr.use_cache, 0}, + {"rawrouter-use-cache", optional_argument, 0, "use uWSGI cache as hostname->server mapper for the rawrouter", uwsgi_opt_set_str, &urr.cr.use_cache, 0}, {"rawrouter-use-pattern", required_argument, 0, "use a pattern for rawrouter hostname->server mapping", uwsgi_opt_corerouter_use_pattern, &urr, 0}, {"rawrouter-use-base", required_argument, 0, "use a base dir for rawrouter hostname->server mapping", uwsgi_opt_corerouter_use_base, &urr, 0},