// private methods
        private BulkWriteBatchResult ExecuteBatch(MongoConnection connection, Run run)
        {
            BulkWriteResult    result;
            BulkWriteException exception = null;

            try
            {
                switch (run.RequestType)
                {
                case WriteRequestType.Delete:
                    result = ExecuteDeletes(connection, run.Requests.Cast <DeleteRequest>());
                    break;

                case WriteRequestType.Insert:
                    result = ExecuteInserts(connection, run.Requests.Cast <InsertRequest>());
                    break;

                case WriteRequestType.Update:
                    result = ExecuteUpdates(connection, run.Requests.Cast <UpdateRequest>());
                    break;

                default:
                    throw new MongoInternalException("Unrecognized RequestType.");
                }
            }
            catch (BulkWriteException ex)
            {
                result    = ex.Result;
                exception = ex;
            }

            return(BulkWriteBatchResult.Create(result, exception, run.IndexMap));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        // 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));
        }
        // 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));
        }