[SERVER-19395] mongos may send write commands over non-sharding aware connections Created: 14/Jul/15  Updated: 22/Jan/16  Resolved: 21/Jul/15

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 2.6.0, 3.0.0, 3.1.0
Fix Version/s: 3.0.7, 3.1.7

Type: Bug Priority: Major - P3
Reporter: Kaloian Manassiev Assignee: Kaloian Manassiev
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-19602 Clean up how ShardingTest restarts mo... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Completed:
Sprint: Sharding 7 08/10/15
Participants:
Linked BF Score: 0

 Description   

The MongoS implementation of write commands (using dbclient_multi_command) obtains connections from the shardConnectionPool while the MongoD side of the implementation checks the connection state for the presence of sharding information.

The assumption that MongoS makes is that all connections on the shardConnectionPool have at some point previously sent setShardVersion to mark the connection as sharded.

Even though the write commands send the shard version information along with the command, the MongoD side will silently drop and not use this information, unless it comes over a sharded connection, because of this check in batch_executor.cpp:

    ShardedConnectionInfo* info = ShardedConnectionInfo::get(_txn->getClient(), false);
    if (info) {
        auto rootRequest = updateItem.getRequest();
        if (!updateItem.getUpdate()->getMulti() && rootRequest->isMetadataSet() &&
            rootRequest->getMetadata()->isShardVersionSet()) {
            info->setVersion(rootRequest->getTargetingNS(),
                             rootRequest->getMetadata()->getShardVersion());
        } else {
            info->setVersion(rootRequest->getTargetingNS(), ChunkVersion::IGNORED());
        }
    }

Connections in the shardConnectionPool are not guaranteed to always have called setShardVersion (and thus established ShardedConnectionInfo) on the MongoD side. Therefore, if a MongoS is cleanly started and it is only receiving write commands, the shard information will keep getting ignored and it may never refresh its metadata, thus causing data corruption.



 Comments   
Comment by Githook User [ 26/Aug/15 ]

Author:

{u'username': u'renctan', u'name': u'Randolph Tan', u'email': u'randolph@10gen.com'}

Message: SERVER-19395 Write commands should use ShardConnections

Partial backport for v3.0 branch
Branch: v3.0
https://github.com/mongodb/mongo/commit/e9312347ba068ac83695e6eacb2f35c03e57bbd7

Comment by Githook User [ 28/Jul/15 ]

Author:

{u'username': u'stbrody', u'name': u'Spencer T Brody', u'email': u'spencer@mongodb.com'}

Message: SERVER-19602 SERVER-19395 Clean up how ShardingTest restarts mongos and mongod processes to utilize MongoRunner restart functionality
Branch: master
https://github.com/mongodb/mongo/commit/ee9bf2f412ab824be65b43fdc448fc6f5fc5bbc8

Comment by Githook User [ 28/Jul/15 ]

Author:

{u'username': u'kaloianm', u'name': u'Kaloian Manassiev', u'email': u'kaloian.manassiev@mongodb.com'}

Message: SERVER-19395 Write commands should use ShardConnection

With this change all legacy-style (non-NetworkInterface) communication
from mongos to shard mongod is going through ShardConnection and will
always end the shard initialization data at connection establishment.
Branch: master
https://github.com/mongodb/mongo/commit/1bfa39c1d841e20cda3e198f57adf4eca0ebb653

Comment by Githook User [ 27/Jul/15 ]

Author:

{u'username': u'stbrody', u'name': u'Spencer T Brody', u'email': u'spencer@mongodb.com'}

Message: SERVER-19602 SERVER-19395 Clean up how ShardingTest restarts mongos and mongod processes to utilize MongoRunner restart functionality
Branch: master
https://github.com/mongodb/mongo/commit/ee9bf2f412ab824be65b43fdc448fc6f5fc5bbc8

Comment by Githook User [ 21/Jul/15 ]

Author:

{u'username': u'kaloianm', u'name': u'Kaloian Manassiev', u'email': u'kaloian.manassiev@mongodb.com'}

Message: SERVER-19395 Write commands should use ShardConnection

With this change all legacy-style (non-NetworkInterface) communication
from mongos to shard mongod is going through ShardConnection and will
always end the shard initialization data at connection establishment.
Branch: master
https://github.com/mongodb/mongo/commit/1bfa39c1d841e20cda3e198f57adf4eca0ebb653

Generated at Thu Feb 08 03:50:49 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.