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

Function DoSingleUpdateWithSubTxn

pg_documentdb/src/commands/update.c:1212–1275  ·  view source on GitHub ↗

* Updates a single update in a single sub-transaction. */

Source from the content-addressed store, hash-verified

1210 * Updates a single update in a single sub-transaction.
1211 */
1212static bool
1213DoSingleUpdateWithSubTxn(MongoCollection *collection, UpdateSpec *updateSpec,
1214 text *transactionId,
1215 BatchUpdateResult *batchResult, int updateIndex, bool
1216 forceInlineWrites,
1217 ExprEvalState *volatile stateForSchemaValidation)
1218{
1219 /*
1220 * Execute the query inside a sub-transaction, so we can restore order
1221 * after a failure.
1222 */
1223 MemoryContext oldContext = CurrentMemoryContext;
1224 ResourceOwner oldOwner = CurrentResourceOwner;
1225
1226 /* declared volatile because of the longjmp in PG_CATCH */
1227 volatile bool isSuccess = false;
1228
1229 UpdateResult updateResult;
1230 memset(&updateResult, 0, sizeof(updateResult));
1231
1232 /* use a subtransaction to correctly handle failures */
1233 BeginInternalSubTransaction(NULL);
1234
1235 PG_TRY();
1236 {
1237 ProcessUpdate(collection, updateSpec, transactionId, &updateResult,
1238 forceInlineWrites, stateForSchemaValidation);
1239
1240 /* Commit the inner transaction, return to outer xact context */
1241 ReleaseCurrentSubTransaction();
1242 MemoryContextSwitchTo(oldContext);
1243 CurrentResourceOwner = oldOwner;
1244
1245 UpdateResultInBatch(batchResult, &updateResult,
1246 batchResult->resultMemoryContext, updateIndex);
1247 isSuccess = true;
1248 }
1249 PG_CATCH();
1250 {
1251 MemoryContextSwitchTo(oldContext);
1252 ErrorData *errorData = CopyErrorDataAndFlush();
1253
1254 /* Abort the inner transaction */
1255 RollbackAndReleaseCurrentSubTransaction();
1256 MemoryContextSwitchTo(oldContext);
1257 CurrentResourceOwner = oldOwner;
1258
1259 if (IsOperatorInterventionError(errorData))
1260 {
1261 ReThrowError(errorData);
1262 }
1263
1264 MemoryContextSwitchTo(batchResult->resultMemoryContext);
1265 batchResult->writeErrors = lappend(batchResult->writeErrors,
1266 GetWriteErrorFromErrorData(errorData,
1267 updateIndex));
1268 MemoryContextSwitchTo(oldContext);
1269 FreeErrorData(errorData);

Callers 1

ProcessBatchUpdateCoreFunction · 0.85

Calls 5

ProcessUpdateFunction · 0.85
UpdateResultInBatchFunction · 0.85
CopyErrorDataAndFlushFunction · 0.85

Tested by

no test coverage detected