Skip to content

Commit 985e8e6

Browse files
committed
CSHARP-2031: Parse logicalSessionTimeoutMinutes and update SDAM tests and runners.
1 parent 1005873 commit 985e8e6

File tree

146 files changed

+5808
-3744
lines changed

Some content is hidden

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

146 files changed

+5808
-3744
lines changed

src/MongoDB.Driver.Core/Core/Clusters/Cluster.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2013-2015 MongoDB Inc.
1+
/* Copyright 2013-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.
@@ -38,8 +38,17 @@ internal abstract class Cluster : ICluster
3838
#region static
3939
// static fields
4040
private static readonly TimeSpan __minHeartbeatInterval = TimeSpan.FromMilliseconds(500);
41-
private static readonly Range<int> __supportedWireVersionRange = new Range<int>(0, 3);
41+
private static readonly Range<int> __supportedWireVersionRange = new Range<int>(2, 6);
4242
private static readonly IServerSelector __randomServerSelector = new RandomServerSelector();
43+
44+
// static properties
45+
/// <summary>
46+
/// Gets the supported wire version range.
47+
/// </summary>
48+
/// <value>
49+
/// The supported wire version range.
50+
/// </value>
51+
public static Range<int> SupportedWireVersionRange => __supportedWireVersionRange;
4352
#endregion
4453

4554
// fields

src/MongoDB.Driver.Core/Core/Clusters/ClusterDescription.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2013-2015 MongoDB Inc.
1+
/* Copyright 2013-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.
@@ -43,6 +43,7 @@ internal static ClusterDescription CreateInitial(ClusterId clusterId, ClusterCon
4343
// fields
4444
private readonly ClusterId _clusterId;
4545
private readonly ClusterConnectionMode _connectionMode;
46+
private readonly TimeSpan? _logicalSessionTimeout;
4647
private readonly IReadOnlyList<ServerDescription> _servers;
4748
private readonly ClusterType _type;
4849

@@ -64,6 +65,7 @@ public ClusterDescription(
6465
_connectionMode = connectionMode;
6566
_type = type;
6667
_servers = (servers ?? new ServerDescription[0]).OrderBy(n => n.EndPoint, new ToStringComparer<EndPoint>()).ToList();
68+
_logicalSessionTimeout = CalculateLogicalSessionTimeout(_servers);
6769
}
6870

6971
// properties
@@ -83,6 +85,28 @@ public ClusterConnectionMode ConnectionMode
8385
get { return _connectionMode; }
8486
}
8587

88+
/// <summary>
89+
/// Gets a value indicating whether this cluster is compatible with the driver.
90+
/// </summary>
91+
/// <value>
92+
/// <c>true</c> if this cluster is compatible with the driver; otherwise, <c>false</c>.
93+
/// </value>
94+
public bool IsCompatibleWithDriver
95+
{
96+
get
97+
{
98+
return _servers.All(s => s.IsCompatibleWithDriver);
99+
}
100+
}
101+
102+
/// <summary>
103+
/// Gets the logical session timeout.
104+
/// </summary>
105+
public TimeSpan? LogicalSessionTimeout
106+
{
107+
get { return _logicalSessionTimeout; }
108+
}
109+
86110
/// <summary>
87111
/// Gets the servers.
88112
/// </summary>
@@ -216,5 +240,26 @@ public ClusterDescription WithType(ClusterType value)
216240
{
217241
return _type == value ? this : new ClusterDescription(_clusterId, _connectionMode, value, _servers);
218242
}
243+
244+
// private methods
245+
private TimeSpan? CalculateLogicalSessionTimeout(IEnumerable<ServerDescription> servers)
246+
{
247+
TimeSpan? logicalSessionTimeout = null;
248+
249+
foreach (var server in servers)
250+
{
251+
if (server.LogicalSessionTimeout == null)
252+
{
253+
return null;
254+
}
255+
256+
if (logicalSessionTimeout == null || server.LogicalSessionTimeout.Value < logicalSessionTimeout.Value)
257+
{
258+
logicalSessionTimeout = server.LogicalSessionTimeout;
259+
}
260+
}
261+
262+
return logicalSessionTimeout;
263+
}
219264
}
220265
}

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

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2013-2016 MongoDB Inc.
1+
/* Copyright 2013-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.
@@ -17,9 +17,6 @@
1717
using System.Collections.Generic;
1818
using System.Linq;
1919
using System.Net;
20-
using System.Net.Sockets;
21-
using System.Text;
22-
using System.Threading.Tasks;
2320
using MongoDB.Bson;
2421
using MongoDB.Driver.Core.Clusters;
2522
using MongoDB.Driver.Core.Misc;
@@ -105,6 +102,33 @@ public DateTime? LastWriteTimestamp
105102
}
106103
}
107104

105+
/// <summary>
106+
/// Gets the logical session timeout.
107+
/// </summary>
108+
/// <value>
109+
/// The logical session timeout.
110+
/// </value>
111+
public TimeSpan? LogicalSessionTimeout
112+
{
113+
get
114+
{
115+
BsonValue value;
116+
if (_wrapped.TryGetValue("logicalSessionTimeoutMinutes", out value))
117+
{
118+
if (value.BsonType == BsonType.Null)
119+
{
120+
return null;
121+
}
122+
else
123+
{
124+
return TimeSpan.FromMinutes(value.ToDouble());
125+
}
126+
}
127+
128+
return null;
129+
}
130+
}
131+
108132
/// <summary>
109133
/// Gets the maximum number of documents in a batch.
110134
/// </summary>

src/MongoDB.Driver.Core/Core/Servers/ServerDescription.cs

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2013-2016 MongoDB Inc.
1+
/* Copyright 2013-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.
@@ -14,15 +14,9 @@
1414
*/
1515

