Welcome! Log In Create A New Profile

Advanced

Re: memcached_hash + nginx 0.8.x

Maxim Dounin
May 13, 2011 10:56AM
Hello!

On Fri, May 13, 2011 at 03:56:35PM +0200, Sergey Bondari wrote:

> Добрый день,
>
> безуспешно пытаюсь собрать nginx c патчами для директивы
> memcached_hash на ветке 0.8.х
>
> Я правильно понял что это невозможно и что оно собирается
> только из GIT nginx-patched 0.6 & 0.7 ?

Прилагающийся патчик на memcached hash 0.4 был сделан во времена
0.8.50. Для 0.8.* должен работать, для 1.0.* потребуются
небольшие изменения в связи с появлением ngx_memmove().

Из исходного комплекта патчей memcached hash накладывать только
тот, что про upstream name.

Maxim Dounin
Cleanup for recent versions and reduce number of required patches.

- Type ngx_peer_addr_t was renamed to ngx_addr_t.
- Don't depend on ngx_memmove() patch, define it inline.
- Don't require $memcached_namespace variable to be defined.
- Check if key length still positive after extracting namespace to
avoid SIGSEGV without memcached_namespace patch and with namespace
set.

The only patch currently required is one for upstream name.

--- ../ngx_http_upstream_memcached_hash_module-0.04/ngx_http_upstream_memcached_hash_module.c
+++ ../ngx_http_upstream_memcached_hash_module-0.04/ngx_http_upstream_memcached_hash_module.c
@@ -17,6 +17,9 @@
#define CONTINUUM_MAX_POINT 0xffffffffU


+#define ngx_memmove(dst, src, n) (void) memmove(dst, src, n)
+
+
static ngx_str_t memcached_ns = ngx_string("memcached_namespace");


@@ -102,7 +105,7 @@ memcached_hash_find_peer(struct memcache
{
struct memcached_hash *memd = find_ctx->memd;
u_char *key;
- size_t len;
+ ssize_t len;
unsigned int point, bucket, index;

if (memd->peer_count == 1)
@@ -128,6 +131,15 @@ memcached_hash_find_peer(struct memcache

len = request_bufs->buf->last - key - (sizeof("\r\n") - 1);

+ if (len < 0)
+ {
+ ngx_log_error(NGX_LOG_ALERT, find_ctx->request->connection->log, 0,
+ "memcached hash negative key length");
+
+ index = 0;
+ goto out;
+ }
+
point = ngx_crc32_long(key, len);

if (memd->ketama_points == 0)
@@ -149,6 +161,8 @@ memcached_hash_find_peer(struct memcache
index = memd->buckets[bucket].index;
}

+out:
+
find_ctx->peer = &memd->peers[index];

return index;
@@ -161,7 +175,7 @@ memcached_hash_get_peer(ngx_peer_connect
{
struct memcached_hash_find_ctx *find_ctx = data;
struct memcached_hash_peer *peer = find_ctx->peer;
- ngx_peer_addr_t *addr;
+ ngx_addr_t *addr;

if (! peer)
{
@@ -445,12 +459,22 @@ memcached_init_hash(ngx_conf_t *cf, ngx_
}


+static ngx_int_t
+memcached_hash_var(ngx_http_request_t *r, ngx_http_variable_value_t *v,
+ uintptr_t data)
+{
+ v->not_found = 1;
+ return NGX_OK;
+}
+
+
static
char *
memcached_hash(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_str_t *value = cf->args->elts;
ngx_http_upstream_srv_conf_t *uscf;
+ ngx_http_variable_t *v;
struct memcached_hash *memd;
int ketama_points, scale;
unsigned int i;
@@ -497,6 +521,15 @@ memcached_hash(ngx_conf_t *cf, ngx_comma
return NGX_CONF_ERROR;
}

+ v = ngx_http_add_variable(cf, &memcached_ns, NGX_HTTP_VAR_CHANGEABLE);
+ if (v == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ if (v->get_handler == NULL) {
+ v->get_handler = memcached_hash_var;
+ }
+
uscf->peer.data = memd;

uscf->peer.init_upstream = memcached_init_hash;
_______________________________________________
nginx-ru mailing list
nginx-ru@nginx.org
http://nginx.org/mailman/listinfo/nginx-ru
Subject Author Posted

memcached_hash + nginx 0.8.x

Sergey Bondari May 13, 2011 09:58AM

Re: memcached_hash + nginx 0.8.x

Maxim Dounin May 13, 2011 10:56AM

Proxy cache temporary files problem

Grigory A. Mozhaev May 14, 2011 10:10AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 111
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready