Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-23341

Replace ShardRegistry::reload() method with swap()

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.3.8
    • Affects Version/s: None
    • Component/s: Sharding
    • Fully Compatible
    • ALL
    • Sharding 14 (05/13/16), Sharding 15 (06/03/16)
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      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();
      

            Assignee:
            misha.tyulenev@mongodb.com Misha Tyulenev (Inactive)
            Reporter:
            misha.tyulenev@mongodb.com Misha Tyulenev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: