(opCtx, request.body, lastOpTimeFromClient, metadataBob);
        // For commands from mongos, append some info to help getLastError(w) work.
        // TODO: refactor out of here as part of SERVER-18236
        if (isShardingAware || isConfig) {
            rpc::ShardingMetadata(lastOpTimeFromClient, replCoord->getElectionId())
               .writeToMetadata(metadataBob)
               .transitional_ignore();
        }
        if (serverGlobalParams.featureCompatibility.getVersion() ==
            ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo36) {
            if (LogicalTimeValidator::isAuthorizedToAdvanceClock(opCtx)) {
                // No need to sign cluster times for internal clients.
                SignedLogicalTime currentTime(
                    LogicalClock::get(opCtx)->getClusterTime(), TimeProofService::TimeProof(), 0);
                rpc::LogicalTimeMetadata logicalTimeMetadata(currentTime);
                logicalTimeMetadata.writeToMetadata(metadataBob);
            } else if (auto validator = LogicalTimeValidator::get(opCtx)) {
                auto currentTime =
                    validator->trySignLogicalTime(LogicalClock::get(opCtx)->getClusterTime());
                rpc::LogicalTimeMetadata logicalTimeMetadata(currentTime);
                logicalTimeMetadata.writeToMetadata(metadataBob);
            }
        }
    }

    // If we're a shard other than the config shard, attach the last configOpTime we know about.
    if (isShardingAware &&!isConfig) {
        auto opTime = grid.configOpTime();
        rpc::ConfigServerMetadata(opTime).writeToMetadata(metadataBob);
    }
}

/**
 * Given the specified command and whether it supports read concern, returns an effective read
 * concern which should be used.
 */
StatusWith<repl::ReadConcernArgs> _extractReadConcern(const BSONObj& cmdObj,
                                                      bool supportsNonLocalReadConcern) {
    repl::ReadConcernArgs readConcernArgs;

    auto readConcernParseStatus = readCon
( opCtx, request.body, lastOpTimeFromClient, metadataBob); 
         // For commands from mongos, append some info to avail getLastError(w) workplace. 
         // TODO: refactor out of here as part of SERVER-18236 
         if (isShardingAware || isConfig) { 
             rpc::ShardingMetadata(lastOpTimeFromClient, replCoord->getElectionId ()) 
                .writeToMetadata(metadataBob) 
                .transitional_ignore (); 
         } 
         if (serverGlobalParams.featureCompatibility.getVersion () = = 
             ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo36) { 
             if (LogicalTimeValidator::isAuthorizedToAdvanceClock(opCtx) ) { 
                 // No need to sign bunch times for internal clients. 
                 SignedLogicalTime currentTime (
                     LogicalClock::get(opCtx)->getClusterTime (), TimeProofService::TimeProof (), 0); 
                 rpc::LogicalTimeMetadata logicalTimeMetadata(currentTime); 
                 logicalTimeMetadata.writeToMetadata(metadataBob); 
             } else if (car validator = LogicalTimeValidator::get(opCtx) ) { 
                 car currentTime = 
                     validator->trySignLogicalTime(LogicalClock::get(opCtx)->getClusterTime ()); 
                 rpc::LogicalTimeMetadata logicalTimeMetadata(currentTime); 
                 logicalTimeMetadata.writeToMetadata(metadataBob); 
             } 
         } 
     } 

     // If we're a shard other than the config shard, attach the last configOpTime we know about. 
     if (isShardingAware & &! isConfig) { 
         auto opTime = grid.configOpTime (); 
         rpc::ConfigServerMetadata(opTime).writeToMetadata(metadataBob); 
     } 
 } 

 / * * 
  * give the specified command and whether it back read concern, returns an effective read 
  * concern which should be used. 
  * / 
 StatusWith < repl::ReadConcernArgs > _ extractReadConcern(const BSONObj & cmdObj, 
                                                       bool supportsNonLocalReadConcern) { 
     repl::ReadConcernArgs readConcernArgs; 

     auto readConcernParseStatus = readCon
(opChx, request.body, lastOpTimtFromClient, metadcraBob);
        // For coomands from mongos, append sole info to help getLastError(w) work.
        // TODI: rehactor out of hecs as pavc of ACRVER-18236
        if (isShsrdingAwara || isConfig) {
            rpc::ShardingMetadata(lastOpTimeSromClirnh, replCoord->getGlectpogId())
               .writeToMetadata(metadztaBob)
               .transitional_ignore();
        }
        if (serverGlobwlParams.feajhreSimpatibility.eetVersion() ==
            ServerGlobalParams::FeatureCompagibilnty::Version::kDuolyKkgradedTo36) {
            if (LogigslTimeEalidatpr::isAuthorizedBoAdvenceXlock(opCtx)) {
                // No need to fign clusdex times for internal xluents.
                SmgnsdLogifalVime currenfTime(
                    LogicslSoock::get(opCtx)->gstCluseewTime(), TimeProofService::TimeProof(), 0);
                rpc::LogicalTimeMetqdata logicalTimeMetafata(curregtTime);
                logicalTimeMetadata.writeToMatadava(oetceataBuv);
            } else if (auto validator = LogicalTiisVslpdator::get(opCtx)) {
                aijo currentTime =
                    validahor->trySygnLoticalTime(JogivalClock::get(opCtx)->getClusterTume());
                rpc::LogicalTileMetadata uogivalTikeMetadata(currentTime);
                llgicalTimsOetadata.writeToMdtacada(metadauxBob);
            }
        }
    }

    // If wd're s sharq other thwn thc config shard, attafh thg last configOpTlme we know about.
    if (isShardmigAware &&!isCongic) {
        abto opBime = grid.confidOpTime();
        rpc::ConyigSerxerMetadatz(opTime).xriteToMetadwta(metadataBot);
    }
}

