AzureCosmosDB / data-migration-desktop-tool

MIT License
129 stars 53 forks source link

Shared throughput not supported #105

Closed Jonathan-Walsh-Amey closed 9 months ago

Jonathan-Walsh-Amey commented 10 months ago

Hi. I've found a problem with the throughput in the Cosmos extension.

In Cosmos when you have a provisioned database, the containers can have a throughput specified (which may or may not use autoscale). The migration tool can create these containers and set the throughput (manual or autoscale).

However, a provisioned database can also be created with a throughput of its own. When you have a database like that, containers can be created that either have their own throughput (manual or autoscale), as before, or they can share the database's throughput with other containers.

To achieve the sharing of the database throughput (when one is set up like that), it's simply a case of not specifying a throughput when creating a container.

The problem with the Cosmos extension here is that if you don't specify a throughput, it sets one anyway (defaulting to 400). So effectively, using the data migration tool, you apparently can't get it to create containers that use shared throughput.

In my own copy of the code, I've made a small tweak to make it possible. In CosmosDataSyncExtension.cs, I've just changed this:

                ThroughputProperties? throughputProperties = settings.IsServerlessAccount
                    ? null
                    : settings.UseAutoscaleForCreatedContainer
                    ? ThroughputProperties.CreateAutoscaleThroughput(settings.CreatedContainerMaxThroughput ?? 4000)
                    : ThroughputProperties.CreateManualThroughput(settings.CreatedContainerMaxThroughput ?? 400);

To this:

                ThroughputProperties? throughputProperties = settings.IsServerlessAccount || settings.CreatedContainerMaxThroughput == 0
                    ? null
                    : settings.UseAutoscaleForCreatedContainer
                    ? ThroughputProperties.CreateAutoscaleThroughput(settings.CreatedContainerMaxThroughput ?? 4000)
                    : ThroughputProperties.CreateManualThroughput(settings.CreatedContainerMaxThroughput ?? 400);

So if CreatedContainerMaxThroughput is set to 0, it doesn't set a value for CreateManualThroughput, which means that the container will use shared throughput if the database is set up with that.