Skip to content

Commit fb5521d

Browse files
committed
CSHARP-2026: All writes retryable support.
1 parent 4309cfb commit fb5521d

File tree

119 files changed

+7620
-1553
lines changed

Some content is hidden

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

119 files changed

+7620
-1553
lines changed

build.cake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ Task("BuildNet45")
7373
CopyFile(outputFile, artifactFile);
7474
}
7575
}
76+
77+
foreach (var dnsClientFileName in new[] { "DnsClient.dll", "DnsClient.xml"})
78+
{
79+
var sourceDirectory = srcDirectory.Combine("MongoDB.Driver.Core").Combine("bin").Combine("Release");
80+
var sourceFile = sourceDirectory.CombineWithFilePath(dnsClientFileName);
81+
var destinationFile = artifactsBinNet45Directory.CombineWithFilePath(dnsClientFileName);
82+
CopyFile(sourceFile, destinationFile);
83+
}
7684
})
7785
.Finally(() =>
7886
{

src/MongoDB.Bson/IO/BsonBinaryWriter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ public override long Position
9292
get { return _baseStream.Position; }
9393
}
9494

95-
/// <inheritdoc />
95+
/// <summary>
96+
/// Gets the settings of the writer.
97+
/// </summary>
9698
public new BsonBinaryWriterSettings Settings
9799
{
98100
get { return (BsonBinaryWriterSettings)base.Settings; }

src/MongoDB.Bson/IO/JsonWriter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ public TextWriter BaseTextWriter
7474
/// <inheritdoc />
7575
public override long Position => 0L;
7676

77-
/// <inheritdoc />
77+
/// <summary>
78+
/// Gets the settings of the writer.
79+
/// </summary>
7880
public new JsonWriterSettings Settings
7981
{
8082
get { return (JsonWriterSettings)base.Settings; }

src/MongoDB.Driver.Core/ChangeStreamDocument.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace MongoDB.Driver
2121
/// <summary>
2222
/// An output document from a $changeStream pipeline stage.
2323
/// </summary>
24+
/// <typeparam name="TDocument">The type of the document.</typeparam>
2425
public sealed class ChangeStreamDocument<TDocument>
2526
{
2627
// private fields

src/MongoDB.Driver.Core/Core/Bindings/ICoreSession.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ public interface ICoreSession : IDisposable
7777
/// <param name="newOperationTime">The new operation time.</param>
7878
void AdvanceOperationTime(BsonTimestamp newOperationTime);
7979

80+
/// <summary>
81+
/// Advances the transaction id.
82+
/// </summary>
83+
/// <returns>The transaction id.</returns>
84+
long AdvanceTransactionNumber();
85+
8086
/// <summary>
8187
/// Called by the driver when the session is used (i.e. sent to the server).
8288
/// </summary>

src/MongoDB.Driver.Core/Core/Bindings/NoCoreSession.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public sealed class NoCoreSession : ICoreSession
4040
/// <summary>
4141
/// Returns a new handle to a NoCoreSession object.
4242
/// </summary>
43-
/// <returns></returns>
43+
/// <returns>A new handle to the NoCoreSession object.</returns>
4444
public static ICoreSessionHandle NewHandle()
4545
{
4646
return new CoreSessionHandle(__instance);
@@ -73,6 +73,12 @@ public void AdvanceOperationTime(BsonTimestamp newOperationTime)
7373
{
7474
}
7575

76+
/// <inheritdoc />
77+
public long AdvanceTransactionNumber()
78+
{
79+
return -1;
80+
}
81+
7682
/// <inheritdoc />
7783
public void Dispose()
7884
{

src/MongoDB.Driver.Core/Core/Bindings/WrappingCoreSession.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ public virtual void AdvanceOperationTime(BsonTimestamp newOperationTime)
123123
_wrapped.AdvanceOperationTime(newOperationTime);
124124
}
125125

126+
/// <inheritdoc />
127+
public long AdvanceTransactionNumber()
128+
{
129+
return _wrapped.AdvanceTransactionNumber();
130+
}
131+
126132
/// <inheritdoc />
127133
public void Dispose()
128134
{
@@ -138,7 +144,10 @@ public virtual void WasUsed()
138144
}
139145

140146
// protected methods
141-
/// <inheritdoc />
147+
/// <summary>
148+
/// Releases unmanaged and - optionally - managed resources.
149+
/// </summary>
150+
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
142151
protected virtual void Dispose(bool disposing)
143152
{
144153
if (!_disposed)

src/MongoDB.Driver.Core/Core/Configuration/ConnectionString.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public sealed class ConnectionString
8686
private ReadPreferenceMode? _readPreference;
8787
private IReadOnlyList<TagSet> _readPreferenceTags;
8888
private string _replicaSet;
89+
private bool? _retryWrites;
8990
private ConnectionStringScheme _scheme;
9091
private TimeSpan? _serverSelectionTimeout;
9192
private TimeSpan? _socketTimeout;
@@ -327,6 +328,14 @@ public IReadOnlyList<TagSet> ReadPreferenceTags
327328
}
328329

329330
/// <summary>
331+
/// Gets a value indicating whether or not to retry writes.
332+
/// </summary>
333+
public bool? RetryWrites
334+
{
335+
get { return _retryWrites; }
336+
}
337+
338+
/// <summary>
330339
/// Gets the scheme.
331340
/// </summary>
332341
public ConnectionStringScheme Scheme
@@ -464,6 +473,7 @@ public ConnectionString Resolve()
464473
/// Resolves a connection string. If the connection string indicates more information is available
465474
/// in the DNS system, it will acquire that information as well.
466475
/// </summary>
476+
/// <param name="cancellationToken">The cancellation token.</param>
467477
/// <returns>A resolved ConnectionString.</returns>
468478
public async Task<ConnectionString> ResolveAsync(CancellationToken cancellationToken = default(CancellationToken))
469479
{
@@ -764,6 +774,9 @@ private void ParseOption(string name, string value)
764774
case "replicaset":
765775
_replicaSet = value;
766776
break;
777+
case "retrywrites":
778+
_retryWrites = ParseBoolean(name, value);
779+
break;
767780
case "safe":
768781
var safe = ParseBoolean(name, value);
769782
if (_w == null)

src/MongoDB.Driver.Core/Core/Connections/CommandEventHelper.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2015-2016 MongoDB Inc.
1+
/* Copyright 2015-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.
@@ -377,7 +377,7 @@ private void ProcessInsertMessage(RequestMessage message, Queue<RequestMessage>
377377
// Plus, for this we really want BsonDocuments, not whatever the generic type is.
378378
var decodedMessage = encoder.ReadMessage();
379379

380-
var documents = decodedMessage.DocumentSource.GetRemainingItems().ToList();
380+
var documents = decodedMessage.DocumentSource.GetBatchItems();
381381
numberOfDocuments = documents.Count;
382382
try
383383
{
@@ -409,7 +409,10 @@ private void ProcessInsertMessage(RequestMessage message, Queue<RequestMessage>
409409
}
410410
finally
411411
{
412-
documents.ForEach(d => d.Dispose());
412+
foreach (var document in documents)
413+
{
414+
document.Dispose();
415+
}
413416
}
414417
}
415418

0 commit comments

Comments
 (0)