diff options
author | Randolph Tan <randolph@10gen.com> | 2017-04-10 15:39:01 -0400 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2017-04-11 14:07:52 -0400 |
commit | 72e4f9167099b54732c3c537f0143e1044d7da4a (patch) | |
tree | fbae97e928e5f4f4ec69df8a3521f19e95677df5 | |
parent | 043ea2e5a24c3e3b819f4f57d96e72c10f34f602 (diff) | |
download | mongo-72e4f9167099b54732c3c537f0143e1044d7da4a.tar.gz |
SERVER-28435 Skeleton code for KeysCollectionCacheReader
-rw-r--r-- | src/mongo/db/SConscript | 12 | ||||
-rw-r--r-- | src/mongo/db/keys_collection_cache.h | 55 | ||||
-rw-r--r-- | src/mongo/db/keys_collection_cache_reader.cpp | 50 | ||||
-rw-r--r-- | src/mongo/db/keys_collection_cache_reader.h | 62 |
4 files changed, 179 insertions, 0 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index 3a8ee0e8168..667ef37e8db 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -1032,11 +1032,23 @@ env.Library( ) env.Library( + target='keys_collection_manager', + source=[ + 'keys_collection_cache_reader.cpp', + ], + LIBDEPS=[ + 'keys_collection_document', + 'logical_time', + ], +) + +env.Library( target='logical_clock', source=[ 'logical_clock.cpp', ], LIBDEPS=[ + 'keys_collection_manager', 'server_parameters', 'service_context', 'signed_logical_time', diff --git a/src/mongo/db/keys_collection_cache.h b/src/mongo/db/keys_collection_cache.h new file mode 100644 index 00000000000..2e7348e5687 --- /dev/null +++ b/src/mongo/db/keys_collection_cache.h @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2017 MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#pragma once + +#include "mongo/base/status_with.h" +#include "mongo/db/keys_collection_document.h" + +namespace mongo { + +class LogicalTime; +class OperationContext; + +class KeysCollectionCache { +public: + virtual ~KeysCollectionCache() = default; + + /** + * Refreshes cache and returns the latest key seen. + */ + virtual StatusWith<KeysCollectionDocument> refresh(OperationContext* opCtx) = 0; + + /** + * 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; +}; + +} // namespace mongo diff --git a/src/mongo/db/keys_collection_cache_reader.cpp b/src/mongo/db/keys_collection_cache_reader.cpp new file mode 100644 index 00000000000..5d90ba846e0 --- /dev/null +++ b/src/mongo/db/keys_collection_cache_reader.cpp @@ -0,0 +1,50 @@ +/** + * Copyright (C) 2017 MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/db/keys_collection_cache_reader.h" + +namespace mongo { + +KeysCollectionCacheReader::KeysCollectionCacheReader(std::string purpose) + : _purpose(std::move(purpose)) {} + +StatusWith<KeysCollectionDocument> KeysCollectionCacheReader::refresh(OperationContext* opCtx) { + // forThisTime = latest keyDoc.expiresAt or LogicalTime.MIN if _cache is empty + // read must be { level: 'majority' }. + // admin.system.keys.find({purpose: 'signLogicalTime', expiresAt: {$gt: <forThisTime>}); + return {ErrorCodes::InternalError, "Not yet implemented"}; +} + +StatusWith<KeysCollectionDocument> KeysCollectionCacheReader::getKey( + const LogicalTime& forThisTime) { + return {ErrorCodes::InternalError, "Not yet implemented"}; +} + +} // namespace mongo diff --git a/src/mongo/db/keys_collection_cache_reader.h b/src/mongo/db/keys_collection_cache_reader.h new file mode 100644 index 00000000000..001fb3e736f --- /dev/null +++ b/src/mongo/db/keys_collection_cache_reader.h @@ -0,0 +1,62 @@ +/** + * Copyright (C) 2017 MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#pragma once + +#include <map> + +#include "mongo/db/keys_collection_cache.h" +#include "mongo/stdx/mutex.h" + +namespace mongo { + +/** + * 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 KeysCollectionCacheReader : public KeysCollectionCache { +public: + KeysCollectionCacheReader(std::string purpose); + ~KeysCollectionCacheReader() = default; + + /** + * Check if there are new documents expiresAt > latestKeyDoc.expiresAt. + */ + StatusWith<KeysCollectionDocument> refresh(OperationContext* opCtx) override; + + StatusWith<KeysCollectionDocument> getKey(const LogicalTime& forThisTime) override; + +private: + const std::string _purpose; + + stdx::mutex _cacheMutex; + std::map<LogicalTime, KeysCollectionDocument> _cache; // expiresAt -> KeysDocument +}; + +} // namespace mongo |