Mercurial > hg > nginx-quic
annotate src/stream/ngx_stream_upstream_hash_module.c @ 6142:53bccdc4923a
Removed the deprecated "imap" directive.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Wed, 29 Apr 2015 13:53:24 +0300 |
parents | b6047abf5f30 |
children | bf8b6534db3a |
rev | line source |
---|---|
6115 | 1 |
2 /* | |
3 * Copyright (C) Roman Arutyunyan | |
4 * Copyright (C) Nginx, Inc. | |
5 */ | |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_stream.h> | |
11 | |
12 | |
13 typedef struct { | |
14 uint32_t hash; | |
15 ngx_str_t *server; | |
16 } ngx_stream_upstream_chash_point_t; | |
17 | |
18 | |
19 typedef struct { | |
20 ngx_uint_t number; | |
21 ngx_stream_upstream_chash_point_t point[1]; | |
22 } ngx_stream_upstream_chash_points_t; | |
23 | |
24 | |
25 typedef struct { | |
26 ngx_stream_upstream_chash_points_t *points; | |
27 } ngx_stream_upstream_hash_srv_conf_t; | |
28 | |
29 | |
30 typedef struct { | |
31 /* the round robin data must be first */ | |
32 ngx_stream_upstream_rr_peer_data_t rrp; | |
33 ngx_stream_upstream_hash_srv_conf_t *conf; | |
34 ngx_str_t key; | |
35 ngx_uint_t tries; | |
36 ngx_uint_t rehash; | |
37 uint32_t hash; | |
38 ngx_event_get_peer_pt get_rr_peer; | |
39 } ngx_stream_upstream_hash_peer_data_t; | |
40 | |
41 | |
42 static ngx_int_t ngx_stream_upstream_init_hash(ngx_conf_t *cf, | |
43 ngx_stream_upstream_srv_conf_t *us); | |
44 static ngx_int_t ngx_stream_upstream_init_hash_peer(ngx_stream_session_t *s, | |
45 ngx_stream_upstream_srv_conf_t *us); | |
46 static ngx_int_t ngx_stream_upstream_get_hash_peer(ngx_peer_connection_t *pc, | |
47 void *data); | |
48 | |
49 static ngx_int_t ngx_stream_upstream_init_chash(ngx_conf_t *cf, | |
50 ngx_stream_upstream_srv_conf_t *us); | |
51 static int ngx_libc_cdecl | |
52 ngx_stream_upstream_chash_cmp_points(const void *one, const void *two); | |
53 static ngx_uint_t ngx_stream_upstream_find_chash_point( | |
54 ngx_stream_upstream_chash_points_t *points, uint32_t hash); | |
55 static ngx_int_t ngx_stream_upstream_init_chash_peer(ngx_stream_session_t *s, | |
56 ngx_stream_upstream_srv_conf_t *us); | |
57 static ngx_int_t ngx_stream_upstream_get_chash_peer(ngx_peer_connection_t *pc, | |
58 void *data); | |
59 | |
60 static void *ngx_stream_upstream_hash_create_conf(ngx_conf_t *cf); | |
61 static char *ngx_stream_upstream_hash(ngx_conf_t *cf, ngx_command_t *cmd, | |
62 void *conf); | |
63 | |
64 | |
65 static ngx_command_t ngx_stream_upstream_hash_commands[] = { | |
66 | |
67 { ngx_string("hash"), | |
68 NGX_STREAM_UPS_CONF|NGX_CONF_TAKE12, | |
69 ngx_stream_upstream_hash, | |
70 NGX_STREAM_SRV_CONF_OFFSET, | |
71 0, | |
72 NULL }, | |
73 | |
74 ngx_null_command | |
75 }; | |
76 | |
77 | |
78 static ngx_stream_module_t ngx_stream_upstream_hash_module_ctx = { | |
79 NULL, /* create main configuration */ | |
80 NULL, /* init main configuration */ | |
81 | |
82 ngx_stream_upstream_hash_create_conf, /* create server configuration */ | |
83 NULL, /* merge server configuration */ | |
84 }; | |
85 | |
86 | |
87 ngx_module_t ngx_stream_upstream_hash_module = { | |
88 NGX_MODULE_V1, | |
89 &ngx_stream_upstream_hash_module_ctx, /* module context */ | |
90 ngx_stream_upstream_hash_commands, /* module directives */ | |
91 NGX_STREAM_MODULE, /* module type */ | |
92 NULL, /* init master */ | |
93 NULL, /* init module */ | |
94 NULL, /* init process */ | |
95 NULL, /* init thread */ | |
96 NULL, /* exit thread */ | |
97 NULL, /* exit process */ | |
98 NULL, /* exit master */ | |
99 NGX_MODULE_V1_PADDING | |
100 }; | |
101 | |
102 | |
103 static ngx_int_t | |
104 ngx_stream_upstream_init_hash(ngx_conf_t *cf, | |
105 ngx_stream_upstream_srv_conf_t *us) | |
106 { | |
107 if (ngx_stream_upstream_init_round_robin(cf, us) != NGX_OK) { | |
108 return NGX_ERROR; | |
109 } | |
110 | |
111 us->peer.init = ngx_stream_upstream_init_hash_peer; | |
112 | |
113 return NGX_OK; | |
114 } | |
115 | |
116 | |
117 static ngx_int_t | |
118 ngx_stream_upstream_init_hash_peer(ngx_stream_session_t *s, | |
119 ngx_stream_upstream_srv_conf_t *us) | |
120 { | |
121 ngx_stream_upstream_hash_srv_conf_t *hcf; | |
122 ngx_stream_upstream_hash_peer_data_t *hp; | |
123 | |
124 hp = ngx_palloc(s->connection->pool, | |
125 sizeof(ngx_stream_upstream_hash_peer_data_t)); | |
126 if (hp == NULL) { | |
127 return NGX_ERROR; | |
128 } | |
129 | |
130 s->upstream->peer.data = &hp->rrp; | |
131 | |
132 if (ngx_stream_upstream_init_round_robin_peer(s, us) != NGX_OK) { | |
133 return NGX_ERROR; | |
134 } | |
135 | |
136 s->upstream->peer.get = ngx_stream_upstream_get_hash_peer; | |
137 | |
138 hcf = ngx_stream_conf_upstream_srv_conf(us, | |
139 ngx_stream_upstream_hash_module); | |
140 | |
141 hp->key = s->connection->addr_text; | |
142 | |
143 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, | |
144 "upstream hash key:\"%V\"", &hp->key); | |
145 | |
146 hp->conf = hcf; | |
147 hp->tries = 0; | |
148 hp->rehash = 0; | |
149 hp->hash = 0; | |
150 hp->get_rr_peer = ngx_stream_upstream_get_round_robin_peer; | |
151 | |
152 return NGX_OK; | |
153 } | |
154 | |
155 | |
156 static ngx_int_t | |
157 ngx_stream_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data) | |
158 { | |
159 ngx_stream_upstream_hash_peer_data_t *hp = data; | |
160 | |
161 time_t now; | |
162 u_char buf[NGX_INT_T_LEN]; | |
163 size_t size; | |
164 uint32_t hash; | |
165 ngx_int_t w; | |
166 uintptr_t m; | |
6121
b6047abf5f30
Upstream: simplified ip_hash and hash peer selection code.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
167 ngx_uint_t n, p; |
6115 | 168 ngx_stream_upstream_rr_peer_t *peer; |
169 | |
170 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, pc->log, 0, | |
171 "get hash peer, try: %ui", pc->tries); | |
172 | |
173 ngx_stream_upstream_rr_peers_wlock(hp->rrp.peers); | |
174 | |
175 if (hp->tries > 20 || hp->rrp.peers->single) { | |
176 ngx_stream_upstream_rr_peers_unlock(hp->rrp.peers); | |
177 return hp->get_rr_peer(pc, &hp->rrp); | |
178 } | |
179 | |
180 now = ngx_time(); | |
181 | |
182 pc->connection = NULL; | |
183 | |
184 for ( ;; ) { | |
185 | |
186 /* | |
187 * Hash expression is compatible with Cache::Memcached: | |
188 * ((crc32([REHASH] KEY) >> 16) & 0x7fff) + PREV_HASH | |
189 * with REHASH omitted at the first iteration. | |
190 */ | |
191 | |
192 ngx_crc32_init(hash); | |
193 | |
194 if (hp->rehash > 0) { | |
195 size = ngx_sprintf(buf, "%ui", hp->rehash) - buf; | |
196 ngx_crc32_update(&hash, buf, size); | |
197 } | |
198 | |
199 ngx_crc32_update(&hash, hp->key.data, hp->key.len); | |
200 ngx_crc32_final(hash); | |
201 | |
202 hash = (hash >> 16) & 0x7fff; | |
203 | |
204 hp->hash += hash; | |
205 hp->rehash++; | |
206 | |
6121
b6047abf5f30
Upstream: simplified ip_hash and hash peer selection code.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
207 w = hp->hash % hp->rrp.peers->total_weight; |
b6047abf5f30
Upstream: simplified ip_hash and hash peer selection code.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
208 peer = hp->rrp.peers->peer; |
b6047abf5f30
Upstream: simplified ip_hash and hash peer selection code.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
209 p = 0; |
6115 | 210 |
6121
b6047abf5f30
Upstream: simplified ip_hash and hash peer selection code.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
211 while (w >= peer->weight) { |
b6047abf5f30
Upstream: simplified ip_hash and hash peer selection code.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
212 w -= peer->weight; |
b6047abf5f30
Upstream: simplified ip_hash and hash peer selection code.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
213 peer = peer->next; |
b6047abf5f30
Upstream: simplified ip_hash and hash peer selection code.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
214 p++; |
6115 | 215 } |
216 | |
217 n = p / (8 * sizeof(uintptr_t)); | |
218 m = (uintptr_t) 1 << p % (8 * sizeof(uintptr_t)); | |
219 | |
220 if (hp->rrp.tried[n] & m) { | |
221 goto next; | |
222 } | |
223 | |
224 ngx_log_debug2(NGX_LOG_DEBUG_STREAM, pc->log, 0, | |
225 "get hash peer, value:%uD, peer:%ui", hp->hash, p); | |
226 | |
227 if (peer->down) { | |
228 goto next; | |
229 } | |
230 | |
231 if (peer->max_fails | |
232 && peer->fails >= peer->max_fails | |
233 && now - peer->checked <= peer->fail_timeout) | |
234 { | |
235 goto next; | |
236 } | |
237 | |
238 break; | |
239 | |
240 next: | |
241 | |
242 if (++hp->tries > 20) { | |
243 ngx_stream_upstream_rr_peers_unlock(hp->rrp.peers); | |
244 return hp->get_rr_peer(pc, &hp->rrp); | |
245 } | |
246 } | |
247 | |
248 hp->rrp.current = peer; | |
249 | |
250 pc->sockaddr = peer->sockaddr; | |
251 pc->socklen = peer->socklen; | |
252 pc->name = &peer->name; | |
253 | |
254 peer->conns++; | |
255 | |
256 if (now - peer->checked > peer->fail_timeout) { | |
257 peer->checked = now; | |
258 } | |
259 | |
260 ngx_stream_upstream_rr_peers_unlock(hp->rrp.peers); | |
261 | |
262 hp->rrp.tried[n] |= m; | |
263 | |
264 return NGX_OK; | |
265 } | |
266 | |
267 | |
268 static ngx_int_t | |
269 ngx_stream_upstream_init_chash(ngx_conf_t *cf, | |
270 ngx_stream_upstream_srv_conf_t *us) | |
271 { | |
272 u_char *host, *port, c; | |
273 size_t host_len, port_len, size; | |
274 uint32_t hash, base_hash, prev_hash; | |
275 ngx_str_t *server; | |
276 ngx_uint_t npoints, i, j; | |
277 ngx_stream_upstream_rr_peer_t *peer; | |
278 ngx_stream_upstream_rr_peers_t *peers; | |
279 ngx_stream_upstream_chash_points_t *points; | |
280 ngx_stream_upstream_hash_srv_conf_t *hcf; | |
281 | |
282 if (ngx_stream_upstream_init_round_robin(cf, us) != NGX_OK) { | |
283 return NGX_ERROR; | |
284 } | |
285 | |
286 us->peer.init = ngx_stream_upstream_init_chash_peer; | |
287 | |
288 peers = us->peer.data; | |
289 npoints = peers->total_weight * 160; | |
290 | |
291 size = sizeof(ngx_stream_upstream_chash_points_t) | |
292 + sizeof(ngx_stream_upstream_chash_point_t) * (npoints - 1); | |
293 | |
294 points = ngx_palloc(cf->pool, size); | |
295 if (points == NULL) { | |
296 return NGX_ERROR; | |
297 } | |
298 | |
299 points->number = 0; | |
300 | |
301 for (peer = peers->peer; peer; peer = peer->next) { | |
302 server = &peer->server; | |
303 | |
304 /* | |
305 * Hash expression is compatible with Cache::Memcached::Fast: | |
306 * crc32(HOST \0 PORT PREV_HASH). | |
307 */ | |
308 | |
309 if (server->len >= 5 | |
310 && ngx_strncasecmp(server->data, (u_char *) "unix:", 5) == 0) | |
311 { | |
312 host = server->data + 5; | |
313 host_len = server->len - 5; | |
314 port = NULL; | |
315 port_len = 0; | |
316 goto done; | |
317 } | |
318 | |
319 for (j = 0; j < server->len; j++) { | |
320 c = server->data[server->len - j - 1]; | |
321 | |
322 if (c == ':') { | |
323 host = server->data; | |
324 host_len = server->len - j - 1; | |
325 port = server->data + server->len - j; | |
326 port_len = j; | |
327 goto done; | |
328 } | |
329 | |
330 if (c < '0' || c > '9') { | |
331 break; | |
332 } | |
333 } | |
334 | |
335 host = server->data; | |
336 host_len = server->len; | |
337 port = NULL; | |
338 port_len = 0; | |
339 | |
340 done: | |
341 | |
342 ngx_crc32_init(base_hash); | |
343 ngx_crc32_update(&base_hash, host, host_len); | |
344 ngx_crc32_update(&base_hash, (u_char *) "", 1); | |
345 ngx_crc32_update(&base_hash, port, port_len); | |
346 | |
347 prev_hash = 0; | |
348 npoints = peer->weight * 160; | |
349 | |
350 for (j = 0; j < npoints; j++) { | |
351 hash = base_hash; | |
352 | |
353 ngx_crc32_update(&hash, (u_char *) &prev_hash, sizeof(uint32_t)); | |
354 ngx_crc32_final(hash); | |
355 | |
356 points->point[points->number].hash = hash; | |
357 points->point[points->number].server = server; | |
358 points->number++; | |
359 | |
360 prev_hash = hash; | |
361 } | |
362 } | |
363 | |
364 ngx_qsort(points->point, | |
365 points->number, | |
366 sizeof(ngx_stream_upstream_chash_point_t), | |
367 ngx_stream_upstream_chash_cmp_points); | |
368 | |
369 for (i = 0, j = 1; j < points->number; j++) { | |
370 if (points->point[i].hash != points->point[j].hash) { | |
371 points->point[++i] = points->point[j]; | |
372 } | |
373 } | |
374 | |
375 points->number = i + 1; | |
376 | |
377 hcf = ngx_stream_conf_upstream_srv_conf(us, | |
378 ngx_stream_upstream_hash_module); | |
379 hcf->points = points; | |
380 | |
381 return NGX_OK; | |
382 } | |
383 | |
384 | |
385 static int ngx_libc_cdecl | |
386 ngx_stream_upstream_chash_cmp_points(const void *one, const void *two) | |
387 { | |
388 ngx_stream_upstream_chash_point_t *first = | |
389 (ngx_stream_upstream_chash_point_t *) one; | |
390 ngx_stream_upstream_chash_point_t *second = | |
391 (ngx_stream_upstream_chash_point_t *) two; | |
392 | |
393 if (first->hash < second->hash) { | |
394 return -1; | |
395 | |
396 } else if (first->hash > second->hash) { | |
397 return 1; | |
398 | |
399 } else { | |
400 return 0; | |
401 } | |
402 } | |
403 | |
404 | |
405 static ngx_uint_t | |
406 ngx_stream_upstream_find_chash_point(ngx_stream_upstream_chash_points_t *points, | |
407 uint32_t hash) | |
408 { | |
409 ngx_uint_t i, j, k; | |
410 ngx_stream_upstream_chash_point_t *point; | |
411 | |
412 /* find first point >= hash */ | |
413 | |
414 point = &points->point[0]; | |
415 | |
416 i = 0; | |
417 j = points->number; | |
418 | |
419 while (i < j) { | |
420 k = (i + j) / 2; | |
421 | |
422 if (hash > point[k].hash) { | |
423 i = k + 1; | |
424 | |
425 } else if (hash < point[k].hash) { | |
426 j = k; | |
427 | |
428 } else { | |
429 return k; | |
430 } | |
431 } | |
432 | |
433 return i; | |
434 } | |
435 | |
436 | |
437 static ngx_int_t | |
438 ngx_stream_upstream_init_chash_peer(ngx_stream_session_t *s, | |
439 ngx_stream_upstream_srv_conf_t *us) | |
440 { | |
441 uint32_t hash; | |
442 ngx_stream_upstream_hash_srv_conf_t *hcf; | |
443 ngx_stream_upstream_hash_peer_data_t *hp; | |
444 | |
445 if (ngx_stream_upstream_init_hash_peer(s, us) != NGX_OK) { | |
446 return NGX_ERROR; | |
447 } | |
448 | |
449 s->upstream->peer.get = ngx_stream_upstream_get_chash_peer; | |
450 | |
451 hp = s->upstream->peer.data; | |
452 hcf = ngx_stream_conf_upstream_srv_conf(us, | |
453 ngx_stream_upstream_hash_module); | |
454 | |
455 hash = ngx_crc32_long(hp->key.data, hp->key.len); | |
456 | |
457 ngx_stream_upstream_rr_peers_rlock(hp->rrp.peers); | |
458 | |
459 hp->hash = ngx_stream_upstream_find_chash_point(hcf->points, hash); | |
460 | |
461 ngx_stream_upstream_rr_peers_unlock(hp->rrp.peers); | |
462 | |
463 return NGX_OK; | |
464 } | |
465 | |
466 | |
467 static ngx_int_t | |
468 ngx_stream_upstream_get_chash_peer(ngx_peer_connection_t *pc, void *data) | |
469 { | |
470 ngx_stream_upstream_hash_peer_data_t *hp = data; | |
471 | |
472 time_t now; | |
473 intptr_t m; | |
474 ngx_str_t *server; | |
475 ngx_int_t total; | |
476 ngx_uint_t i, n, best_i; | |
477 ngx_stream_upstream_rr_peer_t *peer, *best; | |
478 ngx_stream_upstream_chash_point_t *point; | |
479 ngx_stream_upstream_chash_points_t *points; | |
480 ngx_stream_upstream_hash_srv_conf_t *hcf; | |
481 | |
482 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, pc->log, 0, | |
483 "get consistent hash peer, try: %ui", pc->tries); | |
484 | |
485 ngx_stream_upstream_rr_peers_wlock(hp->rrp.peers); | |
486 | |
487 pc->connection = NULL; | |
488 | |
489 now = ngx_time(); | |
490 hcf = hp->conf; | |
491 | |
492 points = hcf->points; | |
493 point = &points->point[0]; | |
494 | |
495 for ( ;; ) { | |
496 server = point[hp->hash % points->number].server; | |
497 | |
498 ngx_log_debug2(NGX_LOG_DEBUG_STREAM, pc->log, 0, | |
499 "consistent hash peer:%uD, server:\"%V\"", | |
500 hp->hash, server); | |
501 | |
502 best = NULL; | |
503 best_i = 0; | |
504 total = 0; | |
505 | |
506 for (peer = hp->rrp.peers->peer, i = 0; | |
507 peer; | |
508 peer = peer->next, i++) | |
509 { | |
510 | |
511 n = i / (8 * sizeof(uintptr_t)); | |
512 m = (uintptr_t) 1 << i % (8 * sizeof(uintptr_t)); | |
513 | |
514 if (hp->rrp.tried[n] & m) { | |
515 continue; | |
516 } | |
517 | |
518 if (peer->down) { | |
519 continue; | |
520 } | |
521 | |
522 if (peer->server.len != server->len | |
523 || ngx_strncmp(peer->server.data, server->data, server->len) | |
524 != 0) | |
525 { | |
526 continue; | |
527 } | |
528 | |
529 if (peer->max_fails | |
530 && peer->fails >= peer->max_fails | |
531 && now - peer->checked <= peer->fail_timeout) | |
532 { | |
533 continue; | |
534 } | |
535 | |
536 peer->current_weight += peer->effective_weight; | |
537 total += peer->effective_weight; | |
538 | |
539 if (peer->effective_weight < peer->weight) { | |
540 peer->effective_weight++; | |
541 } | |
542 | |
543 if (best == NULL || peer->current_weight > best->current_weight) { | |
544 best = peer; | |
545 best_i = i; | |
546 } | |
547 } | |
548 | |
549 if (best) { | |
550 best->current_weight -= total; | |
551 break; | |
552 } | |
553 | |
554 hp->hash++; | |
555 hp->tries++; | |
556 | |
557 if (hp->tries >= points->number) { | |
558 ngx_stream_upstream_rr_peers_unlock(hp->rrp.peers); | |
559 return NGX_BUSY; | |
560 } | |
561 } | |
562 | |
563 hp->rrp.current = best; | |
564 | |
565 pc->sockaddr = best->sockaddr; | |
566 pc->socklen = best->socklen; | |
567 pc->name = &best->name; | |
568 | |
569 best->conns++; | |
570 | |
571 if (now - best->checked > best->fail_timeout) { | |
572 best->checked = now; | |
573 } | |
574 | |
575 ngx_stream_upstream_rr_peers_unlock(hp->rrp.peers); | |
576 | |
577 n = best_i / (8 * sizeof(uintptr_t)); | |
578 m = (uintptr_t) 1 << best_i % (8 * sizeof(uintptr_t)); | |
579 | |
580 hp->rrp.tried[n] |= m; | |
581 | |
582 return NGX_OK; | |
583 } | |
584 | |
585 | |
586 static void * | |
587 ngx_stream_upstream_hash_create_conf(ngx_conf_t *cf) | |
588 { | |
589 ngx_stream_upstream_hash_srv_conf_t *conf; | |
590 | |
591 conf = ngx_palloc(cf->pool, sizeof(ngx_stream_upstream_hash_srv_conf_t)); | |
592 if (conf == NULL) { | |
593 return NULL; | |
594 } | |
595 | |
596 conf->points = NULL; | |
597 | |
598 return conf; | |
599 } | |
600 | |
601 | |
602 static char * | |
603 ngx_stream_upstream_hash(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
604 { | |
605 ngx_str_t *value; | |
606 ngx_stream_upstream_srv_conf_t *uscf; | |
607 | |
608 value = cf->args->elts; | |
609 | |
610 if (ngx_strcmp(value[1].data, "$remote_addr")) { | |
611 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
612 "unsupported hash key \"%V\", use $remote_addr", | |
613 &value[1]); | |
614 return NGX_CONF_ERROR; | |
615 } | |
616 | |
617 uscf = ngx_stream_conf_get_module_srv_conf(cf, ngx_stream_upstream_module); | |
618 | |
619 if (uscf->peer.init_upstream) { | |
620 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
621 "load balancing method redefined"); | |
622 } | |
623 | |
624 uscf->flags = NGX_STREAM_UPSTREAM_CREATE | |
625 |NGX_STREAM_UPSTREAM_WEIGHT | |
626 |NGX_STREAM_UPSTREAM_MAX_FAILS | |
627 |NGX_STREAM_UPSTREAM_FAIL_TIMEOUT | |
628 |NGX_STREAM_UPSTREAM_DOWN; | |
629 | |
630 if (cf->args->nelts == 2) { | |
631 uscf->peer.init_upstream = ngx_stream_upstream_init_hash; | |
632 | |
633 } else if (ngx_strcmp(value[2].data, "consistent") == 0) { | |
634 uscf->peer.init_upstream = ngx_stream_upstream_init_chash; | |
635 | |
636 } else { | |
637 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
638 "invalid parameter \"%V\"", &value[2]); | |
639 return NGX_CONF_ERROR; | |
640 } | |
641 | |
642 return NGX_CONF_OK; | |
643 } |