use of com.microsoft.azure.cosmosdb.RetryOptions in project ambry by linkedin.
the class AzureContainerCompactorIntegrationTest method cleanup.
/**
* Cleanup entries in the cosmos db container deletion table.
* @throws DocumentClientException in case of any exception.
*/
private void cleanup() throws DocumentClientException {
ConnectionPolicy connectionPolicy = new ConnectionPolicy();
connectionPolicy.setRequestTimeoutInMillis(cloudConfig.cloudQueryRequestTimeout);
// Note: retry decisions are made at CloudBlobStore level. Configure Cosmos with no retries.
RetryOptions noRetries = new RetryOptions();
noRetries.setMaxRetryAttemptsOnThrottledRequests(0);
connectionPolicy.setRetryOptions(noRetries);
if (azureCloudConfig.cosmosDirectHttps) {
logger.info("Using CosmosDB DirectHttps connection mode");
connectionPolicy.setConnectionMode(ConnectionMode.Direct);
}
AsyncDocumentClient asyncDocumentClient = new AsyncDocumentClient.Builder().withServiceEndpoint(azureCloudConfig.cosmosEndpoint).withMasterKeyOrResourceToken(azureCloudConfig.cosmosKey).withConnectionPolicy(connectionPolicy).withConsistencyLevel(ConsistencyLevel.Session).build();
Set<CosmosContainerDeletionEntry> entries = cloudDestination.getCosmosDataAccessor().getDeprecatedContainers(100);
AtomicBoolean error = new AtomicBoolean(false);
while (!entries.isEmpty() && !error.get()) {
entries.stream().forEach(entry -> {
try {
RequestOptions requestOptions = new RequestOptions();
requestOptions.setPartitionKey(new PartitionKey(entry.getId()));
cloudRequestAgent.doWithRetries(() -> CosmosDataAccessor.executeCosmosAction(() -> asyncDocumentClient.deleteDocument(azureCloudConfig.cosmosDeletedContainerCollectionLink + "/docs/" + entry.getId(), requestOptions).toBlocking().single(), null), "Test Cleanup", entry.getId());
} catch (CloudStorageException ex) {
logger.warn("Failed to delete container deprecation entry {}. Unable to cleanup", entry);
error.set(true);
}
});
entries = cloudDestination.getCosmosDataAccessor().getDeprecatedContainers(100);
}
}
Aggregations