[英]Java Api for Azure Cosmos Documents DB (SQL Api)
[英]How to rename a container in Azure Cosmos DB with Java SQL API?
是的你是對的。 目前無法更改容器名稱。 據我了解,您想丟棄舊容器(因為您最初想重命名)並將數據遷移到新容器。
數據遷移工具是一個很好的工具:教程:使用數據遷移工具將數據遷移到 Azure Cosmos DB
另外,請查看Java 、 API 文檔和示例的批量執行程序庫。
您可以在BulkExecutor class 中使用importAll
:
ConnectionPolicy connectionPolicy = new ConnectionPolicy();
RetryOptions retryOptions = new RetryOptions();
// Set client's retry options high for initialization
retryOptions.setMaxRetryWaitTimeInSeconds(120);
retryOptions.setMaxRetryAttemptsOnThrottledRequests(100);
connectionPolicy.setRetryOptions(retryOptions);
connectionPolicy.setMaxPoolSize(1000);
DocumentClient client = new DocumentClient(HOST, MASTER_KEY, connectionPolicy, null);
String collectionLink = String.format("/dbs/%s/colls/%s", "mydb", "mycol");
DocumentCollection collection = client.readCollection(collectionLink, null).getResource();
DocumentBulkExecutor executor = DocumentBulkExecutor.builder().from(client, collection,
collection.getPartitionKey(), collectionOfferThroughput).build();
// Set retries to 0 to pass control to bulk executor
client.getConnectionPolicy().getRetryOptions().setMaxRetryWaitTimeInSeconds(0);
client.getConnectionPolicy().getRetryOptions().setMaxRetryAttemptsOnThrottledRequests(0);
for(int i = 0; i < 10; i++) {
List documents = documentSource.getMoreDocuments();
BulkImportResponse bulkImportResponse = executor.importAll(documents, false, true, 40);
// Validate that all documents inserted to ensure no failure.
if (bulkImportResponse.getNumberOfDocumentsImported() < documents.size()) {
for(Exception e: bulkImportResponse.getErrors()) {
// Validate why there were some failures.
e.printStackTrace();
}
break;
}
}
executor.close();
client.close();
我通過鏈接而不是復制所有數據來解決問題。 這模擬了容器的重命名。 我現在使用兩個容器而不是一個容器。 第一個僅包含第二個容器的名稱。
現在我可以構建新版本的容器了。 如果我完成了,我會更改已保存容器名稱的名稱。 然后我放下舊容器。
棘手的是通知應用程序的所有節點使用新的容器名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.