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

Function DeleteOneObjectId

pg_documentdb/src/commands/delete.c:1742–1793  ·  view source on GitHub ↗

* DeleteOneObjectId handles the case where we are deleting a single document * by _id from a collection that is sharded on some other key. In this case, * we need to look across all shards for a matching _id, then delete only that * one. * * Citus does not support SELECT .. FOR UPDATE, and it is very difficult to * support efficiently without running into frequent deadlocks. Therefore, * we

Source from the content-addressed store, hash-verified

1740 * be deleted or updated concurrently. In that case, we try again.
1741 */
1742static void
1743DeleteOneObjectId(MongoCollection *collection, DeleteOneParams *deleteOneParams,
1744 bson_value_t *objectId, bool isIdValueCollationAware, bool
1745 queryHasNonIdFilters,
1746 bool forceInlineWrites, text *transactionId, DeleteOneResult *result)
1747{
1748 const int maxTries = 5;
1749
1750 if (transactionId != NULL)
1751 {
1752 RetryableWriteResult writeResult;
1753
1754 /*
1755 * Try to find a retryable write record for the transaction ID in any shard.
1756 */
1757 if (FindRetryRecordInAnyShard(collection->collectionId, transactionId,
1758 &writeResult))
1759 {
1760 /* found a record, return the previous result */
1761 result->isRowDeleted = writeResult.rowsAffected > 0;
1762 return;
1763 }
1764 }
1765
1766 for (int tryNumber = 0; tryNumber < maxTries; tryNumber++)
1767 {
1768 int64 shardKeyValue = 0;
1769
1770 if (!FindShardKeyValueForDocumentId(collection, deleteOneParams->query, objectId,
1771 isIdValueCollationAware, queryHasNonIdFilters,
1772 &shardKeyValue,
1773 deleteOneParams->variableSpec,
1774 deleteOneParams->collationString))
1775 {
1776 /* no document matches both the query and the object ID */
1777 return;
1778 }
1779
1780 CallDeleteOne(collection, deleteOneParams, shardKeyValue, transactionId,
1781 forceInlineWrites, result);
1782
1783 if (result->isRowDeleted)
1784 {
1785 /* Document has been successfully removed */
1786 return;
1787 }
1788 }
1789
1790 ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR),
1791 errmsg("Unable to remove document even after %d attempts",
1792 maxTries)));
1793}
1794
1795
1796/*

Callers 1

ProcessDeletionFunction · 0.85

Calls 3

CallDeleteOneFunction · 0.85

Tested by

no test coverage detected