Search in sources :

Example 1 with ChangeFeedOptions

use of com.microsoft.azure.cosmosdb.ChangeFeedOptions in project ambry by linkedin.

the class CosmosDataAccessor method queryChangeFeed.

/**
 * Query Cosmos change feed to get the next set of {@code CloudBlobMetadata} objects in specified {@code partitionPath}
 * after {@code requestContinationToken}, capped by specified {@code maxFeedSize} representing the max number of items to
 * be queried from the change feed.
 * @param requestContinuationToken Continuation token after which change feed is requested.
 * @param maxFeedSize max item count to be requested in the feed query.
 * @param changeFeed {@link CloudBlobMetadata} {@code List} to be populated with the next set of entries returned by change feed query.
 * @param partitionPath partition for which the change feed is requested.
 * @param timer the {@link Timer} to use to record query time (excluding waiting).
 * @return next continuation token.
 * @throws DocumentClientException
 */
public String queryChangeFeed(String requestContinuationToken, int maxFeedSize, List<CloudBlobMetadata> changeFeed, String partitionPath, Timer timer) throws DocumentClientException {
    azureMetrics.changeFeedQueryCount.inc();
    ChangeFeedOptions changeFeedOptions = new ChangeFeedOptions();
    changeFeedOptions.setPartitionKey(new PartitionKey(partitionPath));
    changeFeedOptions.setMaxItemCount(maxFeedSize);
    if (Utils.isNullOrEmpty(requestContinuationToken)) {
        changeFeedOptions.setStartFromBeginning(true);
    } else {
        changeFeedOptions.setRequestContinuation(requestContinuationToken);
    }
    try {
        FeedResponse<Document> feedResponse = executeCosmosChangeFeedQuery(changeFeedOptions, timer);
        feedResponse.getResults().stream().map(this::createMetadataFromDocument).forEach(changeFeed::add);
        return feedResponse.getResponseContinuation();
    } catch (RuntimeException rex) {
        azureMetrics.changeFeedQueryFailureCount.inc();
        if (rex.getCause() instanceof DocumentClientException) {
            throw (DocumentClientException) rex.getCause();
        }
        throw rex;
    } catch (Exception ex) {
        azureMetrics.changeFeedQueryFailureCount.inc();
        throw ex;
    }
}
Also used : PartitionKey(com.microsoft.azure.cosmosdb.PartitionKey) ChangeFeedOptions(com.microsoft.azure.cosmosdb.ChangeFeedOptions) Document(com.microsoft.azure.cosmosdb.Document) DocumentClientException(com.microsoft.azure.cosmosdb.DocumentClientException) CloudStorageException(com.github.ambry.cloud.CloudStorageException) DocumentClientException(com.microsoft.azure.cosmosdb.DocumentClientException)

Aggregations

CloudStorageException (com.github.ambry.cloud.CloudStorageException)1 ChangeFeedOptions (com.microsoft.azure.cosmosdb.ChangeFeedOptions)1 Document (com.microsoft.azure.cosmosdb.Document)1 DocumentClientException (com.microsoft.azure.cosmosdb.DocumentClientException)1 PartitionKey (com.microsoft.azure.cosmosdb.PartitionKey)1