[CSHARP-627] Remove FireAndForget and use magic values for "w" instead Created: 08/Nov/12  Updated: 20/Mar/14  Resolved: 08/Nov/12

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.7
Fix Version/s: 1.7

Type: Task Priority: Major - P3
Reporter: Robert Stam Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CSHARP-614 Change default WriteConcern behavior ... Closed
Backwards Compatibility: Major Change

 Description   

After we had already finished implementing support for FireAndForget it was decided that FireAndForget was not an acceptable keyword after all. Instead, we are to use certain magic values for "w" to imply whether write concern is enabled or not, as follows:

w meaning
w=0 implies write concern is disabled
w=1 implies write concern is enabled
w=n n>1 implies write concern is enabled and provides the "w" value for the getLastError command

At a low level these values result in the following getLastError commands being sent to the server:

w getLastError command
w=0 do not send a getLastError command
w=1 send { getLastError : 1 }
w=n n>1 send { getLastError : 1, w : n }

see: http://www.mongodb.org/display/DOCS/getLastError+Command

Interaction with getLastErrorDefaults

A replica set can be configured with getLastErrorDefaults to be used when the driver sends a bare getLastError command with no arguments.

See: http://docs.mongodb.org/manual/reference/replica-configuration/

You override getLastErrorDefaults by providing some arguments to the getLastError command. This is done in the C# driver by assigning values to one or more properties of the new WriteConcern object (or setting the equivalent options in the connection string).

For example, to override the getLastErrorDefaults with w=3 and journal=true you could either use this connection string:

var connectionString = "mongodb://localhost/?w=3;journal=true";

or this code:

var writeConcern = new WriteConcern { W = 3, Journal = true };
var clientSettings = new ClientSettings
{
    Server = new MongoServerAddress("localhost"),
    WriteConcern = writeConcern
};
var client = new MongoClient(clientSettings);

Either way results in the following getLastError command being sent to the server:

{ getLastError : 1, w : 3, journal : true }

A consequence of this design is that it is impossible to send the following getLastError command:

{ getLastError : 1, w : 1 }

because w=1 is a magic value that means to send a bare getLastError command instead.

The result of this limitation is that it is impossible to override getLastErrorDefaults with a value of

{ w : 1 }

.



 Comments   
Comment by auto [ 20/Nov/12 ]

Author:

{u'date': u'2012-11-15T03:24:49Z', u'email': u'robert@10gen.com', u'name': u'rstam'}

Message: CSHARP-627: Remove use of safe=true (still accepted on connection string for backward compatibility). Standardize on Acknowledged and Unacknowledged as the names of the WriteConcern constants for w=1 and w=0. Get unit tests to pass again.

Conflicts:
Driver/Core/MongoConnectionStringBuilder.cs
DriverUnitTests/Core/MongoConnectionStringBuilderTests.cs
MongoDB.Driver/GridFS/MongoGridFSSettings.cs
MongoDB.Driver/MongoUrlBuilder.cs
MongoDB.DriverUnitTests/Configuration.cs
MongoDB.DriverUnitTests/GridFS/MongoGridFSSettingsTests.cs
MongoDB.DriverUnitTests/Jira/CSharp346Tests.cs
MongoDB.DriverUnitTests/MongoClientSettingsTests.cs
MongoDB.DriverUnitTests/MongoCollectionSettingsTests.cs
MongoDB.DriverUnitTests/MongoDatabaseSettingsTests.cs
MongoDB.DriverUnitTests/MongoServerSettingsTests.cs
Branch: x2.0
https://github.com/mongodb/mongo-csharp-driver/commit/ac3a0c625688fb1364481153a72ff83441b9cab2

Comment by auto [ 20/Nov/12 ]

Author:

{u'date': u'2012-11-11T23:04:42Z', u'email': u'robert@10gen.com', u'name': u'rstam'}

Message: CSHARP-627: remove FireAndForget keyword.

Conflicts:
Driver/Core/MongoConnectionStringBuilder.cs
DriverUnitTests/Core/MongoConnectionStringBuilderTests.cs
MongoDB.Driver/MongoClientSettings.cs
MongoDB.Driver/MongoServerSettings.cs
MongoDB.Driver/MongoUrlBuilder.cs
MongoDB.DriverUnitTests/MongoClientSettingsTests.cs
MongoDB.DriverUnitTests/MongoServerSettingsTests.cs
Branch: x2.0
https://github.com/mongodb/mongo-csharp-driver/commit/66d17df2de312334c8c6c083084ef8a18d056ea5

Comment by auto [ 16/Nov/12 ]

Author:

{u'date': u'2012-11-15T03:24:49Z', u'email': u'robert@10gen.com', u'name': u'rstam'}

Message: CSHARP-627: Remove use of safe=true (still accepted on connection string for backward compatibility). Standardize on Acknowledged and Unacknowledged as the names of the WriteConcern constants for w=1 and w=0. Get unit tests to pass again.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/53c8c8e137ca9e6fbdc5ed28c22c88f936a0d089

Comment by auto [ 16/Nov/12 ]

Author:

{u'date': u'2012-11-11T23:04:42Z', u'email': u'robert@10gen.com', u'name': u'rstam'}

Message: CSHARP-627: remove FireAndForget keyword.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/45a070fc5bdad0135ba19cac91a322e5fb720698

Generated at Wed Feb 07 21:37:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.