public override void Configure(IFunctionsHostBuilder builder) { string endPoint = Environment.GetEnvironmentVariable($"{"EndPoint"}"); string authKey = Environment.GetEnvironmentVariable($"{"AuthKey"}"); string database = Environment.GetEnvironmentVariable($"{"TargetDatabase"}"); string collection = Environment.GetEnvironmentVariable($"{"TargetCollection"}"); Uri targetContainerUri = UriFactory.CreateDocumentCollectionUri(database, collection); DocumentClient client = GetCustomClient(endPoint, authKey); DocumentCollection customTargetContainer = GetTargetCollection(database, collection, client); IBulkExecutor bulkExecutor = GetBulkExecutor(client, customTargetContainer); client.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 30; client.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 30; bulkExecutor.InitializeAsync().GetAwaiter().GetResult(); // Set retry options to 0 to pass congestion control to bulk executor. client.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 0; client.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 0; builder.Services.AddSingleton <DocumentClient>(client); builder.Services.AddSingleton <Uri>(targetContainerUri); builder.Services.AddSingleton <IBulkExecutor>(bulkExecutor); }
public async Task InitializeAsync(bool shouldRestart) { var(endpoint, authKey, database, container, partitionKey, offerThroughput) = GetConfiguration(); _logger.Information(endpoint); _documentClient = new DocumentClient(new Uri(endpoint), authKey, new ConnectionPolicy { ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp }); if (shouldRestart) { await HandleRestartAsync(database, container); } var documentCollection = await CreateCollectionIfNotExistsAsync(database, container, partitionKey, offerThroughput); _logger.Information("{@documentCollection}", documentCollection); PartitionKey = documentCollection.PartitionKey.Paths.FirstOrDefault()?.Replace("/", string.Empty); // Set retry options high during initialization (default values). _documentClient.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 30; _documentClient.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 9; _graphBulkExecutor = new GraphBulkExecutor(_documentClient, documentCollection); await _graphBulkExecutor.InitializeAsync(); // Set retries to 0 to pass complete control to bulk executor. _documentClient.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 0; _documentClient.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 0; }
private async Task InitBulkExecutor() { Client.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 30; Client.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 9; bulkExecutor = new GraphBulkExecutor(Client, Collection); await bulkExecutor.InitializeAsync(); Client.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 0; Client.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 0; }
public static async void InitBulkExecutor(DocumentClient client, DocumentCollection documentCollection) { if (bulkExecutor != null) { return; } bulkExecutor = new BulkExecutor(client, documentCollection); await bulkExecutor.InitializeAsync(); client.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 0; client.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 0; }
public async Task InitializeBulkExecutor(DocumentClient targetClient, DocumentCollection targetCollection) { logger.LogInfo("Inside InitializeBulkExecutor "); // Set retry options high for initialization (default values). targetClient.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 30; targetClient.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 9; bulkExecutor = new BulkExecutor(targetClient, targetCollection); await bulkExecutor.InitializeAsync(); // Set retries to 0 to pass control to bulk executor. targetClient.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 0; targetClient.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 0; }
private static async Task InitTask() { // Set retry options high for initialization (default values). Client.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 30; Client.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 9; _graphBulkExecutor = new GraphBulkExecutor(Client, _dataCollection); await _graphBulkExecutor.InitializeAsync(); Trace.TraceInformation("InitializeAsync"); // Set retries to 0 to pass control to bulk executor. Client.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 0; Client.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 0; }
public async Task OpenAsync(IChangeFeedObserverContext context) { client.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 100000; client.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 100000; DocumentCollection destinationCollection = await client.ReadDocumentCollectionAsync(this.destinationCollectionUri); bulkExecutor = new BulkExecutor(client, destinationCollection); client.ConnectionPolicy.UserAgentSuffix = (" migrationService"); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("Observer opened for partition Key Range: {0}", context.PartitionKeyRangeId); Console.ForegroundColor = ConsoleColor.White; await bulkExecutor.InitializeAsync(); }
private static async Task InitializeCosmosDbAsync() { _documentClient = new DocumentClient(new Uri(_accountEndpoint), _accountKey, _connectionPolicy); var dataCollection = _documentClient.CreateDocumentCollectionQuery(UriFactory.CreateDatabaseUri(_database)) .Where(c => c.Id == _collection).AsEnumerable().FirstOrDefault(); _partitionKey = dataCollection.PartitionKey.Paths.First().Replace("/", string.Empty); // Set retry options high during initialization (default values). _documentClient.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 30; _documentClient.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 9; _graphBulkExecutor = new GraphBulkExecutor(_documentClient, dataCollection); await _graphBulkExecutor.InitializeAsync(); // Set retries to 0 to pass complete control to bulk executor. _documentClient.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 0; _documentClient.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 0; }