comparison src/http/modules/ngx_http_memcached_module.c @ 260:0effe91f6083 NGINX_0_5_0

nginx 0.5.0 *) Change: the parameters in the "%name" form in the "log_format" directive are not supported anymore. *) Change: the "proxy_upstream_max_fails", "proxy_upstream_fail_timeout", "fastcgi_upstream_max_fails", "fastcgi_upstream_fail_timeout", "memcached_upstream_max_fails", and "memcached_upstream_fail_timeout" directives are not supported anymore. *) Feature: the "server" directive in the "upstream" context supports the "max_fails", "fail_timeout", and "down" parameters. *) Feature: the "ip_hash" directive inside the "upstream" block. *) Feature: the WAIT status in the "Auth-Status" header line of the IMAP/POP3 proxy authentication server response. *) Bugfix: nginx could not be built on 64-bit platforms; bug appeared in 0.4.14.
author Igor Sysoev <http://sysoev.ru>
date Mon, 04 Dec 2006 00:00:00 +0300
parents 644510700914
children e0b1d0a6c629
comparison
equal deleted inserted replaced
259:c68f18041059 260:0effe91f6083
10 #include <ngx_http.h> 10 #include <ngx_http.h>
11 11
12 12
13 typedef struct { 13 typedef struct {
14 ngx_http_upstream_conf_t upstream; 14 ngx_http_upstream_conf_t upstream;
15 ngx_peers_t *peers;
16 } ngx_http_memcached_loc_conf_t; 15 } ngx_http_memcached_loc_conf_t;
17 16
18 17
19 typedef struct { 18 typedef struct {
20 size_t rest; 19 size_t rest;
37 void *parent, void *child); 36 void *parent, void *child);
38 37
39 static char *ngx_http_memcached_pass(ngx_conf_t *cf, ngx_command_t *cmd, 38 static char *ngx_http_memcached_pass(ngx_conf_t *cf, ngx_command_t *cmd,
40 void *conf); 39 void *conf);
41 40
41 static char *ngx_http_memcached_upstream_max_fails_unsupported(ngx_conf_t *cf,
42 ngx_command_t *cmd, void *conf);
43 static char *ngx_http_memcached_upstream_fail_timeout_unsupported(ngx_conf_t *cf,
44 ngx_command_t *cmd, void *conf);
45
42 46
43 static ngx_conf_bitmask_t ngx_http_memcached_next_upstream_masks[] = { 47 static ngx_conf_bitmask_t ngx_http_memcached_next_upstream_masks[] = {
44 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR }, 48 { ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR },
45 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT }, 49 { ngx_string("timeout"), NGX_HTTP_UPSTREAM_FT_TIMEOUT },
46 { ngx_string("invalid_response"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER }, 50 { ngx_string("invalid_response"), NGX_HTTP_UPSTREAM_FT_INVALID_HEADER },
94 offsetof(ngx_http_memcached_loc_conf_t, upstream.next_upstream), 98 offsetof(ngx_http_memcached_loc_conf_t, upstream.next_upstream),
95 &ngx_http_memcached_next_upstream_masks }, 99 &ngx_http_memcached_next_upstream_masks },
96 100
97 { ngx_string("memcached_upstream_max_fails"), 101 { ngx_string("memcached_upstream_max_fails"),
98 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 102 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
99 ngx_conf_set_num_slot, 103 ngx_http_memcached_upstream_max_fails_unsupported,
100 NGX_HTTP_LOC_CONF_OFFSET, 104 0,
101 offsetof(ngx_http_memcached_loc_conf_t, upstream.max_fails), 105 0,
102 NULL }, 106 NULL },
103 107
104 { ngx_string("memcached_upstream_fail_timeout"), 108 { ngx_string("memcached_upstream_fail_timeout"),
105 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 109 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
106 ngx_conf_set_sec_slot, 110 ngx_http_memcached_upstream_fail_timeout_unsupported,
107 NGX_HTTP_LOC_CONF_OFFSET, 111 0,
108 offsetof(ngx_http_memcached_loc_conf_t, upstream.fail_timeout), 112 0,
109 NULL }, 113 NULL },
110 114
111 ngx_null_command 115 ngx_null_command
112 }; 116 };
113 117
176 return NGX_HTTP_INTERNAL_SERVER_ERROR; 180 return NGX_HTTP_INTERNAL_SERVER_ERROR;
177 } 181 }
178 182
179 u->peer.log = r->connection->log; 183 u->peer.log = r->connection->log;
180 u->peer.log_error = NGX_ERROR_ERR; 184 u->peer.log_error = NGX_ERROR_ERR;
181 u->peer.peers = mlcf->peers;
182 u->peer.tries = mlcf->peers->number;
183 #if (NGX_THREADS) 185 #if (NGX_THREADS)
184 u->peer.lock = &r->connection->lock; 186 u->peer.lock = &r->connection->lock;
185 #endif 187 #endif
186 188
187 u->output.tag = (ngx_buf_tag_t) &ngx_http_memcached_module; 189 u->output.tag = (ngx_buf_tag_t) &ngx_http_memcached_module;
509 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC; 511 conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC;
510 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC; 512 conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC;
511 513
512 conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE; 514 conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE;
513 515
514 conf->upstream.max_fails = NGX_CONF_UNSET_UINT; 516 /* the hardcoded values */
515 conf->upstream.fail_timeout = NGX_CONF_UNSET;
516
517 /* "fastcgi_cyclic_temp_file" is disabled */
518 conf->upstream.cyclic_temp_file = 0; 517 conf->upstream.cyclic_temp_file = 0;
519
520 /* the hardcoded values */
521 conf->upstream.buffering = 0; 518 conf->upstream.buffering = 0;
522 conf->upstream.ignore_client_abort = 0; 519 conf->upstream.ignore_client_abort = 0;
523 conf->upstream.send_lowat = 0; 520 conf->upstream.send_lowat = 0;
524 conf->upstream.bufs.num = 0; 521 conf->upstream.bufs.num = 0;
525 conf->upstream.busy_buffers_size = 0; 522 conf->upstream.busy_buffers_size = 0;
538 ngx_http_memcached_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) 535 ngx_http_memcached_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
539 { 536 {
540 ngx_http_memcached_loc_conf_t *prev = parent; 537 ngx_http_memcached_loc_conf_t *prev = parent;
541 ngx_http_memcached_loc_conf_t *conf = child; 538 ngx_http_memcached_loc_conf_t *conf = child;
542 539
543 ngx_uint_t i;
544
545 ngx_conf_merge_msec_value(conf->upstream.connect_timeout, 540 ngx_conf_merge_msec_value(conf->upstream.connect_timeout,
546 prev->upstream.connect_timeout, 60000); 541 prev->upstream.connect_timeout, 60000);
547 542
548 ngx_conf_merge_msec_value(conf->upstream.send_timeout, 543 ngx_conf_merge_msec_value(conf->upstream.send_timeout,
549 prev->upstream.send_timeout, 60000); 544 prev->upstream.send_timeout, 60000);
564 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { 559 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) {
565 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET 560 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET
566 |NGX_HTTP_UPSTREAM_FT_OFF; 561 |NGX_HTTP_UPSTREAM_FT_OFF;
567 } 562 }
568 563
569 ngx_conf_merge_uint_value(conf->upstream.max_fails,
570 prev->upstream.max_fails, 1);
571
572 ngx_conf_merge_sec_value(conf->upstream.fail_timeout,
573 prev->upstream.fail_timeout, 10);
574
575 if (conf->peers && conf->peers->number > 1) {
576 for (i = 0; i < conf->peers->number; i++) {
577 conf->peers->peer[i].weight = 1;
578 conf->peers->peer[i].max_fails = conf->upstream.max_fails;
579 conf->peers->peer[i].fail_timeout = conf->upstream.fail_timeout;
580 }
581 }
582
583 return NGX_CONF_OK; 564 return NGX_CONF_OK;
584 } 565 }
585 566
586 567
587 static char * 568 static char *
600 value = cf->args->elts; 581 value = cf->args->elts;
601 582
602 ngx_memzero(&u, sizeof(ngx_url_t)); 583 ngx_memzero(&u, sizeof(ngx_url_t));
603 584
604 u.url = value[1]; 585 u.url = value[1];
605 u.uri_part = 1; 586 u.no_resolve = 1;
606 587 /* u.uri_part = 1; may be used as namespace */
607 if (ngx_parse_url(cf, &u) != NGX_OK) { 588
608 if (u.err) { 589 lcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0);
609 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 590 if (lcf->upstream.upstream == NULL) {
610 "%s in \"%V\"", u.err, &u.url); 591 return NGX_CONF_ERROR;
611 } 592 }
612 } 593
613
614 lcf->peers = u.peers;
615 lcf->upstream.schema.len = sizeof("memcached://") - 1; 594 lcf->upstream.schema.len = sizeof("memcached://") - 1;
616 lcf->upstream.schema.data = (u_char *) "memcached://"; 595 lcf->upstream.schema.data = (u_char *) "memcached://";
617 596
618 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); 597 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
619 598
625 clcf->auto_redirect = 1; 604 clcf->auto_redirect = 1;
626 } 605 }
627 606
628 return NGX_CONF_OK; 607 return NGX_CONF_OK;
629 } 608 }
609
610
611 static char *
612 ngx_http_memcached_upstream_max_fails_unsupported(ngx_conf_t *cf,
613 ngx_command_t *cmd, void *conf)
614 {
615 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
616 "\"memcached_upstream_max_fails\" is not supported, "
617 "use the \"max_fails\" parameter of the \"server\" directive ",
618 "inside the \"upstream\" block");
619
620 return NGX_CONF_ERROR;
621 }
622
623
624 static char *
625 ngx_http_memcached_upstream_fail_timeout_unsupported(ngx_conf_t *cf,
626 ngx_command_t *cmd, void *conf)
627 {
628 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
629 "\"memcached_upstream_fail_timeout\" is not supported, "
630 "use the \"fail_timeout\" parameter of the \"server\" directive ",
631 "inside the \"upstream\" block");
632
633 return NGX_CONF_ERROR;
634 }