* Worker function for the update on a remote shard. */
| 2434 | * Worker function for the update on a remote shard. |
| 2435 | */ |
| 2436 | Datum |
| 2437 | command_update_worker(PG_FUNCTION_ARGS) |
| 2438 | { |
| 2439 | uint64 collectionId = PG_GETARG_INT64(0); |
| 2440 | int64 shardKeyHash = PG_GETARG_INT64(1); |
| 2441 | Oid shardOid = PG_GETARG_OID(2); |
| 2442 | |
| 2443 | pgbson *updateInternalSpec = PG_GETARG_MAYBE_NULL_PGBSON(3); |
| 2444 | pgbsonsequence *updateSequence = PG_GETARG_MAYBE_NULL_PGBSON_SEQUENCE(4); |
| 2445 | text *transactionId = PG_ARGISNULL(5) ? NULL : PG_GETARG_TEXT_P(5); |
| 2446 | |
| 2447 | if (shardOid == InvalidOid) |
| 2448 | { |
| 2449 | /* The planner is expected to replace this */ |
| 2450 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), |
| 2451 | errmsg("Explicit shardOid must be set - this is a server bug"), |
| 2452 | errdetail_log( |
| 2453 | "Explicit shardOid must be set - this is a server bug"))); |
| 2454 | } |
| 2455 | |
| 2456 | if (updateSequence == NULL && updateInternalSpec == NULL) |
| 2457 | { |
| 2458 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), |
| 2459 | errmsg( |
| 2460 | "update spec or update documents argument must be not null."))); |
| 2461 | } |
| 2462 | |
| 2463 | ThrowIfServerOrTransactionReadOnly(); |
| 2464 | |
| 2465 | WorkerUpdateParam params; |
| 2466 | memset(¶ms, 0, sizeof(WorkerUpdateParam)); |
| 2467 | DeserializeUpdateWorkerSpec(updateInternalSpec, ¶ms); |
| 2468 | |
| 2469 | AllowNestedDistributionInCurrentTransaction(); |
| 2470 | |
| 2471 | MongoCollection *mongoCollection = GetMongoCollectionByColId(collectionId, NoLock); |
| 2472 | |
| 2473 | if (mongoCollection == NULL) |
| 2474 | { |
| 2475 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), |
| 2476 | errmsg( |
| 2477 | "Collection not found for collectionId %lu on command_update_worker. This could be a metadata sync issue", |
| 2478 | collectionId), |
| 2479 | errdetail_log( |
| 2480 | "Collection not found for collectionId %lu on command_update_worker. This could be a metadata sync issue.", |
| 2481 | collectionId))); |
| 2482 | } |
| 2483 | |
| 2484 | UpdateMongoCollectionUsingIds(mongoCollection, collectionId, shardOid); |
| 2485 | |
| 2486 | mongoCollection->shardKey = params.shardKeyBson; |
| 2487 | |
| 2488 | /* Document validation occurs regardless of whether the validation action is set to error or warn. |
| 2489 | * If validation fails and the action is error, an error is thrown; if the action is warn, a warning is logged. |
| 2490 | * Since we do not need to log a warning in this context, we will avoid calling ValidateSchemaOnDocumentInsert when the validation action is set to warn. |
| 2491 | * To reduce unnecessary overhead, we create evalState separately for updateOne and updateBatch. |
| 2492 | */ |
| 2493 | ExprEvalState *stateForSchemaValidation = NULL; |
nothing calls this directly
no test coverage detected