* Performs a single insert; if it fails, rolls back the change. * Applicable only for inserts invoked via a procedure. * * Applicable only when the insert batch contains a single document. */
| 718 | * Applicable only when the insert batch contains a single document. |
| 719 | */ |
| 720 | static bool |
| 721 | DoSingleInsert(MongoCollection *collection, |
| 722 | Oid insertShardOid, |
| 723 | const bson_value_t *document, |
| 724 | text *transactionId, |
| 725 | BatchInsertionResult *batchResult, int insertIndex, |
| 726 | ExprEvalState *evalState) |
| 727 | { |
| 728 | /* declared volatile because of the longjmp in PG_CATCH */ |
| 729 | volatile bool isSuccess = false; |
| 730 | volatile uint64 numDocsInserted = 0; |
| 731 | |
| 732 | |
| 733 | PG_TRY(); |
| 734 | { |
| 735 | numDocsInserted = ProcessInsertion(collection, insertShardOid, document, |
| 736 | transactionId, evalState); |
| 737 | batchResult->rowsInserted += numDocsInserted; |
| 738 | isSuccess = true; |
| 739 | } |
| 740 | PG_CATCH(); |
| 741 | { |
| 742 | MemoryContext oldContext = MemoryContextSwitchTo( |
| 743 | batchResult->resultMemoryContext); |
| 744 | ErrorData *errorData = CopyErrorDataAndFlush(); |
| 745 | MemoryContextSwitchTo(oldContext); |
| 746 | |
| 747 | if (IsOperatorInterventionError(errorData)) |
| 748 | { |
| 749 | ReThrowError(errorData); |
| 750 | } |
| 751 | |
| 752 | PopAllActiveSnapshots(); |
| 753 | AbortCurrentTransaction(); |
| 754 | StartTransactionCommand(); |
| 755 | |
| 756 | oldContext = MemoryContextSwitchTo(batchResult->resultMemoryContext); |
| 757 | batchResult->writeErrors = lappend(batchResult->writeErrors, |
| 758 | GetWriteErrorFromErrorData(errorData, |
| 759 | insertIndex)); |
| 760 | MemoryContextSwitchTo(oldContext); |
| 761 | FreeErrorData(errorData); |
| 762 | isSuccess = false; |
| 763 | } |
| 764 | PG_END_TRY(); |
| 765 | return isSuccess; |
| 766 | } |
| 767 | |
| 768 | |
| 769 | /* |
no test coverage detected