COSMOS DB批量插入Initialize()无效

编程入门 行业动态 更新时间:2024-10-20 09:22:29
本文介绍了COSMOS DB批量插入Initialize()无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好,

自过去一周以来,我正在检查用COSMOS DB替换现有SQL服务器数据库的可行性对于我的项目,

Since past 1 week, i am checking feasibility to replace my Existing SQL server DB with COSMOS DB for my project,

在那,我的一个实验是使用COSMOS DB SQL API更新近1M记录的批量插入概念

In that, one of my experiment is Bulk insert concepts to update nearly 1M records using COSMOS DB SQL API

我推荐如下链接,但我没有得到执行intializeasync(),例外是该值不能为空,参数名是'键'

I referred following link, but i am failed to get execute intializeasync(), the exception is The value cannot be null,Parametername is 'Key'

github/Azure/azure-cosmosdb-bulkexecutor- dotnet-getting-started / blob / master / BulkImportSample / BulkImportSample / Program.cs

github/Azure/azure-cosmosdb-bulkexecutor-dotnet-getting-started/blob/master/BulkImportSample/BulkImportSample/Program.cs

版本是: Microsoft.Azure.CosmosDB - 2.1.3

Version is : Microsoft.Azure.CosmosDB -2.1.3

我的代码如下,

私人DocumentClient客户;

private DocumentClient client;

DocumentCollection collectionInfo; private static readonly ConnectionPolicy ConnectionPolicy = new ConnectionPolicy { ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp };

DocumentCollection collectionInfo; private static readonly ConnectionPolicy ConnectionPolicy = new ConnectionPolicy { ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp };

private void StartBulk()

private void StartBulk()

{

this.client = new DocumentClient(new Uri(EndpointUri),AuthKey,ConnectionPolicy); 数据库databaseInfo =新数据库{Id = DatabaseId}; await this.client.CreateDatabaseIfNotExistsAsync(databaseInfo); collectionInfo = new DocumentCollection(); collectionInfo.Id = ContainerId; PartitionKeyDefinition partitionKey = new PartitionKeyDefinition { Paths = new Collection< string> {PartitionKey} $ };

this.client = new DocumentClient(new Uri(EndpointUri), AuthKey, ConnectionPolicy); Database databaseInfo = new Database { Id = DatabaseId }; await this.client.CreateDatabaseIfNotExistsAsync(databaseInfo); collectionInfo = new DocumentCollection(); collectionInfo.Id = ContainerId; PartitionKeyDefinition partitionKey = new PartitionKeyDefinition { Paths = new Collection<string> { PartitionKey } };

await this.client.CreateDocumentCollectionIfNotExistsAsync( ; UriFactory.CreateDatabaseUri(databaseInfo.Id), collectionInfo, new RequestOptions {OfferThroughput = 400});

await this.client.CreateDocumentCollectionIfNotExistsAsync( UriFactory.CreateDatabaseUri(databaseInfo.Id), collectionInfo, new RequestOptions { OfferThroughput = 400 });

client.ConnectionPolicy.RetryOptions .MaxRetryWaitTimeInSeconds = 30; client.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 9; IBulkExecutor bulkExecutor = new BulkExecutor(client,collectionInfo); 等待bulkExecutor.InitializeAsync(); var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; //将重试次数设置为0以将完全控制权传递给批量执行者。 client.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 0; client.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 0; BulkImportResponse bulkImportResponse = await bulkExecutor.BulkImportAsync( documents:result, enableUpsert:true, disableAutomaticIdGeneration:true, maxConcurrencyPerPartitionKeyRange:null, maxInMemorySortingBatchSize:null, cancellationToken:token);

client.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 30; client.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 9; IBulkExecutor bulkExecutor = new BulkExecutor(client, collectionInfo); await bulkExecutor.InitializeAsync(); var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; // Set retries to 0 to pass complete control to bulk executor. client.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 0; client.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 0; BulkImportResponse bulkImportResponse = await bulkExecutor.BulkImportAsync( documents: result, enableUpsert: true, disableAutomaticIdGeneration: true, maxConcurrencyPerPartitionKeyRange: null, maxInMemorySortingBatchSize: null, cancellationToken: token);

}

异常是,例外是,该值不能为空,参数名称为'Key'

Exception is,the exception is, The value cannot be null,Parameter name is 'Key'

请帮我解决,

谢谢,

Thiru

推荐答案

Hi Thiru,

Hi Thiru,

需要调查的两个方面:

  • 你有一个分区键吗?是否为您的收藏进行了配置?
  • In BulkImportSample / BulkImportSample / App.config 你在appSettings中缺少一个(或有一个不正确的)条目:
  • Do you have a partition key configured for your collection?
  • InBulkImportSample/BulkImportSample/App.config you are missing an (or have an incorrect) entry in appSettings:

<appSettings> <add key="EndPointUrl" value="localhost:443/" /> <add key="AuthorizationKey" value="C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" /> <add key="DatabaseName" value="TestDb" /> <add key="CollectionName" value="TestColl" /> <add key="CollectionThroughput" value="50000" /> <add key="ShouldCleanupOnStart" value="true" /> <add key="ShouldCleanupOnFinish" value="true" /> <add key="NumberOfDocumentsToImport" value="200000" /> <add key="NumberOfBatches" value="2" /> <add key="CollectionPartitionKey" value="/profileid" /> <add key="SampleDocumentTemplateFile" value="SampleDocumentTemplate.json" /> </appSettings>

如果您有其他问题,请告诉我们。谢谢,〜迈克

Please let us know if you have additional questions. Thanks, ~Mike

更多推荐

COSMOS DB批量插入Initialize()无效

本文发布于:2023-11-17 02:22:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608461.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:批量   COSMOS   DB   Initialize

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!