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

Implement KeysCollectionCacheReaderAndUpdater

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 3.5.7
    • None
    • Sharding
    • None
    • Fully Compatible
    • Sharding 2017-05-08

    Description

      class KeysCollectionCacheReaderAndUpdater : public KeysCollectionCacheReader {
      public:
          StatusWith<KeysCollectionDocument> refresh(OperationContext* opCtx) override {
              // assumption: users never insert new keys
              coll = admin.system.keys;
       
              auto currentTime = getCurrentLogicalTime(opCtx);
       
              // readConcern level local
              cursor = coll.find({ purpose: _purpose, expiresAt: { $gt: currentTime }}).sort({ expiresAt: 1 });
              
              // all writes have { w: majority } write concern
       
              if (!cursor.hasNext()) {
                  currentKeyExpiresAt = currentTime + _keyRotationInterval;
                  coll.insert({ newKey using currentKeyExpirsAt });
              }
              else {
                  currentKeyExpiresAt = cursor.next()["expiresAt"];
              }
              
              // Create a new key in advance if we don't have a key on standby after the current one
              // expires.
              if (!cursor.hasNext()) {
                  reserveKeyExpiresAt = currentKeyExpiresAt + _keyRotationInterval;
                  coll.insert({ newKey using reserveKeyExpiresAt });
              }
              
              return KeysCollectionCacheReader::refresh(opCtx);
          }
          
      private:
          std::string _purpose;
      };
      

      Attachments

        Activity

          People

            randolph@mongodb.com Randolph Tan
            misha.tyulenev@mongodb.com Misha Tyulenev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: