MCPcopy Create free account
hub / github.com/documentdb/documentdb / DoSingleInsert

Function DoSingleInsert

pg_documentdb/src/commands/insert.c:720–766  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

718 * Applicable only when the insert batch contains a single document.
719 */
720static bool
721DoSingleInsert(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/*

Callers 1

ProcessBatchInsertionFunction · 0.85

Calls 5

ProcessInsertionFunction · 0.85
CopyErrorDataAndFlushFunction · 0.85
PopAllActiveSnapshotsFunction · 0.85

Tested by

no test coverage detected