Skip to content

Commit 25cd545

Browse files
authored
CSHARP-3547: CSOT: read-write concern (#1752)
1 parent c96b803 commit 25cd545

29 files changed

+307
-187
lines changed

src/MongoDB.Driver/Core/Operations/AggregateToCollectionOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public BsonDocument CreateCommand(OperationContext operationContext, ICoreSessio
182182
var readConcern = _readConcern != null
183183
? ReadConcernHelper.GetReadConcernForCommand(session, connectionDescription, _readConcern)
184184
: null;
185-
var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern);
185+
var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(operationContext, session, _writeConcern);
186186
return new BsonDocument
187187
{
188188
{ "aggregate", _collectionNamespace == null ? (BsonValue)1 : _collectionNamespace.CollectionName },

src/MongoDB.Driver/Core/Operations/ClientBulkWriteOperation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public ClientBulkWriteOperation(
5555
WriteConcern = options?.WriteConcern;
5656
}
5757

58-
protected override BsonDocument CreateCommand(ICoreSessionHandle session, int attempt, long? transactionNumber)
58+
protected override BsonDocument CreateCommand(OperationContext operationContext, ICoreSessionHandle session, int attempt, long? transactionNumber)
5959
{
60-
var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, WriteConcern);
60+
var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(operationContext, session, WriteConcern);
6161
return new BsonDocument
6262
{
6363
{ "bulkWrite", 1 },

src/MongoDB.Driver/Core/Operations/CreateCollectionOperation.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2013-present MongoDB Inc.
1+
/* Copyright 2010-present 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.
@@ -211,9 +211,9 @@ public BsonDocument ClusteredIndex
211211
set => _clusteredIndex = value;
212212
}
213213

214-
internal BsonDocument CreateCommand(ICoreSessionHandle session)
214+
internal BsonDocument CreateCommand(OperationContext operationContext, ICoreSessionHandle session)
215215
{
216-
var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern);
216+
var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(operationContext, session, _writeConcern);
217217
return new BsonDocument
218218
{
219219
{ "create", _collectionNamespace.CollectionName },
@@ -247,7 +247,7 @@ public BsonDocument Execute(OperationContext operationContext, IWriteBinding bin
247247
EnsureServerIsValid(channel.ConnectionDescription.MaxWireVersion);
248248
using (var channelBinding = new ChannelReadWriteBinding(channelSource.Server, channel, binding.Session.Fork()))
249249
{
250-
var operation = CreateOperation(channelBinding.Session);
250+
var operation = CreateOperation(operationContext, channelBinding.Session);
251251
return operation.Execute(operationContext, channelBinding);
252252
}
253253
}
@@ -264,17 +264,17 @@ public async Task<BsonDocument> ExecuteAsync(OperationContext operationContext,
264264
EnsureServerIsValid(channel.ConnectionDescription.MaxWireVersion);
265265
using (var channelBinding = new ChannelReadWriteBinding(channelSource.Server, channel, binding.Session.Fork()))
266266
{
267-
var operation = CreateOperation(channelBinding.Session);
267+
var operation = CreateOperation(operationContext, channelBinding.Session);
268268
return await operation.ExecuteAsync(operationContext, channelBinding).ConfigureAwait(false);
269269
}
270270
}
271271
}
272272

273273
private IDisposable BeginOperation() => EventContext.BeginOperation("create");
274274

275-
private WriteCommandOperation<BsonDocument> CreateOperation(ICoreSessionHandle session)
275+
private WriteCommandOperation<BsonDocument> CreateOperation(OperationContext operationContext, ICoreSessionHandle session)
276276
{
277-
var command = CreateCommand(session);
277+
var command = CreateCommand(operationContext, session);
278278
return new WriteCommandOperation<BsonDocument>(_collectionNamespace.DatabaseNamespace, command, BsonDocumentSerializer.Instance, _messageEncoderSettings);
279279
}
280280

src/MongoDB.Driver/Core/Operations/CreateIndexesOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public async Task<BsonDocument> ExecuteAsync(OperationContext operationContext,
113113
internal BsonDocument CreateCommand(OperationContext operationContext, ICoreSessionHandle session, ConnectionDescription connectionDescription)
114114
{
115115
var maxWireVersion = connectionDescription.MaxWireVersion;
116-
var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern);
116+
var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(operationContext, session, _writeConcern);
117117
if (_commitQuorum != null)
118118
{
119119
Feature.CreateIndexCommitQuorum.ThrowIfNotSupported(maxWireVersion);

src/MongoDB.Driver/Core/Operations/CreateViewOperation.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2016-present MongoDB Inc.
1+
/* Copyright 2010-present 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.
@@ -94,7 +94,7 @@ public BsonDocument Execute(OperationContext operationContext, IWriteBinding bin
9494
using (var channel = channelSource.GetChannel(operationContext))
9595
using (var channelBinding = new ChannelReadWriteBinding(channelSource.Server, channel, binding.Session.Fork()))
9696
{
97-
var operation = CreateOperation(channelBinding.Session, channel.ConnectionDescription);
97+
var operation = CreateOperation(operationContext, channelBinding.Session, channel.ConnectionDescription);
9898
return operation.Execute(operationContext, channelBinding);
9999
}
100100
}
@@ -107,14 +107,14 @@ public async Task<BsonDocument> ExecuteAsync(OperationContext operationContext,
107107
using (var channel = await channelSource.GetChannelAsync(operationContext).ConfigureAwait(false))
108108
using (var channelBinding = new ChannelReadWriteBinding(channelSource.Server, channel, binding.Session.Fork()))
109109
{
110-
var operation = CreateOperation(channelBinding.Session, channel.ConnectionDescription);
110+
var operation = CreateOperation(operationContext, channelBinding.Session, channel.ConnectionDescription);
111111
return await operation.ExecuteAsync(operationContext, channelBinding).ConfigureAwait(false);
112112
}
113113
}
114114

115-
public BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription)
115+
public BsonDocument CreateCommand(OperationContext operationContext, ICoreSessionHandle session, ConnectionDescription connectionDescription)
116116
{
117-
var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern);
117+
var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(operationContext, session, _writeConcern);
118118
return new BsonDocument
119119
{
120120
{ "create", _viewName },
@@ -125,9 +125,9 @@ public BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescript
125125
};
126126
}
127127

128-
private WriteCommandOperation<BsonDocument> CreateOperation(ICoreSessionHandle session, ConnectionDescription connectionDescription)
128+
private WriteCommandOperation<BsonDocument> CreateOperation(OperationContext operationContext, ICoreSessionHandle session, ConnectionDescription connectionDescription)
129129
{
130-
var command = CreateCommand(session, connectionDescription);
130+
var command = CreateCommand(operationContext, session, connectionDescription);
131131
return new WriteCommandOperation<BsonDocument>(_databaseNamespace, command, BsonDocumentSerializer.Instance, _messageEncoderSettings);
132132
}
133133
}

src/MongoDB.Driver/Core/Operations/DropCollectionOperation.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2013-present MongoDB Inc.
1+
/* Copyright 2010-present 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.
@@ -104,7 +104,7 @@ public BsonDocument Execute(OperationContext operationContext, IWriteBinding bin
104104
using (var channel = channelSource.GetChannel(operationContext))
105105
using (var channelBinding = new ChannelReadWriteBinding(channelSource.Server, channel, binding.Session.Fork()))
106106
{
107-
var operation = CreateOperation(channelBinding.Session);
107+
var operation = CreateOperation(operationContext, channelBinding.Session);
108108
BsonDocument result;
109109
try
110110
{
@@ -131,7 +131,7 @@ public async Task<BsonDocument> ExecuteAsync(OperationContext operationContext,
131131
using (var channel = await channelSource.GetChannelAsync(operationContext).ConfigureAwait(false))
132132
using (var channelBinding = new ChannelReadWriteBinding(channelSource.Server, channel, binding.Session.Fork()))
133133
{
134-
var operation = CreateOperation(channelBinding.Session);
134+
var operation = CreateOperation(operationContext, channelBinding.Session);
135135
BsonDocument result;
136136
try
137137
{
@@ -149,9 +149,9 @@ public async Task<BsonDocument> ExecuteAsync(OperationContext operationContext,
149149
}
150150
}
151151

152-
internal BsonDocument CreateCommand(ICoreSessionHandle session)
152+
internal BsonDocument CreateCommand(OperationContext operationContext, ICoreSessionHandle session)
153153
{
154-
var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern);
154+
var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(operationContext, session, _writeConcern);
155155
return new BsonDocument
156156
{
157157
{ "drop", _collectionNamespace.CollectionName },
@@ -161,9 +161,9 @@ internal BsonDocument CreateCommand(ICoreSessionHandle session)
161161

162162
private IDisposable BeginOperation() => EventContext.BeginOperation("drop");
163163

164-
private WriteCommandOperation<BsonDocument> CreateOperation(ICoreSessionHandle session)
164+
private WriteCommandOperation<BsonDocument> CreateOperation(OperationContext operationContext, ICoreSessionHandle session)
165165
{
166-
var command = CreateCommand(session);
166+
var command = CreateCommand(operationContext, session);
167167
return new WriteCommandOperation<BsonDocument>(_collectionNamespace.DatabaseNamespace, command, BsonDocumentSerializer.Instance, _messageEncoderSettings);
168168
}
169169

src/MongoDB.Driver/Core/Operations/DropDatabaseOperation.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2013-present MongoDB Inc.
1+
/* Copyright 2010-present 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.
@@ -54,9 +54,9 @@ public WriteConcern WriteConcern
5454
set { _writeConcern = value; }
5555
}
5656

57-
public BsonDocument CreateCommand(ICoreSessionHandle session)
57+
public BsonDocument CreateCommand(OperationContext operationContext, ICoreSessionHandle session)
5858
{
59-
var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern);
59+
var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(operationContext, session, _writeConcern);
6060
return new BsonDocument
6161
{
6262
{ "dropDatabase", 1 },
@@ -73,7 +73,7 @@ public BsonDocument Execute(OperationContext operationContext, IWriteBinding bin
7373
using (var channel = channelSource.GetChannel(operationContext))
7474
using (var channelBinding = new ChannelReadWriteBinding(channelSource.Server, channel, binding.Session.Fork()))
7575
{
76-
var operation = CreateOperation(channelBinding.Session);
76+
var operation = CreateOperation(operationContext, channelBinding.Session);
7777
return operation.Execute(operationContext, channelBinding);
7878
}
7979
}
@@ -87,16 +87,16 @@ public async Task<BsonDocument> ExecuteAsync(OperationContext operationContext,
8787
using (var channel = await channelSource.GetChannelAsync(operationContext).ConfigureAwait(false))
8888
using (var channelBinding = new ChannelReadWriteBinding(channelSource.Server, channel, binding.Session.Fork()))
8989
{
90-
var operation = CreateOperation(channelBinding.Session);
90+
var operation = CreateOperation(operationContext, channelBinding.Session);
9191
return await operation.ExecuteAsync(operationContext, channelBinding).ConfigureAwait(false);
9292
}
9393
}
9494

9595
private IDisposable BeginOperation() => EventContext.BeginOperation("dropDatabase");
9696

97-
private WriteCommandOperation<BsonDocument> CreateOperation(ICoreSessionHandle session)
97+
private WriteCommandOperation<BsonDocument> CreateOperation(OperationContext operationContext, ICoreSessionHandle session)
9898
{
99-
var command = CreateCommand(session);
99+
var command = CreateCommand(operationContext, session);
100100
return new WriteCommandOperation<BsonDocument>(_databaseNamespace, command, BsonDocumentSerializer.Instance, _messageEncoderSettings);
101101
}
102102
}

src/MongoDB.Driver/Core/Operations/DropIndexOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public TimeSpan? MaxTime
8686

8787
public BsonDocument CreateCommand(OperationContext operationContext, ICoreSessionHandle session)
8888
{
89-
var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern);
89+
var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(operationContext, session, _writeConcern);
9090
return new BsonDocument
9191
{
9292
{ "dropIndexes", _collectionNamespace.CollectionName },

src/MongoDB.Driver/Core/Operations/EndTransactionOperation.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2018-present MongoDB Inc.
1+
/* Copyright 2010-present 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.
@@ -78,10 +78,16 @@ public virtual async Task<BsonDocument> ExecuteAsync(OperationContext operationC
7878

7979
protected virtual BsonDocument CreateCommand(OperationContext operationContext)
8080
{
81+
var writeConcern = _writeConcern;
82+
if (operationContext.IsRootContextTimeoutConfigured())
83+
{
84+
writeConcern = writeConcern.With(wTimeout: null);
85+
}
86+
8187
return new BsonDocument
8288
{
8389
{ CommandName, 1 },
84-
{ "writeConcern", () => _writeConcern.ToBsonDocument(), !_writeConcern.IsServerDefault },
90+
{ "writeConcern", () => _writeConcern.ToBsonDocument(), !writeConcern.IsServerDefault },
8591
{ "recoveryToken", _recoveryToken, _recoveryToken != null }
8692
};
8793
}

src/MongoDB.Driver/Core/Operations/FindOneAndDeleteOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public override BsonDocument CreateCommand(OperationContext operationContext, IC
8787
}
8888
}
8989

90-
var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, WriteConcern);
90+
var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(operationContext, session, WriteConcern);
9191
return new BsonDocument
9292
{
9393
{ "findAndModify", CollectionNamespace.CollectionName },

0 commit comments

Comments
 (0)