private BulkWriteBatchResult ExecuteBatch(IChannelHandle channel, ICoreSessionHandle session, Run run, bool isLast, CancellationToken cancellationToken) { BulkWriteOperationResult result; MongoBulkWriteOperationException exception = null; try { switch (run.RequestType) { case WriteRequestType.Delete: result = ExecuteDeletes(channel, session, run.Requests.Cast <DeleteRequest>(), isLast, cancellationToken); break; case WriteRequestType.Insert: result = ExecuteInserts(channel, session, run.Requests.Cast <InsertRequest>(), isLast, cancellationToken); break; case WriteRequestType.Update: result = ExecuteUpdates(channel, session, run.Requests.Cast <UpdateRequest>(), isLast, cancellationToken); break; default: throw new MongoInternalException("Unrecognized RequestType."); } } catch (MongoBulkWriteOperationException ex) { result = ex.Result; exception = ex; } return(BulkWriteBatchResult.Create(result, exception, run.IndexMap)); }
protected virtual async Task <BulkWriteBatchResult> EmulateSingleRequestAsync(IConnectionHandle connection, WriteRequest request, int originalIndex, TimeSpan timeout, CancellationToken cancellationToken) { var protocol = CreateProtocol(connection, request); WriteConcernResult writeConcernResult = null; WriteConcernException writeConcernException = null; try { writeConcernResult = await protocol.ExecuteAsync(connection, timeout, cancellationToken); } catch (WriteConcernException ex) { writeConcernResult = ex.WriteConcernResult; writeConcernException = ex; } var indexMap = new IndexMap.RangeBased(0, originalIndex, 1); return(BulkWriteBatchResult.Create( request, writeConcernResult, writeConcernException, indexMap)); }
private BulkWriteBatchResult CreateBatchResult(BatchableSource <WriteRequest> requestSource, int originalIndex, BsonDocument writeCommandResult) { var indexMap = new IndexMap.RangeBased(0, originalIndex, requestSource.Batch.Count); return(BulkWriteBatchResult.Create( _isOrdered, requestSource.Batch, writeCommandResult, indexMap)); }
private BulkWriteBatchResult CreateSingleRequestResult(TWriteRequest request, int originalIndex, WriteConcernResult writeConcernResult, MongoWriteConcernException writeConcernException) { var indexMap = new IndexMap.RangeBased(0, originalIndex, 1); return(BulkWriteBatchResult.Create( request, writeConcernResult, writeConcernException, indexMap)); }
// private methods private BulkWriteBatchResult CreateBatchResult(Batch batch, BsonDocument writeCommandResult) { var requests = batch.Requests; var requestsInBatch = requests.GetProcessedItems(); var indexMap = new IndexMap.RangeBased(0, requests.Offset, requests.Count); return(BulkWriteBatchResult.Create( _isOrdered, requestsInBatch, writeCommandResult, indexMap)); }
private async Task <BulkWriteBatchResult> ExecuteBatchAsync(RetryableWriteContext context, Batch batch, CancellationToken cancellationToken) { BulkWriteOperationResult result; MongoBulkWriteOperationException exception = null; try { var operation = CreateUnmixedBatchOperation(batch); result = await operation.ExecuteAsync(context, cancellationToken).ConfigureAwait(false); } catch (MongoBulkWriteOperationException ex) { result = ex.Result; exception = ex; } return(BulkWriteBatchResult.Create(result, exception, batch.IndexMap)); }
private BulkWriteBatchResult ExecuteBatch(RetryableWriteContext context, Batch batch, CancellationToken cancellationToken) { BulkWriteOperationResult result; MongoBulkWriteOperationException exception = null; try { var operation = CreateUnmixedBatchOperation(batch); result = operation.Execute(context, cancellationToken); } catch (MongoBulkWriteOperationException ex) { result = ex.Result; exception = ex; } return(BulkWriteBatchResult.Create(result, exception, batch.IndexMap)); }
private async Task <BulkWriteBatchResult> ExecuteBatchAsync(IChannelHandle channel, BatchableSource <WriteRequest> requestSource, int originalIndex, CancellationToken cancellationToken) { var maxBatchCount = Math.Min(_maxBatchCount ?? int.MaxValue, channel.ConnectionDescription.MaxBatchCount); var maxBatchLength = Math.Min(_maxBatchLength ?? int.MaxValue, channel.ConnectionDescription.MaxDocumentSize); var maxDocumentSize = channel.ConnectionDescription.MaxDocumentSize; var maxWireDocumentSize = channel.ConnectionDescription.MaxWireDocumentSize; var batchSerializer = CreateBatchSerializer(maxBatchCount, maxBatchLength, maxDocumentSize, maxWireDocumentSize); var writeCommand = CreateWriteCommand(batchSerializer, requestSource); var writeCommandResult = await ExecuteProtocolAsync(channel, writeCommand, cancellationToken).ConfigureAwait(false); var indexMap = new IndexMap.RangeBased(0, originalIndex, requestSource.Batch.Count); return(BulkWriteBatchResult.Create( _isOrdered, requestSource.Batch, writeCommandResult, indexMap)); }
private async Task <BulkWriteBatchResult> ExecuteBatchAsync(IConnectionHandle connection, BatchableSource <WriteRequest> requestSource, int originalIndex, TimeSpan timeout, CancellationToken cancellationToken) { var maxBatchCount = Math.Min(_maxBatchCount, connection.Description.MaxBatchCount); var maxBatchLength = Math.Min(_maxBatchLength, connection.Description.MaxDocumentSize); var maxDocumentSize = connection.Description.MaxDocumentSize; var maxWireDocumentSize = connection.Description.MaxWireDocumentSize; var batchSerializer = CreateBatchSerializer(maxBatchCount, maxBatchLength, maxDocumentSize, maxWireDocumentSize); var writeCommand = CreateWriteCommand(batchSerializer, requestSource); var protocol = CreateWriteCommandProtocol(writeCommand); var writeCommandResult = await protocol.ExecuteAsync(connection, timeout, cancellationToken); var indexMap = new IndexMap.RangeBased(0, originalIndex, requestSource.Batch.Count); return(BulkWriteBatchResult.Create( _isOrdered, requestSource.Batch, writeCommandResult, indexMap)); }
// methods protected virtual async Task <BulkWriteBatchResult> EmulateSingleRequestAsync(IChannelHandle channel, WriteRequest request, int originalIndex, CancellationToken cancellationToken) { WriteConcernResult writeConcernResult = null; MongoWriteConcernException writeConcernException = null; try { writeConcernResult = await ExecuteProtocolAsync(channel, request, cancellationToken).ConfigureAwait(false); } catch (MongoWriteConcernException ex) { writeConcernResult = ex.WriteConcernResult; writeConcernException = ex; } var indexMap = new IndexMap.RangeBased(0, originalIndex, 1); return(BulkWriteBatchResult.Create( request, writeConcernResult, writeConcernException, indexMap)); }
private async Task <BulkWriteBatchResult> ExecuteBatchAsync(IChannelHandle channel, Run run, CancellationToken cancellationToken) { BulkWriteOperationResult result; MongoBulkWriteOperationException exception = null; try { switch (run.RequestType) { case WriteRequestType.Delete: result = await ExecuteDeletesAsync(channel, run.Requests.Cast <DeleteRequest>(), cancellationToken).ConfigureAwait(false); break; case WriteRequestType.Insert: result = await ExecuteInsertsAsync(channel, run.Requests.Cast <InsertRequest>(), cancellationToken).ConfigureAwait(false); break; case WriteRequestType.Update: result = await ExecuteUpdatesAsync(channel, run.Requests.Cast <UpdateRequest>(), cancellationToken).ConfigureAwait(false); break; default: throw new MongoInternalException("Unrecognized RequestType."); } } catch (MongoBulkWriteOperationException ex) { result = ex.Result; exception = ex; } return(BulkWriteBatchResult.Create(result, exception, run.IndexMap)); }
private async Task <BulkWriteBatchResult> ExecuteBatchAsync(IConnectionHandle connection, Run run, TimeSpan timeout, CancellationToken cancellationToken) { BulkWriteResult result; BulkWriteException exception = null; try { switch (run.RequestType) { case WriteRequestType.Delete: result = await ExecuteDeletesAsync(connection, run.Requests.Cast <DeleteRequest>(), timeout, cancellationToken); break; case WriteRequestType.Insert: result = await ExecuteInsertsAsync(connection, run.Requests.Cast <InsertRequest>(), timeout, cancellationToken); break; case WriteRequestType.Update: result = await ExecuteUpdatesAsync(connection, run.Requests.Cast <UpdateRequest>(), timeout, cancellationToken); break; default: throw new InternalException("Unrecognized RequestType."); } } catch (BulkWriteException ex) { result = ex.Result; exception = ex; } return(BulkWriteBatchResult.Create(result, exception, run.IndexMap)); }