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

Create a RAII type to temporarily override the read/write concern associated to an OperationContext

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Do
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Catalog and Routing

      When having to perform an operation through the DBDirectClient, server code needs often to apply read/write concern options that are specific to that single interaction.

      The fact that such parameters have to be specified as fields of the operation context makes nevertheless the code error prone, since the opCtx may already specify r/w concern values that need to be re-established once the interaction with the DBDirectClient is over.

      The usage of RAII objects is considered a convenient way to robustly set/clear parameter overrides: the codebase already contains examples of this pattern being applied for manipulating read and write concerns, but their scope could be further promoted by creating a more explicit type, like in the example below:

       

      class ScopedWriteConcern {  
      public:  
        ScopedWriteConcern(OperationContext* opCtx, WriteConcern wc) {  
          _originalWC = opCtx->getWriteConcern();  
          opCtx->setWriteConcern(wc);  
        }  
        ~ScopedWriteConcern() {  
          opCtx->setWriteConcern(_originalWC);  
        }  
      
      private:  
        WriteConcern _originalWC;  
      };   

            Assignee:
            Unassigned Unassigned
            Reporter:
            paolo.polato@mongodb.com Paolo Polato
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: