-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
MongoDefaults.cs
297 lines (272 loc) · 9.93 KB
/
MongoDefaults.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/* Copyright 2010-present MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Text;
using MongoDB.Bson;
using MongoDB.Bson.IO;
using MongoDB.Driver.Core.Misc;
namespace MongoDB.Driver
{
/// <summary>
/// Default values for various Mongo settings.
/// </summary>
public static class MongoDefaults
{
// private static fields
private static bool __assignIdOnInsert = true;
private static string __authenticationMechanism = null;
private static TimeSpan __connectTimeout = TimeSpan.FromSeconds(30);
private static TimeSpan __localThreshold = TimeSpan.FromMilliseconds(15);
private static TimeSpan __maxConnectionIdleTime = TimeSpan.FromMinutes(10);
private static TimeSpan __maxConnectionLifeTime = TimeSpan.FromMinutes(30);
private static int __maxBatchCount = 1000;
private static int __maxConnectionPoolSize = 100;
private static int __maxMessageLength = 16000000; // 16MB (not 16 MiB!)
private static int __minConnectionPoolSize = 0;
private static TimeSpan __operationTimeout = TimeSpan.FromSeconds(30);
private static UTF8Encoding __readEncoding = Utf8Encodings.Strict;
private static TimeSpan __serverSelectionTimeout = TimeSpan.FromSeconds(30);
private static TimeSpan __socketTimeout = TimeSpan.Zero; // use operating system default (presumably infinite)
private static int __tcpReceiveBufferSize = 64 * 1024; // 64KiB (note: larger than 2MiB fails on Mac using Mono)
private static int __tcpSendBufferSize = 64 * 1024; // 64KiB (TODO: what is the optimum value for the buffers?)
private static double __waitQueueMultiple = 5.0; // default wait queue multiple is 5.0
private static int __waitQueueSize = 0; // use multiple by default
private static TimeSpan __waitQueueTimeout = TimeSpan.FromMinutes(2); // default wait queue timeout is 2 minutes
private static UTF8Encoding __writeEncoding = Utf8Encodings.Strict;
private static int __maxDocumentSize = 4 * 1024 * 1024; // 4 MiB. Original MongoDB max document size
// public static properties
/// <summary>
/// Gets or sets whether the driver should assign a value to empty Ids on Insert.
/// </summary>
public static bool AssignIdOnInsert
{
get { return __assignIdOnInsert; }
set { __assignIdOnInsert = value; }
}
/// <summary>
/// Gets or sets the default authentication mechanism.
/// </summary>
public static string AuthenticationMechanism
{
get { return __authenticationMechanism; }
set { __authenticationMechanism = value; }
}
/// <summary>
/// Gets the actual wait queue size (either WaitQueueSize or WaitQueueMultiple x MaxConnectionPoolSize).
/// </summary>
[Obsolete("This property will be removed in a later release.")]
public static int ComputedWaitQueueSize
{
get
{
if (__waitQueueMultiple == 0.0)
{
return __waitQueueSize;
}
else
{
return ConnectionStringConversions.GetComputedWaitQueueSize(__maxConnectionPoolSize, __waitQueueMultiple);
}
}
}
/// <summary>
/// Gets or sets the connect timeout.
/// </summary>
public static TimeSpan ConnectTimeout
{
get { return __connectTimeout; }
set { __connectTimeout = value; }
}
/// <summary>
/// Gets or sets the representation to use for Guids (this is an alias for BsonDefaults.GuidRepresentation).
/// </summary>
[Obsolete("Configure serializers instead.")]
public static GuidRepresentation GuidRepresentation
{
#pragma warning disable 618
get { return BsonDefaults.GuidRepresentation; }
set { BsonDefaults.GuidRepresentation = value; }
#pragma warning restore 618
}
/// <summary>
/// Gets or sets the default local threshold.
/// </summary>
public static TimeSpan LocalThreshold
{
get { return __localThreshold; }
set { __localThreshold = value; }
}
/// <summary>
/// Gets or sets the maximum batch count.
/// </summary>
public static int MaxBatchCount
{
get { return __maxBatchCount; }
set { __maxBatchCount = value; }
}
/// <summary>
/// Gets or sets the max connection idle time.
/// </summary>
public static TimeSpan MaxConnectionIdleTime
{
get { return __maxConnectionIdleTime; }
set { __maxConnectionIdleTime = value; }
}
/// <summary>
/// Gets or sets the max connection life time.
/// </summary>
public static TimeSpan MaxConnectionLifeTime
{
get { return __maxConnectionLifeTime; }
set { __maxConnectionLifeTime = value; }
}
/// <summary>
/// Gets or sets the max connection pool size.
/// </summary>
public static int MaxConnectionPoolSize
{
get { return __maxConnectionPoolSize; }
set { __maxConnectionPoolSize = Ensure.IsGreaterThanZero(value, nameof(MaxConnectionPoolSize)); }
}
/// <summary>
/// Gets or sets the max document size
/// </summary>
public static int MaxDocumentSize
{
get { return __maxDocumentSize; }
set { __maxDocumentSize = value; }
}
/// <summary>
/// Gets or sets the max message length.
/// </summary>
public static int MaxMessageLength
{
get { return __maxMessageLength; }
set { __maxMessageLength = value; }
}
/// <summary>
/// Gets or sets the min connection pool size.
/// </summary>
public static int MinConnectionPoolSize
{
get { return __minConnectionPoolSize; }
set { __minConnectionPoolSize = value; }
}
/// <summary>
/// Gets or sets the operation timeout.
/// </summary>
public static TimeSpan OperationTimeout
{
get { return __operationTimeout; }
set { __operationTimeout = value; }
}
/// <summary>
/// Gets or sets the Read Encoding.
/// </summary>
public static UTF8Encoding ReadEncoding
{
get { return __readEncoding; }
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}
__readEncoding = value;
}
}
/// <summary>
/// Gets or sets the server selection timeout.
/// </summary>
public static TimeSpan ServerSelectionTimeout
{
get { return __serverSelectionTimeout; }
set { __serverSelectionTimeout = value; }
}
/// <summary>
/// Gets or sets the socket timeout.
/// </summary>
public static TimeSpan SocketTimeout
{
get { return __socketTimeout; }
set { __socketTimeout = value; }
}
/// <summary>
/// Gets or sets the TCP receive buffer size.
/// </summary>
public static int TcpReceiveBufferSize
{
get { return __tcpReceiveBufferSize; }
set { __tcpReceiveBufferSize = value; }
}
/// <summary>
/// Gets or sets the TCP send buffer size.
/// </summary>
public static int TcpSendBufferSize
{
get { return __tcpSendBufferSize; }
set { __tcpSendBufferSize = value; }
}
/// <summary>
/// Gets or sets the wait queue multiple (the actual wait queue size will be WaitQueueMultiple x MaxConnectionPoolSize, see also WaitQueueSize).
/// </summary>
[Obsolete("This property will be removed in a later release.")]
public static double WaitQueueMultiple
{
get { return __waitQueueMultiple; }
set
{
__waitQueueMultiple = value;
__waitQueueSize = 0;
}
}
/// <summary>
/// Gets or sets the wait queue size (see also WaitQueueMultiple).
/// </summary>
[Obsolete("This property will be removed in a later release.")]
public static int WaitQueueSize
{
get { return __waitQueueSize; }
set
{
__waitQueueMultiple = 0.0;
__waitQueueSize = value;
}
}
/// <summary>
/// Gets or sets the wait queue timeout.
/// </summary>
public static TimeSpan WaitQueueTimeout
{
get { return __waitQueueTimeout; }
set { __waitQueueTimeout = value; }
}
/// <summary>
/// Gets or sets the Write Encoding.
/// </summary>
public static UTF8Encoding WriteEncoding
{
get { return __writeEncoding; }
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}
__writeEncoding = value;
}
}
}
}