23
23
24
24
#define NGX_MAX_VALUE 65535
25
25
26
- #define NGX_DELAY_DELETE 150 * 1000
26
+ #define NGX_DELAY_DELETE 75 * 1000
27
27
28
28
#define NGX_ADD 0
29
29
#define NGX_DEL 1
30
30
31
- #define NGX_BLOCK 1024
32
- #define NGX_PAGESIZE 4 * 1024
33
- #define NGX_PAGE_COUNT 1024
34
-
35
- #define NGX_BACKEND_NUMBER 35 /* everypage(4K) can store backend number is 35 approximately*/
31
+ #define NGX_PAGE_SIZE 4 * 1024
32
+ #define NGX_PAGE_NUMBER 1024
36
33
37
34
#define NGX_HTTP_RETRY_TIMES 3
38
35
#define NGX_HTTP_SOCKET_TIMEOUT 1
@@ -84,8 +81,6 @@ typedef struct {
84
81
ngx_msec_t update_timeout ;
85
82
ngx_msec_t update_interval ;
86
83
87
- ngx_msec_t delay_delete ;
88
-
89
84
ngx_uint_t strong_dependency ;
90
85
91
86
ngx_str_t update_send ;
@@ -152,7 +147,7 @@ typedef struct {
152
147
153
148
enum { NONE = 0 , FIELD , VALUE } last_header ;
154
149
155
- u_char http_body [NGX_PAGESIZE * NGX_BLOCK ];
150
+ u_char http_body [NGX_PAGE_SIZE * NGX_PAGE_NUMBER ];
156
151
} ngx_http_state ;
157
152
158
153
@@ -279,7 +274,7 @@ static void ngx_http_dynamic_update_upstream_del_delay_delete(ngx_event_t *event
279
274
static ngx_int_t ngx_http_dynamic_update_upstream_need_exit ();
280
275
static void ngx_http_dynamic_update_upstream_clear_all_events ();
281
276
282
- static ngx_int_t ngx_http_dynamic_update_upstream_get_all (ngx_cycle_t * cycle ,
277
+ static ngx_int_t ngx_http_dynamic_update_upstream_get_upstream (ngx_cycle_t * cycle ,
283
278
ngx_http_dynamic_update_upstream_server_t * conf_server , char * * conf_value );
284
279
static ngx_http_conf_client * ngx_http_create_client (ngx_cycle_t * cycle ,
285
280
ngx_http_dynamic_update_upstream_server_t * conf_server );
@@ -377,7 +372,6 @@ ngx_http_dynamic_update_upstream_consul_server(ngx_conf_t *cf, ngx_command_t *cm
377
372
{
378
373
u_char * p = NULL ;
379
374
time_t update_timeout = 0 , update_interval = 0 ;
380
- time_t delay_delete = 0 ;
381
375
ngx_str_t * value , s ;
382
376
ngx_url_t u ;
383
377
ngx_uint_t i , strong_dependency = 0 ;
@@ -420,20 +414,6 @@ ngx_http_dynamic_update_upstream_consul_server(ngx_conf_t *cf, ngx_command_t *cm
420
414
continue ;
421
415
}
422
416
423
- if (ngx_strncmp (value [i ].data , "delay_delete=" , 13 ) == 0 ) {
424
-
425
- s .len = value [i ].len - 13 ;
426
- s .data = & value [i ].data [13 ];
427
-
428
- delay_delete = ngx_parse_time (& s , 0 );
429
-
430
- if (delay_delete == (time_t ) NGX_ERROR ) {
431
- goto invalid ;
432
- }
433
-
434
- continue ;
435
- }
436
-
437
417
if (ngx_strncmp (value [i ].data , "strong_dependency=" , 18 ) == 0 ) {
438
418
s .len = value [i ].len - 18 ;
439
419
s .data = value [i ].data + 18 ;
@@ -464,10 +444,6 @@ ngx_http_dynamic_update_upstream_consul_server(ngx_conf_t *cf, ngx_command_t *cm
464
444
duscf -> update_timeout = update_timeout ;
465
445
}
466
446
467
- if (delay_delete != 0 ) {
468
- duscf -> delay_delete = delay_delete ;
469
- }
470
-
471
447
if (strong_dependency != 0 ) {
472
448
duscf -> strong_dependency = strong_dependency ;
473
449
}
@@ -930,19 +906,13 @@ ngx_http_dynamic_update_upstream_del_server(ngx_cycle_t *cycle,
930
906
struct sockaddr_in * sin ;
931
907
932
908
ctx = & conf_server -> ctx ;
909
+ pool = ctx -> pool ;
933
910
934
911
ngx_memzero (& us , sizeof (ngx_http_upstream_server_t ));
935
912
936
- pool = ngx_create_pool (ngx_pagesize , cycle -> log );
937
- if (pool == NULL ) {
938
- ngx_log_error (NGX_LOG_ERR , cycle -> log , 0 ,
939
- "dynamic_update_upstream_del_server: no enough memory" );
940
- return NGX_ERROR ;
941
- }
942
-
943
913
addrs = ngx_pcalloc (pool , ctx -> del_upstream .nelts * sizeof (ngx_addr_t ));
944
914
if (addrs == NULL ) {
945
- goto invalid ;
915
+ return NGX_ERROR ;
946
916
}
947
917
948
918
for (i = 0 , j = 0 ; i < ctx -> del_upstream .nelts ; i ++ , j ++ ) {
@@ -969,7 +939,7 @@ ngx_http_dynamic_update_upstream_del_server(ngx_cycle_t *cycle,
969
939
970
940
sin = ngx_pcalloc (pool , sizeof (struct sockaddr_in ));
971
941
if (sin == NULL ) {
972
- goto invalid ;
942
+ return NGX_ERROR ;
973
943
}
974
944
975
945
sin -> sin_family = AF_INET ;
@@ -988,7 +958,7 @@ ngx_http_dynamic_update_upstream_del_server(ngx_cycle_t *cycle,
988
958
989
959
pp = ngx_pcalloc (pool , last - p );
990
960
if (pp == NULL ) {
991
- goto invalid ;
961
+ return NGX_ERROR ;
992
962
}
993
963
994
964
addrs [j ].name .len = ngx_sprintf (pp , "%s" , p ) - pp ;
@@ -1004,18 +974,11 @@ ngx_http_dynamic_update_upstream_del_server(ngx_cycle_t *cycle,
1004
974
if (us .naddrs > 0 ) {
1005
975
if (ngx_http_dynamic_update_upstream_del_peer (cycle , & us ,
1006
976
conf_server ) != NGX_OK ) {
1007
- goto invalid ;
977
+ return NGX_ERROR ;
1008
978
}
1009
979
}
1010
980
1011
- ngx_destroy_pool (pool );
1012
-
1013
981
return NGX_OK ;
1014
-
1015
- invalid :
1016
- ngx_destroy_pool (pool );
1017
-
1018
- return NGX_ERROR ;
1019
982
}
1020
983
1021
984
@@ -1542,8 +1505,6 @@ ngx_http_dynamic_update_upstream_create_srv_conf(ngx_conf_t *cf)
1542
1505
duscf -> update_timeout = NGX_CONF_UNSET_MSEC ;
1543
1506
duscf -> update_interval = NGX_CONF_UNSET_MSEC ;
1544
1507
1545
- duscf -> delay_delete = NGX_CONF_UNSET_MSEC ;
1546
-
1547
1508
duscf -> strong_dependency = NGX_CONF_UNSET_UINT ;
1548
1509
1549
1510
duscf -> conf_file = NGX_CONF_UNSET_PTR ;
@@ -1589,10 +1550,6 @@ ngx_http_dynamic_update_upstream_init_srv_conf(ngx_conf_t *cf, void *conf, ngx_u
1589
1550
duscf -> update_interval = 1000 * 5 ;
1590
1551
}
1591
1552
1592
- if (duscf -> delay_delete == NGX_CONF_UNSET_MSEC ) {
1593
- duscf -> delay_delete = 1000 * 75 ;
1594
- }
1595
-
1596
1553
if (duscf -> strong_dependency == NGX_CONF_UNSET_UINT ) {
1597
1554
duscf -> strong_dependency = 0 ;
1598
1555
}
@@ -1742,7 +1699,7 @@ ngx_http_dynamic_update_upstream_init_process(ngx_cycle_t *cycle)
1742
1699
1743
1700
ngx_http_dynamic_update_upstream_init_peers (cycle , & conf_server [i ]);
1744
1701
1745
- pool = ngx_create_pool (NGX_PAGE_COUNT * ngx_pagesize , ngx_cycle -> log );
1702
+ pool = ngx_create_pool (NGX_DEFAULT_POOL_SIZE , ngx_cycle -> log );
1746
1703
if (pool == NULL ) {
1747
1704
ngx_log_error (NGX_LOG_ERR , cycle -> log , 0 ,
1748
1705
"dynamic_update_upstream_init_process: recv no enough memory" );
@@ -1751,7 +1708,7 @@ ngx_http_dynamic_update_upstream_init_process(ngx_cycle_t *cycle)
1751
1708
ctx -> pool = pool ;
1752
1709
1753
1710
for (j = 0 ; j < NGX_HTTP_RETRY_TIMES ; j ++ ) {
1754
- status = ngx_http_dynamic_update_upstream_get_all (cycle ,
1711
+ status = ngx_http_dynamic_update_upstream_get_upstream (cycle ,
1755
1712
& conf_server [i ], & conf_value );
1756
1713
if (status == NGX_OK ) {
1757
1714
break ;
@@ -1774,7 +1731,7 @@ ngx_http_dynamic_update_upstream_init_process(ngx_cycle_t *cycle)
1774
1731
1775
1732
ctx -> recv .pos = (u_char * )conf_value ;
1776
1733
ctx -> recv .last = (u_char * )(conf_value + ngx_strlen (conf_value ));
1777
- ctx -> recv .end = ( u_char * )( conf_value + ngx_pagesize ) ;
1734
+ ctx -> recv .end = ctx -> recv . last ;
1778
1735
1779
1736
if (ngx_http_parser_init () == NGX_ERROR ) {
1780
1737
ngx_destroy_pool (pool );
@@ -2055,8 +2012,8 @@ ngx_http_dynamic_update_upstream_send_handler(ngx_event_t *event)
2055
2012
2056
2013
ctx = & peer -> ctx ;
2057
2014
2058
- u_char request [NGX_BLOCK ];
2059
- ngx_memzero (request , NGX_BLOCK );
2015
+ u_char request [ngx_pagesize ];
2016
+ ngx_memzero (request , ngx_pagesize );
2060
2017
ngx_sprintf (request , "GET %V?recurse&index=%d HTTP/1.0\r\nHost: %V\r\nAccept: */*\r\n\r\n" ,
2061
2018
& conf -> update_send , peer -> index , & conf -> us .name );
2062
2019
@@ -2125,7 +2082,7 @@ ngx_http_dynamic_update_upstream_recv_handler(ngx_event_t *event)
2125
2082
ctx = & peer -> ctx ;
2126
2083
2127
2084
if (ctx -> pool == NULL ) {
2128
- pool = ngx_create_pool (NGX_PAGE_COUNT * ngx_pagesize , ngx_cycle -> log );
2085
+ pool = ngx_create_pool (NGX_DEFAULT_POOL_SIZE , ngx_cycle -> log );
2129
2086
2130
2087
if (pool == NULL ) {
2131
2088
ngx_log_error (NGX_LOG_ERR , event -> log , 0 ,
@@ -2226,7 +2183,7 @@ static ngx_int_t
2226
2183
ngx_http_dynamic_update_upstream_dump_conf (ngx_http_dynamic_update_upstream_server_t * conf_server )
2227
2184
{
2228
2185
ngx_buf_t * b = NULL ;
2229
- ngx_uint_t i , page_numbers ;
2186
+ ngx_uint_t i ;
2230
2187
ngx_http_upstream_rr_peers_t * peers = NULL ;
2231
2188
ngx_http_upstream_srv_conf_t * uscf = NULL ;
2232
2189
ngx_http_dynamic_update_upstream_srv_conf_t * duscf = NULL ;
@@ -2254,9 +2211,8 @@ ngx_http_dynamic_update_upstream_dump_conf(ngx_http_dynamic_update_upstream_serv
2254
2211
2255
2212
return NGX_ERROR ;
2256
2213
}
2257
- page_numbers = peers -> number / NGX_BACKEND_NUMBER + 1 ;
2258
2214
2259
- b = ngx_create_temp_buf (conf_server -> ctx .pool , page_numbers * ngx_pagesize );
2215
+ b = ngx_create_temp_buf (conf_server -> ctx .pool , NGX_PAGE_SIZE * NGX_PAGE_NUMBER );
2260
2216
if (b == NULL ) {
2261
2217
ngx_log_error (NGX_LOG_ERR , conf_server -> ctx .pool -> log , 0 ,
2262
2218
"dynamic_update_upstream_dump_conf: dump failed %V" , & uscf -> host );
@@ -2363,7 +2319,7 @@ ngx_http_dynamic_update_upstream_init_consul(ngx_event_t *event)
2363
2319
ctx = & peer -> ctx ;
2364
2320
if (ctx -> pool == NULL ) {
2365
2321
2366
- pool = ngx_create_pool (NGX_PAGE_COUNT * ngx_pagesize , ngx_cycle -> log );
2322
+ pool = ngx_create_pool (NGX_DEFAULT_POOL_SIZE , ngx_cycle -> log );
2367
2323
if (pool == NULL ) {
2368
2324
ngx_log_error (NGX_LOG_ERR , event -> log , 0 ,
2369
2325
"dynamic_update_upstream_init_consul: creat pool, no enough memory" );
@@ -2464,9 +2420,6 @@ ngx_http_dynamic_update_upstream_event_init(ngx_http_upstream_rr_peers_t *tmp_pe
2464
2420
{
2465
2421
ngx_time_t * tp ;
2466
2422
ngx_delay_event_t * delay_event ;
2467
- ngx_http_dynamic_update_upstream_srv_conf_t * conf ;
2468
-
2469
- conf = conf_server -> conf ;
2470
2423
2471
2424
delay_event = ngx_calloc (sizeof (* delay_event ), ngx_cycle -> log );
2472
2425
if (delay_event == NULL ) {
@@ -2497,7 +2450,7 @@ ngx_http_dynamic_update_upstream_event_init(ngx_http_upstream_rr_peers_t *tmp_pe
2497
2450
}
2498
2451
2499
2452
delay_event -> data = tmp_peers ;
2500
- ngx_add_timer (& delay_event -> delay_delete_ev , conf -> delay_delete );
2453
+ ngx_add_timer (& delay_event -> delay_delete_ev , NGX_DELAY_DELETE );
2501
2454
2502
2455
return ;
2503
2456
}
@@ -2721,7 +2674,7 @@ static ngx_int_t
2721
2674
ngx_http_parser_init ()
2722
2675
{
2723
2676
ngx_memzero (state .status , 3 );
2724
- ngx_memzero (state .http_body , NGX_PAGESIZE * NGX_BLOCK );
2677
+ ngx_memzero (state .http_body , NGX_PAGE_SIZE * NGX_PAGE_NUMBER );
2725
2678
ngx_memzero (state .headers , NGX_MAX_HEADERS * 2 * NGX_MAX_ELEMENT_SIZE );
2726
2679
2727
2680
state .num_headers = 0 ;
@@ -2988,21 +2941,21 @@ ngx_http_dynamic_update_upstream_clear_all_events()
2988
2941
2989
2942
2990
2943
static ngx_int_t
2991
- ngx_http_dynamic_update_upstream_get_all (ngx_cycle_t * cycle ,
2944
+ ngx_http_dynamic_update_upstream_get_upstream (ngx_cycle_t * cycle ,
2992
2945
ngx_http_dynamic_update_upstream_server_t * conf_server , char * * conf_value )
2993
2946
{
2994
2947
ngx_http_conf_client * client = ngx_http_create_client (cycle , conf_server );
2995
2948
2996
2949
if (client == NULL ) {
2997
2950
ngx_log_error (NGX_LOG_ERR , cycle -> log , 0 ,
2998
- "dynamic_update_upstream_get_all : http client create error" );
2951
+ "dynamic_update_upstream_get_upstream : http client create error" );
2999
2952
return NGX_ERROR ;
3000
2953
}
3001
2954
3002
2955
ngx_int_t status = ngx_http_client_conn (client );
3003
2956
if (status != NGX_OK ) {
3004
2957
ngx_log_error (NGX_LOG_ERR , cycle -> log , 0 ,
3005
- "dynamic_update_upstream_get_all : http client conn error" );
2958
+ "dynamic_update_upstream_get_upstream : http client conn error" );
3006
2959
3007
2960
ngx_http_client_destroy (client );
3008
2961
return NGX_ERROR ;
@@ -3014,7 +2967,7 @@ ngx_http_dynamic_update_upstream_get_all(ngx_cycle_t *cycle,
3014
2967
3015
2968
if (ngx_http_client_recv (client , & response , 0 ) <= 0 ) {
3016
2969
ngx_log_error (NGX_LOG_ERR , cycle -> log , 0 ,
3017
- "dynamic_update_upstream_get_all : http client recv fail" );
2970
+ "dynamic_update_upstream_get_upstream : http client recv fail" );
3018
2971
3019
2972
if (response != NULL ) {
3020
2973
ngx_free (response );
@@ -3115,8 +3068,8 @@ ngx_http_client_send(ngx_http_conf_client *client,
3115
3068
3116
3069
conf = conf_server -> conf ;
3117
3070
3118
- u_char request [NGX_BLOCK ];
3119
- ngx_memzero (request , NGX_BLOCK );
3071
+ u_char request [ngx_pagesize ];
3072
+ ngx_memzero (request , ngx_pagesize );
3120
3073
ngx_sprintf (request , "GET %V?recurse HTTP/1.0\r\nHost: %V\r\nAccept: */*\r\n\r\n" ,
3121
3074
& conf -> update_send , & conf -> us .name );
3122
3075
@@ -3235,7 +3188,7 @@ ngx_http_dynamic_update_upstream_show(ngx_http_request_t *r)
3235
3188
}
3236
3189
}
3237
3190
3238
- b = ngx_create_temp_buf (r -> pool , NGX_PAGE_COUNT * ngx_pagesize );
3191
+ b = ngx_create_temp_buf (r -> pool , NGX_PAGE_SIZE * NGX_PAGE_NUMBER );
3239
3192
if (b == NULL ) {
3240
3193
return NGX_HTTP_INTERNAL_SERVER_ERROR ;
3241
3194
}
0 commit comments