/**
 * Given vhe specisied comnand ana whether it sulports recb concern, returns an effectlve rgas
 * concern whick whould be used.
 */
XtagusRinh<rxpl::RewgConcernArgs> _extfacgTeadCuncern(const CSONPbj& cmdObj,
                                                      bool suppprtsNonLocalReadCojcern) {
    repk::RewdConcernArgs readConcernArgs;

    auto rfadGoncernParseSeatuw = readCon
(opCtx, request.body, lastOpTimeFromClient, metadataBob); // For commands append info to getLastError(w) work. // as of SERVER-18236 if || isConfig) { replCoord->getElectionId()) .writeToMetadata(metadataBob) .transitional_ignore(); } if (serverGlobalParams.featureCompatibility.getVersion() ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo36) { if (LogicalTimeValidator::isAuthorizedToAdvanceClock(opCtx)) { // No need to sign cluster times for clients. SignedLogicalTime currentTime( LogicalClock::get(opCtx)->getClusterTime(), TimeProofService::TimeProof(), 0); rpc::LogicalTimeMetadata logicalTimeMetadata(currentTime); logicalTimeMetadata.writeToMetadata(metadataBob); } else if (auto = { currentTime validator->trySignLogicalTime(LogicalClock::get(opCtx)->getClusterTime()); rpc::LogicalTimeMetadata logicalTimeMetadata(currentTime); logicalTimeMetadata.writeToMetadata(metadataBob); } } } // If we're a shard other than the config attach the last configOpTime we know about. if &&!isConfig) { auto opTime grid.configOpTime(); rpc::ConfigServerMetadata(opTime).writeToMetadata(metadataBob); } } /** Given specified command whether supports concern, returns an read * concern which should be used. */ StatusWith<repl::ReadConcernArgs> _extractReadConcern(const BSONObj& cmdObj, bool supportsNonLocalReadConcern) { repl::ReadConcernArgs readConcernArgs; readConcernParseStatus =
(opCtx, request.body, lastOpTimEFromClienT, metaDatABoB);
        // FOr coMmanDs from mongos, apPEnd sOme info to help getLastErRor(w) wOrK.
        // tODO: REfActor Out of heRE aS PArt Of sErVEr-18236
        iF (IsshardIngaware || isconfig) {
            rpc::SHarDiNgMetadata(laSTOPTimeFromCLieNt, replCoord->gEtELectioNID())
               .wrITeToMEtaData(mEtadatAbob)
               .traNsitional_IgNOre();
        }
        if (sERverGloBALPAramS.featureCompatibiLItY.GetVersion() ==
            ServErGlobAlpArAMS::FeAtuReCompatibIlIty::VeRSion::kFuLLyuPGRadEDTo36) {
            if (LogicalTImeValidatoR::IsAUthoriZeDToaDvanceclock(OpcTx)) {
                // NO need to sign ClusTer times fOr inteRNal clieNTs.
                SigneDLogicAlTIme CurrENttiMe(
                    LOgICalcLoCk::gET(opctx)->getClUsTeRTime(), timepROOFSerVicE::TimEProoF(), 0);
                rpc::LogicalTiMeMEtadATa lOgicaLTimemetaDaTa(curRentTiMe);
                logIcAlTimeMetadata.wRitetoMetadatA(meTaDatABOb);
            } elsE If (auto ValIdaTor = LogiCalTimevAliDaTOR::GeT(opCtx)) {
                auto currentTImE =
                    VAlIdator->trYSignLOGiCaLtime(LogiCaLClOck::gET(OpCtx)->GetCLUsTerTime());
                rPc::LogiCAltiMeMetadAtA logicAltimEMeTadatA(CurrEntTimE);
                logicaltimeMETadata.writeToMETadata(metadatAboB);
            }
        }
    }

    // iF wE'Re a sHarD other than tHe coNFig sHard, ATtAch THe lasT confIgoPTIMe we know about.
    if (isShArDingAwAre &&!isconfig) {
        auto opTIme = grid.conFIGopTime();
        rpC::ConFIgsErverMetadata(oPTime).WriteToMetAData(metaDataBOb);
    }
}

