Skip to content

Commit 933c1db

Browse files
committed
refactoring remove parallel subrequest feature
1 parent cf98ade commit 933c1db

File tree

1 file changed

+64
-60
lines changed

1 file changed

+64
-60
lines changed

src/ngx_link_func_module.c

Lines changed: 64 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@
4646
*/
4747
#if (nginx_version > 1013003)
4848

49-
#define NGX_SUBREQ_SEQUENTIAL 0
50-
#define NGX_SUBREQ_PARALLEL 1
51-
#define NGX_SUBREQ_SEQUENTIAL_CHK 2
49+
#define NGX_SUBREQ_NORMAL 0
50+
#define NGX_SUBREQ_CHECK_STATUS 1
51+
#define NGX_SUBREQ_INCL_BODY 2
52+
#define NGX_SUBREQ_INCL_ARGS 3
5253

5354
static ngx_conf_enum_t ngx_http_link_func_subrequest_flags[] = {
54-
{ ngx_string("sequential"), NGX_SUBREQ_SEQUENTIAL }, // subrequest run synchronizely but waiting for response
55-
{ ngx_string("sequential_check"), NGX_SUBREQ_SEQUENTIAL_CHK }, // subrequest run synchronizely but waiting for response and check status
56-
{ ngx_string("parallel"), NGX_SUBREQ_PARALLEL }, // subrequest run parallely but waiting for response
55+
{ ngx_string("check_status"), NGX_SUBREQ_CHECK_STATUS }, // subrequest run synchronizely but waiting for response and check status
56+
{ ngx_string("incl_body"), NGX_SUBREQ_INCL_BODY }, // include body with the subrequest
57+
{ ngx_string("incl_args"), NGX_SUBREQ_INCL_ARGS }, // include args with the subrequest
58+
// { ngx_string("parallel"), NGX_SUBREQ_PARALLEL }, // subrequest run parallely but waiting for response
5759
{ ngx_null_string, 0 }
5860
};
5961
#endif
@@ -100,9 +102,10 @@ typedef struct {
100102
#if (nginx_version > 1013003)
101103
typedef struct {
102104
ngx_str_t uri;
103-
ngx_uint_t flag;
105+
// ngx_uint_t flag;
104106
ngx_flag_t incl_args;
105107
ngx_flag_t incl_body;
108+
ngx_flag_t check_status;
106109
} ngx_http_link_func_subreq_conf_t;
107110
#endif
108111

@@ -155,8 +158,8 @@ static char *ngx_http_link_func_ext_req_headers_add_cmd(ngx_conf_t *cf, ngx_comm
155158
static char *ngx_http_link_func_init_method(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
156159
#if (nginx_version > 1013003)
157160
static char *ngx_http_link_func_subrequest_cmd(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
158-
static ngx_int_t ngx_http_link_func_subreqest_parallel_done(ngx_http_request_t *r, void *data, ngx_int_t rc);
159-
static ngx_int_t ngx_http_link_func_subreqest_sequential_done(ngx_http_request_t *r, void *data, ngx_int_t rc);
161+
// static ngx_int_t ngx_http_link_func_subreqest_parallel_done(ngx_http_request_t *r, void *data, ngx_int_t rc);
162+
static ngx_int_t ngx_http_link_func_subreqest_done(ngx_http_request_t *r, void *data, ngx_int_t rc);
160163
static ngx_int_t ngx_http_link_func_process_subrequest(ngx_http_request_t *r, ngx_http_link_func_subreq_conf_t *subreq, ngx_http_link_func_internal_ctx_t *ctx);
161164
#endif
162165
static ngx_int_t ngx_http_link_func_content_handler(ngx_http_request_t *r);
@@ -542,34 +545,47 @@ ngx_http_link_func_subrequest_cmd(ngx_conf_t *cf, ngx_command_t *cmd, void *conf
542545
for (i = 1; i < cf->args->nelts; i++) {
543546
if (i == 1) {
544547
subreq->uri = values[i];
545-
} else if (i == 2) {
548+
} else {
546549
e = ngx_http_link_func_subrequest_flags;
547550
for (j = 0; e[j].name.len != 0; j++) {
548551
if (e[j].name.len == values[i].len
549552
&& ngx_strcasecmp(e[j].name.data, values[i].data) == 0) {
550-
subreq->flag = e[j].value;
551-
// #if(nginx_version < 1013010)
552-
#if(NGX_THREADS)
553-
if (subreq->flag == NGX_SUBREQ_PARALLEL) {
554-
return "parallel request is not applicable in aio threads yet.";
553+
// subreq->flag = e[j].value;
554+
// #if(NGX_THREADS)
555+
// if (subreq->flag == NGX_SUBREQ_PARALLEL) {
556+
// return "parallel request is not applicable in aio threads yet.";
557+
// }
558+
// #endif
559+
switch (e[j].value) {
560+
case NGX_SUBREQ_CHECK_STATUS:
561+
subreq->check_status = 1;
562+
break;
563+
case NGX_SUBREQ_INCL_ARGS:
564+
subreq->incl_args = 1;
565+
break;
566+
case NGX_SUBREQ_INCL_BODY:
567+
subreq->incl_body = 1;
568+
break;
569+
default:
570+
return "invalid subrequest flag given, either incl_args, incl_body or check_status.";
555571
}
556-
#endif
557572
break;
558573
}
559574
}
560575

561576
if (e[j].name.len == 0) {
562-
return "invalid subrequest flag given, either parallel, sequential or sequential_check.";
577+
return "invalid subrequest flag given, either incl_args, incl_body or check_status.";
563578
}
564-
} else if (i == 3) {
579+
580+
} /*else if (i == 3) {
565581
if ( (sizeof("on") - 1) == values[i].len && ngx_strcasecmp((u_char*)"on", values[i].data) == 0) {
566582
subreq->incl_args = 1;
567583
}
568584
} else if (i == 4) {
569585
if ( (sizeof("on") - 1) == values[i].len && ngx_strcasecmp((u_char*)"on", values[i].data) == 0) {
570586
subreq->incl_body = 1;
571587
}
572-
}
588+
}*/
573589
}
574590
return NGX_CONF_OK;
575591
}
@@ -1080,20 +1096,20 @@ ngx_http_link_func_after_process(ngx_event_t *ev) {
10801096
#endif
10811097

10821098
#if (nginx_version > 1013003)
1099+
// static ngx_int_t
1100+
// ngx_http_link_func_subreqest_parallel_done(ngx_http_request_t *r, void *data, ngx_int_t rc) {
1101+
// ngx_http_link_func_internal_ctx_t *ctx = data;
1102+
// ngx_uint_t status = r->headers_out.status;
1103+
1104+
// ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1105+
// "subrequest parallel done:%ui", status);
1106+
// if (status) {
1107+
// ctx->subreq_parallel_wait_cnt--;
1108+
// }
1109+
// return rc;
1110+
// }
10831111
static ngx_int_t
1084-
ngx_http_link_func_subreqest_parallel_done(ngx_http_request_t *r, void *data, ngx_int_t rc) {
1085-
ngx_http_link_func_internal_ctx_t *ctx = data;
1086-
ngx_uint_t status = r->headers_out.status;
1087-
1088-
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1089-
"subrequest parallel done:%ui", status);
1090-
if (status) {
1091-
ctx->subreq_parallel_wait_cnt--;
1092-
}
1093-
return rc;
1094-
}
1095-
static ngx_int_t
1096-
ngx_http_link_func_subreqest_sequential_done(ngx_http_request_t *r, void *data, ngx_int_t rc) {
1112+
ngx_http_link_func_subreqest_done(ngx_http_request_t *r, void *data, ngx_int_t rc) {
10971113
ngx_http_link_func_internal_ctx_t *ctx = data;
10981114
ngx_uint_t status = r->headers_out.status;
10991115

@@ -1135,30 +1151,17 @@ ngx_http_link_func_process_subrequest(ngx_http_request_t *r, ngx_http_link_func_
11351151
}
11361152
ps->data = ctx;
11371153

1138-
switch (subreq->flag) {
1139-
case NGX_SUBREQ_PARALLEL:
1140-
ps->handler = ngx_http_link_func_subreqest_parallel_done;
1141-
ctx->subreq_parallel_wait_cnt++;
1142-
rc = NGX_AGAIN;
1143-
break;
1144-
case NGX_SUBREQ_SEQUENTIAL_CHK:
1145-
ps->handler = ngx_http_link_func_subreqest_sequential_done;
1146-
ctx->subreq_sequential_wait_cnt++;
1154+
if (subreq->check_status) {
11471155
ctx->status_check = 1;
1148-
rc = NGX_DONE;
1149-
break;
1150-
case NGX_SUBREQ_SEQUENTIAL:
1151-
default:
1152-
ps->handler = ngx_http_link_func_subreqest_sequential_done;
1153-
ctx->subreq_sequential_wait_cnt++;
1154-
rc = NGX_DONE;
1155-
// ps = NULL;
1156-
break;
11571156
}
11581157

1158+
ps->handler = ngx_http_link_func_subreqest_done;
1159+
ctx->subreq_sequential_wait_cnt++;
1160+
rc = NGX_DONE;
1161+
11591162
ctx->subreq_curr_index++;
11601163

1161-
if (ngx_http_subrequest(r, &subreq->uri, args, &sr, ps, NGX_HTTP_SUBREQUEST_IN_MEMORY) == NGX_ERROR) {
1164+
if (ngx_http_subrequest(r, &subreq->uri, args, &sr, ps, NGX_HTTP_SUBREQUEST_WAITED) == NGX_ERROR) {
11621165
return NGX_ERROR;
11631166
}
11641167

@@ -1203,7 +1206,7 @@ ngx_http_link_func_precontent_handler(ngx_http_request_t *r) {
12031206

12041207
#if (nginx_version > 1013003)
12051208
ngx_int_t rc;
1206-
ngx_uint_t i, n_sub_reqs;
1209+
ngx_uint_t i;//, n_sub_reqs;
12071210
ngx_http_link_func_subreq_conf_t *subreqs, *subreq;
12081211

12091212
if (lcf->_handler == NULL && lcf->subrequests == NULL) {
@@ -1237,25 +1240,26 @@ ngx_http_link_func_precontent_handler(ngx_http_request_t *r) {
12371240
}
12381241

12391242

1240-
n_sub_reqs = lcf->subrequests->nelts;
1243+
// n_sub_reqs = lcf->subrequests->nelts;
1244+
i = internal_ctx->subreq_curr_index;
12411245
subreqs = lcf->subrequests->elts;
12421246

1243-
for (i = internal_ctx->subreq_curr_index; i < n_sub_reqs; i++) {
1247+
if (i < lcf->subrequests->nelts) {
12441248
subreq = subreqs + i;
12451249
if ( (rc = ngx_http_link_func_process_subrequest(r, subreq, internal_ctx)) == NGX_ERROR ) {
12461250
return NGX_ERROR;
12471251
}
12481252

1249-
if (rc == NGX_AGAIN) {
1250-
continue;
1251-
}
1253+
// if (rc == NGX_AGAIN) {
1254+
// continue;
1255+
// }
12521256

12531257
return rc; /*NGX_DONE*/
12541258
}
12551259

1256-
if (internal_ctx->subreq_parallel_wait_cnt) {
1257-
return NGX_DONE;
1258-
}
1260+
// if (internal_ctx->subreq_parallel_wait_cnt) {
1261+
// return NGX_DONE;
1262+
// }
12591263
}
12601264

12611265
if (lcf->_handler == NULL) {

0 commit comments

Comments
 (0)