[CSHARP-118] DropCollection fails with "not master" when SlaveOK is specified in connection string Created: 01/Dec/10  Updated: 02/Apr/15  Resolved: 01/Dec/10

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

Type: Bug Priority: Major - P3
Reporter: J W Lee Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

N/A


Backwards Compatibility: Fully Compatible

 Description   

When SlaveOk is specified in the connection string, the DropCollection command fails as the driver uses the generic FindOneAs() function to send the command to mongodb. FindOneAs() will pick a slave as it thinks it is a read operation and SlaveOk has been set.

Steps to reproduce:

1) Create a mongodb replica set with at least one master and one slave

2) Use a connection string that specifies SlaveOk

3) Execute DropCollection on a database

4) "Not master" exception is thrown

Callstack (line numbers may be incorrect):
> MongoDB.Driver.dll!MongoDB.Driver.MongoDatabase.RunCommandAs<MongoDB.Bson.BsonDocument,MongoDB.Driver.CommandResult>(MongoDB.Bson.BsonDocument command) Line 343 C#
MongoDB.Driver.dll!MongoDB.Driver.MongoDatabase.RunCommand<MongoDB.Bson.BsonDocument>(MongoDB.Bson.BsonDocument command) Line 319 + 0x30 bytes C#
MongoDB.Driver.dll!MongoDB.Driver.MongoDatabase.DropCollection(string collectionName) Line 178 + 0x10 bytes C#

Root cause:
var result = CommandCollection.FindOneAs<TCommand, TCommandResult>(command); // this will cause a slave to be chosen as the connection



 Comments   
Comment by Robert Stam [ 01/Dec/10 ]

Fixed. For now all commands will be routed to the primary (in the future we might figure out which commands must be routed to the primary and which are OK to route to the secondaries).

Comment by Robert Stam [ 01/Dec/10 ]

You are right. Even though commands are technically queries many of them involve writes and should be routed to the primary.

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