【发布时间】:2015-05-30 06:59:48
【问题描述】:
y 查询类似于
this.ProcessRequestSync(() => this.Client.CreateDocumentQuery<Model>(this.DocumentDBCollectionLink).Where(d => d.name.Equals(name) && d.code.Equals(code) && d.Type.Equals(this.documentType) && d.CreatedBy.Equals(myName).ToList<Model>());
public dynamic ProcessRequestSync(Func<dynamic> getRequest)
{
var delay = TimeSpan.Zero;
var minDelayTime = new TimeSpan(0, 0, 1);
for (;;)
{
try
{
Thread.Sleep(delay);
return getRequest();
}
catch (DocumentClientException documentClientException)
{
var statusCode = (int)documentClientException.StatusCode;
if (statusCode == 429 || statusCode == 503)
{
string errorMessage = string.Format("failed at DocumentDB with {0} status and {1} retry time", statusCode, documentClientException.RetryAfter);
this.Logger.Log(errorMessage );
// Back off if the request rate is too large or the service is temporarily unavailable
delay = TimeSpan.Compare(documentClientException.RetryAfter, minDelayTime) >= 0 ? documentClientException.RetryAfter: minDelayTime;
}
else
{
throw;
}
}
}
}
这是requestRateTooLarge异常引发时重试逻辑的方法。
我不确定,它是否工作正常,
我在一次查询和插入大约 4000 条记录时遇到异常:Microsoft.Azure.Documents.RequestRateTooLargeException,
我使用相同的重试逻辑进行插入,它工作正常。 我没有收到任何错误,也成功插入了所有记录,但无法获取查询数据。
【问题讨论】:
标签: c# bulkinsert azure-cosmosdb resque-retry