comparison src/http/ngx_http_upstream.c @ 7006:9552758a786e

Background subrequests for cache updates. Previously, cache background update might not work as expected, making client wait for it to complete before receiving the final part of a stale response. This could happen if the response could not be sent to the client socket in one filter chain call. Now background cache update is done in a background subrequest. This type of subrequest does not block any other subrequests or the main request.
author Roman Arutyunyan <arut@nginx.com>
date Thu, 25 May 2017 15:57:59 +0300
parents 0cdee26605f3
children ed1101bbf19f
comparison
equal deleted inserted replaced
7005:3e2d90073adf 7006:9552758a786e
877 switch (rc) { 877 switch (rc) {
878 878
879 case NGX_HTTP_CACHE_STALE: 879 case NGX_HTTP_CACHE_STALE:
880 880
881 if (((u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING) 881 if (((u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING)
882 || c->stale_updating) && !r->cache_updater 882 || c->stale_updating) && !r->background
883 && u->conf->cache_background_update) 883 && u->conf->cache_background_update)
884 { 884 {
885 r->cache->background = 1; 885 r->cache->background = 1;
886 u->cache_status = rc; 886 u->cache_status = rc;
887 rc = NGX_OK; 887 rc = NGX_OK;
890 break; 890 break;
891 891
892 case NGX_HTTP_CACHE_UPDATING: 892 case NGX_HTTP_CACHE_UPDATING:
893 893
894 if (((u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING) 894 if (((u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING)
895 || c->stale_updating) && !r->cache_updater) 895 || c->stale_updating) && !r->background)
896 { 896 {
897 u->cache_status = rc; 897 u->cache_status = rc;
898 rc = NGX_OK; 898 rc = NGX_OK;
899 899
900 } else { 900 } else {
1074 if (!r->cached || !r->cache->background) { 1074 if (!r->cached || !r->cache->background) {
1075 return NGX_OK; 1075 return NGX_OK;
1076 } 1076 }
1077 1077
1078 if (ngx_http_subrequest(r, &r->uri, &r->args, &sr, NULL, 1078 if (ngx_http_subrequest(r, &r->uri, &r->args, &sr, NULL,
1079 NGX_HTTP_SUBREQUEST_CLONE) 1079 NGX_HTTP_SUBREQUEST_CLONE
1080 |NGX_HTTP_SUBREQUEST_BACKGROUND)
1080 != NGX_OK) 1081 != NGX_OK)
1081 { 1082 {
1082 return NGX_ERROR; 1083 return NGX_ERROR;
1083 } 1084 }
1084 1085
1085 sr->header_only = 1; 1086 sr->header_only = 1;
1086 sr->cache_updater = 1;
1087 1087
1088 return NGX_OK; 1088 return NGX_OK;
1089 } 1089 }
1090 1090
1091 1091