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)); }
public void TestRangeBasedWith1() { var map = new IndexMap.RangeBased(0, 1, 1); Assert.AreEqual(1, map.Map(0)); Assert.Throws <KeyNotFoundException>(() => map.Map(1)); }
public void TestRangeBasedAdd1() { IndexMap map = new IndexMap.RangeBased(); map = map.Add(0, 1); Assert.IsInstanceOf <IndexMap.RangeBased>(map); Assert.AreEqual(1, map.Map(0)); Assert.Throws <KeyNotFoundException>(() => map.Map(1)); }
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 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)); }
public void TestRangeBasedAdd2() { IndexMap map = new IndexMap.RangeBased(); map = map.Add(0, 1); map = map.Add(1, 2); Assert.IsType <IndexMap.RangeBased>(map); Assert.Equal(1, map.Map(0)); Assert.Equal(2, map.Map(1)); Assert.Throws <KeyNotFoundException>(() => map.Map(2)); }
public void TestMixedWith1Then1() { IndexMap map = new IndexMap.RangeBased(); map = map.Add(0, 1); Assert.IsInstanceOf <IndexMap.RangeBased>(map); map = map.Add(1, 3); Assert.IsInstanceOf <IndexMap.DictionaryBased>(map); Assert.AreEqual(1, map.Map(0)); Assert.AreEqual(3, map.Map(1)); Assert.Throws <KeyNotFoundException>(() => map.Map(2)); }
// 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)); }
public void TestMixedWith2Then1() { IndexMap map = new IndexMap.RangeBased(); map = map.Add(0, 1); map = map.Add(1, 2); Assert.IsType <IndexMap.RangeBased>(map); map = map.Add(2, 4); Assert.IsType <IndexMap.DictionaryBased>(map); Assert.Equal(1, map.Map(0)); Assert.Equal(2, map.Map(1)); Assert.Equal(4, map.Map(2)); Assert.Throws <KeyNotFoundException>(() => map.Map(3)); }
private BulkWriteBatchResult ExecuteBatch(MongoConnection connection, Batch <WriteRequest> batch, int originalIndex) { var batchSerializer = CreateBatchSerializer(); var writeCommand = CreateWriteCommand(batchSerializer, batch); var writeCommandOperation = CreateWriteCommandOperation(writeCommand); var writeCommandResult = writeCommandOperation.Execute(connection); var batchProgress = batchSerializer.BatchProgress; var indexMap = new IndexMap.RangeBased(0, originalIndex, batchProgress.BatchCount); return(BulkWriteBatchResult.Create( _args.IsOrdered, batchProgress.BatchItems, writeCommandResult.Response, indexMap, batchProgress.NextBatch)); }
// protected methods protected override BulkWriteBatchResult EmulateSingleRequest(MongoConnection connection, WriteRequest request, int originalIndex) { var serverInstance = connection.ServerInstance; var insertRequest = (InsertRequest)request; var insertRequests = new[] { insertRequest }; var operationArgs = new BulkInsertOperationArgs( _args.AssignId, _args.CheckElementNames, _args.CollectionName, _args.DatabaseName, 1, // maxBatchCount serverInstance.MaxMessageLength, // maxBatchLength true, // isOrdered _args.ReaderSettings, insertRequests, _args.WriteConcern, _args.WriterSettings); var operation = new InsertOpcodeOperation(operationArgs); WriteConcernResult writeConcernResult = null; WriteConcernException writeConcernException = null; try { var operationResult = operation.Execute(connection); if (operationResult != null) { writeConcernResult = operationResult.First(); } } catch (WriteConcernException ex) { writeConcernResult = ex.WriteConcernResult; writeConcernException = ex; } var indexMap = new IndexMap.RangeBased(0, originalIndex, 1); return(BulkWriteBatchResult.Create( insertRequest, writeConcernResult, writeConcernException, 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 methods private Batch GetNextBatch() { var batchType = _unprocessed[0].Request.RequestType; List <WriteRequest> requests; IndexMap indexMap; if (_isOrdered) { var index = _unprocessed.FindIndex(r => r.Request.RequestType != batchType); var count = index == -1 ? _unprocessed.Count : index; requests = _unprocessed.Take(count).Select(r => r.Request).ToList(); indexMap = new IndexMap.RangeBased(0, _unprocessed[0].Index, count); _unprocessed.RemoveRange(0, count); } else { var matching = _unprocessed.Where(r => r.Request.RequestType == batchType).ToList(); requests = matching.Select(r => r.Request).ToList(); indexMap = new IndexMap.DictionaryBased(); for (var i = 0; i < matching.Count; i++) { indexMap.Add(i, matching[i].Index); } _unprocessed = _unprocessed.Where(r => r.Request.RequestType != batchType).ToList(); } var writeConcern = _writeConcern; if (!writeConcern.IsAcknowledged && _isOrdered && _unprocessed.Count > 0) { writeConcern = WriteConcern.W1; // explicitly do not use the server's default } return(new Batch { BatchType = batchType, Requests = requests, IndexMap = indexMap, WriteConcern = writeConcern }); }
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)); }
// protected methods protected override BulkWriteBatchResult EmulateSingleRequest(MongoConnection connection, WriteRequest request, int originalIndex) { var serverInstance = connection.ServerInstance; var deleteRequest = (DeleteRequest)request; var deleteRequests = new[] { deleteRequest }; var operationArgs = new BulkDeleteOperationArgs( _args.CollectionName, _args.DatabaseName, 1, // maxBatchCount serverInstance.MaxMessageLength, // maxBatchLength serverInstance.MaxDocumentSize, serverInstance.MaxWireDocumentSize, true, // isOrdered _args.ReaderSettings, deleteRequests, _args.WriteConcern, _args.WriterSettings); var operation = new DeleteOpcodeOperation(operationArgs); WriteConcernResult writeConcernResult; WriteConcernException writeConcernException = null; try { writeConcernResult = operation.Execute(connection); } catch (WriteConcernException ex) { writeConcernResult = ex.WriteConcernResult; writeConcernException = ex; } var indexMap = new IndexMap.RangeBased(0, originalIndex, 1); return(BulkWriteBatchResult.Create( deleteRequest, writeConcernResult, writeConcernException, indexMap)); }
private BulkWriteBatchResult ExecuteBatch(MongoConnection connection, Batch <WriteRequest> batch, int originalIndex) { var maxBatchCount = Math.Min(_args.MaxBatchCount, connection.ServerInstance.MaxBatchCount); var maxBatchLength = Math.Min(_args.MaxBatchLength, connection.ServerInstance.MaxDocumentSize); var maxDocumentSize = connection.ServerInstance.MaxDocumentSize; var maxWireDocumentSize = connection.ServerInstance.MaxWireDocumentSize; var batchSerializer = CreateBatchSerializer(maxBatchCount, maxBatchLength, maxDocumentSize, maxWireDocumentSize); var writeCommand = CreateWriteCommand(batchSerializer, batch); var writeCommandOperation = CreateWriteCommandOperation(writeCommand); var writeCommandResult = writeCommandOperation.Execute(connection); var batchProgress = batchSerializer.BatchProgress; var indexMap = new IndexMap.RangeBased(0, originalIndex, batchProgress.BatchCount); return(BulkWriteBatchResult.Create( _args.IsOrdered, batchProgress.BatchItems, writeCommandResult.Response, indexMap, batchProgress.NextBatch)); }
// 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)); }
public void TestRangeBasedWith0() { var map = new IndexMap.RangeBased(); Assert.Throws <KeyNotFoundException>(() => map.Map(0)); }