CreateDocumentCollectionIfNotExistsAsync并非始终有效 [英] CreateDocumentCollectionIfNotExistsAsync does not always work

查看:48
本文介绍了CreateDocumentCollectionIfNotExistsAsync并非始终有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个不存在的集合.

I am trying to create a collection if it does not exist.

首先,我通过以下方式创建我的DocumentClient:

First, I create my DocumentClient by:

public DocumentClient CreateClient(ConnectionPolicy connectionPolicy = null)
{
   return new DocumentClient(new Uri(this.AccountEndpoint), this.AccountKey, connectionPolicy);
}

现在我有了我的文档客户端(我们称它为documentDbClient),我尝试使用CreateDocumentCollectionIfNotExistsAsync:

Now that I have my document client (let's call it documentDbClient), I attempt to use CreateDocumentCollectionIfNotExistsAsync:

var documentDbClient = dbConnection.CreateClient();

await documentDbClient.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri("mydatabase"),
            new DocumentCollection { Id = "testcollection" });

现在,我希望这会在名为mydatabase的数据库下创建一个名为testcollection的集合.但是,什么也没有发生.不创建任何集合,不引发任何异常.

Now, I would expect this to create a collection named testcollection under my database named mydatabase. However, nothing happens. No collection is created, no exceptions are thrown.

我以为可能只是很慢,所以我等了30分钟,然后回到门户网站查看我的收藏夹是否已制成...

I thought perhaps it was just slow, and so I waited 30 minutes and went back to the portal to see if my collection had been made...

没有.

怎么了?

更新

好的,因此我发现,如果我更改要创建的集合的名称,则它可以工作.我以前已经多次创建和删除了该集合,现在看来Azure无法90%地创建它.

Okay, so I have discovered that if I change the name of the collection that I am attempting to create, it works. I have previously created and deleted the collection many times and now it appears that Azure is failing to create it 90% of the time.

推荐答案

因此,当您反复创建和销毁集合时,您可能会遇到限制的情况.这是常见问题解答(同样适用于文档集合):

So, you're likely running into a throttling situation when repeatedly creating and destroying collections. Here's an excerpt from the Table API section of the FAQ (which applies equally to document collections):

检测并限制表的快速创建速度.我们 建议您查看表的创建速率并将其降低 到每分钟少于5个.

The rapid rate of creation of tables is detected and throttled. We recommend that you look at the rate of creation of tables and lower it to less than 5 per minute.

当前节气门速度为5个创建/分钟.因此,对于单元测试方案,您需要解决此问题(例如保留一个集合,但在每次测试运行后只清空其内容).

The current throttle rate is 5 creates / minute. So, for a unit-testing scenario, you'd need to work around this (e.g. keeping a collection, but just emptying its contents after each test run).

注意:我通知产品团队,节气门仅在Table API部分中提供,并相应地更新FAQ.

这篇关于CreateDocumentCollectionIfNotExistsAsync并非始终有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