[SERVER-23341] Replace ShardRegistry::reload() method with swap() Created: 24/Mar/16  Updated: 06/Jun/16  Resolved: 18/May/16

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: None
Fix Version/s: 3.3.8

Type: Bug Priority: Major - P3
Reporter: Misha Tyulenev Assignee: Misha Tyulenev
Resolution: Done Votes: 0
Labels: ShardRegistry
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Sharding 14 (05/13/16), Sharding 15 (06/03/16)
Participants:

 Description   

ShardRegistry::reload() is called in many places and internally it performs a call to CatalogManager::getAllShards() and then rebuilds all internal maps.

To encapsulate the reload functionality:
1) Add ShardRegistryData class (ShardRegistry eventually will get stripped of its other responsibilities and so ShardRegistryData can become what is ShardRegistry now)

2) Provide a helper method (pseudocode)

void ShardRegistryData::swap(ShardRegistryData* other) {
        if (other->newerThan(this) {
        // swap
        }
}
 
shared_ptr<Shard> getShard(txn) {
    auto shard = grid.shardResistry()->getShard();
    if (!shard) {
           ShardRegistryData newShardRegistry(txn);
            grid.shardRegistry().data().swap(&newShardRegistry);
        }
        shard = grid.shardResistry()->getShard();   
   }
   return shard;
}

3) replace calls to ShardRegistry::getShard() with the new method

4) Add a class ShardRegistryUpdater
owned by ShardRegistry that will be used to update ShardRegistryData via swap:

    ShardRegistryData newShardRegistry(txn);
    grid.shardRegistry().data().swap(&newShardRegistry);

Protect the calls with a lock to serialize the reload order.

5) In place of reload() use

grid.shardRegistry()->shardRegistryUpdater()->reload();



 Comments   
Comment by Githook User [ 19/May/16 ]

Author:

{u'username': u'milkie', u'name': u'Eric Milkie', u'email': u'milkie@10gen.com'}

Message: SERVER-23341 fix pessimizing move
Branch: master
https://github.com/mongodb/mongo/commit/0c2dfa5d4bf8af738465579aba3259c28742d465

Comment by Githook User [ 18/May/16 ]

Author:

{u'username': u'mikety', u'name': u'Misha Tyulenev', u'email': u'misha@mongodb.com'}

Message: SERVER-23341 replace ShardRegistry::reload with swap
Branch: master
https://github.com/mongodb/mongo/commit/ed21c6d9ad3e0333732688b71011e69a0cb1d1dd

Comment by Randolph Tan [ 24/Mar/16 ]

We have to be careful on using which criteria to determine which one is newer as we currently don't have a good one right now. Note: it is not correct to use last visible opTime from the config server. Also see SERVER-22797.

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