summaryrefslogtreecommitdiff
path: root/src/mongo/db/keys_collection_cache.h
diff options
context:
space:
mode:
authorBlake Oler <blake.oler@mongodb.com>2018-01-30 18:00:27 -0500
committerBlake Oler <blake.oler@mongodb.com>2018-01-31 12:17:18 -0500
commit0fb3ff2ee1fc5305b9523cdeaaae9c7279f1c117 (patch)
tree688b5a332893fe28e2a8486cd36de2e912180a6d /src/mongo/db/keys_collection_cache.h
parent3c34eda8d8a38b982a1659b919e9f4b5971ba512 (diff)
downloadmongo-0fb3ff2ee1fc5305b9523cdeaaae9c7279f1c117.tar.gz
SERVER-28887 Cleanup KeysCollectionCacheReader/AndUpdater
Diffstat (limited to 'src/mongo/db/keys_collection_cache.h')
-rw-r--r--src/mongo/db/keys_collection_cache.h40
1 files changed, 26 insertions, 14 deletions
diff --git a/src/mongo/db/keys_collection_cache.h b/src/mongo/db/keys_collection_cache.h
index 1a7f0a4d1e0..091e1906fdc 100644
--- a/src/mongo/db/keys_collection_cache.h
+++ b/src/mongo/db/keys_collection_cache.h
@@ -28,35 +28,47 @@
#pragma once
+#include <map>
+
#include "mongo/base/status_with.h"
#include "mongo/db/keys_collection_document.h"
+#include "mongo/db/operation_context.h"
+#include "mongo/stdx/mutex.h"
namespace mongo {
-class LogicalTime;
-class OperationContext;
+class KeysCollectionClient;
+/**
+ * Keeps a local cache of the keys with the ability to refresh.
+ *
+ * Note: This assumes that user does not manually update the keys collection.
+ */
class KeysCollectionCache {
public:
- virtual ~KeysCollectionCache() = default;
+ KeysCollectionCache(std::string purpose, KeysCollectionClient* client);
+ ~KeysCollectionCache() = default;
/**
- * Refreshes cache and returns the latest key seen.
+ * Check if there are new documents expiresAt > latestKeyDoc.expiresAt.
*/
- virtual StatusWith<KeysCollectionDocument> refresh(OperationContext* opCtx) = 0;
+ StatusWith<KeysCollectionDocument> refresh(OperationContext* opCtx);
- /**
- * Returns the key in the cache that has the smallest expiresAt value that is also greater than
- * the forThisTime argument.
- */
- virtual StatusWith<KeysCollectionDocument> getKey(const LogicalTime& forThisTime) = 0;
+ StatusWith<KeysCollectionDocument> getKey(const LogicalTime& forThisTime);
+ StatusWith<KeysCollectionDocument> getKeyById(long long keyId, const LogicalTime& forThisTime);
/**
- * Returns the key in the cache that matches the keyId and expiresAt value to be no less than
- * the forThisTime argument.
+ * Resets the cache of keys if the client doesnt allow readConcern level:majority reads.
+ * This method intended to be called on the rollback of the node.
*/
- virtual StatusWith<KeysCollectionDocument> getKeyById(long long keyId,
- const LogicalTime& forThisTime) = 0;
+ void resetCache();
+
+private:
+ const std::string _purpose;
+ KeysCollectionClient* const _client;
+
+ stdx::mutex _cacheMutex;
+ std::map<LogicalTime, KeysCollectionDocument> _cache; // expiresAt -> KeysDocument
};
} // namespace mongo