Skip to content

Commit 1c20602

Browse files
committed
CSHARP-2021: Implement Driver Sessions API
1 parent ed0eab7 commit 1c20602

File tree

249 files changed

+17998
-2574
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

249 files changed

+17998
-2574
lines changed

evergreen/evergreen.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ functions:
136136
params:
137137
script: |
138138
${PREPARE_SHELL}
139-
find $MONGO_ORCHESTRATION_HOME -name \*.log | xargs tar czf ${PROJECT_DIRECTORY}/mongodb-logs.tar.gz
139+
find $MONGO_ORCHESTRATION_HOME -name \*.log | xargs tar czf mongodb-logs.tar.gz
140140
- command: s3.put
141141
params:
142142
aws_key: ${aws_key}
143143
aws_secret: ${aws_secret}
144-
local_file: ${PROJECT_DIRECTORY}/mongodb-logs.tar.gz
144+
local_file: mongodb-logs.tar.gz
145145
remote_file: ${UPLOAD_BUCKET}/${build_variant}/${revision}/${version_id}/${build_id}/logs/${task_id}-${execution}-mongodb-logs.tar.gz
146146
bucket: mciuploads
147147
permissions: public-read
@@ -151,7 +151,7 @@ functions:
151151
params:
152152
aws_key: ${aws_key}
153153
aws_secret: ${aws_secret}
154-
local_file: ${DRIVERS_TOOLS}/.evergreen/orchestration/server.log
154+
local_file: drivers-tools/.evergreen/orchestration/server.log
155155
remote_file: ${UPLOAD_BUCKET}/${build_variant}/${revision}/${version_id}/${build_id}/logs/${task_id}-${execution}-orchestration.log
156156
bucket: mciuploads
157157
permissions: public-read
@@ -349,10 +349,14 @@ axes:
349349
- id: version
350350
display_name: MongoDB Version
351351
values:
352-
- id: "latest"
353-
display_name: "latest"
352+
# - id: "latest"
353+
# display_name: "latest"
354+
# variables:
355+
# VERSION: "latest"
356+
- id: "3.6"
357+
display_name: "3.6"
354358
variables:
355-
VERSION: "latest"
359+
VERSION: "3.6"
356360
- id: "3.4"
357361
display_name: "3.4"
358362
variables:

