| 435 | } |
| 436 | |
| 437 | static void |
| 438 | cdbCopyEndInternal(CdbCopy *c, char *abort_msg, |
| 439 | int64 *total_rows_completed_p, |
| 440 | int64 *total_rows_rejected_p) |
| 441 | { |
| 442 | Gang *gp; |
| 443 | int num_bad_connections = 0; |
| 444 | int64 total_rows_completed = 0; /* total num rows completed by all |
| 445 | * QEs */ |
| 446 | int64 total_rows_rejected = 0; /* total num rows rejected by all |
| 447 | * QEs */ |
| 448 | ErrorData *first_error = NULL; |
| 449 | int seg; |
| 450 | struct pollfd *pollRead; |
| 451 | bool io_errors = false; |
| 452 | StringInfoData io_err_msg; |
| 453 | List *oidList = NIL; |
| 454 | int nest_level; |
| 455 | |
| 456 | SIMPLE_FAULT_INJECTOR("cdb_copy_end_internal_start"); |
| 457 | |
| 458 | initStringInfo(&io_err_msg); |
| 459 | |
| 460 | /* |
| 461 | * Don't try to end a copy that already ended with the destruction of the |
| 462 | * writer gang. We know that this has happened if the CdbCopy's |
| 463 | * primary_writer is NULL. |
| 464 | * |
| 465 | * GPDB_91_MERGE_FIXME: ugh, this is nasty. We shouldn't be calling |
| 466 | * cdbCopyEnd twice on the same CdbCopy in the first place! |
| 467 | */ |
| 468 | gp = getCdbCopyPrimaryGang(c); |
| 469 | if (!gp) |
| 470 | { |
| 471 | if (total_rows_completed_p != NULL) |
| 472 | *total_rows_completed_p = 0; |
| 473 | if (total_rows_rejected_p != NULL) |
| 474 | *total_rows_completed_p = -1; |
| 475 | return; |
| 476 | } |
| 477 | |
| 478 | /* |
| 479 | * In COPY in mode, call PQputCopyEnd() to tell the segments that we're done. |
| 480 | */ |
| 481 | if (c->copy_in) |
| 482 | { |
| 483 | for (seg = 0; seg < gp->size; seg++) |
| 484 | { |
| 485 | SegmentDatabaseDescriptor *q = gp->db_descriptors[seg]; |
| 486 | int result; |
| 487 | |
| 488 | elog(DEBUG1, "PQputCopyEnd seg %d ", q->segindex); |
| 489 | /* end this COPY command */ |
| 490 | result = PQputCopyEnd(q->conn, abort_msg); |
| 491 | |
| 492 | /* get command end status */ |
| 493 | if (result == -1) |
| 494 | { |
no test coverage detected