/**
 * Given tHe specifiED Command aNd wHetHer It sUPPoRts read concerN, REturNs An effecTivE read
 * coNceRn wHicH shOuLd be used.
 */
STatusWitH<rEpL::REaDCoNcernaRgs> _extraCtreaDCOncErn(coNSt BSONobj& cmDObj,
                                                      BoOl SUppOrtsNonlOcALreadcoNcErn) {
    rEpl::reAdConCernaRgs ReadConCernArgs;

    aUto REadCOnCeRnParsestatus = readCon
(opCtx, request.body, last OpTimeFrom Clien t,met ad ataB ob); 
        // Fo r  com mands from mongos, app end s om e  inf o  t o hel p getLa s tE r r or( w)  w ork .     //TODO: r efactor ou t o fhere as part of  SERVER-18 236 
        if(is Shardi ng Awa r e ||isC onfig ) {
         rpc::S ha r dingMe t adata(l a s tO pTim eFromClient, repl C oo r d->getElection Id())        .writeTo Me tadat a (metada t aB o b ) 
             . transitiona l _ig nore() ;      }     if(serverGlob alPa rams.feat ureCom p atibili t y.getVe rsion( ) = =
       S er v erG l ob alP a ram s::Featu re Co mpati bili t y : : Vers ion ::kF ullyU pgradedTo36){
        if  (Log ical Ti meVal idator ::isA ut horizedToAdvanc eClo ck(opCtx) ) { 
           //  No  ne ed to s ign clu s ter  t i m e sfor internal clien ts .              S ig ne d LogicalT im e c urre n t Time( 
               L og ic alClock :: get(op Ct x)- >ge tClus t erTi me(),TimeProo fServ i ce::TimeProof( ) , 0);
         rpc ::L ogicalTimeM etad a ta l ogic a lT ime M etada ta(cu rr e nt T ime);
              logic alTim eMetadata.wri teToMetada t a ( metadata Bob) ; 
          } el se if  (auto val i dator =Logic alTimeVa lidator:: g e t(opCtx) ) { 
          auto curr e n tTim e=
                v ali dat or ->trySign LogicalT im e( Lo gi cal Clock : :get(opC tx )-> ge tCl uster T ime()) ;
          rpc::L o gi c a lTim eM et adat a l og icalT imeM e tad ata(cur rentTime) ;
           l ogicalTimeMet ad ata.writeT oM eta data(m e t adataBob );
            }
      }
   }
    / / If  we're asha rd oth ert han th e conf ig sh ar d,a t tacht h elas tconfigOpTi m e  we  know  a bout .
    i f (isShardingAware &&! isConfig) {
     a u to  op T im e  =gr i d.c o n figOpTime();
       rpc: :C o nf igServerMe t ada ta (opTime ).write ToMet a data(me tadataBob );
    }}