1616
using System;
17-
using System.Collections.Generic;
18-
using System.Linq;
1917
using System.Net;
20-
using System.Net.Sockets;
2118
using System.Text;
22-
using System.Threading.Tasks;
23-
using MongoDB.Bson;
2419
using MongoDB.Driver.Core.Clusters;
25-
using MongoDB.Driver.Core.Connections;
2620
using MongoDB.Driver.Core.Misc;
2721
using MongoDB.Shared;
2822

@@ -42,6 +36,7 @@ public sealed class ServerDescription : IEquatable<ServerDescription>
4236
private readonly TimeSpan _heartbeatInterval;
4337
private readonly DateTime _lastUpdateTimestamp;
4438
private readonly DateTime? _lastWriteTimestamp;
39+
private readonly TimeSpan? _logicalSessionTimeout;
4540
private readonly int _maxBatchCount;
4641
private readonly int _maxDocumentSize;
4742
private readonly int _maxMessageSize;
@@ -67,6 +62,7 @@ public sealed class ServerDescription : IEquatable<ServerDescription>
6762
/// <param name="heartbeatInterval">The heartbeat interval.</param>
6863
/// <param name="lastUpdateTimestamp">The last update timestamp.</param>
6964
/// <param name="lastWriteTimestamp">The last write timestamp.</param>
65+
/// <param name="logicalSessionTimeout">The logical session timeout.</param>
7066
/// <param name="maxBatchCount">The maximum batch count.</param>
7167
/// <param name="maxDocumentSize">The maximum size of a document.</param>
7268
/// <param name="maxMessageSize">The maximum size of a message.</param>
@@ -77,6 +73,7 @@ public sealed class ServerDescription : IEquatable<ServerDescription>
7773
/// <param name="type">The server type.</param>
7874
/// <param name="version">The server version.</param>
7975
/// <param name="wireVersionRange">The wire version range.</param>
76+
/// <exception cref="ArgumentException">EndPoint and ServerId.EndPoint must match.</exception>
8077
public ServerDescription(
8178
ServerId serverId,
8279
EndPoint endPoint,
@@ -87,6 +84,7 @@ public ServerDescription(
8784
Optional<TimeSpan> heartbeatInterval = default(Optional<TimeSpan>),
8885
Optional<DateTime> lastUpdateTimestamp = default(Optional<DateTime>),
8986
Optional<DateTime?> lastWriteTimestamp = default(Optional<DateTime?>),
87+
Optional<TimeSpan?> logicalSessionTimeout = default(Optional<TimeSpan?>),
9088
Optional<int> maxBatchCount = default(Optional<int>),
9189
Optional<int> maxDocumentSize = default(Optional<int>),
9290
Optional<int> maxMessageSize = default(Optional<int>),
@@ -113,6 +111,7 @@ public ServerDescription(
113111
_heartbeatInterval = heartbeatInterval.WithDefault(TimeSpan.Zero);
114112
_lastUpdateTimestamp = lastUpdateTimestamp.WithDefault(DateTime.UtcNow);
115113
_lastWriteTimestamp = lastWriteTimestamp.WithDefault(null);
114+
_logicalSessionTimeout = logicalSessionTimeout.WithDefault(null);
116115
_maxBatchCount = maxBatchCount.WithDefault(1000);
117116
_maxDocumentSize = maxDocumentSize.WithDefault(4 * 1024 * 1024);
118117
_maxMessageSize = maxMessageSize.WithDefault(Math.Max(_maxDocumentSize + 1024, 16000000));
@@ -189,6 +188,20 @@ public TimeSpan HeartbeatInterval
189188
get { return _heartbeatInterval; }
190189
}
191190

191+
/// <summary>
192+
/// Gets a value indicating whether this server is compatible with the driver.
193+
/// </summary>
194+
/// <value>
195+
/// <c>true</c> if this server is compatible with the driver; otherwise, <c>false</c>.
196+
/// </value>
197+
public bool IsCompatibleWithDriver
198+
{
199+
get
200+
{
201+
return _wireVersionRange == null || _wireVersionRange.Overlaps(Cluster.SupportedWireVersionRange);
202+
}
203+
}
204+
192205
/// <summary>
193206
/// Gets the last update timestamp (when the ServerDescription itself was last updated).
194207
/// </summary>
@@ -211,6 +224,17 @@ public DateTime? LastWriteTimestamp
211224
get { return _lastWriteTimestamp; }
212225
}
213226

227+
/// <summary>
228+
/// Gets the logical session timeout.
229+
/// </summary>
230+
/// <value>
231+
/// The logical session timeout.
232+
/// </value>
233+
public TimeSpan? LogicalSessionTimeout
234+
{
235+
get { return _logicalSessionTimeout; }
236+
}
237+
214238
/// <summary>
215239
/// Gets the maximum number of documents in a batch.
216240
/// </summary>
@@ -356,6 +380,7 @@ public bool Equals(ServerDescription other)
356380
_heartbeatInterval == other._heartbeatInterval &&
357381
_lastUpdateTimestamp == other._lastUpdateTimestamp &&
358382
_lastWriteTimestamp == other._lastWriteTimestamp &&
383+
_logicalSessionTimeout == other._logicalSessionTimeout &&
359384
_maxBatchCount == other._maxBatchCount &&
360385
_maxDocumentSize == other._maxDocumentSize &&
361386
_maxMessageSize == other._maxMessageSize &&
@@ -382,6 +407,7 @@ public override int GetHashCode()
382407
.Hash(_heartbeatInterval)
383408
.Hash(_lastUpdateTimestamp)
384409
.Hash(_lastWriteTimestamp)
410+
.Hash(_logicalSessionTimeout)
385411
.Hash(_maxBatchCount)
386412
.Hash(_maxDocumentSize)
387413
.Hash(_maxMessageSize)
@@ -423,6 +449,7 @@ public override string ToString()
423449
/// <param name="heartbeatInterval">The heartbeat interval.</param>
424450
/// <param name="lastUpdateTimestamp">The last update timestamp.</param>
425451
/// <param name="lastWriteTimestamp">The last write timestamp.</param>
452+
/// <param name="logicalSessionTimeout">The logical session timeout.</param>
426453
/// <param name="maxBatchCount">The maximum batch count.</param>
427454
/// <param name="maxDocumentSize">The maximum size of a document.</param>
428455
/// <param name="maxMessageSize">The maximum size of a message.</param>
@@ -444,6 +471,7 @@ public ServerDescription With(
444471
Optional<TimeSpan> heartbeatInterval = default(Optional<TimeSpan>),
445472
Optional<DateTime> lastUpdateTimestamp = default(Optional<DateTime>),
446473
Optional<DateTime?> lastWriteTimestamp = default(Optional<DateTime?>),
474+
Optional<TimeSpan?> logicalSessionTimeout = default(Optional<TimeSpan?>),
447475
Optional<int> maxBatchCount = default(Optional<int>),
448476
Optional<int> maxDocumentSize = default(Optional<int>),
449477
Optional<int> maxMessageSize = default(Optional<int>),
@@ -468,6 +496,7 @@ public ServerDescription With(
468496
heartbeatInterval.Replaces(_heartbeatInterval) ||
469497
lastUpdateTimestamp.Replaces(_lastUpdateTimestamp) ||
470498
lastWriteTimestamp.Replaces(_lastWriteTimestamp) ||
499+
logicalSessionTimeout.Replaces(_logicalSessionTimeout) ||
471500
maxBatchCount.Replaces(_maxBatchCount) ||
472501
maxDocumentSize.Replaces(_maxDocumentSize) ||
473502
maxMessageSize.Replaces(_maxMessageSize) ||
@@ -489,6 +518,7 @@ public ServerDescription With(
489518
heartbeatInterval: heartbeatInterval.WithDefault(_heartbeatInterval),
490519
lastUpdateTimestamp: lastUpdateTimestamp.WithDefault(_lastUpdateTimestamp),
491520
lastWriteTimestamp: lastWriteTimestamp.WithDefault(_lastWriteTimestamp),
521+
logicalSessionTimeout: logicalSessionTimeout.WithDefault(_logicalSessionTimeout),
492522
maxBatchCount: maxBatchCount.WithDefault(_maxBatchCount),
493523
maxDocumentSize: maxDocumentSize.WithDefault(_maxDocumentSize),
494524
maxMessageSize: maxMessageSize.WithDefault(_maxMessageSize),

src/MongoDB.Driver.Core/Core/Servers/ServerMonitor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2016 MongoDB Inc.
1+
/* Copyright 2016-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.
@@ -177,6 +177,7 @@ private async Task<bool> HeartbeatAsync(CancellationToken cancellationToken)
177177
canonicalEndPoint: isMasterResult.Me,
178178
electionId: isMasterResult.ElectionId,
179179
lastWriteTimestamp: isMasterResult.LastWriteTimestamp,
180+
logicalSessionTimeout: isMasterResult.LogicalSessionTimeout,
180181
maxBatchCount: isMasterResult.MaxBatchCount,
181182
maxDocumentSize: isMasterResult.MaxDocumentSize,
182183
maxMessageSize: isMasterResult.MaxMessageSize,

0 commit comments

Comments
 (0)