Primary does not need to do a complete chunk metadata read in ShardServerCatalogCacheLoader

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 3.5.12
    • Affects Version/s: None
    • Component/s: Sharding
    • None
    • Fully Compatible
    • Sharding 2017-08-21
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      Once indexes are in, the primary can safely do incomplete metadata reads. Put this helper function in

      /**
       * Attempt to read the collection and chunk metadata. May not read all the updates if the metadata
       * for the collection is being updated concurrently.
       *
       * TODO: this is unsafe without an index on the relevant chunks collection. Will be used when
       * SERVER-27714 is done.
       *
       * If the epoch changes while reading the chunks, returns an empty object.
       */
      StatusWith<CollectionAndChangedChunks> getImcompletePersistediMetadataSinceVersion(
          OperationContext* opCtx,
          const NamespaceString& nss,
          ChunkVersion version) {
      
          try {
              CollectionAndChangedChunks collAndChunks = getPersistedMetadataSinceVersion(
                  opCtx,
                  nss,
                  version,
                  false);
              if (collAndChunks.changedChunks.empty()) {
                  // Found a collections entry, but the chunks are being updated.
                  return CollectionAndChangedChunks();
              }
      
              // Make sure the collections entry epoch has not changed since we began reading chunks --
              // an epoch change between reading the collections entry and reading the chunk metadata
              // would invalidate the chunks.
      
              auto afterShardCollectionsEntry = uassertStatusOK(readShardCollectionsEntry(opCtx, nss));
              if (shardCollectionEntry.getEpoch() != afterShardCollectionsEntry.getEpoch()) {
                  // The collection was dropped and recreated since we began. Return empty results.
                  return CollectionAndChangedChunks();
              }
      
              return collAndChunks;
          } catch (const DBException& ex) {
              Status status = ex.toStatus();
              if (status == ErrorCodes::NamespaceNotFound) {
                  return CollectionAndChangedChunks();
              }
              return Status(
                      ErrorCodes::OperationFailed,
                      str::stream() << "Failed to reload local metadata due to '"
                                    << status.toString()
                                    << "'.");
          }
      }
      

            Assignee:
            Dianna Hohensee (Inactive)
            Reporter:
            Dianna Hohensee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: