// methods
        public async Task <BulkWriteOperationResult> ExecuteAsync(IChannelHandle channel, CancellationToken cancellationToken)
        {
            var batchResults      = new List <BulkWriteBatchResult>();
            var remainingRequests = Enumerable.Empty <WriteRequest>();
            var hasWriteErrors    = false;

            var runCount     = 0;
            var maxRunLength = Math.Min(_maxBatchCount ?? int.MaxValue, channel.ConnectionDescription.MaxBatchCount);

            foreach (var run in FindRuns(maxRunLength))
            {
                runCount++;

                if (hasWriteErrors && _isOrdered)
                {
                    remainingRequests = remainingRequests.Concat(run.Requests);
                    continue;
                }

                var batchResult = await ExecuteBatchAsync(channel, run, cancellationToken).ConfigureAwait(false);

                batchResults.Add(batchResult);

                hasWriteErrors |= batchResult.HasWriteErrors;
            }

            if (runCount == 0)
            {
                throw new InvalidOperationException("Bulk write operation is empty.");
            }

            var combiner = new BulkWriteBatchResultCombiner(batchResults, _writeConcern.IsAcknowledged);

            return(combiner.CreateResultOrThrowIfHasErrors(channel.ConnectionDescription.ConnectionId, remainingRequests.ToList()));
        }
            public BulkWriteOperationResult CreateFinalResultOrThrow(IChannelHandle channel)
            {
                var combiner          = new BulkWriteBatchResultCombiner(_batchResults, _writeConcern.IsAcknowledged);
                var remainingRequests = _requests.GetUnprocessedItems();

                return(combiner.CreateResultOrThrowIfHasErrors(channel.ConnectionDescription.ConnectionId, remainingRequests));
            }
        // methods
        public async Task <BulkWriteOperationResult> ExecuteAsync(IConnectionHandle connection, TimeSpan timeout, CancellationToken cancellationToken)
        {
            var slidingTimeout    = new SlidingTimeout(timeout);
            var batchResults      = new List <BulkWriteBatchResult>();
            var remainingRequests = Enumerable.Empty <WriteRequest>();
            var hasWriteErrors    = false;

            var runCount = 0;

            foreach (var run in FindRuns())
            {
                runCount++;

                if (hasWriteErrors && _isOrdered)
                {
                    remainingRequests = remainingRequests.Concat(run.Requests);
                    continue;
                }

                var batchResult = await ExecuteBatchAsync(connection, run, slidingTimeout, cancellationToken);

                batchResults.Add(batchResult);

                hasWriteErrors |= batchResult.HasWriteErrors;
            }

            if (runCount == 0)
            {
                throw new InvalidOperationException("Bulk write operation is empty.");
            }

            var combiner = new BulkWriteBatchResultCombiner(batchResults, _writeConcern.IsAcknowledged);

            return(combiner.CreateResultOrThrowIfHasErrors(remainingRequests.ToList()));
        }
Esempio n. 4
0
        public async Task <BulkWriteOperationResult> ExecuteAsync(IChannelHandle channel, CancellationToken cancellationToken)
        {
            var batchResults      = new List <BulkWriteBatchResult>();
            var remainingRequests = new List <WriteRequest>();
            var hasWriteErrors    = false;

            var originalIndex = 0;

            foreach (WriteRequest request in _requests)
            {
                if (hasWriteErrors && _isOrdered)
                {
                    remainingRequests.Add(request);
                    continue;
                }

                var batchResult = await EmulateSingleRequestAsync(channel, request, originalIndex, cancellationToken).ConfigureAwait(false);

                batchResults.Add(batchResult);

                hasWriteErrors |= batchResult.HasWriteErrors;
                originalIndex++;
            }

            var combiner = new BulkWriteBatchResultCombiner(batchResults, _writeConcern.IsAcknowledged);

            return(combiner.CreateResultOrThrowIfHasErrors(channel.ConnectionDescription.ConnectionId, remainingRequests));
        }
        public async Task <BulkWriteOperationResult> ExecuteAsync(IConnectionHandle connection, TimeSpan timeout, CancellationToken cancellationToken)
        {
            var slidingTimeout = new SlidingTimeout(timeout);

            var batchResults      = new List <BulkWriteBatchResult>();
            var remainingRequests = new List <WriteRequest>();
            var hasWriteErrors    = false;

            var originalIndex = 0;

            foreach (WriteRequest request in _requests)
            {
                if (hasWriteErrors && _isOrdered)
                {
                    remainingRequests.Add(request);
                    continue;
                }

                var batchResult = await EmulateSingleRequestAsync(connection, request, originalIndex, slidingTimeout, cancellationToken);

                batchResults.Add(batchResult);

                hasWriteErrors |= batchResult.HasWriteErrors;
                originalIndex++;
            }

            var combiner = new BulkWriteBatchResultCombiner(batchResults, _writeConcern.IsAcknowledged);

            return(combiner.CreateResultOrThrowIfHasErrors(remainingRequests));
        }
Esempio n. 6
0
        private async Task <BulkWriteOperationResult> ExecuteBatchesAsync(IConnectionHandle connection, TimeSpan timeout, CancellationToken cancellationToken)
        {
            var slidingTimeout    = new SlidingTimeout(timeout);
            var batchResults      = new List <BulkWriteBatchResult>();
            var remainingRequests = Enumerable.Empty <WriteRequest>();
            var hasWriteErrors    = false;

            var decoratedRequests = DecorateRequests(_requests);

            using (var enumerator = decoratedRequests.GetEnumerator())
            {
                var originalIndex = 0;

                var requestSource = new BatchableSource <WriteRequest>(enumerator);
                while (requestSource.HasMore)
                {
                    if (hasWriteErrors && _isOrdered)
                    {
                        // note: we have to materialize the list of remaining items before the enumerator gets Disposed
                        remainingRequests = remainingRequests.Concat(requestSource.GetRemainingItems()).ToList();
                        break;
                    }

                    var batchResult = await ExecuteBatchAsync(connection, requestSource, originalIndex, slidingTimeout, cancellationToken).ConfigureAwait(false);

                    batchResults.Add(batchResult);
                    hasWriteErrors |= batchResult.HasWriteErrors;
                    originalIndex  += batchResult.BatchCount;

                    requestSource.ClearBatch();
                }
            }

            var combiner = new BulkWriteBatchResultCombiner(batchResults, _writeConcern.IsAcknowledged);

            return(combiner.CreateResultOrThrowIfHasErrors(remainingRequests.ToList()));
        }
            public BulkWriteOperationResult GetFinalResultOrThrow()
            {
                var combiner = new BulkWriteBatchResultCombiner(_batchResults, _operation._writeConcern.IsAcknowledged);

                return(combiner.CreateResultOrThrowIfHasErrors(_channel.ConnectionDescription.ConnectionId, _remainingRequests.ToList()));
            }
 public BulkWriteOperationResult GetFinalResultOrThrow()
 {
     var combiner = new BulkWriteBatchResultCombiner(_batchResults, _operation._writeConcern.IsAcknowledged);
     return combiner.CreateResultOrThrowIfHasErrors(_channel.ConnectionDescription.ConnectionId, _remainingRequests);
 }
        public async Task<BulkWriteResult> ExecuteAsync(IConnectionHandle connection, TimeSpan timeout, CancellationToken cancellationToken)
        {
            var slidingTimeout = new SlidingTimeout(timeout);

            var batchResults = new List<BulkWriteBatchResult>();
            var remainingRequests = new List<WriteRequest>();
            var hasWriteErrors = false;

            var originalIndex = 0;
            foreach (WriteRequest request in _requests)
            {
                if (hasWriteErrors && _isOrdered)
                {
                    remainingRequests.Add(request);
                    continue;
                }

                var batchResult = await EmulateSingleRequestAsync(connection, request, originalIndex, slidingTimeout, cancellationToken);
                batchResults.Add(batchResult);

                hasWriteErrors |= batchResult.HasWriteErrors;
                originalIndex++;
            }

            var combiner = new BulkWriteBatchResultCombiner(batchResults, !_writeConcern.Equals(WriteConcern.Unacknowledged));
            return combiner.CreateResultOrThrowIfHasErrors(remainingRequests);
        }
        public async Task<BulkWriteOperationResult> ExecuteAsync(IChannelHandle channel, CancellationToken cancellationToken)
        {
            var batchResults = new List<BulkWriteBatchResult>();
            var remainingRequests = new List<WriteRequest>();
            var hasWriteErrors = false;

            var originalIndex = 0;
            foreach (WriteRequest request in _requests)
            {
                if (hasWriteErrors && _isOrdered)
                {
                    remainingRequests.Add(request);
                    continue;
                }

                var batchResult = await EmulateSingleRequestAsync(channel, request, originalIndex, cancellationToken).ConfigureAwait(false);
                batchResults.Add(batchResult);

                hasWriteErrors |= batchResult.HasWriteErrors;
                originalIndex++;
            }

            var combiner = new BulkWriteBatchResultCombiner(batchResults, _writeConcern.IsAcknowledged);
            return combiner.CreateResultOrThrowIfHasErrors(channel.ConnectionDescription.ConnectionId, remainingRequests);
        }
Esempio n. 11
0
            public BulkWriteOperationResult GetFinalResultOrThrow(ConnectionId connectionId)
            {
                var combiner = new BulkWriteBatchResultCombiner(_batchResults, _writeConcern.IsAcknowledged);

                return(combiner.CreateResultOrThrowIfHasErrors(connectionId, _unprocessed.Select(r => r.Request).ToList()));
            }