* Updates a single update and rollback on failures. * Applicable only for update invoked via a procedure. */
| 1280 | * Applicable only for update invoked via a procedure. |
| 1281 | */ |
| 1282 | static bool |
| 1283 | DoSingleUpdate(MongoCollection *collection, UpdateSpec *updateSpec, text *transactionId, |
| 1284 | BatchUpdateResult *batchResult, int updateIndex, bool forceInlineWrites, |
| 1285 | ExprEvalState *volatile stateForSchemaValidation) |
| 1286 | { |
| 1287 | /* declared volatile because of the longjmp in PG_CATCH */ |
| 1288 | volatile bool isSuccess = false; |
| 1289 | |
| 1290 | UpdateResult updateResult; |
| 1291 | memset(&updateResult, 0, sizeof(updateResult)); |
| 1292 | |
| 1293 | PG_TRY(); |
| 1294 | { |
| 1295 | ProcessUpdate(collection, updateSpec, transactionId, &updateResult, |
| 1296 | forceInlineWrites, stateForSchemaValidation); |
| 1297 | UpdateResultInBatch(batchResult, &updateResult, |
| 1298 | batchResult->resultMemoryContext, updateIndex); |
| 1299 | isSuccess = true; |
| 1300 | } |
| 1301 | PG_CATCH(); |
| 1302 | { |
| 1303 | MemoryContext oldContext = MemoryContextSwitchTo( |
| 1304 | batchResult->resultMemoryContext); |
| 1305 | ErrorData *errorData = CopyErrorDataAndFlush(); |
| 1306 | MemoryContextSwitchTo(oldContext); |
| 1307 | |
| 1308 | if (IsOperatorInterventionError(errorData)) |
| 1309 | { |
| 1310 | ReThrowError(errorData); |
| 1311 | } |
| 1312 | |
| 1313 | PopAllActiveSnapshots(); |
| 1314 | AbortCurrentTransaction(); |
| 1315 | StartTransactionCommand(); |
| 1316 | |
| 1317 | oldContext = MemoryContextSwitchTo(batchResult->resultMemoryContext); |
| 1318 | batchResult->writeErrors = lappend(batchResult->writeErrors, |
| 1319 | GetWriteErrorFromErrorData(errorData, |
| 1320 | updateIndex)); |
| 1321 | MemoryContextSwitchTo(oldContext); |
| 1322 | FreeErrorData(errorData); |
| 1323 | isSuccess = false; |
| 1324 | } |
| 1325 | PG_END_TRY(); |
| 1326 | |
| 1327 | return isSuccess; |
| 1328 | } |
| 1329 | |
| 1330 | |
| 1331 | /* |
no test coverage detected