Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cosmos DB trigger - Shared throughput collection should have a partition key

I have an Azure Function with a Cosmos DB trigger configured to auto-create a lease collection on-demand, I get the following error when running against a Cosmos DB with throughput configured at database level

[30/11/2018 23:33:04] Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.Foo'. Microsoft.Azure.WebJobs.Extensions.CosmosDB: Cannot create Collection Information for X in database Y with lease leases in database Y : Shared throughput collection should have a partition key

Works absolutely fine when the throughput is solely configured at container level. Also tried manually creating a lease collection and setting id as the partition key (given from my other DB it looked like all a lease has was an id / ttl) but then it complains about the PK not being provided.

Any ideas?

like image 794
James Avatar asked Nov 30 '18 23:11

James


People also ask

Is partition key mandatory for Cosmos DB?

Most small containers in Azure Cosmos DB only require one or two physical partitions. If your container could grow to more than a few physical partitions, then you should make sure you pick a partition key that minimizes cross-partition queries.

Why do we need partition key in cosmos?

Azure Cosmos DB is highly scalable And that is because it uses a partitioning system to scale, which consists of physical and logical partitions. To optimize the scalability and performance of Azure Cosmos DB, you need to choose the right partition key for your container.

Can we have multiple partition keys in Cosmos DB?

In this lab, you will create multiple Azure Cosmos DB containers. Some of the containers will be unlimited and configured with a partition key, while others will be fixed-sized. You will then use the SQL API and Java Async SDK to query specific containers using a single partition key or across multiple partition keys.

How do I change the throughput of a Cosmos database?

Navigate to your Azure Cosmos DB account and open the Data Explorer tab. Select New Container. Enter a name for your database, container, and a partition key. Under database or container throughput, select the Autoscale option, and set the maximum throughput (RU/s) that you want the database or container to scale to.


2 Answers

EDIT : this is now supported with the version 3.0.3 of the Microsoft.Azure.WebJobs.Extensions.CosmosDB NuGet package. Tested and works fine with Azure Functions 2.0.


James, this is being supported soon, the PR is already being reviewed to add Partitioned Lease Collections, please see https://github.com/Azure/azure-webjobs-sdk-extensions/pull/520

At this moment the version of the Change Feed Processor library used in Azure Functions does not support partitioned lease collections, the latest version does, so part of that PR is updating the library dependency.

This is mostly common on Shared RU at the Database level.

like image 197
Matias Quaranta Avatar answered Jan 04 '23 10:01

Matias Quaranta


Please take a look at the Function Output - configuration Please note that this is for version 2.0 of Azure Function bindings for Cosmos DB.

Azure Cosmos DB bindings for Azure Functions 2.x

like image 21
Mike Ubezzi Avatar answered Jan 04 '23 11:01

Mike Ubezzi