Skip to content

Commit 7a2af91

Browse files
committed
CSHARP-2898: Deprecate oplogReplay find command option from CRUD spec.
1 parent f832ea9 commit 7a2af91

27 files changed

+366
-20
lines changed

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

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,41 @@ Task KillCursorsAsync(
374374
MessageEncoderSettings messageEncoderSettings,
375375
CancellationToken cancellationToken);
376376

377+
/// <summary>
378+
/// Executes a Query protocol.
379+
/// </summary>
380+
/// <typeparam name="TDocument">The type of the document.</typeparam>
381+
/// <param name="collectionNamespace">The collection namespace.</param>
382+
/// <param name="query">The query.</param>
383+
/// <param name="fields">The fields.</param>
384+
/// <param name="queryValidator">The query validator.</param>
385+
/// <param name="skip">The number of documents to skip.</param>
386+
/// <param name="batchSize">The size of a batch.</param>
387+
/// <param name="slaveOk">if set to <c>true</c> sets the SlaveOk bit to true in the query message sent to the server.</param>
388+
/// <param name="partialOk">if set to <c>true</c> the server is allowed to return partial results if any shards are unavailable.</param>
389+
/// <param name="noCursorTimeout">if set to <c>true</c> the server will not timeout the cursor.</param>
390+
/// <param name="tailableCursor">if set to <c>true</c> the query should return a tailable cursor.</param>
391+
/// <param name="awaitData">if set to <c>true</c> the server should await awhile before returning an empty batch for a tailable cursor.</param>
392+
/// <param name="serializer">The serializer.</param>
393+
/// <param name="messageEncoderSettings">The message encoder settings.</param>
394+
/// <param name="cancellationToken">The cancellation token.</param>
395+
/// <returns>The result of the Insert protocol.</returns>
396+
CursorBatch<TDocument> Query<TDocument>(
397+
CollectionNamespace collectionNamespace,
398+
BsonDocument query,
399+
BsonDocument fields,
400+
IElementNameValidator queryValidator,
401+
int skip,
402+
int batchSize,
403+
bool slaveOk,
404+
bool partialOk,
405+
bool noCursorTimeout,
406+
bool tailableCursor,
407+
bool awaitData,
408+
IBsonSerializer<TDocument> serializer,
409+
MessageEncoderSettings messageEncoderSettings,
410+
CancellationToken cancellationToken);
411+
377412
/// <summary>
378413
/// Executes a Query protocol.
379414
/// </summary>
@@ -394,6 +429,7 @@ Task KillCursorsAsync(
394429
/// <param name="messageEncoderSettings">The message encoder settings.</param>
395430
/// <param name="cancellationToken">The cancellation token.</param>
396431
/// <returns>The result of the Insert protocol.</returns>
432+
[Obsolete("Use an overload that does not have an oplogReplay parameter instead.")]
397433
CursorBatch<TDocument> Query<TDocument>(
398434
CollectionNamespace collectionNamespace,
399435
BsonDocument query,
@@ -404,7 +440,42 @@ CursorBatch<TDocument> Query<TDocument>(
404440
bool slaveOk,
405441
bool partialOk,
406442
bool noCursorTimeout,
407-
bool oplogReplay,
443+
bool oplogReplay, // obsolete: OplogReplay is ignored by server versions 4.4.0 and newer
444+
bool tailableCursor,
445+
bool awaitData,
446+
IBsonSerializer<TDocument> serializer,
447+
MessageEncoderSettings messageEncoderSettings,
448+
CancellationToken cancellationToken);
449+
450+
/// <summary>
451+
/// Executes a Query protocol.
452+
/// </summary>
453+
/// <typeparam name="TDocument">The type of the document.</typeparam>
454+
/// <param name="collectionNamespace">The collection namespace.</param>
455+
/// <param name="query">The query.</param>
456+
/// <param name="fields">The fields.</param>
457+
/// <param name="queryValidator">The query validator.</param>
458+
/// <param name="skip">The number of documents to skip.</param>
459+
/// <param name="batchSize">The size of a batch.</param>
460+
/// <param name="slaveOk">if set to <c>true</c> sets the SlaveOk bit to true in the query message sent to the server.</param>
461+
/// <param name="partialOk">if set to <c>true</c> the server is allowed to return partial results if any shards are unavailable.</param>
462+
/// <param name="noCursorTimeout">if set to <c>true</c> the server will not timeout the cursor.</param>
463+
/// <param name="tailableCursor">if set to <c>true</c> the query should return a tailable cursor.</param>
464+
/// <param name="awaitData">if set to <c>true</c> the server should await awhile before returning an empty batch for a tailable cursor.</param>
465+
/// <param name="serializer">The serializer.</param>
466+
/// <param name="messageEncoderSettings">The message encoder settings.</param>
467+
/// <param name="cancellationToken">The cancellation token.</param>
468+
/// <returns>A Task whose result is the result of the Insert protocol.</returns>
469+
Task<CursorBatch<TDocument>> QueryAsync<TDocument>(
470+
CollectionNamespace collectionNamespace,
471+
BsonDocument query,
472+
BsonDocument fields,
473+
IElementNameValidator queryValidator,
474+
int skip,
475+
int batchSize,
476+
bool slaveOk,
477+
bool partialOk,
478+
bool noCursorTimeout,
408479
bool tailableCursor,
409480
bool awaitData,
410481
IBsonSerializer<TDocument> serializer,
@@ -431,6 +502,7 @@ CursorBatch<TDocument> Query<TDocument>(
431502
/// <param name="messageEncoderSettings">The message encoder settings.</param>
432503
/// <param name="cancellationToken">The cancellation token.</param>
433504
/// <returns>A Task whose result is the result of the Insert protocol.</returns>
505+
[Obsolete("Use an overload that does not have an oplogReplay parameter instead.")]
434506
Task<CursorBatch<TDocument>> QueryAsync<TDocument>(
435507
CollectionNamespace collectionNamespace,
436508
BsonDocument query,
@@ -441,7 +513,7 @@ Task<CursorBatch<TDocument>> QueryAsync<TDocument>(
441513
bool slaveOk,
442514
bool partialOk,
443515
bool noCursorTimeout,
444-
bool oplogReplay,
516+
bool oplogReplay, // obsolete: OplogReplay is ignored by server versions 4.4.0 and newer
445517
bool tailableCursor,
446518
bool awaitData,
447519
IBsonSerializer<TDocument> serializer,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,9 @@ private BsonDocument BuildFindCommandFromQuery(QueryMessage message)
10091009
{ "noCursorTimeout", message.NoCursorTimeout, message.NoCursorTimeout },
10101010
{ "allowPartialResults", message.PartialOk, message.PartialOk },
10111011
{ "tailable", message.TailableCursor, message.TailableCursor },
1012+
#pragma warning disable 618
10121013
{ "oplogReplay", message.OplogReplay, message.OplogReplay }
1014+
#pragma warning restore 618
10131015
};
10141016

10151017
var query = message.Query;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ public bool? NoCursorTimeout
315315
/// <value>
316316
/// <c>true</c> if the OplogReplay bit will be set; otherwise, <c>false</c>.
317317
/// </value>
318+
[Obsolete("OplogReplay is ignored by server versions 4.4.0 and newer.")]
318319
public bool? OplogReplay
319320
{
320321
get { return _oplogReplay; }

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ public bool? NoCursorTimeout
278278
/// <value>
279279
/// <c>true</c> if the OplogReplay bit will be set; otherwise, <c>false</c>.
280280
/// </value>
281+
[Obsolete("OplogReplay is ignored by server versions 4.4.0 and newer.")]
281282
public bool? OplogReplay
282283
{
283284
get { return _oplogReplay; }
@@ -361,6 +362,7 @@ private CursorBatch<TDocument> ExecuteProtocol(IChannelHandle channel, BsonDocum
361362
{
362363
var firstBatchSize = QueryHelper.CalculateFirstBatchSize(_limit, _firstBatchSize ?? _batchSize);
363364

365+
#pragma warning disable 618
364366
return channel.Query<TDocument>(
365367
_collectionNamespace,
366368
wrappedQuery,
@@ -377,12 +379,14 @@ private CursorBatch<TDocument> ExecuteProtocol(IChannelHandle channel, BsonDocum
377379
_resultSerializer,
378380
_messageEncoderSettings,
379381
cancellationToken);
382+
#pragma warning restore 618
380383
}
381384

382385
private Task<CursorBatch<TDocument>> ExecuteProtocolAsync(IChannelHandle channel, BsonDocument wrappedQuery, bool slaveOk, CancellationToken cancellationToken)
383386
{
384387
var firstBatchSize = QueryHelper.CalculateFirstBatchSize(_limit, _firstBatchSize ?? _batchSize);
385388

389+
#pragma warning disable 618
386390
return channel.QueryAsync<TDocument>(
387391
_collectionNamespace,
388392
wrappedQuery,
@@ -399,6 +403,7 @@ private Task<CursorBatch<TDocument>> ExecuteProtocolAsync(IChannelHandle channel
399403
_resultSerializer,
400404
_messageEncoderSettings,
401405
cancellationToken);
406+
#pragma warning restore 618
402407
}
403408

404409
internal BsonDocument CreateWrappedQuery(ServerType serverType, ReadPreference readPreference)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ public bool? NoCursorTimeout
315315
/// <value>
316316
/// <c>true</c> if the OplogReplay bit will be set; otherwise, <c>false</c>.
317317
/// </value>
318+
[Obsolete("OplogReplay is ignored by server versions 4.4.0 and newer.")]
318319
public bool? OplogReplay
319320
{
320321
get { return _oplogReplay; }

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

Lines changed: 94 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,43 @@ public Task KillCursorsAsync(
810810
return ExecuteProtocolAsync(protocol, cancellationToken);
811811
}
812812

813+
public CursorBatch<TDocument> Query<TDocument>(
814+
CollectionNamespace collectionNamespace,
815+
BsonDocument query,
816+
BsonDocument fields,
817+
IElementNameValidator queryValidator,
818+
int skip,
819+
int batchSize,
820+
bool slaveOk,
821+
bool partialOk,
822+
bool noCursorTimeout,
823+
bool tailableCursor,
824+
bool awaitData,
825+
IBsonSerializer<TDocument> serializer,
826+
MessageEncoderSettings messageEncoderSettings,
827+
CancellationToken cancellationToken)
828+
{
829+
#pragma warning disable 618
830+
return Query(
831+
collectionNamespace,
832+
query,
833+
fields,
834+
queryValidator,
835+
skip,
836+
batchSize,
837+
slaveOk,
838+
partialOk,
839+
noCursorTimeout,
840+
oplogReplay: false,
841+
tailableCursor,
842+
awaitData,
843+
serializer,
844+
messageEncoderSettings,
845+
cancellationToken);
846+
#pragma warning restore 618
847+
}
848+
849+
[Obsolete("Use the newest overload instead.")]
813850
public CursorBatch<TDocument> Query<TDocument>(
814851
CollectionNamespace collectionNamespace,
815852
BsonDocument query,
@@ -828,6 +865,7 @@ public CursorBatch<TDocument> Query<TDocument>(
828865
CancellationToken cancellationToken)
829866
{
830867
slaveOk = GetEffectiveSlaveOk(slaveOk);
868+
#pragma warning disable 618
831869
var protocol = new QueryWireProtocol<TDocument>(
832870
collectionNamespace,
833871
query,
@@ -843,28 +881,67 @@ public CursorBatch<TDocument> Query<TDocument>(
843881
awaitData,
844882
serializer,
845883
messageEncoderSettings);
884+
#pragma warning restore 618
846885

847886
return ExecuteProtocol(protocol, cancellationToken);
848887
}
849888

850889
public Task<CursorBatch<TDocument>> QueryAsync<TDocument>(
851-
CollectionNamespace collectionNamespace,
852-
BsonDocument query,
853-
BsonDocument fields,
854-
IElementNameValidator queryValidator,
855-
int skip,
856-
int batchSize,
857-
bool slaveOk,
858-
bool partialOk,
859-
bool noCursorTimeout,
860-
bool oplogReplay,
861-
bool tailableCursor,
862-
bool awaitData,
863-
IBsonSerializer<TDocument> serializer,
864-
MessageEncoderSettings messageEncoderSettings,
865-
CancellationToken cancellationToken)
890+
CollectionNamespace collectionNamespace,
891+
BsonDocument query,
892+
BsonDocument fields,
893+
IElementNameValidator queryValidator,
894+
int skip,
895+
int batchSize,
896+
bool slaveOk,
897+
bool partialOk,
898+
bool noCursorTimeout,
899+
bool tailableCursor,
900+
bool awaitData,
901+
IBsonSerializer<TDocument> serializer,
902+
MessageEncoderSettings messageEncoderSettings,
903+
CancellationToken cancellationToken)
904+
{
905+
#pragma warning disable 618
906+
return QueryAsync(
907+
collectionNamespace,
908+
query,
909+
fields,
910+
queryValidator,
911+
skip,
912+
batchSize,
913+
slaveOk,
914+
partialOk,
915+
noCursorTimeout,
916+
oplogReplay: false,
917+
tailableCursor,
918+
awaitData,
919+
serializer,
920+
messageEncoderSettings,
921+
cancellationToken);
922+
#pragma warning restore 618
923+
}
924+
925+
[Obsolete("Use the newest overload instead.")]
926+
public Task<CursorBatch<TDocument>> QueryAsync<TDocument>(
927+
CollectionNamespace collectionNamespace,
928+
BsonDocument query,
929+
BsonDocument fields,
930+
IElementNameValidator queryValidator,
931+
int skip,
932+
int batchSize,
933+
bool slaveOk,
934+
bool partialOk,
935+
bool noCursorTimeout,
936+
bool oplogReplay,
937+
bool tailableCursor,
938+
bool awaitData,
939+
IBsonSerializer<TDocument> serializer,
940+
MessageEncoderSettings messageEncoderSettings,
941+
CancellationToken cancellationToken)
866942
{
867943
slaveOk = GetEffectiveSlaveOk(slaveOk);
944+
#pragma warning disable 618
868945
var protocol = new QueryWireProtocol<TDocument>(
869946
collectionNamespace,
870947
query,
@@ -880,6 +957,7 @@ public Task<CursorBatch<TDocument>> QueryAsync<TDocument>(
880957
awaitData,
881958
serializer,
882959
messageEncoderSettings);
960+
#pragma warning restore 618
883961

884962
return ExecuteProtocolAsync(protocol, cancellationToken);
885963
}
@@ -1002,7 +1080,7 @@ private async Task<TResult> ExecuteProtocolAsync<TResult>(IWireProtocol<TResult>
10021080
throw;
10031081
}
10041082
}
1005-
1083+
10061084
private async Task<TResult> ExecuteProtocolAsync<TResult>(IWireProtocol<TResult> protocol, ICoreSession session, CancellationToken cancellationToken)
10071085
{
10081086
try

src/MongoDB.Driver.Core/Core/WireProtocol/CommandUsingQueryMessageWireProtocol.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ private QueryMessage CreateMessage(ConnectionDescription connectionDescription,
8888
var wrappedCommand = WrapCommandForQueryMessage(commandWithPayloads, connectionDescription, out messageContainsSessionId);
8989
var slaveOk = _readPreference != null && _readPreference.ReadPreferenceMode != ReadPreferenceMode.Primary;
9090

91+
#pragma warning disable 618
9192
return new QueryMessage(
9293
RequestMessage.GetNextRequestId(),
9394
_databaseNamespace.CommandCollection,
@@ -106,6 +107,7 @@ private QueryMessage CreateMessage(ConnectionDescription connectionDescription,
106107
PostWriteAction = _postWriteAction,
107108
ResponseHandling = _responseHandling
108109
};
110+
#pragma warning restore 618
109111
}
110112

111113
public TCommandResult Execute(IConnection connection, CancellationToken cancellationToken)

src/MongoDB.Driver.Core/Core/WireProtocol/Messages/Encoders/BinaryEncoders/QueryMessageBinaryEncoder.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ private QueryFlags BuildQueryFlags(QueryMessage message)
4747
{
4848
flags |= QueryFlags.NoCursorTimeout;
4949
}
50+
#pragma warning disable 618
5051
if (message.OplogReplay)
5152
{
5253
flags |= QueryFlags.OplogReplay;
5354
}
55+
#pragma warning restore 618
5456
if (message.PartialOk)
5557
{
5658
flags |= QueryFlags.Partial;
@@ -107,9 +109,12 @@ internal QueryMessage ReadMessage<TDocument>(IBsonSerializer<TDocument> serializ
107109
var slaveOk = (flags & QueryFlags.SlaveOk) == QueryFlags.SlaveOk;
108110
var partialOk = (flags & QueryFlags.Partial) == QueryFlags.Partial;
109111
var noCursorTimeout = (flags & QueryFlags.NoCursorTimeout) == QueryFlags.NoCursorTimeout;
112+
#pragma warning disable 618
110113
var oplogReplay = (flags & QueryFlags.OplogReplay) == QueryFlags.OplogReplay;
114+
#pragma warning restore 618
111115
var tailableCursor = (flags & QueryFlags.TailableCursor) == QueryFlags.TailableCursor;
112116

117+
#pragma warning disable 618
113118
return new QueryMessage(
114119
requestId,
115120
CollectionNamespace.FromFullName(fullCollectionName),
@@ -124,6 +129,7 @@ internal QueryMessage ReadMessage<TDocument>(IBsonSerializer<TDocument> serializ
124129
oplogReplay,
125130
tailableCursor,
126131
awaitData);
132+
#pragma warning restore 618
127133
}
128134

129135
/// <summary>
@@ -297,6 +303,7 @@ private enum QueryFlags
297303
None = 0,
298304
TailableCursor = 2,
299305
SlaveOk = 4,
306+
[Obsolete("OplogReplay is ignored by server versions 4.4.0 and newer.")]
300307
OplogReplay = 8,
301308
NoCursorTimeout = 16,
302309
AwaitData = 32,

0 commit comments

Comments
 (0)