forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit054325c
libpq: Improve idle state handling in pipeline mode
We were going into IDLE state too soon when executing queries viaPQsendQuery in pipeline mode, causing several scenarios to misbehave indifferent ways -- most notably, as reported by Daniele Varrazzo, that awarning message is produced by libpq: message type 0x33 arrived from server while idleBut it is also possible, if queries are sent and results consumed not inlockstep, for the expected mediating NULL result values from PQgetResultto be lost (a problem which has not been reported, but which is moreserious).Fix this by introducing two new concepts: one is a command queue elementPGQUERY_CLOSE to tell libpq to wait for the CloseComplete serverresponse to the Close message that is sent by PQsendQuery. Because theapplication is not expecting any PGresult from this, the mechanism toconsume it is a bit hackish.The other concept, authored by Horiguchi-san, is a PGASYNC_PIPELINE_IDLEstate for libpq's state machine to differentiate "really idle" frommerely "the idle state that occurs in between reading results from theserver for elements in the pipeline". This makes libpq not go fullyIDLE when the libpq command queue contains entries; in normal cases, weonly go IDLE once at the end of the pipeline, when the server responseto the final SYNC message is received. (However, there are corner casesit doesn't fix, such as terminating the query sequence byPQsendFlushRequest instead of PQpipelineSync; this sort of scenario iswhat requires PGQUERY_CLOSE bit above.)This last bit helps make the libpq state machine clearer; in particularwe can get rid of an ugly hack in pqParseInput3 to avoid consideringIDLE as such when the command queue contains entries.A new test mode is added to libpq_pipeline.c to tickle some relatedproblematic cases.Reported-by: Daniele Varrazzo <daniele.varrazzo@gmail.com>Co-authored-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>Discussion:https://postgr.es/m/CA+mi_8bvD0_CW3sumgwPvWdNzXY32itoG_16tDYRu_1S2gV2iw@mail.gmail.com1 parent5001b44 commit054325c
File tree
6 files changed
+424
-35
lines changed- src
- interfaces/libpq
- test/modules/libpq_pipeline
- t
- traces
6 files changed
+424
-35
lines changedLines changed: 96 additions & 16 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1376 | 1376 |
| |
1377 | 1377 |
| |
1378 | 1378 |
| |
1379 |
| - | |
| 1379 | + | |
| 1380 | + | |
1380 | 1381 |
| |
1381 | 1382 |
| |
1382 | 1383 |
| |
| |||
1432 | 1433 |
| |
1433 | 1434 |
| |
1434 | 1435 |
| |
| 1436 | + | |
1435 | 1437 |
| |
1436 | 1438 |
| |
1437 | 1439 |
| |
| |||
1447 | 1449 |
| |
1448 | 1450 |
| |
1449 | 1451 |
| |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
1450 | 1458 |
| |
1451 | 1459 |
| |
1452 | 1460 |
| |
| |||
1516 | 1524 |
| |
1517 | 1525 |
| |
1518 | 1526 |
| |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
1519 | 1541 |
| |
1520 | 1542 |
| |
1521 | 1543 |
| |
| |||
1763 | 1785 |
| |
1764 | 1786 |
| |
1765 | 1787 |
| |
| 1788 | + | |
1766 | 1789 |
| |
1767 | 1790 |
| |
1768 | 1791 |
| |
1769 | 1792 |
| |
1770 | 1793 |
| |
| 1794 | + | |
1771 | 1795 |
| |
1772 | 1796 |
| |
1773 | 1797 |
| |
| |||
2140 | 2164 |
| |
2141 | 2165 |
| |
2142 | 2166 |
| |
2143 |
| - | |
2144 |
| - | |
2145 |
| - | |
2146 |
| - | |
2147 |
| - | |
2148 |
| - | |
2149 |
| - | |
2150 |
| - | |
2151 |
| - | |
2152 | 2167 |
| |
| 2168 | + | |
| 2169 | + | |
| 2170 | + | |
| 2171 | + | |
| 2172 | + | |
| 2173 | + | |
| 2174 | + | |
| 2175 | + | |
| 2176 | + | |
| 2177 | + | |
| 2178 | + | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
2153 | 2182 |
| |
2154 | 2183 |
| |
2155 | 2184 |
| |
| |||
2170 | 2199 |
| |
2171 | 2200 |
| |
2172 | 2201 |
| |
2173 |
| - | |
| 2202 | + | |
2174 | 2203 |
| |
2175 | 2204 |
| |
2176 | 2205 |
| |
| |||
2216 | 2245 |
| |
2217 | 2246 |
| |
2218 | 2247 |
| |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
2219 | 2264 |
| |
2220 | 2265 |
| |
2221 | 2266 |
| |
| |||
3009 | 3054 |
| |
3010 | 3055 |
| |
3011 | 3056 |
| |
3012 |
| - | |
| 3057 | + | |
| 3058 | + | |
| 3059 | + | |
| 3060 | + | |
3013 | 3061 |
| |
3014 | 3062 |
| |
3015 | 3063 |
| |
| |||
3026 | 3074 |
| |
3027 | 3075 |
| |
3028 | 3076 |
| |
3029 |
| - | |
| 3077 | + | |
| 3078 | + | |
3030 | 3079 |
| |
3031 | 3080 |
| |
| 3081 | + | |
| 3082 | + | |
| 3083 | + | |
| 3084 | + | |
| 3085 | + | |
| 3086 | + | |
3032 | 3087 |
| |
3033 | 3088 |
| |
3034 | 3089 |
| |
| |||
3065 | 3120 |
| |
3066 | 3121 |
| |
3067 | 3122 |
| |
| 3123 | + | |
| 3124 | + | |
| 3125 | + | |
| 3126 | + | |
3068 | 3127 |
| |
3069 | 3128 |
| |
3070 | 3129 |
| |
| |||
3087 | 3146 |
| |
3088 | 3147 |
| |
3089 | 3148 |
| |
| 3149 | + | |
3090 | 3150 |
| |
| 3151 | + | |
| 3152 | + | |
| 3153 | + | |
| 3154 | + | |
| 3155 | + | |
| 3156 | + | |
| 3157 | + | |
| 3158 | + | |
| 3159 | + | |
| 3160 | + | |
| 3161 | + | |
| 3162 | + | |
| 3163 | + | |
| 3164 | + | |
3091 | 3165 |
| |
3092 | 3166 |
| |
3093 | 3167 |
| |
3094 | 3168 |
| |
3095 |
| - | |
3096 |
| - | |
3097 |
| - | |
| 3169 | + | |
| 3170 | + | |
| 3171 | + | |
| 3172 | + | |
| 3173 | + | |
| 3174 | + | |
| 3175 | + | |
3098 | 3176 |
| |
| 3177 | + | |
3099 | 3178 |
| |
3100 | 3179 |
| |
3101 | 3180 |
| |
| |||
3188 | 3267 |
| |
3189 | 3268 |
| |
3190 | 3269 |
| |
| 3270 | + | |
3191 | 3271 |
| |
3192 | 3272 |
| |
3193 | 3273 |
| |
|
Lines changed: 17 additions & 13 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
158 | 158 |
| |
159 | 159 |
| |
160 | 160 |
| |
161 |
| - | |
162 |
| - | |
163 |
| - | |
164 |
| - | |
165 |
| - | |
166 |
| - | |
167 |
| - | |
168 |
| - | |
169 |
| - | |
170 |
| - | |
171 |
| - | |
172 |
| - | |
173 | 161 |
| |
174 | 162 |
| |
175 | 163 |
| |
| |||
296 | 284 |
| |
297 | 285 |
| |
298 | 286 |
| |
| 287 | + | |
| 288 | + | |
299 | 289 |
| |
300 |
| - | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
301 | 305 |
| |
302 | 306 |
| |
303 | 307 |
| |
|
Lines changed: 4 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
225 | 225 |
| |
226 | 226 |
| |
227 | 227 |
| |
228 |
| - | |
| 228 | + | |
| 229 | + | |
229 | 230 |
| |
230 | 231 |
| |
231 | 232 |
| |
| |||
311 | 312 |
| |
312 | 313 |
| |
313 | 314 |
| |
314 |
| - | |
| 315 | + | |
| 316 | + | |
315 | 317 |
| |
316 | 318 |
| |
317 | 319 |
| |
|
0 commit comments
Comments
(0)