-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupsync_max_conns.patch
693 lines (618 loc) · 24.7 KB
/
upsync_max_conns.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
From a7795fee447725ec8c5fccdfa86e268c8064922f Mon Sep 17 00:00:00 2001
From: t-shecha <[email protected]>
Date: Wed, 25 Jul 2018 17:40:29 +0800
Subject: [PATCH 1/4] add conf max_conns
---
.gitignore | 5 ++
src/ngx_http_upsync_module.c | 107 +++++++++++++++++++++++++++++++++--
2 files changed, 106 insertions(+), 6 deletions(-)
create mode 100644 .gitignore
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f14b74d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+################################################################################
+# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。
+################################################################################
+
+/.vs
diff --git a/src/ngx_http_upsync_module.c b/src/ngx_http_upsync_module.c
index 49d8a71..4c711e3 100644
--- a/src/ngx_http_upsync_module.c
+++ b/src/ngx_http_upsync_module.c
@@ -28,6 +28,7 @@ typedef struct {
ngx_int_t weight;
ngx_uint_t max_fails;
time_t fail_timeout;
+ ngx_uint_t max_conns;
unsigned down:1;
unsigned backup:1;
@@ -528,6 +529,7 @@ ngx_http_upsync_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
conf_server->weight = 1;
conf_server->max_fails = 1;
conf_server->fail_timeout = 10;
+ conf_server->max_conns = 0;
return NGX_CONF_OK;
@@ -865,6 +867,7 @@ ngx_http_upsync_add_peers(ngx_cycle_t *cycle,
peer->name.len = server->addrs->name.len;
peer->max_fails = server->max_fails;
peer->fail_timeout = server->fail_timeout;
+ peer->max_conns = server->max_conns;
peer->down = server->down;
peer->weight = server->weight;
peer->effective_weight = server->weight;
@@ -941,7 +944,8 @@ ngx_http_upsync_update_peer(ngx_http_upstream_rr_peers_t *peers,
if (peer->max_fails == upstream_conf->max_fails &&
peer->fail_timeout == upstream_conf->fail_timeout &&
peer->down == upstream_conf->down &&
- peer->weight == upstream_conf->weight) {
+ peer->weight == upstream_conf->weight &&
+ peer->max_conns == upstream_conf->max_conns) {
return;
}
@@ -952,6 +956,7 @@ ngx_http_upsync_update_peer(ngx_http_upstream_rr_peers_t *peers,
peer->weight = upstream_conf->weight;
peer->effective_weight = upstream_conf->weight;
peer->current_weight = 0;
+ peer->max_conns == upstream_conf->max_conns;
w = w + upstream_conf->weight - pw;
@@ -1221,6 +1226,7 @@ ngx_http_upsync_replace_peers(ngx_cycle_t *cycle,
peer->max_fails = tmp_peer[i].max_fails;
peer->fail_timeout = tmp_peer[i].fail_timeout;
+ peer->max_conns = tmp_peer[i].max_conns;
peer->down = tmp_peer[i].down;
peer->weight = tmp_peer[i].weight;
peer->effective_weight = tmp_peer[i].effective_weight;
@@ -1261,7 +1267,7 @@ ngx_http_upsync_consul_parse_json(void *data)
{
u_char *p;
ngx_buf_t *buf;
- ngx_int_t max_fails=2, backup=0, down=0;
+ ngx_int_t max_fails=2, max_conns=0, backup=0, down=0;
ngx_str_t src, dst;
ngx_http_upsync_ctx_t *ctx;
ngx_http_upsync_conf_t *upstream_conf = NULL;
@@ -1333,6 +1339,7 @@ ngx_http_upsync_consul_parse_json(void *data)
upstream_conf->weight = 1;
upstream_conf->max_fails = 2;
upstream_conf->fail_timeout = 10;
+ upstream_conf->max_conns = 0;
upstream_conf->down = 0;
upstream_conf->backup = 0;
@@ -1390,6 +1397,22 @@ ngx_http_upsync_consul_parse_json(void *data)
}
temp1 = NULL;
+ temp1 = cJSON_GetObjectItem(sub_attribute, "max_conns");
+ if (temp1 != NULL) {
+
+ if (temp1->valuestring != NULL) {
+ max_conns = ngx_atoi((u_char *)temp1->valuestring,
+ (size_t)ngx_strlen(temp1->valuestring));
+
+ }
+ else if (temp1->valueint >= 0) {
+ max_conns = temp1->valueint;
+ }
+ }
+ temp1 = NULL;
+
+
+
temp1 = cJSON_GetObjectItem(sub_attribute, "down");
if (temp1 != NULL) {
@@ -1442,6 +1465,17 @@ ngx_http_upsync_consul_parse_json(void *data)
upstream_conf->fail_timeout = 10;
}
+ if (max_conns < 0) {
+ ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
+ "upsync_parse_json: \"max_conns\" value is invalid"
+ ", setting default value 0");
+ }
+ else {
+ upstream_conf->max_conns = (ngx_uint_t)max_conns;
+ }
+
+
+
if (down != 1 && down != 0) {
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
"upsync_parse_json: \"down\" value is invalid"
@@ -1458,7 +1492,7 @@ ngx_http_upsync_consul_parse_json(void *data)
upstream_conf->backup = (ngx_uint_t)backup;
}
- max_fails=2, backup=0, down=0;
+ max_fails=2, backup=0, down=0, max_conns=0;
}
cJSON_Delete(root);
@@ -1541,6 +1575,7 @@ ngx_http_upsync_consul_services_parse_json(void *data)
upstream_conf->weight = 1;
upstream_conf->max_fails = 2;
upstream_conf->fail_timeout = 10;
+ upstream_conf->max_conns = 0;
upstream_conf->down = 0;
upstream_conf->backup = 0;
@@ -1594,6 +1629,21 @@ ngx_http_upsync_consul_services_parse_json(void *data)
upstream_conf->fail_timeout = attr_value;
}
}
+ if (ngx_strncmp(tag, "max_conns=", 10) == 0) {
+ attr_value = ngx_atoi(tag + 10, (size_t)ngx_strlen(tag) - 10);
+
+ if (attr_value == NGX_ERROR || attr_value < 0) {
+ ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
+ "upsync_parse_json: \"max_conns\" value is "
+ "invalid, setting default value 0");
+ continue;
+ }
+ else {
+ upstream_conf->max_conns = attr_value;
+ }
+ }
+
+
if (ngx_strncmp(tag, "down", 4) == 0 && tag[4] == '\0') {
upstream_conf->down = 1;
}
@@ -1686,6 +1736,7 @@ ngx_http_upsync_consul_health_parse_json(void *data)
upstream_conf->weight = 1;
upstream_conf->max_fails = 2;
upstream_conf->fail_timeout = 10;
+ upstream_conf->max_conns = 2;
upstream_conf->down = 0;
upstream_conf->backup = 0;
@@ -1756,6 +1807,20 @@ ngx_http_upsync_consul_health_parse_json(void *data)
upstream_conf->fail_timeout = attr_value;
}
}
+ if (ngx_strncmp(tag, "max_conns=", 10) == 0) {
+ attr_value = ngx_atoi(tag + 10, (size_t)ngx_strlen(tag) - 10);
+
+ if (attr_value == NGX_ERROR || attr_value < 0) {
+ ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
+ "upsync_parse_json: \"max_conns\" value is "
+ "invalid, setting default value 0");
+ continue;
+ }
+ else {
+ upstream_conf->max_conns = attr_value;
+ }
+ }
+
if (ngx_strncmp(tag, "down", 4) == 0 && tag[4] == '\0') {
upstream_conf->down = 1;
}
@@ -1777,7 +1842,7 @@ ngx_http_upsync_etcd_parse_json(void *data)
{
u_char *p;
ngx_buf_t *buf;
- ngx_int_t max_fails=2, backup=0, down=0;
+ ngx_int_t max_fails=2, max_conns=0, backup=0, down=0;
ngx_http_upsync_ctx_t *ctx;
ngx_http_upsync_conf_t *upstream_conf = NULL;
ngx_http_upsync_server_t *upsync_server = data;
@@ -1868,6 +1933,7 @@ ngx_http_upsync_etcd_parse_json(void *data)
upstream_conf->weight = 1;
upstream_conf->max_fails = 2;
upstream_conf->fail_timeout = 10;
+ upstream_conf->max_conns = 2;
upstream_conf->down = 0;
upstream_conf->backup = 0;
@@ -1923,6 +1989,21 @@ ngx_http_upsync_etcd_parse_json(void *data)
}
temp1 = NULL;
+ temp1 = cJSON_GetObjectItem(sub_attribute, "max_conns");
+ if (temp1 != NULL) {
+
+ if (temp1->valuestring != NULL) {
+ max_conns = ngx_atoi((u_char *)temp1->valuestring,
+ (size_t)ngx_strlen(temp1->valuestring));
+
+ }
+ else if (temp1->valueint >= 0) {
+ max_conns = temp1->valueint;
+ }
+ }
+ temp1 = NULL;
+
+
temp1 = cJSON_GetObjectItem(sub_attribute, "down");
if (temp1 != NULL) {
@@ -1975,6 +2056,15 @@ ngx_http_upsync_etcd_parse_json(void *data)
upstream_conf->fail_timeout = 10;
}
+ if (max_conns < 0) {
+ ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
+ "upsync_parse_json: \"max_conns\" value is invalid"
+ ", setting default value 2");
+ }
+ else {
+ upstream_conf->max_conns = (ngx_uint_t)max_conns;
+ }
+
if (down != 1 && down != 0) {
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
"upsync_parse_json: \"down\" value is invalid"
@@ -1991,7 +2081,7 @@ ngx_http_upsync_etcd_parse_json(void *data)
upstream_conf->backup = (ngx_uint_t)backup;
}
- max_fails=2, backup=0, down=0;
+ max_fails=2, backup=0, down=0, max_conns=2;
}
cJSON_Delete(root);
@@ -2095,6 +2185,7 @@ ngx_http_upsync_servers(ngx_cycle_t *cycle,
server->weight = conf->weight;
server->max_fails = conf->max_fails;
server->fail_timeout = conf->fail_timeout;
+ server->max_conns = conf->max_conns;
}
} else {
@@ -2116,6 +2207,7 @@ ngx_http_upsync_servers(ngx_cycle_t *cycle,
server->weight = conf->weight;
server->max_fails = conf->max_fails;
server->fail_timeout = conf->fail_timeout;
+ server->max_conns = conf->max_conns;
}
}
@@ -3051,7 +3143,8 @@ ngx_http_upsync_dump_server(ngx_http_upsync_server_t *upsync_server)
" max_fails=%d", peer->max_fails);
b->last = ngx_snprintf(b->last, b->end - b->last,
" fail_timeout=%ds", peer->fail_timeout);
-
+ b->last = ngx_snprintf(b->last, b->end - b->last,
+ " max_conns=%d", peer->max_conns);
if (peer->down) {
b->last = ngx_snprintf(b->last, b->end - b->last, " down");
}
@@ -3908,6 +4001,8 @@ ngx_http_upsync_show_upstream(ngx_http_upstream_srv_conf_t *uscf, ngx_buf_t *b)
" max_fails=%d", peer->max_fails);
b->last = ngx_snprintf(b->last, b->end - b->last,
" fail_timeout=%ds", peer->fail_timeout);
+ b->last = ngx_snprintf(b->last, b->end - b->last,
+ " max_conns=%d", peer->max_conns);
if (peer->down) {
b->last = ngx_snprintf(b->last, b->end - b->last, " down");
From 9703bece03d519ef2338005be246e7a1ac67560f Mon Sep 17 00:00:00 2001
From: t-shecha <[email protected]>
Date: Wed, 25 Jul 2018 17:50:09 +0800
Subject: [PATCH 2/4] dev
---
src/ngx_http_upsync_module.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/ngx_http_upsync_module.c b/src/ngx_http_upsync_module.c
index 4c711e3..f6531e0 100644
--- a/src/ngx_http_upsync_module.c
+++ b/src/ngx_http_upsync_module.c
@@ -956,7 +956,7 @@ ngx_http_upsync_update_peer(ngx_http_upstream_rr_peers_t *peers,
peer->weight = upstream_conf->weight;
peer->effective_weight = upstream_conf->weight;
peer->current_weight = 0;
- peer->max_conns == upstream_conf->max_conns;
+ peer->max_conns = upstream_conf->max_conns;
w = w + upstream_conf->weight - pw;
From bfaace6a0c85d076136ba2c58c76b7a190c384da Mon Sep 17 00:00:00 2001
From: t-shecha <[email protected]>
Date: Wed, 25 Jul 2018 18:42:35 +0800
Subject: [PATCH 3/4] tab ->4 space
---
src/ngx_http_upsync_module.c | 164 +++++++++++++++++------------------
1 file changed, 82 insertions(+), 82 deletions(-)
diff --git a/src/ngx_http_upsync_module.c b/src/ngx_http_upsync_module.c
index f6531e0..ed4397f 100644
--- a/src/ngx_http_upsync_module.c
+++ b/src/ngx_http_upsync_module.c
@@ -28,7 +28,7 @@ typedef struct {
ngx_int_t weight;
ngx_uint_t max_fails;
time_t fail_timeout;
- ngx_uint_t max_conns;
+ ngx_uint_t max_conns;
unsigned down:1;
unsigned backup:1;
@@ -529,7 +529,7 @@ ngx_http_upsync_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
conf_server->weight = 1;
conf_server->max_fails = 1;
conf_server->fail_timeout = 10;
- conf_server->max_conns = 0;
+ conf_server->max_conns = 0;
return NGX_CONF_OK;
@@ -867,7 +867,7 @@ ngx_http_upsync_add_peers(ngx_cycle_t *cycle,
peer->name.len = server->addrs->name.len;
peer->max_fails = server->max_fails;
peer->fail_timeout = server->fail_timeout;
- peer->max_conns = server->max_conns;
+ peer->max_conns = server->max_conns;
peer->down = server->down;
peer->weight = server->weight;
peer->effective_weight = server->weight;
@@ -945,7 +945,7 @@ ngx_http_upsync_update_peer(ngx_http_upstream_rr_peers_t *peers,
peer->fail_timeout == upstream_conf->fail_timeout &&
peer->down == upstream_conf->down &&
peer->weight == upstream_conf->weight &&
- peer->max_conns == upstream_conf->max_conns) {
+ peer->max_conns == upstream_conf->max_conns) {
return;
}
@@ -956,7 +956,7 @@ ngx_http_upsync_update_peer(ngx_http_upstream_rr_peers_t *peers,
peer->weight = upstream_conf->weight;
peer->effective_weight = upstream_conf->weight;
peer->current_weight = 0;
- peer->max_conns = upstream_conf->max_conns;
+ peer->max_conns = upstream_conf->max_conns;
w = w + upstream_conf->weight - pw;
@@ -1226,7 +1226,7 @@ ngx_http_upsync_replace_peers(ngx_cycle_t *cycle,
peer->max_fails = tmp_peer[i].max_fails;
peer->fail_timeout = tmp_peer[i].fail_timeout;
- peer->max_conns = tmp_peer[i].max_conns;
+ peer->max_conns = tmp_peer[i].max_conns;
peer->down = tmp_peer[i].down;
peer->weight = tmp_peer[i].weight;
peer->effective_weight = tmp_peer[i].effective_weight;
@@ -1339,7 +1339,7 @@ ngx_http_upsync_consul_parse_json(void *data)
upstream_conf->weight = 1;
upstream_conf->max_fails = 2;
upstream_conf->fail_timeout = 10;
- upstream_conf->max_conns = 0;
+ upstream_conf->max_conns = 0;
upstream_conf->down = 0;
upstream_conf->backup = 0;
@@ -1397,19 +1397,19 @@ ngx_http_upsync_consul_parse_json(void *data)
}
temp1 = NULL;
- temp1 = cJSON_GetObjectItem(sub_attribute, "max_conns");
- if (temp1 != NULL) {
+ temp1 = cJSON_GetObjectItem(sub_attribute, "max_conns");
+ if (temp1 != NULL) {
- if (temp1->valuestring != NULL) {
- max_conns = ngx_atoi((u_char *)temp1->valuestring,
- (size_t)ngx_strlen(temp1->valuestring));
+ if (temp1->valuestring != NULL) {
+ max_conns = ngx_atoi((u_char *)temp1->valuestring,
+ (size_t)ngx_strlen(temp1->valuestring));
- }
- else if (temp1->valueint >= 0) {
- max_conns = temp1->valueint;
- }
- }
- temp1 = NULL;
+ }
+ else if (temp1->valueint >= 0) {
+ max_conns = temp1->valueint;
+ }
+ }
+ temp1 = NULL;
@@ -1465,14 +1465,14 @@ ngx_http_upsync_consul_parse_json(void *data)
upstream_conf->fail_timeout = 10;
}
- if (max_conns < 0) {
- ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
- "upsync_parse_json: \"max_conns\" value is invalid"
- ", setting default value 0");
- }
- else {
- upstream_conf->max_conns = (ngx_uint_t)max_conns;
- }
+ if (max_conns < 0) {
+ ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
+ "upsync_parse_json: \"max_conns\" value is invalid"
+ ", setting default value 0");
+ }
+ else {
+ upstream_conf->max_conns = (ngx_uint_t)max_conns;
+ }
@@ -1575,7 +1575,7 @@ ngx_http_upsync_consul_services_parse_json(void *data)
upstream_conf->weight = 1;
upstream_conf->max_fails = 2;
upstream_conf->fail_timeout = 10;
- upstream_conf->max_conns = 0;
+ upstream_conf->max_conns = 0;
upstream_conf->down = 0;
upstream_conf->backup = 0;
@@ -1629,19 +1629,19 @@ ngx_http_upsync_consul_services_parse_json(void *data)
upstream_conf->fail_timeout = attr_value;
}
}
- if (ngx_strncmp(tag, "max_conns=", 10) == 0) {
- attr_value = ngx_atoi(tag + 10, (size_t)ngx_strlen(tag) - 10);
+ if (ngx_strncmp(tag, "max_conns=", 10) == 0) {
+ attr_value = ngx_atoi(tag + 10, (size_t)ngx_strlen(tag) - 10);
- if (attr_value == NGX_ERROR || attr_value < 0) {
- ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
- "upsync_parse_json: \"max_conns\" value is "
- "invalid, setting default value 0");
- continue;
- }
- else {
- upstream_conf->max_conns = attr_value;
- }
- }
+ if (attr_value == NGX_ERROR || attr_value < 0) {
+ ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
+ "upsync_parse_json: \"max_conns\" value is "
+ "invalid, setting default value 0");
+ continue;
+ }
+ else {
+ upstream_conf->max_conns = attr_value;
+ }
+ }
if (ngx_strncmp(tag, "down", 4) == 0 && tag[4] == '\0') {
@@ -1736,7 +1736,7 @@ ngx_http_upsync_consul_health_parse_json(void *data)
upstream_conf->weight = 1;
upstream_conf->max_fails = 2;
upstream_conf->fail_timeout = 10;
- upstream_conf->max_conns = 2;
+ upstream_conf->max_conns = 2;
upstream_conf->down = 0;
upstream_conf->backup = 0;
@@ -1807,19 +1807,19 @@ ngx_http_upsync_consul_health_parse_json(void *data)
upstream_conf->fail_timeout = attr_value;
}
}
- if (ngx_strncmp(tag, "max_conns=", 10) == 0) {
- attr_value = ngx_atoi(tag + 10, (size_t)ngx_strlen(tag) - 10);
-
- if (attr_value == NGX_ERROR || attr_value < 0) {
- ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
- "upsync_parse_json: \"max_conns\" value is "
- "invalid, setting default value 0");
- continue;
- }
- else {
- upstream_conf->max_conns = attr_value;
- }
- }
+ if (ngx_strncmp(tag, "max_conns=", 10) == 0) {
+ attr_value = ngx_atoi(tag + 10, (size_t)ngx_strlen(tag) - 10);
+
+ if (attr_value == NGX_ERROR || attr_value < 0) {
+ ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
+ "upsync_parse_json: \"max_conns\" value is "
+ "invalid, setting default value 0");
+ continue;
+ }
+ else {
+ upstream_conf->max_conns = attr_value;
+ }
+ }
if (ngx_strncmp(tag, "down", 4) == 0 && tag[4] == '\0') {
upstream_conf->down = 1;
@@ -1933,7 +1933,7 @@ ngx_http_upsync_etcd_parse_json(void *data)
upstream_conf->weight = 1;
upstream_conf->max_fails = 2;
upstream_conf->fail_timeout = 10;
- upstream_conf->max_conns = 2;
+ upstream_conf->max_conns = 2;
upstream_conf->down = 0;
upstream_conf->backup = 0;
@@ -1989,19 +1989,19 @@ ngx_http_upsync_etcd_parse_json(void *data)
}
temp1 = NULL;
- temp1 = cJSON_GetObjectItem(sub_attribute, "max_conns");
- if (temp1 != NULL) {
+ temp1 = cJSON_GetObjectItem(sub_attribute, "max_conns");
+ if (temp1 != NULL) {
- if (temp1->valuestring != NULL) {
- max_conns = ngx_atoi((u_char *)temp1->valuestring,
- (size_t)ngx_strlen(temp1->valuestring));
+ if (temp1->valuestring != NULL) {
+ max_conns = ngx_atoi((u_char *)temp1->valuestring,
+ (size_t)ngx_strlen(temp1->valuestring));
- }
- else if (temp1->valueint >= 0) {
- max_conns = temp1->valueint;
- }
- }
- temp1 = NULL;
+ }
+ else if (temp1->valueint >= 0) {
+ max_conns = temp1->valueint;
+ }
+ }
+ temp1 = NULL;
temp1 = cJSON_GetObjectItem(sub_attribute, "down");
@@ -2056,14 +2056,14 @@ ngx_http_upsync_etcd_parse_json(void *data)
upstream_conf->fail_timeout = 10;
}
- if (max_conns < 0) {
- ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
- "upsync_parse_json: \"max_conns\" value is invalid"
- ", setting default value 2");
- }
- else {
- upstream_conf->max_conns = (ngx_uint_t)max_conns;
- }
+ if (max_conns < 0) {
+ ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
+ "upsync_parse_json: \"max_conns\" value is invalid"
+ ", setting default value 2");
+ }
+ else {
+ upstream_conf->max_conns = (ngx_uint_t)max_conns;
+ }
if (down != 1 && down != 0) {
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0,
@@ -2185,7 +2185,7 @@ ngx_http_upsync_servers(ngx_cycle_t *cycle,
server->weight = conf->weight;
server->max_fails = conf->max_fails;
server->fail_timeout = conf->fail_timeout;
- server->max_conns = conf->max_conns;
+ server->max_conns = conf->max_conns;
}
} else {
@@ -2207,7 +2207,7 @@ ngx_http_upsync_servers(ngx_cycle_t *cycle,
server->weight = conf->weight;
server->max_fails = conf->max_fails;
server->fail_timeout = conf->fail_timeout;
- server->max_conns = conf->max_conns;
+ server->max_conns = conf->max_conns;
}
}
@@ -3143,8 +3143,8 @@ ngx_http_upsync_dump_server(ngx_http_upsync_server_t *upsync_server)
" max_fails=%d", peer->max_fails);
b->last = ngx_snprintf(b->last, b->end - b->last,
" fail_timeout=%ds", peer->fail_timeout);
- b->last = ngx_snprintf(b->last, b->end - b->last,
- " max_conns=%d", peer->max_conns);
+ b->last = ngx_snprintf(b->last, b->end - b->last,
+ " max_conns=%d", peer->max_conns);
if (peer->down) {
b->last = ngx_snprintf(b->last, b->end - b->last, " down");
}
@@ -4001,8 +4001,8 @@ ngx_http_upsync_show_upstream(ngx_http_upstream_srv_conf_t *uscf, ngx_buf_t *b)
" max_fails=%d", peer->max_fails);
b->last = ngx_snprintf(b->last, b->end - b->last,
" fail_timeout=%ds", peer->fail_timeout);
- b->last = ngx_snprintf(b->last, b->end - b->last,
- " max_conns=%d", peer->max_conns);
+ b->last = ngx_snprintf(b->last, b->end - b->last,
+ " max_conns=%d", peer->max_conns);
if (peer->down) {
b->last = ngx_snprintf(b->last, b->end - b->last, " down");
@@ -4064,12 +4064,12 @@ ngx_http_upsync_show(ngx_http_request_t *r)
goto end;
}
-
- for (i = 0; i < umcf->upstreams.nelts; i++) {
+
+ for (i = 0; i < umcf->upstreams.nelts; i++) {
ngx_http_upsync_show_upstream(uscfp[i], b);
b->last = ngx_snprintf(b->last, b->end - b->last, "\n");
}
-
+
goto end;
}
From 43a77e657bb36786622e18d74634e13716b4deca Mon Sep 17 00:00:00 2001
From: t-shecha <[email protected]>
Date: Wed, 25 Jul 2018 19:20:01 +0800
Subject: [PATCH 4/4] add support for max_conns parameter
---
.gitignore | 5 -----
src/ngx_http_upsync_module.c | 2 +-
2 files changed, 1 insertion(+), 6 deletions(-)
delete mode 100644 .gitignore
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index f14b74d..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,5 +0,0 @@
-################################################################################
-# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。
-################################################################################
-
-/.vs
diff --git a/src/ngx_http_upsync_module.c b/src/ngx_http_upsync_module.c
index ed4397f..8f84a33 100644
--- a/src/ngx_http_upsync_module.c
+++ b/src/ngx_http_upsync_module.c
@@ -28,7 +28,7 @@ typedef struct {
ngx_int_t weight;
ngx_uint_t max_fails;
time_t fail_timeout;
- ngx_uint_t max_conns;
+ ngx_uint_t max_conns;
unsigned down:1;
unsigned backup:1;