use of com.microsoft.azure.cosmosdb.DocumentClientException in project ambry by linkedin.
the class CosmosDataAccessor method queryMetadata.
/**
* Get the list of blobs in the specified partition matching the specified DocumentDB query spec.
* @param partitionPath the partition to query.
* @param querySpec the DocumentDB {@link SqlQuerySpec} to execute.
* @param timer the {@link Timer} to use to record query time (excluding waiting).
* @return a List of {@link CloudBlobMetadata} referencing the matching blobs.
*/
List<CloudBlobMetadata> queryMetadata(String partitionPath, SqlQuerySpec querySpec, Timer timer) throws DocumentClientException {
FeedOptions feedOptions = new FeedOptions();
// TODO: set maxItemCount
feedOptions.setResponseContinuationTokenLimitInKb(continuationTokenLimitKb);
feedOptions.setPartitionKey(new PartitionKey(partitionPath));
// TODO: consolidate error count here
try {
Iterator<FeedResponse<Document>> iterator = executeCosmosQuery(partitionPath, querySpec, feedOptions, timer).getIterator();
List<CloudBlobMetadata> metadataList = new ArrayList<>();
double requestCharge = 0.0;
while (iterator.hasNext()) {
FeedResponse<Document> response = iterator.next();
requestCharge += response.getRequestCharge();
response.getResults().iterator().forEachRemaining(doc -> metadataList.add(createMetadataFromDocument(doc)));
}
if (requestCharge >= requestChargeThreshold) {
logger.info("Query partition {} request charge {} for {} records", partitionPath, requestCharge, metadataList.size());
}
return metadataList;
} catch (RuntimeException rex) {
if (rex.getCause() instanceof DocumentClientException) {
logger.warn("Query {} on partition {} got {}", querySpec.getQueryText(), partitionPath, ((DocumentClientException) rex.getCause()).getStatusCode());
throw (DocumentClientException) rex.getCause();
}
throw rex;
}
}
use of com.microsoft.azure.cosmosdb.DocumentClientException in project ambry by linkedin.
the class AzureStorageCompactorTest method testPurgeWithCosmosBulkDeleteError.
/**
* Test purgeBlobs with Cosmos bulk delete error
*/
@Test
public void testPurgeWithCosmosBulkDeleteError() throws Exception {
Exception mockException = new RuntimeException(new DocumentClientException(HttpConstants.StatusCodes.TOO_MANY_REQUESTS));
doThrow(mockException).when(mockumentClient).executeStoredProcedure(anyString(), any(RequestOptions.class), any());
try {
AzureCompactionUtil.purgeBlobs(blobMetadataList, azureBlobDataAccessor, azureMetrics, cosmosDataAccessor);
fail("Expected CloudStorageException");
} catch (CloudStorageException bex) {
}
assertEquals(0, azureMetrics.blobDeletedCount.getCount());
assertEquals(numBlobsPerQuery, azureMetrics.blobDeleteErrorCount.getCount());
}
Aggregations