* gets a chunk of rows of data from a copy command. * returns boolean true if done. Caller should still * empty the leftovers in the outbuf in that case. */
| 282 | * empty the leftovers in the outbuf in that case. |
| 283 | */ |
| 284 | bool |
| 285 | cdbCopyGetData(CdbCopy *c, bool copy_cancel, uint64 *rows_processed) |
| 286 | { |
| 287 | SegmentDatabaseDescriptor *q; |
| 288 | Gang *gp; |
| 289 | int nbytes; |
| 290 | |
| 291 | /* clean out buf data */ |
| 292 | resetStringInfo(&c->copy_out_buf); |
| 293 | |
| 294 | gp = getCdbCopyPrimaryGang(c); |
| 295 | |
| 296 | /* |
| 297 | * MPP-7712: we used to issue the cancel-requests for each *row* we got |
| 298 | * back from each segment -- this is potentially millions of |
| 299 | * cancel-requests. Cancel requests consist of an out-of-band connection |
| 300 | * to the segment-postmaster, this is *not* a lightweight operation! |
| 301 | */ |
| 302 | if (copy_cancel) |
| 303 | { |
| 304 | ListCell *cur; |
| 305 | |
| 306 | /* iterate through all the segments that still have data to give */ |
| 307 | foreach(cur, c->seglist) |
| 308 | { |
| 309 | int source_seg = lfirst_int(cur); |
| 310 | |
| 311 | q = getSegmentDescriptorFromGang(gp, source_seg); |
| 312 | |
| 313 | /* send a query cancel request to that segdb */ |
| 314 | PQrequestCancel(q->conn); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | /* |
| 319 | * Collect data rows from the segments that still have rows to give until |
| 320 | * chunk minimum size is reached |
| 321 | */ |
| 322 | while (c->copy_out_buf.len < COPYOUT_CHUNK_SIZE) |
| 323 | { |
| 324 | ListCell *cur; |
| 325 | |
| 326 | /* iterate through all the segments that still have data to give */ |
| 327 | foreach(cur, c->seglist) |
| 328 | { |
| 329 | int source_seg = lfirst_int(cur); |
| 330 | char *buffer; |
| 331 | |
| 332 | q = getSegmentDescriptorFromGang(gp, source_seg); |
| 333 | |
| 334 | /* get 1 row of COPY data */ |
| 335 | nbytes = PQgetCopyData(q->conn, &buffer, false); |
| 336 | |
| 337 | /* |
| 338 | * SUCCESS -- got a row of data |
| 339 | */ |
| 340 | if (nbytes > 0 && buffer) |
| 341 | { |
no test coverage detected