mirror of
https://github.com/FerretDB/documentdb.git
synced 2026-11-07 03:22:46 -05:00
### Does this PR have any customer impact? Yes ### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc) Bugfix ### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes) No ### Are you introducing any new config? If yes, do you have tests with and without them being set? No ### ChangeLog (Refer [Template](../oss/CHANGELOG.md)) BugFix, data loss in concurrent upserts. ### Description On conflict for upserts we were replacing the document with newer document which is not the right behavior, we need to apply the second update on top of the first document for upserts. ---- #### AI description (iteration 1) #### PR Classification Bug fix: Resolve a concurrent upsert issue by reapplying the update spec on conflict instead of replacing the document. #### PR Summary This pull request corrects the upsert behavior by modifying the queries and function interfaces to reapply the update specification. It also adds new tests to validate the corrected concurrent upsert logic. - `oss/pg_documentdb/src/commands/insert.c` and `oss/pg_documentdb/include/commands/insert.h`: Modified the upsert SQL query to use `bson_update_document` and updated the function signature to require an additional update document parameter. - `oss/pg_documentdb/src/commands/update.c`: Updated calls to the upsert logic to pass the update spec, ensuring the update is reapplied on conflict. - `oss/pg_documentdb/src/update/bson_update.c`: Added logic to build update metadata when none is provided. - `pgmongo/src/test/regress/specs/isolation-concurrent-upserts.spec` and the corresponding expected output file: Introduced new tests and updated the test schedule to verify the concurrent upsert behavior. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> Related work items: #4644372
26 lines
857 B
C
26 lines
857 B
C
/*-------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
*
|
|
* include/commands/insert.h
|
|
*
|
|
* Functions for inserting documents.
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef COMMANDS_INSERT_H
|
|
#define COMMANDS_INSERT_H
|
|
|
|
#include <io/bson_core.h>
|
|
#include "commands/commands_common.h"
|
|
|
|
MongoCollection * CreateCollectionForInsert(Datum databaseNameDatum,
|
|
Datum collectionNameDatum);
|
|
bool InsertDocument(uint64 collectionId, const char *shardTableName, int64 shardKeyValue,
|
|
pgbson *objectId, pgbson *document);
|
|
|
|
bool InsertOrReplaceDocument(uint64 collectionId, const char *shardTableName, int64
|
|
shardKeyValue,
|
|
pgbson *objectId, pgbson *document,
|
|
const bson_value_t *updateSpecValue);
|
|
#endif
|