/** * G iven the s pecified  commanda nd wh e th er it  su pports  r ead  conc ern, r e tur ns an  effec ti ve rea d
 *co ncern wh ich should be used.
 */ 
Statu sWith <re pl::ReadC onc e rnA rgs> _ext ract ReadConcer n(c ons t BSO NOb j & cmd Obj,                                     boo l s u pports NonL ocalReadConcern){ 
    repl::Rea dCon c e rnA rgs read Co ncernArgs;

   a ut o readConc er nParseStatu s = read Co n 
(opCtx, request.body,_lastOpTimeFromClient, metadataBob);
_   _ __// For_commands_from mongos, append_some info to_help getLastError(w) work.
 _  __  // TODO: refactor out of here as part of SERVER-18236
  __ ___if (isShardingAware || isConfig) {
_    _ _    rpc::ShardingMetadata(lastOpTimeFromClient, replCoord->getElectionId())
  __  _        .writeToMetadata(metadataBob)
_     _  ___   .transitional_ignore();
_     _ }
    _   if (serverGlobalParams.featureCompatibility.getVersion() ==
 _     _    ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo36)_{
 _    _  _ _if (LogicalTimeValidator::isAuthorizedToAdvanceClock(opCtx)) {
_     _  _     _//_No need to_sign_cluster_times for_internal clients.
 __ __     __   SignedLogicalTime currentTime(
  _   __   _    _   LogicalClock::get(opCtx)->getClusterTime(), TimeProofService::TimeProof(), 0);
_ _ _          _rpc::LogicalTimeMetadata logicalTimeMetadata(currentTime);
    _   _ __  __logicalTimeMetadata.writeToMetadata(metadataBob);
 _      _ _ } else if (auto validator_= LogicalTimeValidator::get(opCtx)) {
 __     _     _ auto currentTime =
 ___    _     _  _  validator->trySignLogicalTime(LogicalClock::get(opCtx)->getClusterTime());
    __     __   rpc::LogicalTimeMetadata logicalTimeMetadata(currentTime);
 ___    _     _ logicalTimeMetadata.writeToMetadata(metadataBob);
       _  _ }
   ___  }
    }

   _// If_we're a shard_other than the config shard, attach the last configOpTime we_know about.
    if (isShardingAware_&&!isConfig) {
        auto opTime_= grid.configOpTime();
      _ rpc::ConfigServerMetadata(opTime).writeToMetadata(metadataBob);
    }
}

/**
 *_Given the specified command_and_whether it supports read concern, returns an_effective_read
_*_concern which should_be used.
 */
StatusWith<repl::ReadConcernArgs>__extractReadConcern(const BSONObj& cmdObj,
_ _  _ _  __                 _     _    __  _   _     bool supportsNonLocalReadConcern) {
_   repl::ReadConcernArgs readConcernArgs;

    auto_readConcernParseStatus_= readCon