src/MongoDB.Bson/IO/BsonBinaryWriter.cs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2010-2016 MongoDB Inc.
1+
/* Copyright 2010-2017 MongoDB Inc.
22
*
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
@@ -27,8 +27,6 @@ public class BsonBinaryWriter : BsonWriter
2727
// private fields
2828
private readonly Stream _baseStream;
2929
private readonly BsonStream _bsonStream;
30-
private readonly BsonBinaryWriterSettings _settings; // same value as in base class just declared as derived class
31-
private readonly Stack<int> _maxDocumentSizeStack = new Stack<int>();
3230
private BsonBinaryWriterContext _context;
3331

3432
// constructors
@@ -60,8 +58,6 @@ public BsonBinaryWriter(Stream stream, BsonBinaryWriterSettings settings)
6058

6159
_baseStream = stream;
6260
_bsonStream = (stream as BsonStream) ?? new BsonStreamAdapter(stream);
63-
_settings = settings; // already frozen by base class
64-
_maxDocumentSizeStack.Push(_settings.MaxDocumentSize);
6561

6662
_context = null;
6763
State = BsonWriterState.Initial;
@@ -90,6 +86,18 @@ public BsonStream BsonStream
9086
get { return _bsonStream; }
9187
}
9288

89+
/// <inheritdoc />
90+
public override long Position
91+
{
92+
get { return _baseStream.Position; }
93+
}
94+
95+
/// <inheritdoc />
96+
public new BsonBinaryWriterSettings Settings
97+
{
98+
get { return (BsonBinaryWriterSettings)base.Settings; }
99+
}
100+
93101
// public methods
94102
/// <summary>
95103
/// Closes the writer. Also closes the base stream.
@@ -128,18 +136,20 @@ public override void Flush()
128136
/// <summary>
129137
/// Pops the max document size stack, restoring the previous max document size.
130138
/// </summary>
139+
[Obsolete("Use PopSettings instead.")]
131140
public void PopMaxDocumentSize()
132141
{
133-
_maxDocumentSizeStack.Pop();
142+
PopSettings();
134143
}
135144

136145
/// <summary>
137146
/// Pushes a new max document size onto the max document size stack.
138147
/// </summary>
139148
/// <param name="maxDocumentSize">The maximum size of the document.</param>
149+
[Obsolete("Use PushSettings instead.")]
140150
public void PushMaxDocumentSize(int maxDocumentSize)
141151
{
142-
_maxDocumentSizeStack.Push(Math.Min(maxDocumentSize, _maxDocumentSizeStack.Peek()));
152+
PushSettings(s => ((BsonBinaryWriterSettings)s).MaxDocumentSize = maxDocumentSize);
143153
}
144154

145155
#pragma warning disable 618 // about obsolete BsonBinarySubType.OldBinary
@@ -161,28 +171,28 @@ public override void WriteBinaryData(BsonBinaryData binaryData)
161171
switch (subType)
162172
{
163173
case BsonBinarySubType.OldBinary:
164-
if (_settings.FixOldBinarySubTypeOnOutput)
174+
if (Settings.FixOldBinarySubTypeOnOutput)
165175
{
166176
subType = BsonBinarySubType.Binary; // replace obsolete OldBinary with new Binary sub type
167177
}
168178
break;
169179
case BsonBinarySubType.UuidLegacy:
170180
case BsonBinarySubType.UuidStandard:
171-
if (_settings.GuidRepresentation != GuidRepresentation.Unspecified)
181+
if (Settings.GuidRepresentation != GuidRepresentation.Unspecified)
172182
{
173-
var expectedSubType = (_settings.GuidRepresentation == GuidRepresentation.Standard) ? BsonBinarySubType.UuidStandard : BsonBinarySubType.UuidLegacy;
183+
var expectedSubType = (Settings.GuidRepresentation == GuidRepresentation.Standard) ? BsonBinarySubType.UuidStandard : BsonBinarySubType.UuidLegacy;
174184
if (subType != expectedSubType)
175185
{
176186
var message = string.Format(
177187
"The GuidRepresentation for the writer is {0}, which requires the subType argument to be {1}, not {2}.",
178-
_settings.GuidRepresentation, expectedSubType, subType);
188+
Settings.GuidRepresentation, expectedSubType, subType);
179189
throw new BsonSerializationException(message);
180190
}
181-
if (guidRepresentation != _settings.GuidRepresentation)
191+
if (guidRepresentation != Settings.GuidRepresentation)
182192
{
183193
var message = string.Format(
184194
"The GuidRepresentation for the writer is {0}, which requires the the guidRepresentation argument to also be {0}, not {1}.",
185-
_settings.GuidRepresentation, guidRepresentation);
195+
Settings.GuidRepresentation, guidRepresentation);
186196
throw new BsonSerializationException(message);
187197
}
188198
}
@@ -413,7 +423,7 @@ public override void WriteJavaScript(string code)
413423

414424
_bsonStream.WriteBsonType(BsonType.JavaScript);
415425
WriteNameHelper();
416-
_bsonStream.WriteString(code, _settings.Encoding);
426+
_bsonStream.WriteString(code, Settings.Encoding);
417427

418428
State = GetNextState();
419429
}
@@ -434,7 +444,7 @@ public override void WriteJavaScriptWithScope(string code)
434444
WriteNameHelper();
435445
_context = new BsonBinaryWriterContext(_context, ContextType.JavaScriptWithScope, _bsonStream.Position);
436446
_bsonStream.WriteInt32(0); // reserve space for size of JavaScript with scope value
437-
_bsonStream.WriteString(code, _settings.Encoding);
447+
_bsonStream.WriteString(code, Settings.Encoding);
438448

439449
State = BsonWriterState.ScopeDocument;
440450
}
@@ -640,7 +650,7 @@ public override void WriteString(string value)
640650

641651
_bsonStream.WriteBsonType(BsonType.String);
642652
WriteNameHelper();
643-
_bsonStream.WriteString(value, _settings.Encoding);
653+
_bsonStream.WriteString(value, Settings.Encoding);
644654

645655
State = GetNextState();
646656
}
@@ -659,7 +669,7 @@ public override void WriteSymbol(string value)
659669

660670
_bsonStream.WriteBsonType(BsonType.Symbol);
661671
WriteNameHelper();
662-
_bsonStream.WriteString(value, _settings.Encoding);
672+
_bsonStream.WriteString(value, Settings.Encoding);
663673

664674
State = GetNextState();
665675
}
@@ -722,9 +732,9 @@ protected override void Dispose(bool disposing)
722732
private void BackpatchSize()
723733
{
724734
var size = _bsonStream.Position - _context.StartPosition;
725-
if (size > _maxDocumentSizeStack.Peek())
735+
if (size > Settings.MaxDocumentSize)
726736
{
727-
var message = string.Format("Size {0} is larger than MaxDocumentSize {1}.", size, _maxDocumentSizeStack.Peek());
737+
var message = string.Format("Size {0} is larger than MaxDocumentSize {1}.", size, Settings.MaxDocumentSize);
728738
throw new FormatException(message);
729739
}
730740

src/MongoDB.Bson/IO/BsonDocumentWriter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2010-2016 MongoDB Inc.
1+
/* Copyright 2010-2017 MongoDB Inc.
22
*
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
@@ -63,6 +63,9 @@ public BsonDocument Document
6363
get { return _document; }
6464
}
6565

66+
/// <inheritdoc />
67+
public override long Position => 0L;
68+
6669
// public methods
6770
/// <summary>
6871
/// Closes the writer.

src/MongoDB.Bson/IO/BsonWriter.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2010-2016 MongoDB Inc.
1+
/* Copyright 2010-2017 MongoDB Inc.
22
*
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ public abstract class BsonWriter : IBsonWriter
3232
private IElementNameValidator _elementNameValidator = NoOpElementNameValidator.Instance;
3333
private Stack<IElementNameValidator> _elementNameValidatorStack = new Stack<IElementNameValidator>();
3434
private BsonWriterSettings _settings;
35+
private Stack<BsonWriterSettings> _settingsStack = new Stack<BsonWriterSettings>();
3536
private BsonWriterState _state;
3637
private string _name;
3738
private int _serializationDepth;
@@ -53,6 +54,9 @@ protected BsonWriter(BsonWriterSettings settings)
5354
}
5455

5556
// public properties
57+
/// <inheritdoc />
58+
public abstract long Position { get; }
59+
5660
/// <summary>
5761
/// Gets the current serialization depth.
5862
/// </summary>
@@ -130,6 +134,12 @@ public void PopElementNameValidator()
130134
_childElementNameValidatorFactory = () => _elementNameValidator;
131135
}
132136

137+
/// <inheritdoc />
138+
public void PopSettings()
139+
{
140+
_settings = _settingsStack.Pop();
141+
}
142+
133143
/// <summary>
134144
/// Pushes the element name validator.
135145
/// </summary>
@@ -146,6 +156,16 @@ public void PushElementNameValidator(IElementNameValidator validator)
146156
_childElementNameValidatorFactory = () => _elementNameValidator;
147157
}
148158

159+
/// <inheritdoc />
160+
public void PushSettings(Action<BsonWriterSettings> configurator)
161+
{
162+
var newSettings = _settings.Clone();
163+
configurator(newSettings);
164+
newSettings.Freeze();
165+
_settingsStack.Push(_settings);
166+
_settings = newSettings;
167+
}
168+
149169
/// <summary>
150170
/// Writes BSON binary data to the writer.
151171
/// </summary>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* Copyright 2017 MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Linq;
19+
using MongoDB.Bson.Serialization;
20+
using MongoDB.Bson.Serialization.Serializers;
21+
22+
namespace MongoDB.Bson.IO
23+
{
24+
/// <summary>
25+
/// A BsonWriter that appends elements to the end of a document.
26+
/// </summary>
27+
/// <seealso cref="MongoDB.Bson.IO.IBsonWriter" />
28+
internal sealed class ElementAppendingBsonWriter : WrappingBsonWriter
29+
{
30+
// private fields
31+
private int _depth;
32+
private readonly List<BsonElement> _elements;
33+
private readonly Action<BsonWriterSettings> _settingsConfigurator;
34+
35+
// constructors
36+
/// <summary>
37+
/// Initializes a new instance of the <see cref="ElementAppendingBsonWriter" /> class.
38+
/// </summary>
39+
/// <param name="wrapped">The wrapped writer.</param>
40+
/// <param name="elements">The elements to append.</param>
41+
/// <param name="settingsConfigurator">The settings configurator.</param>
42+
public ElementAppendingBsonWriter(
43+
IBsonWriter wrapped,
44+
IEnumerable<BsonElement> elements,
45+
Action<BsonWriterSettings> settingsConfigurator)
46+
: base(wrapped)
47+
{
48+
if (elements == null) { throw new ArgumentNullException(nameof(elements)); }
49+
_elements = elements.ToList();
50+
_settingsConfigurator = settingsConfigurator ?? (s => { });
51+
}
52+
53+
// public methods
54+
/// <inheritdoc />
55+
public override void WriteEndDocument()
56+
{
57+
if (--_depth == 0)
58+
{
59+
Wrapped.PushSettings(_settingsConfigurator);
60+
try
61+
{
62+
var context = BsonSerializationContext.CreateRoot(Wrapped);
63+
foreach (var element in _elements)
64+
{
65+
Wrapped.WriteName(element.Name);
66+
BsonValueSerializer.Instance.Serialize(context, element.Value);
67+
}
68+
}
69+
finally
70+
{
71+
Wrapped.PopSettings();
72+
}
73+
}
74+
base.WriteEndDocument();
75+
}
76+
77+
/// <inheritdoc />
78+
public override void WriteStartDocument()
79+
{
80+
_depth++;
81+
base.WriteStartDocument();
82+
}
83+
}
84+
}

src/MongoDB.Bson/IO/IBsonWriter.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2010-2016 MongoDB Inc.
1+
/* Copyright 2010-2017 MongoDB Inc.
22
*
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
@@ -20,9 +20,19 @@ namespace MongoDB.Bson.IO
2020
/// <summary>
2121
/// Represents a BSON writer.
2222
/// </summary>
23+
/// <seealso cref="System.IDisposable" />
2324
public interface IBsonWriter : IDisposable
2425
{
2526
// properties
27+
/// <summary>
28+
/// Gets the position.
29+
/// Not all writers are able to report the position. Those that can't simply return zero.
30+
/// </summary>
31+
/// <value>
32+
/// The position.
33+
/// </value>
34+
long Position { get; }
35+
2636
/// <summary>
2737
/// Gets the current serialization depth.
2838
/// </summary>
@@ -56,12 +66,23 @@ public interface IBsonWriter : IDisposable
5666
/// <returns>The popped element validator.</returns>
5767
void PopElementNameValidator();
5868

69+
/// <summary>
70+
/// Pops the settings.
71+
/// </summary>
72+
void PopSettings();
73+
5974
/// <summary>
6075
/// Pushes the element name validator.
6176
/// </summary>
6277
/// <param name="validator">The validator.</param>
6378
void PushElementNameValidator(IElementNameValidator validator);
6479

80+
/// <summary>
81+
/// Pushes new settings for the writer.
82+
/// </summary>
83+
/// <param name="configurator">The settings configurator.</param>
84+
void PushSettings(Action<BsonWriterSettings> configurator);
85+
6586
/// <summary>
6687
/// Writes BSON binary data to the writer.
6788
/// </summary>

0 commit comments

Comments
 (0)